jupyter-ijavascript-utils 1.21.1 → 1.21.3
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 +19 -0
- package/Dockerfile +2 -33
- package/README.md +10 -1
- package/package.json +1 -1
- package/src/chain.js +63 -9
package/DOCS.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://jupyter-ijavascript-utils.onrender.com/" alt="Documentation">
|
|
3
|
+
<img src="https://img.shields.io/badge/Documentation-here-informational" />
|
|
4
|
+
</a>
|
|
5
|
+
<a href="https://jupyter-ijavascript-utils.onrender.com/LICENSE" alt="License">
|
|
6
|
+
<img src="https://img.shields.io/badge/License-MIT-green" />
|
|
7
|
+
</a>
|
|
8
|
+
<img src="https://img.shields.io/badge/Coverage-98-green" />
|
|
9
|
+
<a href="https://www.npmjs.com/package/jupyter-ijavascript-utils" alt="npm">
|
|
10
|
+
<img src="https://img.shields.io/badge/npm-%5E1.X-red" />
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://github.com/paulroth3d/jupyter-ijavascript-utils" alt="npm">
|
|
13
|
+
<img src="https://img.shields.io/badge/github-here-black" />
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://mybinder.org/v2/gh/paulroth3d/jupyter-ijavascript-utils/main" alt="Launch Binder">
|
|
16
|
+
<img src="https://mybinder.org/badge_logo.svg" />
|
|
17
|
+
</a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
1
20
|
# Overview
|
|
2
21
|
|
|
3
22
|
This is a library to help people that understand JavaScript
|
package/Dockerfile
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
#
|
|
2
|
-
# and https://github.com/paulroth3d/jupyter-ijavascript-utils/issues/4
|
|
1
|
+
# syntax=docker/dockerfile:1
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
FROM jupyter/base-notebook:latest
|
|
6
|
-
|
|
7
|
-
# for nbhosting
|
|
8
|
-
USER root
|
|
9
|
-
COPY start-in-dir-as-uid.sh /usr/local/bin
|
|
10
|
-
|
|
11
|
-
# prerequisites with apt-get
|
|
12
|
-
# we do install python(2) here because
|
|
13
|
-
# some npm build part named gyp still requires it
|
|
14
|
-
RUN apt-get update && apt-get install -y gcc g++ make python
|
|
15
|
-
|
|
16
|
-
# !!! dirty trick!!!
|
|
17
|
-
# original PATH is
|
|
18
|
-
# /opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
|
19
|
-
# move conda's path **at the end**
|
|
20
|
-
# so that python resolves in /usr/bin/python(2)
|
|
21
|
-
# but node is still found in conda
|
|
22
|
-
ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/conda/bin"
|
|
23
|
-
USER jovyan
|
|
24
|
-
RUN npm install -g ijavascript
|
|
25
|
-
RUN ijsinstall
|
|
26
|
-
|
|
27
|
-
# for displaying html fragments
|
|
28
|
-
RUN npm install -g jsdom d3
|
|
29
|
-
|
|
30
|
-
# !!! clean up!!!
|
|
31
|
-
USER root
|
|
32
|
-
RUN apt-get autoremove -y python
|
|
33
|
-
ENV PATH="/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
34
|
-
USER jovyan
|
|
3
|
+
FROM darkbluestudios/jupyter-ijavascript-utils:binder
|
package/README.md
CHANGED
|
@@ -6,8 +6,14 @@
|
|
|
6
6
|
<img src="https://img.shields.io/badge/License-MIT-green" />
|
|
7
7
|
</a>
|
|
8
8
|
<img src="https://img.shields.io/badge/Coverage-98-green" />
|
|
9
|
+
<a href="https://www.npmjs.com/package/jupyter-ijavascript-utils" alt="npm">
|
|
10
|
+
<img src="https://img.shields.io/badge/npm-%5E1.X-red" />
|
|
11
|
+
</a>
|
|
9
12
|
<a href="https://github.com/paulroth3d/jupyter-ijavascript-utils" alt="npm">
|
|
10
|
-
<img src="https://img.shields.io/badge/
|
|
13
|
+
<img src="https://img.shields.io/badge/github-here-black" />
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://mybinder.org/v2/gh/paulroth3d/jupyter-ijavascript-utils/main" alt="Launch Binder">
|
|
16
|
+
<img src="https://mybinder.org/badge_logo.svg" />
|
|
11
17
|
</a>
|
|
12
18
|
</p>
|
|
13
19
|
|
|
@@ -23,6 +29,9 @@ Notebooks are a way to explore and experiment, in addition to write and explain
|
|
|
23
29
|
|
|
24
30
|

|
|
25
31
|
|
|
32
|
+
See Example binder here:
|
|
33
|
+
[](https://mybinder.org/v2/gh/paulroth3d/jupyter-ijavascript-utils/main?labpath=example.ipynb)
|
|
34
|
+
|
|
26
35
|
# Documentation
|
|
27
36
|
|
|
28
37
|
See documentation at: [https://jupyter-ijavascript-utils.onrender.com/](https://jupyter-ijavascript-utils.onrender.com/)
|
package/package.json
CHANGED
package/src/chain.js
CHANGED
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
*
|
|
9
9
|
* * .value - the original value passed - or 3 in this case
|
|
10
10
|
* * .chain(function) - where it is passed the value, and returns a new Chain with that value.
|
|
11
|
+
* * .chainMap(function) -> where it treats value as an array, and maps function on every item in the array
|
|
12
|
+
* * .chainReduce(function, initialValue) -> where it treats value as an array, and reduces the value array
|
|
11
13
|
* * .debug() - console.logs the value, and returns a new Chain with that value
|
|
12
14
|
*
|
|
13
15
|
* For example:
|
|
14
16
|
*
|
|
15
17
|
* ```
|
|
16
|
-
*
|
|
18
|
+
* addTwo = (value) => value + 2;
|
|
17
19
|
*
|
|
18
20
|
* //-- we can always get the value
|
|
19
21
|
* console.log(
|
|
@@ -24,22 +26,66 @@
|
|
|
24
26
|
* but this is much easier if we continue to chain it
|
|
25
27
|
*
|
|
26
28
|
* ```
|
|
29
|
+
* addTwo = (value) => value + 2;
|
|
30
|
+
* addTwo(3); // 5
|
|
31
|
+
*
|
|
27
32
|
* console.log(
|
|
28
33
|
* utils.chain(3)
|
|
29
|
-
* .chain(addTwo)
|
|
30
|
-
* .chain(addTwo)
|
|
31
|
-
* .debug()
|
|
32
|
-
*
|
|
34
|
+
* .chain(addTwo) // (3 + 2)
|
|
35
|
+
* .chain(addTwo) // (5 + 2)
|
|
36
|
+
* .debug() // consoles 7 and passes the value along
|
|
37
|
+
* // define a function inline
|
|
38
|
+
* .chain((value) => value + 3) // (7 + 3)
|
|
33
39
|
* .value
|
|
34
40
|
* );
|
|
41
|
+
*
|
|
35
42
|
* // 7
|
|
36
43
|
* // 10
|
|
44
|
+
* ```
|
|
37
45
|
*
|
|
38
|
-
*
|
|
46
|
+
* Note that we can also map against values in the array
|
|
39
47
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* ); //
|
|
48
|
+
* ```
|
|
49
|
+
* initializeArray = (size) => Array.from(Array(size)).map((val, index) => index);
|
|
50
|
+
* initializeArray(3); // [0, 1, 2]
|
|
51
|
+
*
|
|
52
|
+
* addTwo = (value) => value + 2;
|
|
53
|
+
* addTwo(3); // 5
|
|
54
|
+
*
|
|
55
|
+
* utils.chain(3)
|
|
56
|
+
* .chain(initializeArray) // [0, 1, 2]
|
|
57
|
+
* .chainMap(addTwo) // [2, 3, 4] or [0 + 2, 1 + 2, 2 + 2]
|
|
58
|
+
* .chainMap(addTwo)
|
|
59
|
+
* .value;
|
|
60
|
+
* // [4, 5, 6]
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* Or even combine with other utility methods
|
|
64
|
+
*
|
|
65
|
+
* ```
|
|
66
|
+
* badStr = 'I%20am%20the%20very%20model%20of%20a%20modern%20Major'
|
|
67
|
+
* + '-General%0AI\'ve%20information%20vegetable%2C%20animal%2C%20'
|
|
68
|
+
* + 'and%20mineral%0AI%20know%20the%20kings%20of%20England%2C%20'
|
|
69
|
+
* + 'and%20I%20quote%20the%20fights%0AHistorical%0AFrom%20Marath'
|
|
70
|
+
* + 'on%20to%20Waterloo%2C%20in%20order%20categorical';
|
|
71
|
+
*
|
|
72
|
+
* chain(badStr)
|
|
73
|
+
* .chain(decodeURIComponent)
|
|
74
|
+
* .chain(v => v.split('\n'))
|
|
75
|
+
* // .debug() // check the values along the way
|
|
76
|
+
* .chainMap(line => ({ line, length: line.length }))
|
|
77
|
+
* .chain(values => utils.table(values).render());
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* and it renders out a lovely table like this:
|
|
81
|
+
*
|
|
82
|
+
* line |length
|
|
83
|
+
* -- |--
|
|
84
|
+
* I am the very model of a modern Major-General |45
|
|
85
|
+
* I've information vegetable, animal, and mineral |47
|
|
86
|
+
* I know the kings of England, and I quote the fights|51
|
|
87
|
+
* Historical |10
|
|
88
|
+
* From Marathon to Waterloo, in order categorical |47
|
|
43
89
|
*
|
|
44
90
|
* @exports chain
|
|
45
91
|
* @module chain
|
|
@@ -50,6 +96,14 @@ module.exports = function chain(value) {
|
|
|
50
96
|
chain: function innerChain(fn) {
|
|
51
97
|
return chain(fn(value));
|
|
52
98
|
},
|
|
99
|
+
chainMap: function chainMap(fn) {
|
|
100
|
+
if (!Array.isArray(value)) throw Error(`chainMap expected an array, but was passed:${value}`);
|
|
101
|
+
return chain(value.map(fn));
|
|
102
|
+
},
|
|
103
|
+
chainReduce: function chainReduce(fn, initialValue) {
|
|
104
|
+
if (!Array.isArray(value)) throw Error(`chainReduce expected an array, but was passed:${value}`);
|
|
105
|
+
return chain(value.reduce(fn, initialValue));
|
|
106
|
+
},
|
|
53
107
|
debug: function debug(fn) {
|
|
54
108
|
if (fn) {
|
|
55
109
|
fn(value);
|