jupyter-ijavascript-utils 1.20.0 → 1.21.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 CHANGED
@@ -46,6 +46,7 @@ This is not intended to be the only way to accomplish many of these tasks, and a
46
46
 
47
47
  ## What's New
48
48
 
49
+ * 1.21 - include {@link module:chain|chain} - simple monoid
49
50
  * 1.20 - fix vega dependency
50
51
  * 1.19 - add in {@link module:describe|describe} and {@link module:hashMap|hashMap} modules, along with {@link module:format.limitLines|format.limitLines}
51
52
  * 1.18 - tie to vega-datasets avoiding esmodules until ijavascript can support them
package/README.md CHANGED
@@ -46,6 +46,7 @@ This is not intended to be the only way to accomplish many of these tasks, and a
46
46
 
47
47
  # What's New
48
48
 
49
+ * 1.21 - include chain - simple monoid
49
50
  * 1.20 - fix vega dependency
50
51
  * 1.19 - add in describe and hashMap modules, along with format.limitLines
51
52
  * 1.18 - tie to vega-datasets avoiding esmodules until ijavascript can support them
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jupyter-ijavascript-utils",
3
- "version": "1.20.0",
3
+ "version": "1.21.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",
package/src/chain.js ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Simple monad like wrapper.
3
+ *
4
+ * Very helpful for taking values and then progressively working on them,
5
+ * instead of continually wrapping deeper in method calls.
6
+ *
7
+ * Calling `chain(3)` - gives an object with two properties:
8
+ *
9
+ * * .value - the original value passed - or 3 in this case
10
+ * * .chain(function) - where it is passed the value, and returns a new Chain with that value.
11
+ * * .debug() - console.logs the value, and returns a new Chain with that value
12
+ *
13
+ * For example:
14
+ *
15
+ * ```
16
+ * const addTwo = (value) => value + 2;
17
+ *
18
+ * //-- we can always get the value
19
+ * console.log(
20
+ * utils.chain(3).value
21
+ * ); // 3
22
+ * ```
23
+ *
24
+ * but this is much easier if we continue to chain it
25
+ *
26
+ * ```
27
+ * console.log(
28
+ * utils.chain(3)
29
+ * .chain(addTwo)
30
+ * .chain(addTwo)
31
+ * .debug()
32
+ * .chain((value) => value + 3)
33
+ * .value
34
+ * );
35
+ * // 7
36
+ * // 10
37
+ *
38
+ * const addTwo = (value) => value + 2;
39
+ *
40
+ * console.log(
41
+ * utils.chain(3).value
42
+ * ); // 3
43
+ *
44
+ * @exports chain
45
+ * @module chain
46
+ */
47
+ module.exports = function chain(value) {
48
+ return ({
49
+ value,
50
+ chain: function innerChain(fn) {
51
+ return chain(fn(value));
52
+ },
53
+ debug: function debug(fn) {
54
+ if (fn) {
55
+ fn(value);
56
+ } else {
57
+ console.log(value);
58
+ }
59
+ return chain(value);
60
+ }
61
+ });
62
+ };
package/src/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const aggregate = require('./aggregate');
2
2
  const array = require('./array');
3
3
  const base64 = require('./base64');
4
+ const chain = require('./chain');
4
5
  const datasets = require('./datasets');
5
6
  const describe = require('./describe');
6
7
  const group = require('./group');
@@ -38,6 +39,8 @@ module.exports = {
38
39
  array,
39
40
  /** @see {@link module:base64} */
40
41
  base64,
42
+ /** @see {@link module:chain} */
43
+ chain,
41
44
  /** @see {@link module:datasets} */
42
45
  datasets,
43
46
  dataset: datasets,
package/src/object.js CHANGED
@@ -107,7 +107,7 @@ module.exports.MAX_COLLAPSE_DEPTH = 50;
107
107
  * @param {any} value -
108
108
  * @returns {Object}
109
109
  */
110
- module.exports.objAssign = function objAssign(obj, propertyName, value, ...propertyNameValues) {
110
+ module.exports.assign = function objAssign(obj, propertyName, value, ...propertyNameValues) {
111
111
  if ((propertyName === null || propertyName === undefined)) {
112
112
  throw Error('Expecting at least one property name to be passed');
113
113
  } else if (typeof propertyName !== 'string') {
@@ -123,6 +123,7 @@ module.exports.objAssign = function objAssign(obj, propertyName, value, ...prope
123
123
 
124
124
  return obj;
125
125
  };
126
+ module.exports.objAssign = module.exports.assign;
126
127
 
127
128
  /**
128
129
  * Assigns multiple object entities [[property, value], [property, value], ...];
@@ -131,7 +132,7 @@ module.exports.objAssign = function objAssign(obj, propertyName, value, ...prope
131
132
  * @param {Array} entities - 2d array [[property, value], ...]
132
133
  * @returns {Object}
133
134
  */
134
- module.exports.objAssignEntities = function objAssignEntities(obj, entities) {
135
+ module.exports.assignEntities = function objAssignEntities(obj, entities) {
135
136
  if (!obj) obj = {};
136
137
 
137
138
  if (!Array.isArray(entities)) {
@@ -146,6 +147,7 @@ module.exports.objAssignEntities = function objAssignEntities(obj, entities) {
146
147
 
147
148
  return obj;
148
149
  };
150
+ module.exports.objAssignEntities = module.exports.assignEntities;
149
151
 
150
152
  /**
151
153
  * Runs a map over a collection, and adds properties the the objects.