jupyter-ijavascript-utils 1.60.0 → 1.61.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +1 -1
- package/package.json +1 -1
- package/src/TableGenerator.js +1 -1
- package/src/aggregate.js +8 -8
- package/src/array.js +106 -105
- package/src/chain.js +14 -12
- package/src/color.js +36 -17
- package/src/date.js +29 -18
- package/src/format.js +89 -70
- package/src/group.js +2 -3
- package/src/hashMap.js +16 -16
- package/src/ijs.js +1 -1
- package/src/object.js +190 -87
package/Dockerfile
CHANGED
package/package.json
CHANGED
package/src/TableGenerator.js
CHANGED
|
@@ -1751,7 +1751,7 @@ class TableGenerator {
|
|
|
1751
1751
|
const prepResults = this.prepare();
|
|
1752
1752
|
const results = {};
|
|
1753
1753
|
const createFrameList = () => new Array(prepResults.data.length).fill(undefined);
|
|
1754
|
-
prepResults.headers.forEach((header) => ObjectUtils.
|
|
1754
|
+
prepResults.headers.forEach((header) => ObjectUtils.assignIP(results, header, createFrameList()));
|
|
1755
1755
|
|
|
1756
1756
|
prepResults.data.forEach((row, rowIndex) => {
|
|
1757
1757
|
row.forEach((value, valIndex) => {
|
package/src/aggregate.js
CHANGED
|
@@ -549,7 +549,7 @@ module.exports.first = function first(collection, accessor) {
|
|
|
549
549
|
* @param {Array} collection -
|
|
550
550
|
* @returns {Number}
|
|
551
551
|
* @example
|
|
552
|
-
* utils.aggregate.
|
|
552
|
+
* utils.aggregate.length([0.87, 2.68, 5.31, 3.94, 4.13, 3.58, 3.62, 2.56]);
|
|
553
553
|
* // 8
|
|
554
554
|
*/
|
|
555
555
|
module.exports.length = function length(collection) {
|
|
@@ -684,7 +684,7 @@ module.exports.countMap = function countMap(collection, accessor, uniquifierFn)
|
|
|
684
684
|
* { station: 'A', timestamp: new Date(2022, 0, 2, 9, 30) },
|
|
685
685
|
* { station: 'B', timestamp: new Date(2022, 0, 2, 10, 0) },
|
|
686
686
|
* { station: 'A', timestamp: new Date(2022, 0, 3, 10, 0) },
|
|
687
|
-
* { station: 'B', timestamp: new Date(2022, 0, 3, 10, 0 }
|
|
687
|
+
* { station: 'B', timestamp: new Date(2022, 0, 3, 10, 0) }
|
|
688
688
|
* ]
|
|
689
689
|
* utils.aggregate.count(series, 'timestamp', (d) => d.toISOString().slice(0, 10))
|
|
690
690
|
* // { '2022-01-01': 3, '2022-01-02': 2, '2022-01-03': 2 }
|
|
@@ -744,7 +744,7 @@ module.exports.duplicates = function duplicates(collection, accessor, uniquifier
|
|
|
744
744
|
* const superSet = new Set(['a', 'b', 'c']);
|
|
745
745
|
* const data = [{ val: 'a' }, { val: 'b' }, { val: 'c' }, { val: 'd' }];
|
|
746
746
|
*
|
|
747
|
-
* aggregate.notIn(data, 'val', superSet);
|
|
747
|
+
* utils.aggregate.notIn(data, 'val', superSet);
|
|
748
748
|
* // Set('d')
|
|
749
749
|
*/
|
|
750
750
|
module.exports.notIn = function notIn(collection, accessor, targetIterator) {
|
|
@@ -768,13 +768,13 @@ module.exports.notIn = function notIn(collection, accessor, targetIterator) {
|
|
|
768
768
|
* @returns {Boolean} - whether the values in the array are truly unique
|
|
769
769
|
* @example
|
|
770
770
|
* let data = [{ val: 1 }, { val: 2 }, { val: 3 }, { val: 1 }];
|
|
771
|
-
* aggregate.isUnique(data, 'val'); // false
|
|
771
|
+
* utils.aggregate.isUnique(data, 'val'); // false
|
|
772
772
|
*
|
|
773
773
|
* let data = [{ val: 1 }, { val: 2 }, { val: 3 }];
|
|
774
|
-
* aggregate.isUnique(data, 'val'); // true
|
|
774
|
+
* utils.aggregate.isUnique(data, 'val'); // true
|
|
775
775
|
*
|
|
776
776
|
* data = ['a', 'b', 'c', 'd'];
|
|
777
|
-
* aggregate.isUnique(data); // true
|
|
777
|
+
* utils.aggregate.isUnique(data); // true
|
|
778
778
|
*/
|
|
779
779
|
module.exports.isUnique = function isUnique(collection, accessor) {
|
|
780
780
|
const cleanedFunc = ObjectUtils.evaluateFunctionOrProperty(accessor);
|
|
@@ -981,7 +981,7 @@ module.exports.percentile_99 = function percentile(collection, accessor) {
|
|
|
981
981
|
* // 0.87, 2.56, 2.68, 3.58, 3.62
|
|
982
982
|
*
|
|
983
983
|
* //-- you can also combine values to make the values clearer, by passing a function
|
|
984
|
-
* const monthPrecip =
|
|
984
|
+
* const monthPrecip = (record) => `${record.month} (${record.precip})`;
|
|
985
985
|
* utils.aggregate.topValues(collection, 3, monthPrecip, '-precip');
|
|
986
986
|
* // '2021-Oct (5.31)', '2021-Dec (4.13)', '2022-Mar (3.98)'
|
|
987
987
|
* ```
|
|
@@ -998,7 +998,7 @@ module.exports.percentile_99 = function percentile(collection, accessor) {
|
|
|
998
998
|
*
|
|
999
999
|
* //-- bottom 5 values
|
|
1000
1000
|
* utils.aggregate.topValues(collection, 5, null, '');
|
|
1001
|
-
* //
|
|
1001
|
+
* // [0.87, 2.56, 2.68, 3.58, 3.62]
|
|
1002
1002
|
* ```
|
|
1003
1003
|
*
|
|
1004
1004
|
* @param {Array} collection - Collection of values we want to get the top values from
|
package/src/array.js
CHANGED
|
@@ -63,18 +63,16 @@ const ArrayUtils = module.exports;
|
|
|
63
63
|
* @type {Function}
|
|
64
64
|
* @example
|
|
65
65
|
*
|
|
66
|
-
* [3,5,1,2,4].sort(utils.
|
|
67
|
-
* //
|
|
68
|
-
* [1,2,3,4,5]
|
|
66
|
+
* [3,5,1,2,4].sort(utils.array.SIMPLE_ASCENDING)
|
|
67
|
+
* // [1,2,3,4,5]
|
|
69
68
|
*/
|
|
70
69
|
module.exports.SORT_ASCENDING = (a, b) => a === b ? 0 : a > b ? 1 : -1;
|
|
71
70
|
|
|
72
71
|
/**
|
|
73
72
|
* Simple descending sort function
|
|
74
73
|
* @example
|
|
75
|
-
* [3,5,1,2,4].sort(utils.
|
|
76
|
-
* //
|
|
77
|
-
* [5,4,3,2,1]
|
|
74
|
+
* [3,5,1,2,4].sort(utils.array.SORT_DESCENDING)
|
|
75
|
+
* // [5,4,3,2,1]
|
|
78
76
|
* @type {Function}
|
|
79
77
|
*/
|
|
80
78
|
module.exports.SORT_DESCENDING = (a, b) => a === b ? 0 : a > b ? -1 : 1;
|
|
@@ -83,16 +81,17 @@ module.exports.SORT_DESCENDING = (a, b) => a === b ? 0 : a > b ? -1 : 1;
|
|
|
83
81
|
* Creates a sort function based on fields of an object.
|
|
84
82
|
*
|
|
85
83
|
* ```
|
|
86
|
-
*
|
|
84
|
+
* [{score: 200, name: 'jane'}, {score: 300, name: 'john'}, {score: 300, name: 'jonny'}];
|
|
87
85
|
* // sort by score descending, and then by name ascending
|
|
88
|
-
* sampleData.sort(utils.array.createSort('-score','name'))
|
|
86
|
+
* sampleData.sort(utils.array.createSort('-score','name'));
|
|
87
|
+
* // [{ score: 300, name: 'john' }, { score: 300, name: 'jonny' },{ score: 200, name: 'jane' }]
|
|
89
88
|
* ```
|
|
90
89
|
*
|
|
91
90
|
* @example
|
|
92
91
|
*
|
|
93
92
|
* sampleData = [{i:4}, {v:2}, {v:1}, {v:3}];
|
|
94
93
|
* sortedData = sampleData.sort(
|
|
95
|
-
* utils.createSort('-v')
|
|
94
|
+
* utils.array.createSort('-v')
|
|
96
95
|
* );
|
|
97
96
|
* // [{v:4}, {v:3}, {v:2}, {v:1}]
|
|
98
97
|
*
|
|
@@ -427,16 +426,16 @@ module.exports.applyArrayValue = function applyArrayValue(collection, path, valu
|
|
|
427
426
|
* cities = utils.object.extractObjectProperty('city');
|
|
428
427
|
* // ['Seattle', 'New York', 'Chicago'];
|
|
429
428
|
*
|
|
430
|
-
* //--
|
|
431
|
-
* geocodedCities =
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
* // { city: 'Chicago', state: 'IL', country: 'USA' }]
|
|
429
|
+
* //-- get a separate dataset that needs to be joined, like geocodeCity(cities);
|
|
430
|
+
* geocodedCities = [{ city: 'Seattle', state: 'WA', country: 'USA' },
|
|
431
|
+
* { city: 'New York', state: 'NY', country: 'USA' },
|
|
432
|
+
* { city: 'Chicago', state: 'IL', country: 'USA' }];
|
|
435
433
|
*
|
|
436
|
-
* utils.applyArrayValues(weather, 'geo', geocodedCities);
|
|
434
|
+
* utils.array.applyArrayValues(weather, 'geo', geocodedCities);
|
|
437
435
|
* // [{ id: 1, city: 'Seattle', month: 'Aug', precip: 0.87, geo: { city: 'Seattle', state: 'WA', country: 'USA' } },
|
|
438
436
|
* // { id: 3, city: 'New York', month: 'Apr', precip: 3.94, geo: { city: 'New York', state: 'NY', country: 'USA' } },
|
|
439
437
|
* // { id: 6, city: 'Chicago', month: 'Apr', precip: 3.62, geo: { city: 'Chicago', state: 'IL', country: 'USA' } }];
|
|
438
|
+
* ```
|
|
440
439
|
*
|
|
441
440
|
* Note that traditional [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
|
|
442
441
|
* works best for if you are working with objects completely in memory.
|
|
@@ -505,14 +504,14 @@ module.exports.size = function size(length, defaultValue) {
|
|
|
505
504
|
*
|
|
506
505
|
* utils.array.arange(10, 1)
|
|
507
506
|
* .map((val) => `item ${val}`);
|
|
508
|
-
*
|
|
509
|
-
* [
|
|
510
|
-
* 'item 1', 'item 2',
|
|
511
|
-
* 'item 3', 'item 4',
|
|
512
|
-
* 'item 5', 'item 6',
|
|
513
|
-
* 'item 7', 'item 8',
|
|
514
|
-
* 'item 9', 'item 10'
|
|
515
|
-
* ]
|
|
507
|
+
*
|
|
508
|
+
* // [
|
|
509
|
+
* // 'item 1', 'item 2',
|
|
510
|
+
* // 'item 3', 'item 4',
|
|
511
|
+
* // 'item 5', 'item 6',
|
|
512
|
+
* // 'item 7', 'item 8',
|
|
513
|
+
* // 'item 9', 'item 10'
|
|
514
|
+
* // ]
|
|
516
515
|
* @param {Number} length - the number of items toreturn
|
|
517
516
|
* @param {Number} [start=0] - the starting number
|
|
518
517
|
* @param {Number} [step=1] - the number to increment for each step
|
|
@@ -573,13 +572,13 @@ module.exports.arrayLength2d = function arrayLength2d(targetArray) {
|
|
|
573
572
|
* @example
|
|
574
573
|
*
|
|
575
574
|
* baseArray = [ 0, 1, 2, 3, 4 ];
|
|
576
|
-
* utils.array.transpose(utils.array.arrange(5))
|
|
577
|
-
*
|
|
578
|
-
* [ [ 0 ],
|
|
579
|
-
* [ 1 ],
|
|
580
|
-
* [ 2 ],
|
|
581
|
-
* [ 3 ],
|
|
582
|
-
* [ 4 ] ]
|
|
575
|
+
* utils.array.transpose(utils.array.arrange(5));
|
|
576
|
+
*
|
|
577
|
+
* // [ [ 0 ],
|
|
578
|
+
* // [ 1 ],
|
|
579
|
+
* // [ 2 ],
|
|
580
|
+
* // [ 3 ],
|
|
581
|
+
* // [ 4 ] ]
|
|
583
582
|
*/
|
|
584
583
|
module.exports.transpose = function transpose(matrix) {
|
|
585
584
|
//-- fast fail
|
|
@@ -618,22 +617,22 @@ module.exports.transpose = function transpose(matrix) {
|
|
|
618
617
|
* @example
|
|
619
618
|
*
|
|
620
619
|
* baseArray = utils.array.arrange(12);
|
|
621
|
-
* [
|
|
622
|
-
* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
|
|
623
|
-
* ]
|
|
620
|
+
* // [
|
|
621
|
+
* // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
|
|
622
|
+
* // ]
|
|
624
623
|
*
|
|
625
624
|
* //-- reshape the 1d array based on 3 columns
|
|
626
625
|
* newArray = utils.array.reshape(baseArray, 3)
|
|
627
|
-
* [ [ 0, 1, 2 ],
|
|
628
|
-
* [ 3, 4, 5 ],
|
|
629
|
-
* [ 6, 7, 8 ],
|
|
630
|
-
* [ 9, 10, 11 ] ];
|
|
626
|
+
* // [ [ 0, 1, 2 ],
|
|
627
|
+
* // [ 3, 4, 5 ],
|
|
628
|
+
* // [ 6, 7, 8 ],
|
|
629
|
+
* // [ 9, 10, 11 ] ];
|
|
631
630
|
*
|
|
632
631
|
* //-- now reshape the 4x3 array to 3x4
|
|
633
632
|
* utils.array.reshape(newArray, 4);
|
|
634
|
-
* [ [ 0, 1, 2, 3 ],
|
|
635
|
-
* [ 4, 5, 6, 7 ],
|
|
636
|
-
* [ 8, 9, 10, 11 ] ]
|
|
633
|
+
* // [ [ 0, 1, 2, 3 ],
|
|
634
|
+
* // [ 4, 5, 6, 7 ],
|
|
635
|
+
* // [ 8, 9, 10, 11 ] ]
|
|
637
636
|
*/
|
|
638
637
|
module.exports.reshape = function reshape(sourceArray, numColumns) {
|
|
639
638
|
const results = [];
|
|
@@ -710,7 +709,7 @@ module.exports.clone = function clone(target) {
|
|
|
710
709
|
* // [ 3, 0 ], [ 3, 1 ], [ 3, 2 ], [ 3, 3 ]
|
|
711
710
|
* // ]
|
|
712
711
|
*
|
|
713
|
-
*
|
|
712
|
+
* gridPositions.forEach((value, index) => {
|
|
714
713
|
* const [x, y] = gridPositions[index];
|
|
715
714
|
* console.log(`placing ${value} in row:${x}, column:${y}`);
|
|
716
715
|
* });
|
|
@@ -779,41 +778,41 @@ module.exports.arangeMulti = module.exports.arrangeMulti;
|
|
|
779
778
|
* isHeader1('This describes section A'); // false
|
|
780
779
|
*
|
|
781
780
|
* indexedData = utils.array.indexify(data, isHeader1);
|
|
782
|
-
* [
|
|
783
|
-
* { entry: 'Heading', section: [ 0 ], subIndex: 1 },
|
|
784
|
-
* { entry: '# Overview', section: [ 1 ], subIndex: 0 },
|
|
785
|
-
* {
|
|
786
|
-
* entry: 'This entire list is a hierarchy of data.',
|
|
787
|
-
* section: [ 1 ],
|
|
788
|
-
* subIndex: 1
|
|
789
|
-
* },
|
|
790
|
-
* { entry: '# Section A', section: [ 2 ], subIndex: 0 },
|
|
791
|
-
* { entry: 'This describes section A', section: [ 2 ], subIndex: 1 },
|
|
792
|
-
* { entry: '## SubSection 1', section: [ 2 ], subIndex: 2 },
|
|
793
|
-
* {
|
|
794
|
-
* entry: 'With a subsection belonging to Section A',
|
|
795
|
-
* section: [ 2 ],
|
|
796
|
-
* subIndex: 3
|
|
797
|
-
* },
|
|
798
|
-
* { entry: '## SubSection 2', section: [ 2 ], subIndex: 4 },
|
|
799
|
-
* {
|
|
800
|
-
* entry: 'And another subsection sibling to SubSection 1, but also under Section A.',
|
|
801
|
-
* section: [ 2 ],
|
|
802
|
-
* subIndex: 5
|
|
803
|
-
* },
|
|
804
|
-
* { entry: '# Section B', section: [ 3 ], subIndex: 0 },
|
|
805
|
-
* {
|
|
806
|
-
* entry: 'With an entirely unrelated section B, that is sibling to Section A',
|
|
807
|
-
* section: [ 3 ],
|
|
808
|
-
* subIndex: 1
|
|
809
|
-
* },
|
|
810
|
-
* { entry: '## SubSection 1', section: [ 3 ], subIndex: 2 },
|
|
811
|
-
* {
|
|
812
|
-
* entry: 'And another subsection 1, but this time related to Section B.',
|
|
813
|
-
* section: [ 3 ],
|
|
814
|
-
* subIndex: 3
|
|
815
|
-
* }
|
|
816
|
-
* ];
|
|
781
|
+
* // [
|
|
782
|
+
* // { entry: 'Heading', section: [ 0 ], subIndex: 1 },
|
|
783
|
+
* // { entry: '# Overview', section: [ 1 ], subIndex: 0 },
|
|
784
|
+
* // {
|
|
785
|
+
* // entry: 'This entire list is a hierarchy of data.',
|
|
786
|
+
* // section: [ 1 ],
|
|
787
|
+
* // subIndex: 1
|
|
788
|
+
* // },
|
|
789
|
+
* // { entry: '# Section A', section: [ 2 ], subIndex: 0 },
|
|
790
|
+
* // { entry: 'This describes section A', section: [ 2 ], subIndex: 1 },
|
|
791
|
+
* // { entry: '## SubSection 1', section: [ 2 ], subIndex: 2 },
|
|
792
|
+
* // {
|
|
793
|
+
* // entry: 'With a subsection belonging to Section A',
|
|
794
|
+
* // section: [ 2 ],
|
|
795
|
+
* // subIndex: 3
|
|
796
|
+
* // },
|
|
797
|
+
* // { entry: '## SubSection 2', section: [ 2 ], subIndex: 4 },
|
|
798
|
+
* // {
|
|
799
|
+
* // entry: 'And another subsection sibling to SubSection 1, but also under Section A.',
|
|
800
|
+
* // section: [ 2 ],
|
|
801
|
+
* // subIndex: 5
|
|
802
|
+
* // },
|
|
803
|
+
* // { entry: '# Section B', section: [ 3 ], subIndex: 0 },
|
|
804
|
+
* // {
|
|
805
|
+
* // entry: 'With an entirely unrelated section B, that is sibling to Section A',
|
|
806
|
+
* // section: [ 3 ],
|
|
807
|
+
* // subIndex: 1
|
|
808
|
+
* // },
|
|
809
|
+
* // { entry: '## SubSection 1', section: [ 3 ], subIndex: 2 },
|
|
810
|
+
* // {
|
|
811
|
+
* // entry: 'And another subsection 1, but this time related to Section B.',
|
|
812
|
+
* // section: [ 3 ],
|
|
813
|
+
* // subIndex: 3
|
|
814
|
+
* // }
|
|
815
|
+
* // ];
|
|
817
816
|
* ```
|
|
818
817
|
*
|
|
819
818
|
* Note that this only indexes elements by the first header.
|
|
@@ -924,8 +923,8 @@ module.exports.indexify = function indexify(source, ...sectionIndicatorFunctions
|
|
|
924
923
|
* For example, say you got a string formatted like this:
|
|
925
924
|
*
|
|
926
925
|
* ```
|
|
927
|
-
* hardSpacedString =
|
|
928
|
-
* id first_name last_name city email gender ip_address airport_code car_model_year
|
|
926
|
+
* hardSpacedString = '' +
|
|
927
|
+
* `id first_name last_name city email gender ip_address airport_code car_model_year
|
|
929
928
|
* -- ---------- ---------- ----------- ---------------------------- ------ --------------- ------------ --------------
|
|
930
929
|
* 1 Thekla Brokenshaw Chicago tbrokenshaw0@kickstarter.com Female 81.118.170.238 CXI 2003
|
|
931
930
|
* 2 Lexi Dugall New York ldugall1@fc2.com Female 255.140.25.31 LBH 2005
|
|
@@ -976,8 +975,8 @@ module.exports.multiLineSubstr = function multiLineSubstr(target, start, length)
|
|
|
976
975
|
* For example, say you got a string formatted like this:
|
|
977
976
|
*
|
|
978
977
|
* ```
|
|
979
|
-
* hardSpacedString =
|
|
980
|
-
* id first_name last_name city email gender ip_address airport_code car_model_year
|
|
978
|
+
* hardSpacedString = '' +
|
|
979
|
+
* `id first_name last_name city email gender ip_address airport_code car_model_year
|
|
981
980
|
* -- ---------- ---------- ----------- ---------------------------- ------ --------------- ------------ --------------
|
|
982
981
|
* 1 Thekla Brokenshaw Chicago tbrokenshaw0@kickstarter.com Female 81.118.170.238 CXI 2003
|
|
983
982
|
* 2 Lexi Dugall New York ldugall1@fc2.com Female 255.140.25.31 LBH 2005
|
|
@@ -1029,8 +1028,8 @@ module.exports.multiLineSubstring = function multiLineSubstring(target, startPos
|
|
|
1029
1028
|
* For example:
|
|
1030
1029
|
*
|
|
1031
1030
|
* ```
|
|
1032
|
-
* hardSpacedString =
|
|
1033
|
-
* id first_name last_name city email gender ip_address airport_code car_model_year
|
|
1031
|
+
* hardSpacedString = '' +
|
|
1032
|
+
* `id first_name last_name city email gender ip_address airport_code car_model_year
|
|
1034
1033
|
* -- ---------- ---------- ----------- ---------------------------- ------ --------------- ------------ --------------
|
|
1035
1034
|
* 1 Thekla Brokenshaw Chicago tbrokenshaw0@kickstarter.com Female 81.118.170.238 CXI 2003
|
|
1036
1035
|
* 2 Lexi Dugall New York ldugall1@fc2.com Female 255.140.25.31 LBH 2005
|
|
@@ -1072,7 +1071,7 @@ module.exports.multiLineSubstring = function multiLineSubstring(target, startPos
|
|
|
1072
1071
|
* cityStartingCharacter = substrPairs[3][0]; // 25
|
|
1073
1072
|
* cityColumnLength = substrPairs[3][1]; // 12
|
|
1074
1073
|
*
|
|
1075
|
-
* cityData =
|
|
1074
|
+
* cityData = utils.array.multiLineSubstr(hardSpacedString, cityStartingCharacter, cityColumnLength);
|
|
1076
1075
|
* // ['city ', '----------- ', 'Chicago ', 'New York ', 'London ', 'Lainqu ', 'Los Angeles ']
|
|
1077
1076
|
* ```
|
|
1078
1077
|
*
|
|
@@ -1080,18 +1079,18 @@ module.exports.multiLineSubstring = function multiLineSubstring(target, startPos
|
|
|
1080
1079
|
*
|
|
1081
1080
|
* ```
|
|
1082
1081
|
* results = substrPairs.map(
|
|
1083
|
-
* ([startingPos, length]) =>
|
|
1082
|
+
* ([startingPos, length]) => utils.array.multiLineSubstr(hardSpacedString, startingPos, length)
|
|
1084
1083
|
* );
|
|
1085
1084
|
*
|
|
1086
|
-
* [['id ', '-- ', '1 ', '2 ', '3 ', '4 ', '5 '],
|
|
1087
|
-
* ['first_name ', '---------- ', 'Thekla ', 'Lexi ', 'Shawna ', 'Gin...', ...],
|
|
1088
|
-
* ['last_name ', '---------- ', 'Brokenshaw ', 'Dugall ', 'Burghill ', 'Twe...', ...],
|
|
1089
|
-
* ['city ', '----------- ', 'Chicago ', 'New York ', 'London ', ...],
|
|
1090
|
-
* ['email ', '---------------------------- ', 'tbrokenshaw0...', ...],
|
|
1091
|
-
* ['gender ', '------ ', 'Female ', 'Female ', 'Female ', 'Female ', 'Female '],
|
|
1092
|
-
* ['ip_address ', '--------------- ', '81.118.170.238 ', '255.140.25.31 ', ...],
|
|
1093
|
-
* ['airport_code ', '------------ ', 'CXI ', 'LBH ', 'GBA ...', ...],
|
|
1094
|
-
* ['car_model_year', '--------------', '2003 ', '2005 ', '2004 ...', ...]]
|
|
1085
|
+
* // [['id ', '-- ', '1 ', '2 ', '3 ', '4 ', '5 '],
|
|
1086
|
+
* // ['first_name ', '---------- ', 'Thekla ', 'Lexi ', 'Shawna ', 'Gin...', ...],
|
|
1087
|
+
* // ['last_name ', '---------- ', 'Brokenshaw ', 'Dugall ', 'Burghill ', 'Twe...', ...],
|
|
1088
|
+
* // ['city ', '----------- ', 'Chicago ', 'New York ', 'London ', ...],
|
|
1089
|
+
* // ['email ', '---------------------------- ', 'tbrokenshaw0...', ...],
|
|
1090
|
+
* // ['gender ', '------ ', 'Female ', 'Female ', 'Female ', 'Female ', 'Female '],
|
|
1091
|
+
* // ['ip_address ', '--------------- ', '81.118.170.238 ', '255.140.25.31 ', ...],
|
|
1092
|
+
* // ['airport_code ', '------------ ', 'CXI ', 'LBH ', 'GBA ...', ...],
|
|
1093
|
+
* // ['car_model_year', '--------------', '2003 ', '2005 ', '2004 ...', ...]]
|
|
1095
1094
|
* ```
|
|
1096
1095
|
*
|
|
1097
1096
|
* We can then transpose the array to give us the format we might expect (non DataFrame centric)
|
|
@@ -1154,17 +1153,17 @@ module.exports.multiStepReduce = function multiStepReduce(list, fn, initialValue
|
|
|
1154
1153
|
* // [ 3, 11, 11, 12, 29, 7, 16, 13, 15 ];
|
|
1155
1154
|
*
|
|
1156
1155
|
*
|
|
1157
|
-
* results = utils.array.extractFromHardSpacedTable(
|
|
1156
|
+
* results = utils.array.extractFromHardSpacedTable(hardSpacedString, columnWidths);
|
|
1158
1157
|
*
|
|
1159
|
-
* [['id ', '-- ', '1 ', '2 ', '3 ', '4 ', '5 '],
|
|
1160
|
-
* ['first_name ', '---------- ', 'Thekla ', 'Lexi ', 'Shawna ', 'Gin...', ...],
|
|
1161
|
-
* ['last_name ', '---------- ', 'Brokenshaw ', 'Dugall ', 'Burghill ', 'Twe...', ...],
|
|
1162
|
-
* ['city ', '----------- ', 'Chicago ', 'New York ', 'London ', ...],
|
|
1163
|
-
* ['email ', '---------------------------- ', 'tbrokenshaw0...', ...],
|
|
1164
|
-
* ['gender ', '------ ', 'Female ', 'Female ', 'Female ', 'Female ', 'Female '],
|
|
1165
|
-
* ['ip_address ', '--------------- ', '81.118.170.238 ', '255.140.25.31 ', ...],
|
|
1166
|
-
* ['airport_code ', '------------ ', 'CXI ', 'LBH ', 'GBA ...', ...],
|
|
1167
|
-
* ['car_model_year', '--------------', '2003 ', '2005 ', '2004 ...', ...]]
|
|
1158
|
+
* // [['id ', '-- ', '1 ', '2 ', '3 ', '4 ', '5 '],
|
|
1159
|
+
* // ['first_name ', '---------- ', 'Thekla ', 'Lexi ', 'Shawna ', 'Gin...', ...],
|
|
1160
|
+
* // ['last_name ', '---------- ', 'Brokenshaw ', 'Dugall ', 'Burghill ', 'Twe...', ...],
|
|
1161
|
+
* // ['city ', '----------- ', 'Chicago ', 'New York ', 'London ', ...],
|
|
1162
|
+
* // ['email ', '---------------------------- ', 'tbrokenshaw0...', ...],
|
|
1163
|
+
* // ['gender ', '------ ', 'Female ', 'Female ', 'Female ', 'Female ', 'Female '],
|
|
1164
|
+
* // ['ip_address ', '--------------- ', '81.118.170.238 ', '255.140.25.31 ', ...],
|
|
1165
|
+
* // ['airport_code ', '------------ ', 'CXI ', 'LBH ', 'GBA ...', ...],
|
|
1166
|
+
* // ['car_model_year', '--------------', '2003 ', '2005 ', '2004 ...', ...]]
|
|
1168
1167
|
* ```
|
|
1169
1168
|
*
|
|
1170
1169
|
* We can then transpose the array to give us the format we might expect (non DataFrame centric)
|
|
@@ -1458,9 +1457,11 @@ module.exports.asyncWaitAndChain = (seconds, fn, rows) => {
|
|
|
1458
1457
|
* ```
|
|
1459
1458
|
* categoryValues = ['rock', 'paper', 'scissors'];
|
|
1460
1459
|
*
|
|
1460
|
+
* //-- resizes an array to be shorter - truncating
|
|
1461
1461
|
* utils.array.resize(categoryValues, 2); // ['rock', 'paper']
|
|
1462
|
-
*
|
|
1463
|
-
*
|
|
1462
|
+
*
|
|
1463
|
+
* //-- resizes an array to be longer - filling with undefined
|
|
1464
|
+
* utils.array.resize(categoryValues, 7); // ['rock', 'paper', 'scissors', undefined, undefined, undefined, undefined];
|
|
1464
1465
|
* ```
|
|
1465
1466
|
*
|
|
1466
1467
|
* @param {Array} sourceList - array of values
|
package/src/chain.js
CHANGED
|
@@ -87,7 +87,9 @@
|
|
|
87
87
|
* ```
|
|
88
88
|
* results = [{ userId: 'abc123' }, { userId: 'xyz987' }];
|
|
89
89
|
*
|
|
90
|
-
*
|
|
90
|
+
* // joining to existing collection of users
|
|
91
|
+
*
|
|
92
|
+
* activeUsers = utils.chain(results)
|
|
91
93
|
* .chainMap((record) => users.get(record.userId))
|
|
92
94
|
* .chainForEach(record => record.status = 'active')
|
|
93
95
|
* .chain(records => d3.csv.format(records))
|
|
@@ -104,7 +106,7 @@
|
|
|
104
106
|
* + 'and%20I%20quote%20the%20fights%0AHistorical%0AFrom%20Marath'
|
|
105
107
|
* + 'on%20to%20Waterloo%2C%20in%20order%20categorical';
|
|
106
108
|
*
|
|
107
|
-
* chain(badStr)
|
|
109
|
+
* utils.chain(badStr)
|
|
108
110
|
* .chain(decodeURIComponent)
|
|
109
111
|
* .chain(v => v.split('\n'))
|
|
110
112
|
* // .debug() // check the values along the way
|
|
@@ -190,7 +192,7 @@ class ChainContainer {
|
|
|
190
192
|
* value = 2;
|
|
191
193
|
* plus2 = (value) => value + 2;
|
|
192
194
|
*
|
|
193
|
-
* chain(value)
|
|
195
|
+
* utils.chain(value)
|
|
194
196
|
* .chain(plus2) // 2 + 2
|
|
195
197
|
* .chain(plus2) // 4 + 2
|
|
196
198
|
* .debug()
|
|
@@ -210,7 +212,7 @@ class ChainContainer {
|
|
|
210
212
|
* + 'and%20I%20quote%20the%20fights%0AHistorical%0AFrom%20Marath'
|
|
211
213
|
* + 'on%20to%20Waterloo%2C%20in%20order%20categorical';
|
|
212
214
|
*
|
|
213
|
-
* chain(badStr)
|
|
215
|
+
* utils.chain(badStr)
|
|
214
216
|
* .chain(decodeURIComponent)
|
|
215
217
|
* .chain(v => v.split('\n'))
|
|
216
218
|
* // .debug() // check the values along the way
|
|
@@ -338,7 +340,7 @@ class ChainContainer {
|
|
|
338
340
|
* filterOdd(2); // [2]
|
|
339
341
|
* filterOdd(1); // []
|
|
340
342
|
*
|
|
341
|
-
* chain([1, 2, 3, 4, 5])
|
|
343
|
+
* utils.chain([1, 2, 3, 4, 5])
|
|
342
344
|
* .chainFlatMap(filterOdd)
|
|
343
345
|
* .close();
|
|
344
346
|
*
|
|
@@ -359,7 +361,7 @@ class ChainContainer {
|
|
|
359
361
|
* Assuming that value is an array, this maps fn to filter the results in the array.
|
|
360
362
|
*
|
|
361
363
|
* ```
|
|
362
|
-
* chain([1,2,3,4])
|
|
364
|
+
* utils.chain([1,2,3,4])
|
|
363
365
|
* .chainFilter((value) => value < 3)
|
|
364
366
|
* .close();
|
|
365
367
|
* // [1, 2]
|
|
@@ -412,7 +414,7 @@ class ChainContainer {
|
|
|
412
414
|
* value = 2;
|
|
413
415
|
* plus2 = (value) => value + 2;
|
|
414
416
|
*
|
|
415
|
-
* chain(value)
|
|
417
|
+
* utils.chain(value)
|
|
416
418
|
* .chain(plus2) // 2 + 2
|
|
417
419
|
* .chain(plus2) // 4 + 2
|
|
418
420
|
* .debug()
|
|
@@ -443,7 +445,7 @@ class ChainContainer {
|
|
|
443
445
|
* ```
|
|
444
446
|
* results = [{ userId: 'abc123' }, { userId: 'xyz987' }];
|
|
445
447
|
*
|
|
446
|
-
* activeUsers = chain(results)
|
|
448
|
+
* activeUsers = utils.chain(results)
|
|
447
449
|
* .chainMap((record) => users.get(record.userId))
|
|
448
450
|
* .chainForEach(record => record.status = 'active')
|
|
449
451
|
* .chain(records => d3.csv.format(records))
|
|
@@ -472,7 +474,7 @@ class ChainContainer {
|
|
|
472
474
|
* throw Error('Custom Error');
|
|
473
475
|
* };
|
|
474
476
|
*
|
|
475
|
-
* chain(2)
|
|
477
|
+
* utils.chain(2)
|
|
476
478
|
* .errorHandler(flipSwitch)
|
|
477
479
|
* .chain((value) => value + 2)
|
|
478
480
|
* .chain(throwError);
|
|
@@ -642,7 +644,7 @@ class ChainContainer {
|
|
|
642
644
|
* Very helpful for taking values and then progressively working on them,
|
|
643
645
|
* instead of continually wrapping deeper in method calls.
|
|
644
646
|
*
|
|
645
|
-
* Calling `chain(3)` - gives an object you can then chain calls against:
|
|
647
|
+
* Calling `utils.chain(3)` - gives an object you can then chain calls against:
|
|
646
648
|
*
|
|
647
649
|
* * {@link ChainContainer#close|.close()} - gets the value of the current chain
|
|
648
650
|
* * {@link ChainContainer#chain|.chain(function)} - where it is passed the value, and returns a new Chain with that value.
|
|
@@ -720,7 +722,7 @@ class ChainContainer {
|
|
|
720
722
|
* ```
|
|
721
723
|
* results = [{ userId: 'abc123' }, { userId: 'xyz987' }];
|
|
722
724
|
*
|
|
723
|
-
* activeUsers = chain(results)
|
|
725
|
+
* activeUsers = utils.chain(results)
|
|
724
726
|
* .chainMap((record) => users.get(record.userId))
|
|
725
727
|
* .chainForEach(record => record.status = 'active')
|
|
726
728
|
* .chain(records => d3.csv.format(records))
|
|
@@ -737,7 +739,7 @@ class ChainContainer {
|
|
|
737
739
|
* + 'and%20I%20quote%20the%20fights%0AHistorical%0AFrom%20Marath'
|
|
738
740
|
* + 'on%20to%20Waterloo%2C%20in%20order%20categorical';
|
|
739
741
|
*
|
|
740
|
-
* chain(badStr)
|
|
742
|
+
* utils.chain(badStr)
|
|
741
743
|
* .chain(decodeURIComponent)
|
|
742
744
|
* .chain(v => v.split('\n'))
|
|
743
745
|
* // .debug() // check the values along the way
|