jupyter-ijavascript-utils 1.37.0 → 1.38.0
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/DOCS.md +2 -0
- package/Dockerfile +1 -1
- package/README.md +2 -0
- package/package.json +2 -1
- package/src/format.js +19 -0
- package/src/object.js +49 -43
- package/src/plantuml.js +1 -1
package/DOCS.md
CHANGED
|
@@ -75,6 +75,8 @@ Give it a try here:
|
|
|
75
75
|
|
|
76
76
|
## What's New
|
|
77
77
|
|
|
78
|
+
* 1.38 - {@link module:array.extract|array.extract} / {@link module:array.apply|array.apply} and {@link module:object.extract|object.extract} / {@link module:object.apply|object.apply}
|
|
79
|
+
* 1.37 - {@link module:format.replaceString|format.replaceString} as convenience for replacing only a single string.
|
|
78
80
|
* 1.36 - {@link module:format.replaceStrings|format.replaceStrings} to allow for replacement dictionaries and tuplets
|
|
79
81
|
* 1.35 - {@link module:object.extractObjectProperties|extractObjectProperties} / {@link module:object.extractObjectProperty|extractObjectProperty} - to do horizontal transposes on objects
|
|
80
82
|
* 1.34 - {@link module:format.mapArrayDomain|format.mapArrayDomain} and add notes in the header of {@link module:random|random} on using non-uniform distributions.
|
package/Dockerfile
CHANGED
package/README.md
CHANGED
|
@@ -55,6 +55,8 @@ This is not intended to be the only way to accomplish many of these tasks, and a
|
|
|
55
55
|
|
|
56
56
|
# What's New
|
|
57
57
|
|
|
58
|
+
* 1.38 - array.extract / array.apply and object.extract / object.apply
|
|
59
|
+
* 1.37 - {@link module:format.replaceString|format.replaceString} as convenience for replacing only a single string.
|
|
58
60
|
* 1.36 - replaceStrings to allow for replacement dictionaries and tuplets
|
|
59
61
|
* 1.35 - object.extractObjectProperties / object.extractObjectProperty - to do horizontal transposes on objects
|
|
60
62
|
* 1.34 - format.mapArrayDomain and add notes in to random on using non-uniform distributions.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jupyter-ijavascript-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.38.0",
|
|
4
4
|
"description": "Utilities for working with iJavaScript - a Jupyter Kernel",
|
|
5
5
|
"homepage": "https://jupyter-ijavascript-utils.onrender.com/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"test:debug": "TZ=UTC node --inspect-brk node_modules/jest/bin/jest.js --runInBand",
|
|
18
18
|
"test:coverage": "TZ=UTC jest src --collectCoverage",
|
|
19
19
|
"test:watch:coverage": "TZ=UTC jest src --watch --collectCoverage",
|
|
20
|
+
"doc:taffy": "npm install taffydb && npm run doc",
|
|
20
21
|
"docs": "npm run doc",
|
|
21
22
|
"doc": "npm run prep:docdash && node_modules/.bin/jsdoc -c ./jsdoc.json -u ./tutorials ./DOCS.md",
|
|
22
23
|
"prep:docdash": "cp docResources/docdash/layout.tmpl node_modules/docdash/tmpl/layout.tmpl && rm -rf docResources/notebooks/node_modules",
|
package/src/format.js
CHANGED
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
* * {@link module:format.consoleLines|format.consoleLines(...)} - same as limit lines, only console.logs the string out.
|
|
21
21
|
* * {@link module:format.wordWrap|format.wordWrap(str, options)} - breaks apart string by line length
|
|
22
22
|
* * {@link module:format.lineCount|format.lineCount(str, options)} - counts the number of lines in a string
|
|
23
|
+
* * Replacing values in Strings
|
|
24
|
+
* * {@link module:format.replaceString|format.replaceString(string, stringTupletsOrMap)} - applies replace from a collection of [matcher, replacement] tuplets or map based on key-> values
|
|
25
|
+
* * {@link module:format.replaceStrings|format.replaceStrings(stringsArray, stringTupletsOrMap)} - applies replaceString on an array of values
|
|
23
26
|
* * Formatting Time
|
|
24
27
|
* * {@link module:format.millisecondDuration|format.millisecondDuration}
|
|
25
28
|
* * Mapping Values
|
|
@@ -1214,6 +1217,7 @@ module.exports.lineCount = function lineCount(str, newlineCharacter = '\n') {
|
|
|
1214
1217
|
* // 'and jill came tumbling after' ]
|
|
1215
1218
|
*
|
|
1216
1219
|
* //-- or use tuplets of [find, replace] with regular expressions
|
|
1220
|
+
* //-- and strings not in tuplets are simply removed.
|
|
1217
1221
|
* replaceValues = [['jack', 'john'], [/\s+jill/i, ' ringo'], ' down'];
|
|
1218
1222
|
* utils.format.replaceStrings(targetStrings, replaceValues);
|
|
1219
1223
|
* expected = [
|
|
@@ -1267,3 +1271,18 @@ module.exports.replaceStrings = function replaceStrings(targetStr, stringTuplets
|
|
|
1267
1271
|
? result
|
|
1268
1272
|
: result.replace(replaceSearch, replaceWith), stringToClean));
|
|
1269
1273
|
};
|
|
1274
|
+
|
|
1275
|
+
/**
|
|
1276
|
+
* Conveience function for calling {@link module:format.replaceStrings|format.replaceStrings} -
|
|
1277
|
+
* giving and receiving a single value (instead of an array of values).
|
|
1278
|
+
* @param {String} targetStr - A Single string to replace values on.
|
|
1279
|
+
* @param {Array|Map<string|RegExp,string>} stringTupletsOrMap - [[search, replace]] or Map<String|RegExp,String>
|
|
1280
|
+
* @returns {string} - the targetStr with the values replaced
|
|
1281
|
+
* @see {@link module:format.replaceStrings}
|
|
1282
|
+
*/
|
|
1283
|
+
module.exports.replaceString = function replaceString(targetStr, stringTupletsOrMap) {
|
|
1284
|
+
if (Array.isArray(targetStr)) {
|
|
1285
|
+
throw Error('replaceString(targetStr, stringTupletsOrMap): targetStr was sent an array - please use replaceStrings instead');
|
|
1286
|
+
}
|
|
1287
|
+
return FormatUtils.replaceStrings([targetStr], stringTupletsOrMap)[0];
|
|
1288
|
+
};
|
package/src/object.js
CHANGED
|
@@ -498,46 +498,6 @@ module.exports.filterObjectProperties = function filterObjectProperties(list, pr
|
|
|
498
498
|
});
|
|
499
499
|
};
|
|
500
500
|
|
|
501
|
-
/**
|
|
502
|
-
* Options for fetching object properties
|
|
503
|
-
* @typedef {Object} FetchObjectOptions
|
|
504
|
-
* @property {Boolean} safeAccess - whether to safely access, even if the path cannot be found
|
|
505
|
-
* @property {Boolean} append - whether to only return the properties (default) or append
|
|
506
|
-
*/
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* Fetches multiple properties from an object or list of objects.
|
|
510
|
-
* @param {Object | Object[]} list - collection of objects to reduce
|
|
511
|
-
* @param {Map<String,any>} propertyNames - Object with the keys as the properties
|
|
512
|
-
* and the values using dot notation to access related records and properties
|
|
513
|
-
* (ex: {parentName: 'somePropertyObject.parent.parent.name', childName: 'child.Name'})
|
|
514
|
-
* @param {FetchObjectOptions} options - {@link module:object~FetchObjectOptions|See FetchObjectOptions}
|
|
515
|
-
* @returns {Object[]} - objects with the properties resolved
|
|
516
|
-
* (ex: {parentname, childName, etc.})
|
|
517
|
-
*/
|
|
518
|
-
module.exports.fetchObjectProperties = function fetchObjectProperties(list, propertyNames, options = {}) {
|
|
519
|
-
const {
|
|
520
|
-
//-- whether to safely access even if object path cannot be found
|
|
521
|
-
safeAccess = false,
|
|
522
|
-
|
|
523
|
-
//-- whether to fetch only those specific properties, or append to the object
|
|
524
|
-
append = false
|
|
525
|
-
} = options;
|
|
526
|
-
|
|
527
|
-
if (!list) return [];
|
|
528
|
-
const targetList = Array.isArray(list) ? list : [list];
|
|
529
|
-
|
|
530
|
-
const props = Object.getOwnPropertyNames(propertyNames);
|
|
531
|
-
|
|
532
|
-
return targetList.map((obj) => {
|
|
533
|
-
const result = append ? { ...obj } : {};
|
|
534
|
-
props.forEach((prop) => {
|
|
535
|
-
result[prop] = ObjectUtils.fetchObjectProperty(obj, propertyNames[prop], safeAccess);
|
|
536
|
-
});
|
|
537
|
-
return result;
|
|
538
|
-
});
|
|
539
|
-
};
|
|
540
|
-
|
|
541
501
|
/**
|
|
542
502
|
* Similar to a transpose, this finds all the values of a particular property
|
|
543
503
|
* within a list of objects.
|
|
@@ -632,6 +592,42 @@ module.exports.extractObjectProperties = function extractObjectProperties(list,
|
|
|
632
592
|
return results;
|
|
633
593
|
};
|
|
634
594
|
|
|
595
|
+
/**
|
|
596
|
+
* Options for fetching object properties
|
|
597
|
+
* @typedef {Object} FetchObjectOptions
|
|
598
|
+
* @property {Boolean} safeAccess - whether to safely access, even if the path cannot be found
|
|
599
|
+
*/
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Fetches multiple properties from an object or list of objects.
|
|
603
|
+
* @param {Object | Object[]} list - collection of objects to reduce
|
|
604
|
+
* @param {Map<String,any>} propertyNames - Object with the keys as the properties
|
|
605
|
+
* and the values using dot notation to access related records and properties
|
|
606
|
+
* (ex: {parentName: 'somePropertyObject.parent.parent.name', childName: 'child.Name'})
|
|
607
|
+
* @param {FetchObjectOptions} options - {@link module:object~FetchObjectOptions|See FetchObjectOptions}
|
|
608
|
+
* @returns {Object[]} - objects with the properties resolved
|
|
609
|
+
* (ex: {parentname, childName, etc.})
|
|
610
|
+
*/
|
|
611
|
+
module.exports.fetchObjectProperties = function fetchObjectProperties(list, propertyNames, options = {}) {
|
|
612
|
+
if (!list) return [];
|
|
613
|
+
const targetList = Array.isArray(list) ? list : [list];
|
|
614
|
+
|
|
615
|
+
const {
|
|
616
|
+
//-- whether to fetch only those specific properties, or append to the object
|
|
617
|
+
append = false
|
|
618
|
+
} = options;
|
|
619
|
+
|
|
620
|
+
const props = Object.getOwnPropertyNames(propertyNames);
|
|
621
|
+
|
|
622
|
+
return targetList.map((obj) => {
|
|
623
|
+
const result = append ? { ...obj } : {};
|
|
624
|
+
props.forEach((prop) => {
|
|
625
|
+
result[prop] = ObjectUtils.fetchObjectProperty(obj, propertyNames[prop], options);
|
|
626
|
+
});
|
|
627
|
+
return result;
|
|
628
|
+
});
|
|
629
|
+
};
|
|
630
|
+
|
|
635
631
|
/**
|
|
636
632
|
* Accesses a property using a string
|
|
637
633
|
* @param {Object} obj - object to access the properties on
|
|
@@ -640,15 +636,25 @@ module.exports.extractObjectProperties = function extractObjectProperties(list,
|
|
|
640
636
|
* @param {FetchObjectOptions} options - {@link module:object~FetchObjectOptions|See FetchObjectOptions}
|
|
641
637
|
* @returns {any} - the value accessed at the end ofthe property chain
|
|
642
638
|
*/
|
|
643
|
-
module.exports.fetchObjectProperty = function fetchObjectProperty(obj, propertyAccess,
|
|
639
|
+
module.exports.fetchObjectProperty = function fetchObjectProperty(obj, propertyAccess, options = {}) {
|
|
644
640
|
if (!obj || !propertyAccess) return null;
|
|
641
|
+
const {
|
|
642
|
+
//-- whether to safely access even if object path cannot be found
|
|
643
|
+
safeAccess = false
|
|
644
|
+
} = options;
|
|
645
645
|
|
|
646
646
|
//-- @TODO - should we be safe or support elvis operators?
|
|
647
647
|
return propertyAccess.split('.')
|
|
648
648
|
.reduce((currentVal, prop) => {
|
|
649
|
+
let isElvis = false;
|
|
650
|
+
let cleanProp = prop;
|
|
651
|
+
if (prop && prop.length > 0 && prop[0] === '?') {
|
|
652
|
+
isElvis = true;
|
|
653
|
+
cleanProp = prop.slice(1);
|
|
654
|
+
}
|
|
649
655
|
if (currentVal) {
|
|
650
|
-
return currentVal[
|
|
651
|
-
} else if (safeAccess ||
|
|
656
|
+
return currentVal[cleanProp];
|
|
657
|
+
} else if (safeAccess || isElvis) {
|
|
652
658
|
return null;
|
|
653
659
|
}
|
|
654
660
|
throw Error(`Invalid property ${propertyAccess} [${prop}] does not exist - safeAccess:${safeAccess}`);
|
package/src/plantuml.js
CHANGED
|
@@ -214,7 +214,7 @@ module.exports.render = function render(plantUMLText, plantUMLOptions) {
|
|
|
214
214
|
const targetURL = this.generateURL(plantUMLText, plantUMLOptions);
|
|
215
215
|
if (showURL || debug) console.log(`url:${targetURL}`);
|
|
216
216
|
|
|
217
|
-
const result = await fetch(targetURL);
|
|
217
|
+
const result = await global.fetch(targetURL);
|
|
218
218
|
|
|
219
219
|
if (format === 'png') {
|
|
220
220
|
const buf = await result.buffer();
|