jupyter-ijavascript-utils 1.12.0 → 1.12.2
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/README.md +1 -1
- package/package.json +1 -1
- package/src/TableGenerator.js +42 -21
- package/src/datasets.js +2 -2
- package/src/file.js +1 -1
- package/src/ijs.js +2 -0
- package/src/leaflet.js +2 -0
- package/src/object.js +8 -3
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</a>
|
|
8
8
|
<img src="https://img.shields.io/badge/Coverage-98-green" />
|
|
9
9
|
<a href="https://github.com/paulroth3d/jupyter-ijavascript-utils" alt="npm">
|
|
10
|
-
<img src="https://img.shields.io/badge/npm-%5E1.12
|
|
10
|
+
<img src="https://img.shields.io/badge/npm-%5E1.12-red" />
|
|
11
11
|
</a>
|
|
12
12
|
</p>
|
|
13
13
|
|
package/package.json
CHANGED
package/src/TableGenerator.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* eslint-disable
|
|
2
2
|
prefer-template,
|
|
3
3
|
function-paren-newline,
|
|
4
|
-
no-unused-vars,
|
|
5
4
|
implicit-arrow-linebreak,
|
|
6
|
-
|
|
5
|
+
arrow-body-style
|
|
7
6
|
*/
|
|
8
7
|
|
|
9
8
|
//-- TODO: review stringbuilder for large datasets
|
|
@@ -355,7 +354,6 @@ class TableGenerator {
|
|
|
355
354
|
return this;
|
|
356
355
|
}
|
|
357
356
|
|
|
358
|
-
const fnMap = new Map();
|
|
359
357
|
const augmentKeys = Object.getOwnPropertyNames(obj);
|
|
360
358
|
|
|
361
359
|
augmentKeys.forEach((key) => {
|
|
@@ -421,7 +419,7 @@ class TableGenerator {
|
|
|
421
419
|
let cleanCSS = '';
|
|
422
420
|
|
|
423
421
|
if (borderCSS === true) {
|
|
424
|
-
cleanCSS = 'border: 1px solid #
|
|
422
|
+
cleanCSS = 'border: 1px solid #aaa';
|
|
425
423
|
} else if (borderCSS) {
|
|
426
424
|
cleanCSS = `border: ${borderCSS}`;
|
|
427
425
|
}
|
|
@@ -1000,6 +998,8 @@ class TableGenerator {
|
|
|
1000
998
|
* @private
|
|
1001
999
|
*/
|
|
1002
1000
|
prepare() {
|
|
1001
|
+
//-- data should ALWAYS be set to a valid array, but added in case
|
|
1002
|
+
/* istanbul ignore next */
|
|
1003
1003
|
let cleanCollection = this.#data || [];
|
|
1004
1004
|
if (this.#sortFn) {
|
|
1005
1005
|
cleanCollection = cleanCollection.sort(this.#sortFn);
|
|
@@ -1091,29 +1091,48 @@ class TableGenerator {
|
|
|
1091
1091
|
.join('\n\t')
|
|
1092
1092
|
+ '\n</tr>\n';
|
|
1093
1093
|
|
|
1094
|
+
//-- todo - investigate shadow root so css only applies to table
|
|
1095
|
+
const printInlineCSS = (...cssStyles) => {
|
|
1096
|
+
const cleanCSS = cssStyles
|
|
1097
|
+
.filter((style) => style ? true : false);
|
|
1098
|
+
|
|
1099
|
+
//-- short circuit if empty
|
|
1100
|
+
if (cleanCSS.length < 1) {
|
|
1101
|
+
return '';
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
const cssContents = cleanCSS
|
|
1105
|
+
.map((style) => style.trim())
|
|
1106
|
+
.map((style) => style.endsWith(';') ? style : `${style};`)
|
|
1107
|
+
.join(' ');
|
|
1108
|
+
|
|
1109
|
+
return `style="${cssContents}"`;
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1094
1112
|
const printBody = (collection) => collection
|
|
1095
1113
|
.map((dataRow, rowIndex) => {
|
|
1096
1114
|
const record = this.#data[rowIndex];
|
|
1097
|
-
const rowStyle = !styleRowFn ? null : styleRowFn({ rowIndex, row: dataRow, record });
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
+ '>\n\t'
|
|
1115
|
+
const rowStyle = !styleRowFn ? null : styleRowFn({ rowIndex, row: dataRow, record }) || '';
|
|
1116
|
+
|
|
1117
|
+
return `<tr ${printInlineCSS(rowStyle)}>\n\t`
|
|
1101
1118
|
+ dataRow.map((value, columnIndex) => {
|
|
1102
|
-
//--
|
|
1103
|
-
const cellStyle = !styleCellFn
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1119
|
+
//-- style for the cell
|
|
1120
|
+
const cellStyle = !styleCellFn ? '' : styleCellFn({ value, columnIndex, rowIndex, row: dataRow, record });
|
|
1121
|
+
|
|
1122
|
+
return `<td ${
|
|
1123
|
+
printInlineCSS(
|
|
1124
|
+
borderCSS,
|
|
1125
|
+
//-- could be inline, but not as clear
|
|
1126
|
+
cellStyle
|
|
1127
|
+
)
|
|
1128
|
+
}>${
|
|
1129
|
+
cleanFn(value, printOptions)
|
|
1130
|
+
}</td>`;
|
|
1109
1131
|
}).join('\n\t')
|
|
1110
1132
|
+ '\n</tr>';
|
|
1111
1133
|
}).join('\n');
|
|
1112
1134
|
|
|
1113
|
-
const tableResults =
|
|
1114
|
-
+ 'cellspacing="0px" '
|
|
1115
|
-
+ (!styleTable ? '' : `style="${styleTable}"`)
|
|
1116
|
-
+ '>'
|
|
1135
|
+
const tableResults = `<table cellspacing="0px" ${printInlineCSS(styleTable)}>`
|
|
1117
1136
|
+ printHeader(results.headers, '')
|
|
1118
1137
|
+ printBody(results.data)
|
|
1119
1138
|
+ '\n</table>';
|
|
@@ -1131,7 +1150,9 @@ class TableGenerator {
|
|
|
1131
1150
|
align = true
|
|
1132
1151
|
} = options || {};
|
|
1133
1152
|
|
|
1134
|
-
|
|
1153
|
+
//-- review style options for markdown
|
|
1154
|
+
// const styleCellFn = this.#styleCell;
|
|
1155
|
+
|
|
1135
1156
|
const printOptions = this.#printOptions;
|
|
1136
1157
|
const cleanFn = printValue;
|
|
1137
1158
|
|
|
@@ -1146,10 +1167,10 @@ class TableGenerator {
|
|
|
1146
1167
|
data = data.map((row, rowIndex) =>
|
|
1147
1168
|
row.map((value, columnIndex) => {
|
|
1148
1169
|
//-- shift down because the headers are added
|
|
1149
|
-
const record = rowIndex > 0 ? this.#data[rowIndex - 1] : {};
|
|
1150
1170
|
const cleanedValue = cleanFn(value, printOptions);
|
|
1151
1171
|
|
|
1152
1172
|
//-- @TODO - we want to bold / make italic, but this needs more thought
|
|
1173
|
+
// const record = rowIndex > 0 ? this.#data[rowIndex - 1] : {};
|
|
1153
1174
|
// const cellStyle = !styleCellFn
|
|
1154
1175
|
// ? null
|
|
1155
1176
|
// : styleCellFn({ value, columnIndex, rowIndex, row, record });
|
package/src/datasets.js
CHANGED
|
@@ -145,8 +145,8 @@ module.exports.fetch = (library) => {
|
|
|
145
145
|
*
|
|
146
146
|
* // use worldJSON as global variable
|
|
147
147
|
*/
|
|
148
|
-
module.exports.fetchJSON = async function fetchJSON(targetAddress, options
|
|
149
|
-
const response = await fetch(targetAddress, options);
|
|
148
|
+
module.exports.fetchJSON = async function fetchJSON(targetAddress, options) {
|
|
149
|
+
const response = await fetch(targetAddress, options || {});
|
|
150
150
|
if (!response.ok) throw new Error(`unexpected response ${response.statusText}`);
|
|
151
151
|
return response.json();
|
|
152
152
|
};
|
package/src/file.js
CHANGED
|
@@ -249,7 +249,7 @@ module.exports.writeFile = function writeFile(filePath, contents, fsOptions = {}
|
|
|
249
249
|
*/
|
|
250
250
|
module.exports.writeFileStd = function writeFileStd(filePath, contents) {
|
|
251
251
|
//-- allow tests to use, but should be cleared prior to commit
|
|
252
|
-
|
|
252
|
+
/* istanbul ignore next */
|
|
253
253
|
if (process.env.JEST_WORKER_ID !== undefined) console.warn('Warning: Test using writeFileStd');
|
|
254
254
|
|
|
255
255
|
const resolvedPath = path.resolve(filePath);
|
package/src/ijs.js
CHANGED
|
@@ -459,6 +459,8 @@ module.exports.htmlScript = function htmlScripts(
|
|
|
459
459
|
if (!onReadyCode.endsWith(';')) {
|
|
460
460
|
onReadyCode += ';';
|
|
461
461
|
}
|
|
462
|
+
} else {
|
|
463
|
+
throw Error('ijsUtils.htmlScript: onReadyCode must be a string or function');
|
|
462
464
|
}
|
|
463
465
|
|
|
464
466
|
//-- the unique identifier for this run
|
package/src/leaflet.js
CHANGED
|
@@ -316,6 +316,8 @@ module.exports.renderMarkers = function renderMarkers(markers, mapOptions) {
|
|
|
316
316
|
throw Error('leaflet.renderMarkers(markers, options): object markers must follow schema: ({ lat, lon, title? })');
|
|
317
317
|
}
|
|
318
318
|
cleanMarkers = markers.map(({ lat, lon, title }) => [lat, lon, title]);
|
|
319
|
+
} else {
|
|
320
|
+
throw Error('leaflet.renderMarkers(markers, options): object markers must follow schema: ({ lat, lon, title? })');
|
|
319
321
|
}
|
|
320
322
|
|
|
321
323
|
//-- will be executed as JavaScript - not Node
|
package/src/object.js
CHANGED
|
@@ -274,7 +274,7 @@ module.exports.cleanPropertyName = function cleanPropertyName(property) {
|
|
|
274
274
|
return cleanProperty;
|
|
275
275
|
};
|
|
276
276
|
|
|
277
|
-
const renameObjectProperties = function renameObjectProperties(object
|
|
277
|
+
const renameObjectProperties = function renameObjectProperties(object, originalKeys, targetKeys) {
|
|
278
278
|
const result = { ...object };
|
|
279
279
|
originalKeys.forEach((originalKey, index) => {
|
|
280
280
|
const targetKey = targetKeys[index];
|
|
@@ -344,11 +344,16 @@ module.exports.collapse = function collapse(targetObj) {
|
|
|
344
344
|
* @param {String[]} propertyNames - list of the only properties to keep
|
|
345
345
|
* @returns {Object[]}
|
|
346
346
|
*/
|
|
347
|
-
module.exports.selectObjectProperties = function selectObjectProperties(list, propertyNames) {
|
|
347
|
+
module.exports.selectObjectProperties = function selectObjectProperties(list, ...propertyNames) {
|
|
348
|
+
const cleanPropertyNames = propertyNames.length > 0 && Array.isArray(propertyNames[0])
|
|
349
|
+
? propertyNames[0]
|
|
350
|
+
: propertyNames;
|
|
351
|
+
|
|
348
352
|
if (!list) return [];
|
|
349
353
|
const targetList = Array.isArray(list) ? list : [list];
|
|
354
|
+
|
|
350
355
|
return targetList.map(
|
|
351
|
-
(record) =>
|
|
356
|
+
(record) => cleanPropertyNames.reduce(
|
|
352
357
|
(result, prop) => ObjectUtils.objAssign(result, prop, record[prop]), {}
|
|
353
358
|
)
|
|
354
359
|
);
|