jupyter-ijavascript-utils 1.61.1 → 1.62.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 +40 -0
- package/Dockerfile +1 -1
- package/README.md +38 -0
- package/package.json +1 -1
- package/src/array.js +17 -12
package/DOCS.md
CHANGED
|
@@ -74,6 +74,8 @@ Give it a try here:
|
|
|
74
74
|
[](https://mybinder.org/v2/gh/paulroth3d/jupyter-ijavascript-utils/main?labpath=example.ipynb)
|
|
75
75
|
|
|
76
76
|
## What's New
|
|
77
|
+
* 1.62 - Update to Array.peekableIterator to include peekItr() as sugar for .peek
|
|
78
|
+
* 1.61 - Docs Updated
|
|
77
79
|
* 1.60 - Make post-processing of documents easier with {@link module:ijs.markDocumentPosition|ijs.markDocumentPosition}
|
|
78
80
|
* 1.59 -
|
|
79
81
|
* #95 - give control with page breaks. So we can render text before the page break (like for headers) - or even get the html used and render it how we want. (ex: {@link module:ijs.generatePageBreakStylesHTML|ijs.printPageBreak})
|
|
@@ -404,6 +406,44 @@ Depends on:
|
|
|
404
406
|
|
|
405
407
|
See the [How to Use]{@tutorial howToUse} section for more.
|
|
406
408
|
|
|
409
|
+
# Common Questions
|
|
410
|
+
|
|
411
|
+
## Converting Local Functions to a Local Library
|
|
412
|
+
|
|
413
|
+
Often - Jupyter is not the best place to do development, and folks would like to develop in their own favourite IDE.
|
|
414
|
+
|
|
415
|
+
You can write local modules (ex: `lib.js`) relative to your notebook, and then use `require('./lib')` to access them in your notebook. (see the section below on ESM Modules)
|
|
416
|
+
|
|
417
|
+
NOTE: re-running the require will use a `cached version` of your module, and `may not reflect changes you just made`.
|
|
418
|
+
|
|
419
|
+
(For this and other reasons, it can be helpful to have a `version` attribute to your module - to ensure the latest code is accessible)
|
|
420
|
+
|
|
421
|
+
There typically are two options:
|
|
422
|
+
|
|
423
|
+
* re-run the entire notebook
|
|
424
|
+
|
|
425
|
+
* use a "cache bypass" only for your local library. ex: [import-fresh](https://www.npmjs.com/package/import-fresh)
|
|
426
|
+
|
|
427
|
+
Using a cache bypass is fairly simple, and behaves something similar to this:
|
|
428
|
+
|
|
429
|
+
```
|
|
430
|
+
utils = reqire('jupyter-ijavascript-utils');
|
|
431
|
+
importFresh = require('import-fresh');
|
|
432
|
+
// other imports go here
|
|
433
|
+
|
|
434
|
+
//-- clear the output so it doesn't pollute with nonsense we don't care about.
|
|
435
|
+
utils.ijs.clearOutput();
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
and then load your module in a separate cell:
|
|
439
|
+
|
|
440
|
+
```
|
|
441
|
+
lib = importFresh('./lib');
|
|
442
|
+
lib.version; // 1.0.0
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
and if you change your library, you can then just run that cell again
|
|
446
|
+
|
|
407
447
|
## ESM Modules + D3
|
|
408
448
|
|
|
409
449
|
Note that we strongly recommend using this with other modules like D3 - that only support ESM modules now.
|
package/Dockerfile
CHANGED
package/README.md
CHANGED
|
@@ -54,6 +54,8 @@ This is not intended to be the only way to accomplish many of these tasks, and a
|
|
|
54
54
|

|
|
55
55
|
|
|
56
56
|
# What's New
|
|
57
|
+
* 1.62 - Update to Array.peekableIterator to include peekItr() as sugar for .peek
|
|
58
|
+
* 1.61 - Docs Updated
|
|
57
59
|
* 1.60 - Make post-processing of documents easier with ijs.utils.markDocumentPosition
|
|
58
60
|
* 1.59 -
|
|
59
61
|
* #95 - give control with page breaks. So we can render text before the page break (like for headers) - or even get the html used and render it how we want.
|
|
@@ -132,6 +134,42 @@ found under the [docResources/notebooks](https://github.com/paulroth3d/jupyter-i
|
|
|
132
134
|
simply create a package in the folder you will run the `jupyter lab` command
|
|
133
135
|
- such as the sample one under [docResources/notebooks/package.json](https://github.com/paulroth3d/jupyter-ijavascript-utils/blob/main/docResources/notebooks/package.json))
|
|
134
136
|
|
|
137
|
+
## Converting Local Functions to a Local Library
|
|
138
|
+
|
|
139
|
+
Often - Jupyter is not the best place to do development, and folks would like to develop in their own favourite IDE.
|
|
140
|
+
|
|
141
|
+
You can write local modules (ex: `lib.js`) relative to your notebook, and then use `require('./lib')` to access them in your notebook. (see the section below on ESM Modules)
|
|
142
|
+
|
|
143
|
+
NOTE: re-running the require will use a `cached version` of your module, and `may not reflect changes you just made`.
|
|
144
|
+
|
|
145
|
+
(For this and other reasons, it can be helpful to have a `version` attribute to your module - to ensure the latest code is accessible)
|
|
146
|
+
|
|
147
|
+
There typically are two options:
|
|
148
|
+
|
|
149
|
+
* re-run the entire notebook
|
|
150
|
+
|
|
151
|
+
* use a "cache bypass" only for your local library. ex: [https://www.npmjs.com/package/import-fresh](import-fresh)
|
|
152
|
+
|
|
153
|
+
Using a cache bypass is fairly simple, and behaves somethng similar to this:
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
utils = reqire('jupyter-ijavascript-utils');
|
|
157
|
+
importFresh = require('import-fresh');
|
|
158
|
+
// other imports go here
|
|
159
|
+
|
|
160
|
+
//-- clear the output so it doesn't pollute with nonsense we don't care about.
|
|
161
|
+
utils.ijs.clearOutput();
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
and then load your module in a separate cell:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
lib = importFresh('./lib');
|
|
168
|
+
lib.version; // 1.0.0
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
and if you change your library, you can then just rn tat cell again
|
|
172
|
+
|
|
135
173
|
## ESM Modules + D3
|
|
136
174
|
|
|
137
175
|
Note that we strongly recommend using this with other modules like D3 - that only support ESM modules now.
|
package/package.json
CHANGED
package/src/array.js
CHANGED
|
@@ -1210,9 +1210,7 @@ module.exports.extractFromHardSpacedTable = function extractFromHardSpacedTable(
|
|
|
1210
1210
|
/**
|
|
1211
1211
|
* Create an iterator for an array that allows for peeking next values.
|
|
1212
1212
|
*
|
|
1213
|
-
*
|
|
1214
|
-
* @example
|
|
1215
|
-
*
|
|
1213
|
+
* ```
|
|
1216
1214
|
* source = [0, 1, 2, 3, 4, 5];
|
|
1217
1215
|
*
|
|
1218
1216
|
* // also quite helpful for document.querySelector(...)
|
|
@@ -1221,22 +1219,26 @@ module.exports.extractFromHardSpacedTable = function extractFromHardSpacedTable(
|
|
|
1221
1219
|
* console.log(itr.next()); // { done: false, value: 0 }
|
|
1222
1220
|
*
|
|
1223
1221
|
* //-- peek without moving the iterator
|
|
1224
|
-
*
|
|
1225
|
-
* console.log(
|
|
1226
|
-
* console.log(
|
|
1227
|
-
* console.log(
|
|
1228
|
-
* console.log(
|
|
1229
|
-
* console.log(peekItr.next()); // { done: true, value: 5 }
|
|
1222
|
+
* console.log(itr.peek.next()); // { done: false, value: 1 }
|
|
1223
|
+
* console.log(itr.peek.next()); // { done: false, value: 2 }
|
|
1224
|
+
* console.log(itr.peek.next()); // { done: false, value: 3 }
|
|
1225
|
+
* console.log(itr.peek.next()); // { done: false, value: 4 }
|
|
1226
|
+
* console.log(itr.peek.next()); // { done: true, value: 5 }
|
|
1230
1227
|
*
|
|
1231
1228
|
* //-- move the main iterator
|
|
1232
1229
|
* console.log(itr.next()); // { done: false, value: 1 }
|
|
1230
|
+
* ```
|
|
1233
1231
|
*
|
|
1234
1232
|
* Of course, for each will always work
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1233
|
+
*
|
|
1234
|
+
* ```
|
|
1235
|
+
* for (let i of new utils.array.PeekableArrayIterator(source)) {
|
|
1237
1236
|
* console.log(i);
|
|
1238
1237
|
* }
|
|
1239
1238
|
* // 1\n2\n3\n4\n5
|
|
1239
|
+
* ```
|
|
1240
|
+
*
|
|
1241
|
+
* @see https://www.npmjs.com/package/peekable-array-iterator
|
|
1240
1242
|
*/
|
|
1241
1243
|
class PeekableArrayIterator {
|
|
1242
1244
|
/**
|
|
@@ -1261,9 +1263,12 @@ class PeekableArrayIterator {
|
|
|
1261
1263
|
}
|
|
1262
1264
|
return undefined;
|
|
1263
1265
|
})();
|
|
1266
|
+
this.peekItr = function peekItr() {
|
|
1267
|
+
return this.peek;
|
|
1268
|
+
};
|
|
1264
1269
|
|
|
1265
1270
|
this.i += 1;
|
|
1266
|
-
return { done: this.i >= this.array.length
|
|
1271
|
+
return { done: this.i >= this.array.length, value: this.array[this.i] };
|
|
1267
1272
|
}
|
|
1268
1273
|
/* eslint-enable wrap-iife */
|
|
1269
1274
|
}
|