Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

veho

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

veho - npm Package Compare versions

Comparing version 0.1.19 to 0.1.20

580

dist/index.cjs.js

@@ -5,18 +5,2 @@ 'use strict';

// Create an object type VehoError
class VehoError extends Error {
constructor(message) {
super();
this.name = 'VehoError';
this.message = message;
} // Make the exception convert to a pretty string when used as
// a string (e.g. by the error console)
toString() {
return this.name + ': "' + this.message + '"';
}
}
const oc = Object.prototype.toString;

@@ -88,61 +72,113 @@ /**

/**
* Static class containing methods to create 2d-array.
* Static class containing methods create 1d-array.
*/
class Mat {
class Vec {
/**
*
* @param {number} height
* @param {number} width
* @param {function} ject
* @returns {number[][]}
* Create an array.
* @param {number} size Integer starts at zero.
* @param {function|*} [ject] Defines the how index i decides value(i).
* @returns {number[]} The
*/
static ini(height, width, ject) {
return Array(height).fill(null).map((_, x) => Array(width).fill(null).map((_, y) => ject(x, y)));
static ini(size, ject) {
if (typeof ject === 'function') {
if (size <= 128) {
let arr = [];
for (let i = 0; i < size; i++) arr[i] = ject(i);
return arr;
} else {
return Array(size).fill(null).map((_, i) => ject(i));
}
} else {
if (size <= 128) {
let arr = [];
for (let i = 0; i < size; i++) arr[i] = ject;
return arr;
} else {
return Array(size).fill(ject);
}
}
}
static isMat(mx) {
return Array.isArray(mx) && mx.length ? Array.isArray(mx[0]) : false;
static isEmpty(arr) {
return !arr || !arr.length;
}
static is(mx) {
return !!mx && mx.length ? !!mx[0] : false;
static clone(arr) {
return cloneArray(arr);
}
static clone(mx) {
return mx.map(cloneArray);
static indexes(arr) {
return arr.map((_, i) => i);
}
/**
*
* @param {*[][]} mx
* @return {number[]}
* Returns an array built from the elements of a given set of arrays.
* Each element of the returned array is determined by elements from every one of the array-set with the same index.
* The returned array has length of the first array in the array set.
* @param {function} zipper The function {x(i)|x(i) ∈ array(i), i ∈ 0,1...n-1, n=arraySet.size} -> y(i), where y
* is the returned array
* @param {*[][]} arraySet The array-set to determine the returned array.
* @returns {*[]|undefined} array
*/
static columnIndexes(mx) {
if (!!mx && mx.length) {
const arr = mx[0];
return !!arr ? arr.map((_, i) => i) : [];
static multiZip(zipper, ...arraySet) {
const firstArray = arraySet[0];
if (!!firstArray) {
const [len, cnt] = [firstArray.length, arraySet.length];
const result = Array(len);
for (let i = 0; i < len; i++) {
const params = Array(cnt);
for (let j = 0; j < cnt; j++) {
params[j] = arraySet[j][i];
}
result[i] = zipper(params);
}
return result;
} else {
return undefined;
}
return [];
}
/**
* Transpose a 2d-array.
* @param {*[][]} mx
* @returns {*[][]}
*
* @param {number} size
* @param {*} initial
* @param {function} progress
* @returns {*[]}
*/
static transpose(mx) {
return Mat.columnIndexes(mx).map(c => mx.map(r => r[c]));
}
static progression(size, initial, progress) {
switch (size) {
case 0:
return [];
static column(mx, index) {
return mx.map(r => r[index]);
case 1:
return [initial];
default:
const arr = new Array(size);
arr[0] = initial;
for (let i = 1; i < size; i++) {
arr[i] = progress(arr[i - 1]);
}
return arr;
}
}
/**
* Iterate through elements on each (x of rows,y of columns) coordinate of a 2d-array.
* @param {*[][]} mx
* @param elementJect
* Create an arithmetic progression
* @param {number} size
* @param {number|string} initial
* @param {number} delta
* @returns {*[]}

@@ -152,9 +188,22 @@ */

static veho(mx, elementJect) {
return mx.map(row => row.map(elementJect));
static arithmetic(size, initial, delta) {
return Vec.progression(size, initial, previous => previous + delta);
}
/**
* Iterate through the columns of a 2d-array.
* @param {*[][]} mx
* @param {function(*[]):[]} columnJect
* Create a geometric progression
* @param {number} size
* @param {number} initial
* @param {number} ratio
* @returns {*[]}}
*/
static geometric(size, initial, ratio) {
return Vec.progression(size, initial, previous => previous * ratio);
}
/**
*
* @param {*[]} ar1
* @param {*[]} ar2
* @param {function} product
* @returns {*[]}

@@ -164,40 +213,90 @@ */

static vehoCol(mx, columnJect) {
return Mat.transpose(mx).map(columnJect);
static decartes(ar1, ar2, product) {
let arr = [];
for (let x of ar1) {
arr.push(...ar2.map(y => product(x, y)));
}
return arr;
}
static randSample(arr) {
// const len = arr.length
// switch (len) {
// case 0:
// return undefined
// case 1:
// return arr[0]
// default:
// const idx = Zu.rand(0, len)
// return arr[idx]
// }
return arr[~~(Math.random() * arr.length)];
}
static take(arr, len) {
return arr.slice(0, len);
}
} // Array.prototype.zip = function (another, zipper) {
// Create an object type VehoError
class VehoError extends Error {
constructor(message) {
super();
this.name = 'VehoError';
this.message = message;
} // Make the exception convert to a pretty string when used as
// a string (e.g. by the error console)
toString() {
return this.name + ': "' + this.message + '"';
}
}
// let mtx = [];
// for (let j = 0; j < this[0].length; j++) {
// mtx[j] = [];
// for (let i = 0; i < this.length; i++) {
// mtx[j][i] = this[i][j]
// }
// }
// array[0].map((col, i) => array.map(row => row[i]));
// return mtx
// };
class Jso {
/**
* Create an Object from separate key-array and value-array.
* Create a object from separate key-array and value-array.
* @param {*[]} keys Array of keys.
* @param {*[]} values Array of values. The value-array and the key-array need to be equal in size.
* @returns {Map<*, *>}
* @returns {Object<*, *>}
*/
static ini(keys, values) {
const o = {};
let i, k;
for (let [i, k] of keys.entries()) {
o[k] = values[i];
}
for ([i, k] of keys.entries()) o[k] = values[i];
return o;
}
/**
*
* @param {Object<string,*>} jso
* @return {[string, *][]}
*/
static clone(o) {
return cloneObject(o);
static toEntries(jso) {
return Object.entries(jso);
}
/**
* Shallow.
* @param {string[]} arr
* @param {*} val
* @return {Object<string,*>}
*/
static fromArr(arr, val) {
let o = {};
for (let k of arr) o[k] = val;
return o;
}
/**
* Shallow.
* @param {...[*,*]} entries - An array of key-value pair, [key, value]

@@ -211,5 +310,3 @@ * @returns {Object|Object<string,*>}

for (let [k, v] of entries) {
o[k] = v;
}
for (let [k, v] of entries) o[k] = v;

@@ -253,17 +350,10 @@ return o;

/**
* Shallow.
* @param {string[]} arr
* @param {*} val
* @return {Object<string,*>}
*
* @param {Object<string,*>} jso
* @return {Map<string, *>}
*/
static fromArr(arr, val) {
let o = {};
for (let k of arr) {
o[k] = val;
}
return o;
static toMap(jso) {
return new Map(Object.entries(jso));
}

@@ -286,23 +376,7 @@ /**

}
/**
*
* @param {Object<string,*>} jso
* @return {Map<string, *>}
*/
static toMap(jso) {
return new Map(Object.entries(jso));
static clone(jso) {
return cloneObject(jso);
}
/**
*
* @param {Object<string,*>} jso
* @return {[string, *][]}
*/
static toEntries(jso) {
return Object.entries(jso);
}
}

@@ -333,15 +407,18 @@ /**

static tableToSamples(samples, banner) {
if (Mat.isMat(samples)) {
if (!!samples && samples.constructor === Array) {
const firstRow = samples[0];
let len = Math.min(firstRow.length, banner.length);
return samples.map(row => {
let o = {};
for (let i = 0; i < len; i++) {
o[banner[i]] = row[i];
}
if (!!firstRow && firstRow.constructor === Array) {
let [i, len] = [0, Math.min(firstRow.length, banner.length)];
return samples.map(row => {
let o = {};
return o;
});
} else throw new VehoError('The input \'samples\' is not a 2d-array');
for (i = 0; i < len; i++) {
o[banner[i]] = row[i];
}
return o;
});
} else return null;
} else throw new VehoError('The input \'samples\' is not an Array');
}

@@ -358,3 +435,3 @@ /**

static samplesToTable(rows, bannerLabel = 'head', samplesLabel = 'rows') {
if (!!rows && Array.isArray(rows)) {
if (!!rows && rows.constructor === Array) {
const firstRow = rows[0];

@@ -407,137 +484,169 @@

/**
* Static class containing methods create 1d-array.
* Transform between Json table and Json of samples.
* A Json table is formed like :
* {
* head:[a, b, ...],
* rows:*[][]
* }.
* A Json of samples is formed like :
* [
* {a:*, b:*, ...},
* {a:*, b:*, ...},
* ...
* ]
*/
class Vec {
class Samples {
/**
* Create an array.
* @param {number} size Integer starts at zero.
* @param {function|*} [ject] Defines the how index i decides value(i).
* @returns {number[]} The
*
* @param {*[]} head
* @param {*[][]} rows
* @param {*[]} [fields]
* @return {Object[]}
*/
static ini(size, ject) {
if (typeof ject === 'function') {
if (size <= 128) {
let arr = [];
static fromTable({
head,
rows
}, fields) {
if (!head || !Array.isArray(head)) throw new VehoError('The input \'head\' is not valid.');
if (!rows || !Array.isArray(rows)) throw new VehoError('The input \'rows\' is not valid.');
const [row] = rows;
if (!row || !Array.isArray(row)) return null;
let k_i = fields && Array.isArray(fields) ? fields.map(field => [field, head.indexOf(field)]) : [...head.entries()].map(([k, v]) => [v, k]);
return rows.map(row => {
let o = {};
for (let i = 0; i < size; i++) arr[i] = ject(i);
for (let [k, i] of k_i) o[k] = row[i];
return arr;
} else {
return Array(size).fill(null).map((_, i) => ject(i));
}
} else {
if (size <= 128) {
let arr = [];
return o;
});
}
/**
*
* @param {Object[]} samples
* @param {string[]} [fields]
* @param {{head:string,rows:string}} [label]
* @returns {null|{head:*[],rows:*[][]}|Object}
*/
for (let i = 0; i < size; i++) arr[i] = ject;
return arr;
} else {
return Array(size).fill(ject);
}
static toTable(samples, {
fields = null,
label = {
head: 'head',
rows: 'rows'
}
} = {}) {
if (!samples || !Array.isArray(samples)) throw new VehoError('The input \'rows\' is not an Array');
const [sample] = samples;
if (!sample || !(sample instanceof Object)) return null;
const {
head,
rows
} = label;
const [banner, picker] = fields ? [fields, row => banner.map(x => row[x])] : [Object.keys(sample), Object.values];
const rowSet = samples.map(picker);
return Jso.of([head, banner], [rows, rowSet]);
}
/**
* Transform json of samples to matrix(2d-array).
* A Json of samples is formed like :
* [
* {a:*, b:*, ...},
* {a:*, b:*, ...},
* ...
* ]
* A matrix(2d-array) is formed like :
* [
* [*, *, ...],
* [*, *, ...],
* ...
* ]
* @param {Object[]} samples Table in json-array form: [{c1:*,c2:*,..},{c1:*,c2:*,..},..]
* @returns {*[][]} Table content in 2d-array, excluding the input table head.
*/
static isEmpty(arr) {
return !arr || !arr.length;
}
static clone(arr) {
return cloneArray(arr);
static toMatrix(samples) {
return samples.map(Object.values);
}
static indexes(arr) {
return arr.map((_, i) => i);
static fromCrosTab({
matrix,
side,
banner
}) {
const sampleList = matrix.map(row => Jso.ini(banner, row));
const result = Jso.ini(side, sampleList);
return result;
}
/**
* Returns an array built from the elements of a given set of arrays.
* Each element of the returned array is determined by elements from every one of the array-set with the same index.
* The returned array has length of the first array in the array set.
* @param {function} zipper The function {x(i)|x(i) ∈ array(i), i ∈ 0,1...n-1, n=arraySet.size} -> y(i), where y
* is the returned array
* @param {*[][]} arraySet The array-set to determine the returned array.
* @returns {*[]|undefined} array
*/
}
static multiZip(zipper, ...arraySet) {
const firstArray = arraySet[0];
/**
* Static class containing methods to create 2d-array.
*/
if (!!firstArray) {
const [len, cnt] = [firstArray.length, arraySet.length];
const result = Array(len);
class Mat {
/**
*
* @param {number} height
* @param {number} width
* @param {function} ject
* @returns {number[][]}
*/
static ini(height, width, ject) {
return Array(height).fill(null).map((_, x) => Array(width).fill(null).map((_, y) => ject(x, y)));
}
for (let i = 0; i < len; i++) {
const params = Array(cnt);
static isMat(mx) {
return Array.isArray(mx) && mx.length ? Array.isArray(mx[0]) : false;
}
for (let j = 0; j < cnt; j++) {
params[j] = arraySet[j][i];
}
static is(mx) {
return !!mx && mx.length ? !!mx[0] : false;
}
result[i] = zipper(params);
}
return result;
} else {
return undefined;
}
static clone(mx) {
return mx.map(cloneArray);
}
/**
*
* @param {number} size
* @param {*} initial
* @param {function} progress
* @returns {*[]}
* @param {*[][]} mx
* @return {number[]}
*/
static progression(size, initial, progress) {
switch (size) {
case 0:
return [];
case 1:
return [initial];
default:
const arr = new Array(size);
arr[0] = initial;
for (let i = 1; i < size; i++) {
arr[i] = progress(arr[i - 1]);
}
return arr;
}
static columnIndexes(mx) {
return !!mx && mx.length ? !!mx[0] ? mx[0].map((_, i) => i) : [] : [];
}
/**
* Create an arithmetic progression
* @param {number} size
* @param {number|string} initial
* @param {number} delta
* @returns {*[]}
* Transpose a 2d-array.
* @param {*[][]} mx
* @returns {*[][]}
*/
static arithmetic(size, initial, delta) {
return Vec.progression(size, initial, previous => previous + delta);
static transpose(mx) {
return Mat.columnIndexes(mx).map(c => mx.map(r => r[c]));
}
static column(mx, index) {
return mx.map(r => r[index]);
}
/**
* Create a geometric progression
* @param {number} size
* @param {number} initial
* @param {number} ratio
* @returns {*[]}}
* Iterate through elements on each (x of rows,y of columns) coordinate of a 2d-array.
* @param {*[][]} mx
* @param elementJect
* @returns {*[]}
*/
static geometric(size, initial, ratio) {
return Vec.progression(size, initial, previous => previous * ratio);
static veho(mx, elementJect) {
return mx.map(row => row.map(elementJect));
}
/**
*
* @param {*[]} ar1
* @param {*[]} ar2
* @param {function} product
* Iterate through the columns of a 2d-array.
* @param {*[][]} mx
* @param {function(*[]):[]} columnJect
* @returns {*[]}

@@ -547,32 +656,18 @@ */

static decartes(ar1, ar2, product) {
let arr = [];
for (let x of ar1) {
arr.push(...ar2.map(y => product(x, y)));
}
return arr;
static vehoCol(mx, columnJect) {
return Mat.transpose(mx).map(columnJect);
}
static randSample(arr) {
// const len = arr.length
// switch (len) {
// case 0:
// return undefined
// case 1:
// return arr[0]
// default:
// const idx = Zu.rand(0, len)
// return arr[idx]
// }
return arr[~~(Math.random() * arr.length)];
}
}
// let mtx = [];
// for (let j = 0; j < this[0].length; j++) {
// mtx[j] = [];
// for (let i = 0; i < this.length; i++) {
// mtx[j][i] = this[i][j]
// }
// }
// array[0].map((col, i) => array.map(row => row[i]));
// return mtx
// };
static take(arr, len) {
return arr.slice(0, len);
}
} // Array.prototype.zip = function (another, zipper) {
class Dic {

@@ -681,3 +776,4 @@ /**

exports.Mat = Mat;
exports.Samples = Samples;
exports.Vec = Vec;
exports.clone = clone;

@@ -1,17 +0,1 @@

// Create an object type VehoError
class VehoError extends Error {
constructor(message) {
super();
this.name = 'VehoError';
this.message = message;
} // Make the exception convert to a pretty string when used as
// a string (e.g. by the error console)
toString() {
return this.name + ': "' + this.message + '"';
}
}
const oc = Object.prototype.toString;

@@ -83,61 +67,113 @@ /**

/**
* Static class containing methods to create 2d-array.
* Static class containing methods create 1d-array.
*/
class Mat {
class Vec {
/**
*
* @param {number} height
* @param {number} width
* @param {function} ject
* @returns {number[][]}
* Create an array.
* @param {number} size Integer starts at zero.
* @param {function|*} [ject] Defines the how index i decides value(i).
* @returns {number[]} The
*/
static ini(height, width, ject) {
return Array(height).fill(null).map((_, x) => Array(width).fill(null).map((_, y) => ject(x, y)));
static ini(size, ject) {
if (typeof ject === 'function') {
if (size <= 128) {
let arr = [];
for (let i = 0; i < size; i++) arr[i] = ject(i);
return arr;
} else {
return Array(size).fill(null).map((_, i) => ject(i));
}
} else {
if (size <= 128) {
let arr = [];
for (let i = 0; i < size; i++) arr[i] = ject;
return arr;
} else {
return Array(size).fill(ject);
}
}
}
static isMat(mx) {
return Array.isArray(mx) && mx.length ? Array.isArray(mx[0]) : false;
static isEmpty(arr) {
return !arr || !arr.length;
}
static is(mx) {
return !!mx && mx.length ? !!mx[0] : false;
static clone(arr) {
return cloneArray(arr);
}
static clone(mx) {
return mx.map(cloneArray);
static indexes(arr) {
return arr.map((_, i) => i);
}
/**
*
* @param {*[][]} mx
* @return {number[]}
* Returns an array built from the elements of a given set of arrays.
* Each element of the returned array is determined by elements from every one of the array-set with the same index.
* The returned array has length of the first array in the array set.
* @param {function} zipper The function {x(i)|x(i) ∈ array(i), i ∈ 0,1...n-1, n=arraySet.size} -> y(i), where y
* is the returned array
* @param {*[][]} arraySet The array-set to determine the returned array.
* @returns {*[]|undefined} array
*/
static columnIndexes(mx) {
if (!!mx && mx.length) {
const arr = mx[0];
return !!arr ? arr.map((_, i) => i) : [];
static multiZip(zipper, ...arraySet) {
const firstArray = arraySet[0];
if (!!firstArray) {
const [len, cnt] = [firstArray.length, arraySet.length];
const result = Array(len);
for (let i = 0; i < len; i++) {
const params = Array(cnt);
for (let j = 0; j < cnt; j++) {
params[j] = arraySet[j][i];
}
result[i] = zipper(params);
}
return result;
} else {
return undefined;
}
return [];
}
/**
* Transpose a 2d-array.
* @param {*[][]} mx
* @returns {*[][]}
*
* @param {number} size
* @param {*} initial
* @param {function} progress
* @returns {*[]}
*/
static transpose(mx) {
return Mat.columnIndexes(mx).map(c => mx.map(r => r[c]));
}
static progression(size, initial, progress) {
switch (size) {
case 0:
return [];
static column(mx, index) {
return mx.map(r => r[index]);
case 1:
return [initial];
default:
const arr = new Array(size);
arr[0] = initial;
for (let i = 1; i < size; i++) {
arr[i] = progress(arr[i - 1]);
}
return arr;
}
}
/**
* Iterate through elements on each (x of rows,y of columns) coordinate of a 2d-array.
* @param {*[][]} mx
* @param elementJect
* Create an arithmetic progression
* @param {number} size
* @param {number|string} initial
* @param {number} delta
* @returns {*[]}

@@ -147,9 +183,22 @@ */

static veho(mx, elementJect) {
return mx.map(row => row.map(elementJect));
static arithmetic(size, initial, delta) {
return Vec.progression(size, initial, previous => previous + delta);
}
/**
* Iterate through the columns of a 2d-array.
* @param {*[][]} mx
* @param {function(*[]):[]} columnJect
* Create a geometric progression
* @param {number} size
* @param {number} initial
* @param {number} ratio
* @returns {*[]}}
*/
static geometric(size, initial, ratio) {
return Vec.progression(size, initial, previous => previous * ratio);
}
/**
*
* @param {*[]} ar1
* @param {*[]} ar2
* @param {function} product
* @returns {*[]}

@@ -159,40 +208,90 @@ */

static vehoCol(mx, columnJect) {
return Mat.transpose(mx).map(columnJect);
static decartes(ar1, ar2, product) {
let arr = [];
for (let x of ar1) {
arr.push(...ar2.map(y => product(x, y)));
}
return arr;
}
static randSample(arr) {
// const len = arr.length
// switch (len) {
// case 0:
// return undefined
// case 1:
// return arr[0]
// default:
// const idx = Zu.rand(0, len)
// return arr[idx]
// }
return arr[~~(Math.random() * arr.length)];
}
static take(arr, len) {
return arr.slice(0, len);
}
} // Array.prototype.zip = function (another, zipper) {
// Create an object type VehoError
class VehoError extends Error {
constructor(message) {
super();
this.name = 'VehoError';
this.message = message;
} // Make the exception convert to a pretty string when used as
// a string (e.g. by the error console)
toString() {
return this.name + ': "' + this.message + '"';
}
}
// let mtx = [];
// for (let j = 0; j < this[0].length; j++) {
// mtx[j] = [];
// for (let i = 0; i < this.length; i++) {
// mtx[j][i] = this[i][j]
// }
// }
// array[0].map((col, i) => array.map(row => row[i]));
// return mtx
// };
class Jso {
/**
* Create an Object from separate key-array and value-array.
* Create a object from separate key-array and value-array.
* @param {*[]} keys Array of keys.
* @param {*[]} values Array of values. The value-array and the key-array need to be equal in size.
* @returns {Map<*, *>}
* @returns {Object<*, *>}
*/
static ini(keys, values) {
const o = {};
let i, k;
for (let [i, k] of keys.entries()) {
o[k] = values[i];
}
for ([i, k] of keys.entries()) o[k] = values[i];
return o;
}
/**
*
* @param {Object<string,*>} jso
* @return {[string, *][]}
*/
static clone(o) {
return cloneObject(o);
static toEntries(jso) {
return Object.entries(jso);
}
/**
* Shallow.
* @param {string[]} arr
* @param {*} val
* @return {Object<string,*>}
*/
static fromArr(arr, val) {
let o = {};
for (let k of arr) o[k] = val;
return o;
}
/**
* Shallow.
* @param {...[*,*]} entries - An array of key-value pair, [key, value]

@@ -206,5 +305,3 @@ * @returns {Object|Object<string,*>}

for (let [k, v] of entries) {
o[k] = v;
}
for (let [k, v] of entries) o[k] = v;

@@ -248,17 +345,10 @@ return o;

/**
* Shallow.
* @param {string[]} arr
* @param {*} val
* @return {Object<string,*>}
*
* @param {Object<string,*>} jso
* @return {Map<string, *>}
*/
static fromArr(arr, val) {
let o = {};
for (let k of arr) {
o[k] = val;
}
return o;
static toMap(jso) {
return new Map(Object.entries(jso));
}

@@ -281,23 +371,7 @@ /**

}
/**
*
* @param {Object<string,*>} jso
* @return {Map<string, *>}
*/
static toMap(jso) {
return new Map(Object.entries(jso));
static clone(jso) {
return cloneObject(jso);
}
/**
*
* @param {Object<string,*>} jso
* @return {[string, *][]}
*/
static toEntries(jso) {
return Object.entries(jso);
}
}

@@ -328,15 +402,18 @@ /**

static tableToSamples(samples, banner) {
if (Mat.isMat(samples)) {
if (!!samples && samples.constructor === Array) {
const firstRow = samples[0];
let len = Math.min(firstRow.length, banner.length);
return samples.map(row => {
let o = {};
for (let i = 0; i < len; i++) {
o[banner[i]] = row[i];
}
if (!!firstRow && firstRow.constructor === Array) {
let [i, len] = [0, Math.min(firstRow.length, banner.length)];
return samples.map(row => {
let o = {};
return o;
});
} else throw new VehoError('The input \'samples\' is not a 2d-array');
for (i = 0; i < len; i++) {
o[banner[i]] = row[i];
}
return o;
});
} else return null;
} else throw new VehoError('The input \'samples\' is not an Array');
}

@@ -353,3 +430,3 @@ /**

static samplesToTable(rows, bannerLabel = 'head', samplesLabel = 'rows') {
if (!!rows && Array.isArray(rows)) {
if (!!rows && rows.constructor === Array) {
const firstRow = rows[0];

@@ -402,137 +479,169 @@

/**
* Static class containing methods create 1d-array.
* Transform between Json table and Json of samples.
* A Json table is formed like :
* {
* head:[a, b, ...],
* rows:*[][]
* }.
* A Json of samples is formed like :
* [
* {a:*, b:*, ...},
* {a:*, b:*, ...},
* ...
* ]
*/
class Vec {
class Samples {
/**
* Create an array.
* @param {number} size Integer starts at zero.
* @param {function|*} [ject] Defines the how index i decides value(i).
* @returns {number[]} The
*
* @param {*[]} head
* @param {*[][]} rows
* @param {*[]} [fields]
* @return {Object[]}
*/
static ini(size, ject) {
if (typeof ject === 'function') {
if (size <= 128) {
let arr = [];
static fromTable({
head,
rows
}, fields) {
if (!head || !Array.isArray(head)) throw new VehoError('The input \'head\' is not valid.');
if (!rows || !Array.isArray(rows)) throw new VehoError('The input \'rows\' is not valid.');
const [row] = rows;
if (!row || !Array.isArray(row)) return null;
let k_i = fields && Array.isArray(fields) ? fields.map(field => [field, head.indexOf(field)]) : [...head.entries()].map(([k, v]) => [v, k]);
return rows.map(row => {
let o = {};
for (let i = 0; i < size; i++) arr[i] = ject(i);
for (let [k, i] of k_i) o[k] = row[i];
return arr;
} else {
return Array(size).fill(null).map((_, i) => ject(i));
}
} else {
if (size <= 128) {
let arr = [];
return o;
});
}
/**
*
* @param {Object[]} samples
* @param {string[]} [fields]
* @param {{head:string,rows:string}} [label]
* @returns {null|{head:*[],rows:*[][]}|Object}
*/
for (let i = 0; i < size; i++) arr[i] = ject;
return arr;
} else {
return Array(size).fill(ject);
}
static toTable(samples, {
fields = null,
label = {
head: 'head',
rows: 'rows'
}
} = {}) {
if (!samples || !Array.isArray(samples)) throw new VehoError('The input \'rows\' is not an Array');
const [sample] = samples;
if (!sample || !(sample instanceof Object)) return null;
const {
head,
rows
} = label;
const [banner, picker] = fields ? [fields, row => banner.map(x => row[x])] : [Object.keys(sample), Object.values];
const rowSet = samples.map(picker);
return Jso.of([head, banner], [rows, rowSet]);
}
/**
* Transform json of samples to matrix(2d-array).
* A Json of samples is formed like :
* [
* {a:*, b:*, ...},
* {a:*, b:*, ...},
* ...
* ]
* A matrix(2d-array) is formed like :
* [
* [*, *, ...],
* [*, *, ...],
* ...
* ]
* @param {Object[]} samples Table in json-array form: [{c1:*,c2:*,..},{c1:*,c2:*,..},..]
* @returns {*[][]} Table content in 2d-array, excluding the input table head.
*/
static isEmpty(arr) {
return !arr || !arr.length;
}
static clone(arr) {
return cloneArray(arr);
static toMatrix(samples) {
return samples.map(Object.values);
}
static indexes(arr) {
return arr.map((_, i) => i);
static fromCrosTab({
matrix,
side,
banner
}) {
const sampleList = matrix.map(row => Jso.ini(banner, row));
const result = Jso.ini(side, sampleList);
return result;
}
/**
* Returns an array built from the elements of a given set of arrays.
* Each element of the returned array is determined by elements from every one of the array-set with the same index.
* The returned array has length of the first array in the array set.
* @param {function} zipper The function {x(i)|x(i) ∈ array(i), i ∈ 0,1...n-1, n=arraySet.size} -> y(i), where y
* is the returned array
* @param {*[][]} arraySet The array-set to determine the returned array.
* @returns {*[]|undefined} array
*/
}
static multiZip(zipper, ...arraySet) {
const firstArray = arraySet[0];
/**
* Static class containing methods to create 2d-array.
*/
if (!!firstArray) {
const [len, cnt] = [firstArray.length, arraySet.length];
const result = Array(len);
class Mat {
/**
*
* @param {number} height
* @param {number} width
* @param {function} ject
* @returns {number[][]}
*/
static ini(height, width, ject) {
return Array(height).fill(null).map((_, x) => Array(width).fill(null).map((_, y) => ject(x, y)));
}
for (let i = 0; i < len; i++) {
const params = Array(cnt);
static isMat(mx) {
return Array.isArray(mx) && mx.length ? Array.isArray(mx[0]) : false;
}
for (let j = 0; j < cnt; j++) {
params[j] = arraySet[j][i];
}
static is(mx) {
return !!mx && mx.length ? !!mx[0] : false;
}
result[i] = zipper(params);
}
return result;
} else {
return undefined;
}
static clone(mx) {
return mx.map(cloneArray);
}
/**
*
* @param {number} size
* @param {*} initial
* @param {function} progress
* @returns {*[]}
* @param {*[][]} mx
* @return {number[]}
*/
static progression(size, initial, progress) {
switch (size) {
case 0:
return [];
case 1:
return [initial];
default:
const arr = new Array(size);
arr[0] = initial;
for (let i = 1; i < size; i++) {
arr[i] = progress(arr[i - 1]);
}
return arr;
}
static columnIndexes(mx) {
return !!mx && mx.length ? !!mx[0] ? mx[0].map((_, i) => i) : [] : [];
}
/**
* Create an arithmetic progression
* @param {number} size
* @param {number|string} initial
* @param {number} delta
* @returns {*[]}
* Transpose a 2d-array.
* @param {*[][]} mx
* @returns {*[][]}
*/
static arithmetic(size, initial, delta) {
return Vec.progression(size, initial, previous => previous + delta);
static transpose(mx) {
return Mat.columnIndexes(mx).map(c => mx.map(r => r[c]));
}
static column(mx, index) {
return mx.map(r => r[index]);
}
/**
* Create a geometric progression
* @param {number} size
* @param {number} initial
* @param {number} ratio
* @returns {*[]}}
* Iterate through elements on each (x of rows,y of columns) coordinate of a 2d-array.
* @param {*[][]} mx
* @param elementJect
* @returns {*[]}
*/
static geometric(size, initial, ratio) {
return Vec.progression(size, initial, previous => previous * ratio);
static veho(mx, elementJect) {
return mx.map(row => row.map(elementJect));
}
/**
*
* @param {*[]} ar1
* @param {*[]} ar2
* @param {function} product
* Iterate through the columns of a 2d-array.
* @param {*[][]} mx
* @param {function(*[]):[]} columnJect
* @returns {*[]}

@@ -542,32 +651,18 @@ */

static decartes(ar1, ar2, product) {
let arr = [];
for (let x of ar1) {
arr.push(...ar2.map(y => product(x, y)));
}
return arr;
static vehoCol(mx, columnJect) {
return Mat.transpose(mx).map(columnJect);
}
static randSample(arr) {
// const len = arr.length
// switch (len) {
// case 0:
// return undefined
// case 1:
// return arr[0]
// default:
// const idx = Zu.rand(0, len)
// return arr[idx]
// }
return arr[~~(Math.random() * arr.length)];
}
}
// let mtx = [];
// for (let j = 0; j < this[0].length; j++) {
// mtx[j] = [];
// for (let i = 0; i < this.length; i++) {
// mtx[j][i] = this[i][j]
// }
// }
// array[0].map((col, i) => array.map(row => row[i]));
// return mtx
// };
static take(arr, len) {
return arr.slice(0, len);
}
} // Array.prototype.zip = function (another, zipper) {
class Dic {

@@ -671,2 +766,2 @@ /**

export { Dic, Fun, Jso, JsonTable, Mat, Vec, clone };
export { Dic, Fun, Jso, JsonTable, Mat, Samples, Vec, clone };

@@ -7,2 +7,289 @@ (function (global, factory) {

var oc = Object.prototype.toString;
/**
*
* @param {*} o
* @return {*}
*/
function clone(o) {
if (!o || typeof o !== 'object') return o;
switch (oc.call(o).slice(8, 11)) {
case 'Arr':
return cloneArray(o);
case 'Obj':
return cloneObject(o);
case 'Map':
return cloneMap(o);
case 'Dat':
return new Date(+o);
case 'Set':
return new Set(cloneArray([].concat(o)));
}
throw new Error('Unable to copy obj. Unsupported type.');
}
/**
*
* @param {Map<*, *>} o
* @return {Map<*, *>}
*/
function cloneMap(o) {
return new Map([].concat(o.entries()).map(function (_ref) {
var k = _ref[0],
v = _ref[1];
return [k, clone(v)];
}));
}
/**
*
* @param {*[]} o
* @return {*[]}
*/
function cloneArray(o) {
return o.map(clone);
}
/**
* Known issue:
* Unable to clone circular and nested object.
* @param {{}} o
* @return {{}}
*/
function cloneObject(o) {
var x = {};
for (var _i = 0, _Object$entries = Object.entries(o); _i < _Object$entries.length; _i++) {
var _Object$entries$_i = _Object$entries[_i],
k = _Object$entries$_i[0],
v = _Object$entries$_i[1];
x[k] = clone(v);
}
return x;
}
/**
* Static class containing methods create 1d-array.
*/
var Vec =
/*#__PURE__*/
function () {
function Vec() {}
/**
* Create an array.
* @param {number} size Integer starts at zero.
* @param {function|*} [ject] Defines the how index i decides value(i).
* @returns {number[]} The
*/
Vec.ini = function ini(size, ject) {
if (typeof ject === 'function') {
if (size <= 128) {
var arr = [];
for (var i = 0; i < size; i++) {
arr[i] = ject(i);
}
return arr;
} else {
return Array(size).fill(null).map(function (_, i) {
return ject(i);
});
}
} else {
if (size <= 128) {
var _arr = [];
for (var _i = 0; _i < size; _i++) {
_arr[_i] = ject;
}
return _arr;
} else {
return Array(size).fill(ject);
}
}
};
Vec.isEmpty = function isEmpty(arr) {
return !arr || !arr.length;
};
Vec.clone = function clone(arr) {
return cloneArray(arr);
};
Vec.indexes = function indexes(arr) {
return arr.map(function (_, i) {
return i;
});
}
/**
* Returns an array built from the elements of a given set of arrays.
* Each element of the returned array is determined by elements from every one of the array-set with the same index.
* The returned array has length of the first array in the array set.
* @param {function} zipper The function {x(i)|x(i) ∈ array(i), i ∈ 0,1...n-1, n=arraySet.size} -> y(i), where y
* is the returned array
* @param {*[][]} arraySet The array-set to determine the returned array.
* @returns {*[]|undefined} array
*/
;
Vec.multiZip = function multiZip(zipper) {
for (var _len = arguments.length, arraySet = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
arraySet[_key - 1] = arguments[_key];
}
var firstArray = arraySet[0];
if (!!firstArray) {
var _ref = [firstArray.length, arraySet.length],
len = _ref[0],
cnt = _ref[1];
var result = Array(len);
for (var i = 0; i < len; i++) {
var params = Array(cnt);
for (var j = 0; j < cnt; j++) {
params[j] = arraySet[j][i];
}
result[i] = zipper(params);
}
return result;
} else {
return undefined;
}
}
/**
*
* @param {number} size
* @param {*} initial
* @param {function} progress
* @returns {*[]}
*/
;
Vec.progression = function progression(size, initial, progress) {
switch (size) {
case 0:
return [];
case 1:
return [initial];
default:
var arr = new Array(size);
arr[0] = initial;
for (var i = 1; i < size; i++) {
arr[i] = progress(arr[i - 1]);
}
return arr;
}
}
/**
* Create an arithmetic progression
* @param {number} size
* @param {number|string} initial
* @param {number} delta
* @returns {*[]}
*/
;
Vec.arithmetic = function arithmetic(size, initial, delta) {
return Vec.progression(size, initial, function (previous) {
return previous + delta;
});
}
/**
* Create a geometric progression
* @param {number} size
* @param {number} initial
* @param {number} ratio
* @returns {*[]}}
*/
;
Vec.geometric = function geometric(size, initial, ratio) {
return Vec.progression(size, initial, function (previous) {
return previous * ratio;
});
}
/**
*
* @param {*[]} ar1
* @param {*[]} ar2
* @param {function} product
* @returns {*[]}
*/
;
Vec.decartes = function decartes(ar1, ar2, product) {
var arr = [];
var _loop = function _loop() {
if (_isArray) {
if (_i2 >= _iterator.length) return "break";
_ref2 = _iterator[_i2++];
} else {
_i2 = _iterator.next();
if (_i2.done) return "break";
_ref2 = _i2.value;
}
var x = _ref2;
arr.push.apply(arr, ar2.map(function (y) {
return product(x, y);
}));
};
for (var _iterator = ar1, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref2;
var _ret = _loop();
if (_ret === "break") break;
}
return arr;
};
Vec.randSample = function randSample(arr) {
// const len = arr.length
// switch (len) {
// case 0:
// return undefined
// case 1:
// return arr[0]
// default:
// const idx = Zu.rand(0, len)
// return arr[idx]
// }
return arr[~~(Math.random() * arr.length)];
};
Vec.take = function take(arr, len) {
return arr.slice(0, len);
};
return Vec;
}(); // Array.prototype.zip = function (another, zipper) {
function _inheritsLoose(subClass, superClass) {

@@ -124,223 +411,74 @@ subClass.prototype = Object.create(superClass.prototype);

var oc = Object.prototype.toString;
/**
*
* @param {*} o
* @return {*}
*/
function clone(o) {
if (!o || typeof o !== 'object') return o;
switch (oc.call(o).slice(8, 11)) {
case 'Arr':
return cloneArray(o);
case 'Obj':
return cloneObject(o);
case 'Map':
return cloneMap(o);
case 'Dat':
return new Date(+o);
case 'Set':
return new Set(cloneArray([].concat(o)));
}
throw new Error('Unable to copy obj. Unsupported type.');
}
/**
*
* @param {Map<*, *>} o
* @return {Map<*, *>}
*/
function cloneMap(o) {
return new Map([].concat(o.entries()).map(function (_ref) {
var k = _ref[0],
v = _ref[1];
return [k, clone(v)];
}));
}
/**
*
* @param {*[]} o
* @return {*[]}
*/
function cloneArray(o) {
return o.map(clone);
}
/**
* Known issue:
* Unable to clone circular and nested object.
* @param {{}} o
* @return {{}}
*/
function cloneObject(o) {
var x = {};
for (var _i = 0, _Object$entries = Object.entries(o); _i < _Object$entries.length; _i++) {
var _Object$entries$_i = _Object$entries[_i],
k = _Object$entries$_i[0],
v = _Object$entries$_i[1];
x[k] = clone(v);
}
return x;
}
/**
* Static class containing methods to create 2d-array.
*/
var Mat =
var Jso =
/*#__PURE__*/
function () {
function Mat() {}
function Jso() {}
/**
*
* @param {number} height
* @param {number} width
* @param {function} ject
* @returns {number[][]}
* Create a object from separate key-array and value-array.
* @param {*[]} keys Array of keys.
* @param {*[]} values Array of values. The value-array and the key-array need to be equal in size.
* @returns {Object<*, *>}
*/
Mat.ini = function ini(height, width, ject) {
return Array(height).fill(null).map(function (_, x) {
return Array(width).fill(null).map(function (_, y) {
return ject(x, y);
});
});
};
Jso.ini = function ini(keys, values) {
var o = {};
var i, k;
Mat.isMat = function isMat(mx) {
return Array.isArray(mx) && mx.length ? Array.isArray(mx[0]) : false;
};
for (var _iterator = keys.entries(), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
if (_isArray) {
if (_i >= _iterator.length) break;
var _iterator2 = _iterator[_i++];
i = _iterator2[0];
k = _iterator2[1];
} else {
_i = _iterator.next();
if (_i.done) break;
var _i$value = _i.value;
i = _i$value[0];
k = _i$value[1];
}
Mat.is = function is(mx) {
return !!mx && mx.length ? !!mx[0] : false;
};
o[k] = values[i];
}
Mat.clone = function clone(mx) {
return mx.map(cloneArray);
return o;
}
/**
*
* @param {*[][]} mx
* @return {number[]}
* @param {Object<string,*>} jso
* @return {[string, *][]}
*/
;
Mat.columnIndexes = function columnIndexes(mx) {
if (!!mx && mx.length) {
var arr = mx[0];
return !!arr ? arr.map(function (_, i) {
return i;
}) : [];
}
return [];
Jso.toEntries = function toEntries(jso) {
return Object.entries(jso);
}
/**
* Transpose a 2d-array.
* @param {*[][]} mx
* @returns {*[][]}
* Shallow.
* @param {string[]} arr
* @param {*} val
* @return {Object<string,*>}
*/
;
Mat.transpose = function transpose(mx) {
return Mat.columnIndexes(mx).map(function (c) {
return mx.map(function (r) {
return r[c];
});
});
};
Mat.column = function column(mx, index) {
return mx.map(function (r) {
return r[index];
});
}
/**
* Iterate through elements on each (x of rows,y of columns) coordinate of a 2d-array.
* @param {*[][]} mx
* @param elementJect
* @returns {*[]}
*/
;
Mat.veho = function veho(mx, elementJect) {
return mx.map(function (row) {
return row.map(elementJect);
});
}
/**
* Iterate through the columns of a 2d-array.
* @param {*[][]} mx
* @param {function(*[]):[]} columnJect
* @returns {*[]}
*/
;
Mat.vehoCol = function vehoCol(mx, columnJect) {
return Mat.transpose(mx).map(columnJect);
};
return Mat;
}();
// let mtx = [];
// for (let j = 0; j < this[0].length; j++) {
// mtx[j] = [];
// for (let i = 0; i < this.length; i++) {
// mtx[j][i] = this[i][j]
// }
// }
// array[0].map((col, i) => array.map(row => row[i]));
// return mtx
// };
var Jso =
/*#__PURE__*/
function () {
function Jso() {}
/**
* Create an Object from separate key-array and value-array.
* @param {*[]} keys Array of keys.
* @param {*[]} values Array of values. The value-array and the key-array need to be equal in size.
* @returns {Map<*, *>}
*/
Jso.ini = function ini(keys, values) {
Jso.fromArr = function fromArr(arr, val) {
var o = {};
for (var _iterator = keys.entries(), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
for (var _iterator3 = arr, _isArray2 = Array.isArray(_iterator3), _i2 = 0, _iterator3 = _isArray2 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
if (_isArray2) {
if (_i2 >= _iterator3.length) break;
_ref = _iterator3[_i2++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
_i2 = _iterator3.next();
if (_i2.done) break;
_ref = _i2.value;
}
var _ref2 = _ref,
i = _ref2[0],
k = _ref2[1];
o[k] = values[i];
var k = _ref;
o[k] = val;
}
return o;
};
Jso.clone = function clone(o) {
return cloneObject(o);
}

@@ -361,4 +499,4 @@ /**

for (var _i2 = 0, _entries = entries; _i2 < _entries.length; _i2++) {
var _entries$_i = _entries[_i2],
for (var _i3 = 0, _entries = entries; _i3 < _entries.length; _i3++) {
var _entries$_i = _entries[_i3],
k = _entries$_i[0],

@@ -385,17 +523,17 @@ v = _entries$_i[1];

case 1:
for (var _iterator2 = entries, _isArray2 = Array.isArray(_iterator2), _i3 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref3;
for (var _iterator4 = entries, _isArray3 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray3 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
var _ref2;
if (_isArray2) {
if (_i3 >= _iterator2.length) break;
_ref3 = _iterator2[_i3++];
if (_isArray3) {
if (_i4 >= _iterator4.length) break;
_ref2 = _iterator4[_i4++];
} else {
_i3 = _iterator2.next();
if (_i3.done) break;
_ref3 = _i3.value;
_i4 = _iterator4.next();
if (_i4.done) break;
_ref2 = _i4.value;
}
var _ref4 = _ref3,
k = _ref4[0],
v = _ref4[1];
var _ref3 = _ref2,
k = _ref3[0],
v = _ref3[1];
o[k] = ject(v);

@@ -407,19 +545,19 @@ }

case 2:
for (var _iterator3 = entries.entries(), _isArray3 = Array.isArray(_iterator3), _i4 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref5;
for (var _iterator5 = entries.entries(), _isArray4 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray4 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
var _ref4;
if (_isArray3) {
if (_i4 >= _iterator3.length) break;
_ref5 = _iterator3[_i4++];
if (_isArray4) {
if (_i5 >= _iterator5.length) break;
_ref4 = _iterator5[_i5++];
} else {
_i4 = _iterator3.next();
if (_i4.done) break;
_ref5 = _i4.value;
_i5 = _iterator5.next();
if (_i5.done) break;
_ref4 = _i5.value;
}
var _ref6 = _ref5,
i = _ref6[0],
_ref6$ = _ref6[1],
k = _ref6$[0],
v = _ref6$[1];
var _ref5 = _ref4,
i = _ref5[0],
_ref5$ = _ref5[1],
k = _ref5$[0],
v = _ref5$[1];
o[k] = ject(v, i);

@@ -434,17 +572,17 @@ }

} else {
for (var _iterator4 = entries, _isArray4 = Array.isArray(_iterator4), _i5 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
var _ref7;
for (var _iterator6 = entries, _isArray5 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray5 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
var _ref6;
if (_isArray4) {
if (_i5 >= _iterator4.length) break;
_ref7 = _iterator4[_i5++];
if (_isArray5) {
if (_i6 >= _iterator6.length) break;
_ref6 = _iterator6[_i6++];
} else {
_i5 = _iterator4.next();
if (_i5.done) break;
_ref7 = _i5.value;
_i6 = _iterator6.next();
if (_i6.done) break;
_ref6 = _i6.value;
}
var _ref8 = _ref7,
k = _ref8[0],
v = _ref8[1];
var _ref7 = _ref6,
k = _ref7[0],
v = _ref7[1];
o[k] = v;

@@ -457,29 +595,10 @@ }

/**
* Shallow.
* @param {string[]} arr
* @param {*} val
* @return {Object<string,*>}
*
* @param {Object<string,*>} jso
* @return {Map<string, *>}
*/
;
Jso.fromArr = function fromArr(arr, val) {
var o = {};
for (var _iterator5 = arr, _isArray5 = Array.isArray(_iterator5), _i6 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
var _ref9;
if (_isArray5) {
if (_i6 >= _iterator5.length) break;
_ref9 = _iterator5[_i6++];
} else {
_i6 = _iterator5.next();
if (_i6.done) break;
_ref9 = _i6.value;
}
var k = _ref9;
o[k] = val;
}
return o;
Jso.toMap = function toMap(jso) {
return new Map(Object.entries(jso));
}

@@ -496,17 +615,17 @@ /**

for (var _iterator6 = dict.entries(), _isArray6 = Array.isArray(_iterator6), _i7 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
var _ref10;
for (var _iterator7 = dict.entries(), _isArray6 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray6 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
var _ref8;
if (_isArray6) {
if (_i7 >= _iterator6.length) break;
_ref10 = _iterator6[_i7++];
if (_i7 >= _iterator7.length) break;
_ref8 = _iterator7[_i7++];
} else {
_i7 = _iterator6.next();
_i7 = _iterator7.next();
if (_i7.done) break;
_ref10 = _i7.value;
_ref8 = _i7.value;
}
var _ref11 = _ref10,
k = _ref11[0],
v = _ref11[1];
var _ref9 = _ref8,
k = _ref9[0],
v = _ref9[1];
o[k] = v;

@@ -516,22 +635,6 @@ }

return o; // return Object.fromEntries(dict)
}
/**
*
* @param {Object<string,*>} jso
* @return {Map<string, *>}
*/
;
};
Jso.toMap = function toMap(jso) {
return new Map(Object.entries(jso));
}
/**
*
* @param {Object<string,*>} jso
* @return {[string, *][]}
*/
;
Jso.toEntries = function toEntries(jso) {
return Object.entries(jso);
Jso.clone = function clone(jso) {
return cloneObject(jso);
};

@@ -569,15 +672,20 @@

JsonTable.tableToSamples = function tableToSamples(samples, banner) {
if (Mat.isMat(samples)) {
if (!!samples && samples.constructor === Array) {
var firstRow = samples[0];
var len = Math.min(firstRow.length, banner.length);
return samples.map(function (row) {
var o = {};
for (var i = 0; i < len; i++) {
o[banner[i]] = row[i];
}
if (!!firstRow && firstRow.constructor === Array) {
var _ref10 = [0, Math.min(firstRow.length, banner.length)],
i = _ref10[0],
len = _ref10[1];
return samples.map(function (row) {
var o = {};
return o;
});
} else throw new VehoError('The input \'samples\' is not a 2d-array');
for (i = 0; i < len; i++) {
o[banner[i]] = row[i];
}
return o;
});
} else return null;
} else throw new VehoError('The input \'samples\' is not an Array');
}

@@ -602,3 +710,3 @@ /**

if (!!rows && Array.isArray(rows)) {
if (!!rows && rows.constructor === Array) {
var firstRow = rows[0];

@@ -651,17 +759,17 @@

for (var _iterator7 = indexedRows, _isArray7 = Array.isArray(_iterator7), _i8 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
var _ref12;
for (var _iterator8 = indexedRows, _isArray7 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray7 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
var _ref11;
if (_isArray7) {
if (_i8 >= _iterator7.length) break;
_ref12 = _iterator7[_i8++];
if (_i8 >= _iterator8.length) break;
_ref11 = _iterator8[_i8++];
} else {
_i8 = _iterator7.next();
_i8 = _iterator8.next();
if (_i8.done) break;
_ref12 = _i8.value;
_ref11 = _i8.value;
}
var _ref13 = _ref12,
k = _ref13[0],
v = _ref13[1];
var _ref12 = _ref11,
k = _ref12[0],
v = _ref12[1];
obj[k] = v;

@@ -677,159 +785,223 @@ }

/**
* Static class containing methods create 1d-array.
* Transform between Json table and Json of samples.
* A Json table is formed like :
* {
* head:[a, b, ...],
* rows:*[][]
* }.
* A Json of samples is formed like :
* [
* {a:*, b:*, ...},
* {a:*, b:*, ...},
* ...
* ]
*/
var Vec =
var Samples =
/*#__PURE__*/
function () {
function Vec() {}
function Samples() {}
/**
* Create an array.
* @param {number} size Integer starts at zero.
* @param {function|*} [ject] Defines the how index i decides value(i).
* @returns {number[]} The
*
* @param {*[]} head
* @param {*[][]} rows
* @param {*[]} [fields]
* @return {Object[]}
*/
Vec.ini = function ini(size, ject) {
if (typeof ject === 'function') {
if (size <= 128) {
var arr = [];
Samples.fromTable = function fromTable(_ref, fields) {
var head = _ref.head,
rows = _ref.rows;
if (!head || !Array.isArray(head)) throw new VehoError('The input \'head\' is not valid.');
if (!rows || !Array.isArray(rows)) throw new VehoError('The input \'rows\' is not valid.');
var row = rows[0];
if (!row || !Array.isArray(row)) return null;
var k_i = fields && Array.isArray(fields) ? fields.map(function (field) {
return [field, head.indexOf(field)];
}) : [].concat(head.entries()).map(function (_ref2) {
var k = _ref2[0],
v = _ref2[1];
return [v, k];
});
return rows.map(function (row) {
var o = {};
for (var i = 0; i < size; i++) {
arr[i] = ject(i);
for (var _iterator = k_i, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref3;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref3 = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref3 = _i.value;
}
return arr;
} else {
return Array(size).fill(null).map(function (_, i) {
return ject(i);
});
var _ref4 = _ref3,
k = _ref4[0],
i = _ref4[1];
o[k] = row[i];
}
} else {
if (size <= 128) {
var _arr = [];
for (var _i = 0; _i < size; _i++) {
_arr[_i] = ject;
}
return o;
});
}
/**
*
* @param {Object[]} samples
* @param {string[]} [fields]
* @param {{head:string,rows:string}} [label]
* @returns {null|{head:*[],rows:*[][]}|Object}
*/
;
return _arr;
} else {
return Array(size).fill(ject);
}
}
};
Samples.toTable = function toTable(samples, _temp) {
var _ref5 = _temp === void 0 ? {} : _temp,
_ref5$fields = _ref5.fields,
fields = _ref5$fields === void 0 ? null : _ref5$fields,
_ref5$label = _ref5.label,
label = _ref5$label === void 0 ? {
head: 'head',
rows: 'rows'
} : _ref5$label;
Vec.isEmpty = function isEmpty(arr) {
return !arr || !arr.length;
};
if (!samples || !Array.isArray(samples)) throw new VehoError('The input \'rows\' is not an Array');
var sample = samples[0];
if (!sample || !(sample instanceof Object)) return null;
var head = label.head,
rows = label.rows;
Vec.clone = function clone(arr) {
return cloneArray(arr);
};
var _ref6 = fields ? [fields, function (row) {
return banner.map(function (x) {
return row[x];
});
}] : [Object.keys(sample), Object.values],
banner = _ref6[0],
picker = _ref6[1];
Vec.indexes = function indexes(arr) {
return arr.map(function (_, i) {
return i;
});
var rowSet = samples.map(picker);
return Jso.of([head, banner], [rows, rowSet]);
}
/**
* Returns an array built from the elements of a given set of arrays.
* Each element of the returned array is determined by elements from every one of the array-set with the same index.
* The returned array has length of the first array in the array set.
* @param {function} zipper The function {x(i)|x(i) ∈ array(i), i ∈ 0,1...n-1, n=arraySet.size} -> y(i), where y
* is the returned array
* @param {*[][]} arraySet The array-set to determine the returned array.
* @returns {*[]|undefined} array
* Transform json of samples to matrix(2d-array).
* A Json of samples is formed like :
* [
* {a:*, b:*, ...},
* {a:*, b:*, ...},
* ...
* ]
* A matrix(2d-array) is formed like :
* [
* [*, *, ...],
* [*, *, ...],
* ...
* ]
* @param {Object[]} samples Table in json-array form: [{c1:*,c2:*,..},{c1:*,c2:*,..},..]
* @returns {*[][]} Table content in 2d-array, excluding the input table head.
*/
;
Vec.multiZip = function multiZip(zipper) {
for (var _len = arguments.length, arraySet = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
arraySet[_key - 1] = arguments[_key];
}
Samples.toMatrix = function toMatrix(samples) {
return samples.map(Object.values);
};
var firstArray = arraySet[0];
Samples.fromCrosTab = function fromCrosTab(_ref7) {
var matrix = _ref7.matrix,
side = _ref7.side,
banner = _ref7.banner;
var sampleList = matrix.map(function (row) {
return Jso.ini(banner, row);
});
var result = Jso.ini(side, sampleList);
return result;
};
if (!!firstArray) {
var _ref = [firstArray.length, arraySet.length],
len = _ref[0],
cnt = _ref[1];
var result = Array(len);
return Samples;
}();
for (var i = 0; i < len; i++) {
var params = Array(cnt);
/**
* Static class containing methods to create 2d-array.
*/
for (var j = 0; j < cnt; j++) {
params[j] = arraySet[j][i];
}
var Mat =
/*#__PURE__*/
function () {
function Mat() {}
result[i] = zipper(params);
}
/**
*
* @param {number} height
* @param {number} width
* @param {function} ject
* @returns {number[][]}
*/
Mat.ini = function ini(height, width, ject) {
return Array(height).fill(null).map(function (_, x) {
return Array(width).fill(null).map(function (_, y) {
return ject(x, y);
});
});
};
return result;
} else {
return undefined;
}
Mat.isMat = function isMat(mx) {
return Array.isArray(mx) && mx.length ? Array.isArray(mx[0]) : false;
};
Mat.is = function is(mx) {
return !!mx && mx.length ? !!mx[0] : false;
};
Mat.clone = function clone(mx) {
return mx.map(cloneArray);
}
/**
*
* @param {number} size
* @param {*} initial
* @param {function} progress
* @returns {*[]}
* @param {*[][]} mx
* @return {number[]}
*/
;
Vec.progression = function progression(size, initial, progress) {
switch (size) {
case 0:
return [];
case 1:
return [initial];
default:
var arr = new Array(size);
arr[0] = initial;
for (var i = 1; i < size; i++) {
arr[i] = progress(arr[i - 1]);
}
return arr;
}
Mat.columnIndexes = function columnIndexes(mx) {
return !!mx && mx.length ? !!mx[0] ? mx[0].map(function (_, i) {
return i;
}) : [] : [];
}
/**
* Create an arithmetic progression
* @param {number} size
* @param {number|string} initial
* @param {number} delta
* @returns {*[]}
* Transpose a 2d-array.
* @param {*[][]} mx
* @returns {*[][]}
*/
;
Vec.arithmetic = function arithmetic(size, initial, delta) {
return Vec.progression(size, initial, function (previous) {
return previous + delta;
Mat.transpose = function transpose(mx) {
return Mat.columnIndexes(mx).map(function (c) {
return mx.map(function (r) {
return r[c];
});
});
};
Mat.column = function column(mx, index) {
return mx.map(function (r) {
return r[index];
});
}
/**
* Create a geometric progression
* @param {number} size
* @param {number} initial
* @param {number} ratio
* @returns {*[]}}
* Iterate through elements on each (x of rows,y of columns) coordinate of a 2d-array.
* @param {*[][]} mx
* @param elementJect
* @returns {*[]}
*/
;
Vec.geometric = function geometric(size, initial, ratio) {
return Vec.progression(size, initial, function (previous) {
return previous * ratio;
Mat.veho = function veho(mx, elementJect) {
return mx.map(function (row) {
return row.map(elementJect);
});
}
/**
*
* @param {*[]} ar1
* @param {*[]} ar2
* @param {function} product
* Iterate through the columns of a 2d-array.
* @param {*[][]} mx
* @param {function(*[]):[]} columnJect
* @returns {*[]}

@@ -839,53 +1011,19 @@ */

Vec.decartes = function decartes(ar1, ar2, product) {
var arr = [];
var _loop = function _loop() {
if (_isArray) {
if (_i2 >= _iterator.length) return "break";
_ref2 = _iterator[_i2++];
} else {
_i2 = _iterator.next();
if (_i2.done) return "break";
_ref2 = _i2.value;
}
var x = _ref2;
arr.push.apply(arr, ar2.map(function (y) {
return product(x, y);
}));
};
for (var _iterator = ar1, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref2;
var _ret = _loop();
if (_ret === "break") break;
}
return arr;
Mat.vehoCol = function vehoCol(mx, columnJect) {
return Mat.transpose(mx).map(columnJect);
};
Vec.randSample = function randSample(arr) {
// const len = arr.length
// switch (len) {
// case 0:
// return undefined
// case 1:
// return arr[0]
// default:
// const idx = Zu.rand(0, len)
// return arr[idx]
// }
return arr[~~(Math.random() * arr.length)];
};
return Mat;
}();
// let mtx = [];
// for (let j = 0; j < this[0].length; j++) {
// mtx[j] = [];
// for (let i = 0; i < this.length; i++) {
// mtx[j][i] = this[i][j]
// }
// }
// array[0].map((col, i) => array.map(row => row[i]));
// return mtx
// };
Vec.take = function take(arr, len) {
return arr.slice(0, len);
};
return Vec;
}(); // Array.prototype.zip = function (another, zipper) {
var Dic =

@@ -1018,2 +1156,3 @@ /*#__PURE__*/

exports.Mat = Mat;
exports.Samples = Samples;
exports.Vec = Vec;

@@ -1020,0 +1159,0 @@ exports.clone = clone;

{
"name": "veho",
"version": "0.1.19",
"version": "0.1.20",
"description": "An array extension (grammatical sugar) to create, iterate and query 1d, 2d array and JSON object.",

@@ -43,4 +43,4 @@ "main": "dist/index.cjs.js",

"elprimero": "^0.0.18",
"xbrief": "^0.1.33",
"borel": "^0.0.9"
"xbrief": "^0.1.34",
"borel": "^0.1.0"
},

@@ -47,0 +47,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc