vest-utils 0.1.0-dev-f30a30 → 0.1.0-dev-405df5
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/dist/cjs/vest-utils.development.js +68 -66
- package/dist/cjs/vest-utils.production.js +1 -1
- package/dist/es/vest-utils.development.js +67 -67
- package/dist/es/vest-utils.production.js +1 -1
- package/dist/umd/vest-utils.development.js +68 -66
- package/dist/umd/vest-utils.production.js +1 -1
- package/package.json +2 -2
- package/src/__tests__/cache.test.ts +2 -2
- package/src/__tests__/greaterThan.test.ts +13 -4
- package/src/__tests__/lengthEquals.test.ts +4 -2
- package/src/__tests__/longerThan.test.ts +3 -1
- package/src/__tests__/numberEquals.test.ts +13 -5
- package/src/__tests__/seq.test.ts +17 -1
- package/src/__tests__/tinyState.test.ts +67 -0
- package/src/bus.ts +6 -4
- package/src/cache.ts +14 -6
- package/src/deferThrow.ts +2 -0
- package/src/seq.ts +8 -4
- package/src/tinyState.ts +23 -0
- package/src/vest-utils.ts +5 -3
- package/tsconfig.json +2 -1
- package/types/vest-utils.d.ts +49 -16
- package/types/vest-utils.d.ts.map +1 -1
|
@@ -3,32 +3,26 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
function bindNot(fn) {
|
|
6
|
-
return
|
|
7
|
-
var args = [];
|
|
8
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
9
|
-
args[_i] = arguments[_i];
|
|
10
|
-
}
|
|
11
|
-
return !fn.apply(void 0, args);
|
|
12
|
-
};
|
|
6
|
+
return (...args) => !fn(...args);
|
|
13
7
|
}
|
|
14
8
|
|
|
15
9
|
function isNumeric(value) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
const str = String(value);
|
|
11
|
+
const num = Number(value);
|
|
12
|
+
const result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
19
13
|
return Boolean(result);
|
|
20
14
|
}
|
|
21
|
-
|
|
15
|
+
const isNotNumeric = bindNot(isNumeric);
|
|
22
16
|
|
|
23
17
|
function numberEquals(value, eq) {
|
|
24
18
|
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
25
19
|
}
|
|
26
|
-
|
|
20
|
+
const numberNotEquals = bindNot(numberEquals);
|
|
27
21
|
|
|
28
22
|
function lengthEquals(value, arg1) {
|
|
29
23
|
return numberEquals(value.length, arg1);
|
|
30
24
|
}
|
|
31
|
-
|
|
25
|
+
const lengthNotEquals = bindNot(lengthEquals);
|
|
32
26
|
|
|
33
27
|
function greaterThan(value, gt) {
|
|
34
28
|
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
@@ -41,54 +35,48 @@ function longerThan(value, arg1) {
|
|
|
41
35
|
/**
|
|
42
36
|
* Creates a cache function
|
|
43
37
|
*/
|
|
44
|
-
function createCache(maxSize) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var cacheHit = cache.get(deps);
|
|
38
|
+
function createCache(maxSize = 1) {
|
|
39
|
+
const cacheStorage = [];
|
|
40
|
+
const cache = (deps, cacheAction) => {
|
|
41
|
+
const cacheHit = cache.get(deps);
|
|
49
42
|
// cache hit is not null
|
|
50
43
|
if (cacheHit)
|
|
51
44
|
return cacheHit[1];
|
|
52
|
-
|
|
45
|
+
const result = cacheAction();
|
|
53
46
|
cacheStorage.unshift([deps.concat(), result]);
|
|
54
47
|
if (longerThan(cacheStorage, maxSize))
|
|
55
48
|
cacheStorage.length = maxSize;
|
|
56
49
|
return result;
|
|
57
50
|
};
|
|
58
51
|
// invalidate an item in the cache by its dependencies
|
|
59
|
-
cache.invalidate =
|
|
60
|
-
|
|
52
|
+
cache.invalidate = (deps) => {
|
|
53
|
+
const index = findIndex(deps);
|
|
61
54
|
if (index > -1)
|
|
62
55
|
cacheStorage.splice(index, 1);
|
|
63
56
|
};
|
|
64
57
|
// Retrieves an item from the cache.
|
|
65
|
-
cache.get =
|
|
66
|
-
return cacheStorage[findIndex(deps)] || null;
|
|
67
|
-
};
|
|
58
|
+
cache.get = (deps) => cacheStorage[findIndex(deps)] || null;
|
|
68
59
|
return cache;
|
|
69
60
|
function findIndex(deps) {
|
|
70
|
-
return cacheStorage.findIndex(
|
|
71
|
-
|
|
72
|
-
return lengthEquals(deps, cachedDeps.length) &&
|
|
73
|
-
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
74
|
-
});
|
|
61
|
+
return cacheStorage.findIndex(([cachedDeps]) => lengthEquals(deps, cachedDeps.length) &&
|
|
62
|
+
deps.every((dep, i) => dep === cachedDeps[i]));
|
|
75
63
|
}
|
|
76
64
|
}
|
|
77
65
|
|
|
78
66
|
function isNull(value) {
|
|
79
67
|
return value === null;
|
|
80
68
|
}
|
|
81
|
-
|
|
69
|
+
const isNotNull = bindNot(isNull);
|
|
82
70
|
|
|
83
71
|
function isUndefined(value) {
|
|
84
72
|
return value === undefined;
|
|
85
73
|
}
|
|
86
|
-
|
|
74
|
+
const isNotUndefined = bindNot(isUndefined);
|
|
87
75
|
|
|
88
76
|
function isNullish(value) {
|
|
89
77
|
return isNull(value) || isUndefined(value);
|
|
90
78
|
}
|
|
91
|
-
|
|
79
|
+
const isNotNullish = bindNot(isNullish);
|
|
92
80
|
|
|
93
81
|
function asArray(possibleArg) {
|
|
94
82
|
return [].concat(possibleArg);
|
|
@@ -98,12 +86,8 @@ function isFunction(value) {
|
|
|
98
86
|
return typeof value === 'function';
|
|
99
87
|
}
|
|
100
88
|
|
|
101
|
-
function optionalFunctionValue(value) {
|
|
102
|
-
|
|
103
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
104
|
-
args[_i - 1] = arguments[_i];
|
|
105
|
-
}
|
|
106
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
89
|
+
function optionalFunctionValue(value, ...args) {
|
|
90
|
+
return isFunction(value) ? value(...args) : value;
|
|
107
91
|
}
|
|
108
92
|
|
|
109
93
|
function defaultTo(value, defaultValue) {
|
|
@@ -117,10 +101,10 @@ function defaultTo(value, defaultValue) {
|
|
|
117
101
|
function isArray(value) {
|
|
118
102
|
return Boolean(Array.isArray(value));
|
|
119
103
|
}
|
|
120
|
-
|
|
104
|
+
const isNotArray = bindNot(isArray);
|
|
121
105
|
|
|
122
106
|
function last(values) {
|
|
123
|
-
|
|
107
|
+
const valuesArray = asArray(values);
|
|
124
108
|
return valuesArray[valuesArray.length - 1];
|
|
125
109
|
}
|
|
126
110
|
|
|
@@ -128,14 +112,13 @@ function last(values) {
|
|
|
128
112
|
// Normally, behaves like a nested-array map,
|
|
129
113
|
// but returning `null` will drop the element from the array
|
|
130
114
|
function transform(array, cb) {
|
|
131
|
-
|
|
132
|
-
for (
|
|
133
|
-
var v = array_1[_i];
|
|
115
|
+
const res = [];
|
|
116
|
+
for (const v of array) {
|
|
134
117
|
if (isArray(v)) {
|
|
135
118
|
res.push(transform(v, cb));
|
|
136
119
|
}
|
|
137
120
|
else {
|
|
138
|
-
|
|
121
|
+
const output = cb(v);
|
|
139
122
|
if (isNotNull(output)) {
|
|
140
123
|
res.push(output);
|
|
141
124
|
}
|
|
@@ -147,12 +130,12 @@ function valueAtPath(array, path) {
|
|
|
147
130
|
return getCurrent(array, path)[last(path)];
|
|
148
131
|
}
|
|
149
132
|
function setValueAtPath(array, path, value) {
|
|
150
|
-
|
|
133
|
+
const current = getCurrent(array, path);
|
|
151
134
|
current[last(path)] = value;
|
|
152
135
|
return array;
|
|
153
136
|
}
|
|
154
137
|
function flatten(values) {
|
|
155
|
-
return asArray(values).reduce(
|
|
138
|
+
return asArray(values).reduce((acc, value) => {
|
|
156
139
|
if (isArray(value)) {
|
|
157
140
|
return acc.concat(flatten(value));
|
|
158
141
|
}
|
|
@@ -160,9 +143,8 @@ function flatten(values) {
|
|
|
160
143
|
}, []);
|
|
161
144
|
}
|
|
162
145
|
function getCurrent(array, path) {
|
|
163
|
-
|
|
164
|
-
for (
|
|
165
|
-
var p = _a[_i];
|
|
146
|
+
let current = array;
|
|
147
|
+
for (const p of path.slice(0, -1)) {
|
|
166
148
|
current[p] = defaultTo(current[p], []);
|
|
167
149
|
current = current[p];
|
|
168
150
|
}
|
|
@@ -179,7 +161,7 @@ var nestedArray = /*#__PURE__*/Object.freeze({
|
|
|
179
161
|
});
|
|
180
162
|
|
|
181
163
|
function callEach(arr) {
|
|
182
|
-
return arr.forEach(
|
|
164
|
+
return arr.forEach(fn => fn());
|
|
183
165
|
}
|
|
184
166
|
|
|
185
167
|
/**
|
|
@@ -226,27 +208,27 @@ function isBoolean(value) {
|
|
|
226
208
|
}
|
|
227
209
|
|
|
228
210
|
function deferThrow(message) {
|
|
229
|
-
setTimeout(
|
|
211
|
+
setTimeout(() => {
|
|
230
212
|
throw new Error(message);
|
|
231
213
|
}, 0);
|
|
232
214
|
}
|
|
233
215
|
|
|
234
216
|
function createBus() {
|
|
235
|
-
|
|
217
|
+
const listeners = {};
|
|
236
218
|
return {
|
|
237
|
-
emit
|
|
238
|
-
listener(event).forEach(
|
|
219
|
+
emit(event, data) {
|
|
220
|
+
listener(event).forEach(handler => {
|
|
239
221
|
handler(data);
|
|
240
222
|
});
|
|
241
223
|
},
|
|
242
|
-
on
|
|
224
|
+
on(event, handler) {
|
|
243
225
|
listeners[event] = listener(event).concat(handler);
|
|
244
226
|
return {
|
|
245
|
-
off
|
|
246
|
-
listeners[event] = listener(event).filter(
|
|
247
|
-
}
|
|
227
|
+
off() {
|
|
228
|
+
listeners[event] = listener(event).filter(h => h !== handler);
|
|
229
|
+
},
|
|
248
230
|
};
|
|
249
|
-
}
|
|
231
|
+
},
|
|
250
232
|
};
|
|
251
233
|
function listener(event) {
|
|
252
234
|
return listeners[event] || [];
|
|
@@ -261,14 +243,15 @@ var bus = /*#__PURE__*/Object.freeze({
|
|
|
261
243
|
/**
|
|
262
244
|
* @returns a unique numeric id.
|
|
263
245
|
*/
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
246
|
+
const seq = genSeq();
|
|
247
|
+
function genSeq(namespace) {
|
|
248
|
+
return ((n) => () => `${namespace ? namespace + '_' : ''}${n++}`)(0);
|
|
249
|
+
}
|
|
267
250
|
|
|
268
251
|
function mapFirst(array, callback) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
for (
|
|
252
|
+
let broke = false;
|
|
253
|
+
let breakoutValue = null;
|
|
254
|
+
for (let i = 0; i < array.length; i++) {
|
|
272
255
|
callback(array[i], breakout, i);
|
|
273
256
|
if (broke) {
|
|
274
257
|
return breakoutValue;
|
|
@@ -294,12 +277,29 @@ function isEmpty(value) {
|
|
|
294
277
|
}
|
|
295
278
|
return false;
|
|
296
279
|
}
|
|
297
|
-
|
|
280
|
+
const isNotEmpty = bindNot(isEmpty);
|
|
298
281
|
|
|
299
282
|
function isPositive(value) {
|
|
300
283
|
return greaterThan(value, 0);
|
|
301
284
|
}
|
|
302
285
|
|
|
286
|
+
function createTinyState(initialValue) {
|
|
287
|
+
let value;
|
|
288
|
+
resetValue();
|
|
289
|
+
return () => [value, setValue, resetValue];
|
|
290
|
+
function setValue(nextValue) {
|
|
291
|
+
value = optionalFunctionValue(nextValue, value);
|
|
292
|
+
}
|
|
293
|
+
function resetValue() {
|
|
294
|
+
setValue(optionalFunctionValue(initialValue));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
var tinyState = /*#__PURE__*/Object.freeze({
|
|
299
|
+
__proto__: null,
|
|
300
|
+
createTinyState: createTinyState
|
|
301
|
+
});
|
|
302
|
+
|
|
303
303
|
exports.StringObject = StringObject;
|
|
304
304
|
exports.asArray = asArray;
|
|
305
305
|
exports.assign = assign;
|
|
@@ -310,6 +310,7 @@ exports.callEach = callEach;
|
|
|
310
310
|
exports.defaultTo = defaultTo;
|
|
311
311
|
exports.deferThrow = deferThrow;
|
|
312
312
|
exports.either = either;
|
|
313
|
+
exports.genSeq = genSeq;
|
|
313
314
|
exports.greaterThan = greaterThan;
|
|
314
315
|
exports.hasOwnProperty = hasOwnProperty;
|
|
315
316
|
exports.invariant = invariant;
|
|
@@ -340,3 +341,4 @@ exports.numberEquals = numberEquals;
|
|
|
340
341
|
exports.numberNotEquals = numberNotEquals;
|
|
341
342
|
exports.optionalFunctionValue = optionalFunctionValue;
|
|
342
343
|
exports.seq = seq;
|
|
344
|
+
exports.tinyState = tinyState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
1
|
+
"use strict";function t(t){return(...n)=>!t(...n)}function n(t){const n=String(t),r=Number(t),e=!isNaN(parseFloat(n))&&!isNaN(Number(t))&&isFinite(r);return Boolean(e)}Object.defineProperty(exports,"__esModule",{value:!0});const r=t(n);function e(t,r){return n(t)&&n(r)&&Number(t)===Number(r)}const o=t(e);function u(t,n){return e(t.length,n)}const s=t(u);function i(t,r){return n(t)&&n(r)&&Number(t)>Number(r)}function c(t,n){return i(t.length,n)}function f(t){return null===t}const a=t(f);function l(t){return void 0===t}const p=t(l);function x(t){return f(t)||l(t)}const h=t(x);function N(t){return[].concat(t)}function g(t){return"function"==typeof t}function b(t,...n){return g(t)?t(...n):t}function y(t,n){var r;return null!==(r=b(t))&&void 0!==r?r:b(n)}function m(t){return Boolean(Array.isArray(t))}const d=t(m);function v(t){const n=N(t);return n[n.length-1]}function _(t,n){let r=t;for(const t of n.slice(0,-1))r[t]=y(r[t],[]),r=r[t];return r}var E=Object.freeze({__proto__:null,transform:function t(n,r){const e=[];for(const o of n)if(m(o))e.push(t(o,r));else{const t=r(o);a(t)&&e.push(t)}return e},valueAtPath:function(t,n){return _(t,n)[v(n)]},setValueAtPath:function(t,n,r){return _(t,n)[v(n)]=r,t},flatten:function t(n){return N(n).reduce(((n,r)=>m(r)?n.concat(t(r)):N(n).concat(r)),[])},getCurrent:_});function O(t,n){return Object.prototype.hasOwnProperty.call(t,n)}var j=Object.assign;var S=Object.freeze({__proto__:null,createBus:function(){const t={};return{emit(t,r){n(t).forEach((t=>{t(r)}))},on:(r,e)=>(t[r]=n(r).concat(e),{off(){t[r]=n(r).filter((t=>t!==e))}})};function n(n){return t[n]||[]}}});const w=A();function A(t){return n=0,()=>`${t?t+"_":""}${n++}`;var n}function P(t){return!t||(O(t,"length")?u(t,0):"object"==typeof t&&u(Object.keys(t),0))}const q=t(P);var T=Object.freeze({__proto__:null,createTinyState:function(t){let n;return e(),()=>[n,r,e];function r(t){n=b(t,n)}function e(){r(b(t))}}});exports.StringObject=function(t){return new String(b(t))},exports.asArray=N,exports.assign=j,exports.bindNot=t,exports.bus=S,exports.cache=function(t=1){const n=[],r=(e,o)=>{const u=r.get(e);if(u)return u[1];const s=o();return n.unshift([e.concat(),s]),c(n,t)&&(n.length=t),s};return r.invalidate=t=>{const r=e(t);r>-1&&n.splice(r,1)},r.get=t=>n[e(t)]||null,r;function e(t){return n.findIndex((([n])=>u(t,n.length)&&t.every(((t,r)=>t===n[r]))))}},exports.callEach=function(t){return t.forEach((t=>t()))},exports.defaultTo=y,exports.deferThrow=function(t){setTimeout((()=>{throw new Error(t)}),0)},exports.either=function(t,n){return!!t!=!!n},exports.genSeq=A,exports.greaterThan=i,exports.hasOwnProperty=O,exports.invariant=function(t,n){if(!t)throw n instanceof String?n.valueOf():new Error(n?b(n):n)},exports.isArray=m,exports.isBoolean=function(t){return!!t===t},exports.isEmpty=P,exports.isFunction=g,exports.isNotArray=d,exports.isNotEmpty=q,exports.isNotNull=a,exports.isNotNullish=h,exports.isNotNumeric=r,exports.isNotUndefined=p,exports.isNull=f,exports.isNullish=x,exports.isNumeric=n,exports.isPositive=function(t){return i(t,0)},exports.isPromise=function(t){return t&&g(t.then)},exports.isStringValue=function(t){return String(t)===t},exports.isUndefined=l,exports.last=v,exports.lengthEquals=u,exports.lengthNotEquals=s,exports.longerThan=c,exports.mapFirst=function(t,n){let r=!1,e=null;for(let u=0;u<t.length;u++)if(n(t[u],o,u),r)return e;function o(t,n){t&&(r=!0,e=n)}},exports.nestedArray=E,exports.numberEquals=e,exports.numberNotEquals=o,exports.optionalFunctionValue=b,exports.seq=w,exports.tinyState=T;
|
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
function bindNot(fn) {
|
|
2
|
-
return
|
|
3
|
-
var args = [];
|
|
4
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
5
|
-
args[_i] = arguments[_i];
|
|
6
|
-
}
|
|
7
|
-
return !fn.apply(void 0, args);
|
|
8
|
-
};
|
|
2
|
+
return (...args) => !fn(...args);
|
|
9
3
|
}
|
|
10
4
|
|
|
11
5
|
function isNumeric(value) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
const str = String(value);
|
|
7
|
+
const num = Number(value);
|
|
8
|
+
const result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
15
9
|
return Boolean(result);
|
|
16
10
|
}
|
|
17
|
-
|
|
11
|
+
const isNotNumeric = bindNot(isNumeric);
|
|
18
12
|
|
|
19
13
|
function numberEquals(value, eq) {
|
|
20
14
|
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
21
15
|
}
|
|
22
|
-
|
|
16
|
+
const numberNotEquals = bindNot(numberEquals);
|
|
23
17
|
|
|
24
18
|
function lengthEquals(value, arg1) {
|
|
25
19
|
return numberEquals(value.length, arg1);
|
|
26
20
|
}
|
|
27
|
-
|
|
21
|
+
const lengthNotEquals = bindNot(lengthEquals);
|
|
28
22
|
|
|
29
23
|
function greaterThan(value, gt) {
|
|
30
24
|
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
@@ -37,54 +31,48 @@ function longerThan(value, arg1) {
|
|
|
37
31
|
/**
|
|
38
32
|
* Creates a cache function
|
|
39
33
|
*/
|
|
40
|
-
function createCache(maxSize) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var cacheHit = cache.get(deps);
|
|
34
|
+
function createCache(maxSize = 1) {
|
|
35
|
+
const cacheStorage = [];
|
|
36
|
+
const cache = (deps, cacheAction) => {
|
|
37
|
+
const cacheHit = cache.get(deps);
|
|
45
38
|
// cache hit is not null
|
|
46
39
|
if (cacheHit)
|
|
47
40
|
return cacheHit[1];
|
|
48
|
-
|
|
41
|
+
const result = cacheAction();
|
|
49
42
|
cacheStorage.unshift([deps.concat(), result]);
|
|
50
43
|
if (longerThan(cacheStorage, maxSize))
|
|
51
44
|
cacheStorage.length = maxSize;
|
|
52
45
|
return result;
|
|
53
46
|
};
|
|
54
47
|
// invalidate an item in the cache by its dependencies
|
|
55
|
-
cache.invalidate =
|
|
56
|
-
|
|
48
|
+
cache.invalidate = (deps) => {
|
|
49
|
+
const index = findIndex(deps);
|
|
57
50
|
if (index > -1)
|
|
58
51
|
cacheStorage.splice(index, 1);
|
|
59
52
|
};
|
|
60
53
|
// Retrieves an item from the cache.
|
|
61
|
-
cache.get =
|
|
62
|
-
return cacheStorage[findIndex(deps)] || null;
|
|
63
|
-
};
|
|
54
|
+
cache.get = (deps) => cacheStorage[findIndex(deps)] || null;
|
|
64
55
|
return cache;
|
|
65
56
|
function findIndex(deps) {
|
|
66
|
-
return cacheStorage.findIndex(
|
|
67
|
-
|
|
68
|
-
return lengthEquals(deps, cachedDeps.length) &&
|
|
69
|
-
deps.every(function (dep, i) { return dep === cachedDeps[i]; });
|
|
70
|
-
});
|
|
57
|
+
return cacheStorage.findIndex(([cachedDeps]) => lengthEquals(deps, cachedDeps.length) &&
|
|
58
|
+
deps.every((dep, i) => dep === cachedDeps[i]));
|
|
71
59
|
}
|
|
72
60
|
}
|
|
73
61
|
|
|
74
62
|
function isNull(value) {
|
|
75
63
|
return value === null;
|
|
76
64
|
}
|
|
77
|
-
|
|
65
|
+
const isNotNull = bindNot(isNull);
|
|
78
66
|
|
|
79
67
|
function isUndefined(value) {
|
|
80
68
|
return value === undefined;
|
|
81
69
|
}
|
|
82
|
-
|
|
70
|
+
const isNotUndefined = bindNot(isUndefined);
|
|
83
71
|
|
|
84
72
|
function isNullish(value) {
|
|
85
73
|
return isNull(value) || isUndefined(value);
|
|
86
74
|
}
|
|
87
|
-
|
|
75
|
+
const isNotNullish = bindNot(isNullish);
|
|
88
76
|
|
|
89
77
|
function asArray(possibleArg) {
|
|
90
78
|
return [].concat(possibleArg);
|
|
@@ -94,12 +82,8 @@ function isFunction(value) {
|
|
|
94
82
|
return typeof value === 'function';
|
|
95
83
|
}
|
|
96
84
|
|
|
97
|
-
function optionalFunctionValue(value) {
|
|
98
|
-
|
|
99
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
100
|
-
args[_i - 1] = arguments[_i];
|
|
101
|
-
}
|
|
102
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
85
|
+
function optionalFunctionValue(value, ...args) {
|
|
86
|
+
return isFunction(value) ? value(...args) : value;
|
|
103
87
|
}
|
|
104
88
|
|
|
105
89
|
function defaultTo(value, defaultValue) {
|
|
@@ -113,10 +97,10 @@ function defaultTo(value, defaultValue) {
|
|
|
113
97
|
function isArray(value) {
|
|
114
98
|
return Boolean(Array.isArray(value));
|
|
115
99
|
}
|
|
116
|
-
|
|
100
|
+
const isNotArray = bindNot(isArray);
|
|
117
101
|
|
|
118
102
|
function last(values) {
|
|
119
|
-
|
|
103
|
+
const valuesArray = asArray(values);
|
|
120
104
|
return valuesArray[valuesArray.length - 1];
|
|
121
105
|
}
|
|
122
106
|
|
|
@@ -124,14 +108,13 @@ function last(values) {
|
|
|
124
108
|
// Normally, behaves like a nested-array map,
|
|
125
109
|
// but returning `null` will drop the element from the array
|
|
126
110
|
function transform(array, cb) {
|
|
127
|
-
|
|
128
|
-
for (
|
|
129
|
-
var v = array_1[_i];
|
|
111
|
+
const res = [];
|
|
112
|
+
for (const v of array) {
|
|
130
113
|
if (isArray(v)) {
|
|
131
114
|
res.push(transform(v, cb));
|
|
132
115
|
}
|
|
133
116
|
else {
|
|
134
|
-
|
|
117
|
+
const output = cb(v);
|
|
135
118
|
if (isNotNull(output)) {
|
|
136
119
|
res.push(output);
|
|
137
120
|
}
|
|
@@ -143,12 +126,12 @@ function valueAtPath(array, path) {
|
|
|
143
126
|
return getCurrent(array, path)[last(path)];
|
|
144
127
|
}
|
|
145
128
|
function setValueAtPath(array, path, value) {
|
|
146
|
-
|
|
129
|
+
const current = getCurrent(array, path);
|
|
147
130
|
current[last(path)] = value;
|
|
148
131
|
return array;
|
|
149
132
|
}
|
|
150
133
|
function flatten(values) {
|
|
151
|
-
return asArray(values).reduce(
|
|
134
|
+
return asArray(values).reduce((acc, value) => {
|
|
152
135
|
if (isArray(value)) {
|
|
153
136
|
return acc.concat(flatten(value));
|
|
154
137
|
}
|
|
@@ -156,9 +139,8 @@ function flatten(values) {
|
|
|
156
139
|
}, []);
|
|
157
140
|
}
|
|
158
141
|
function getCurrent(array, path) {
|
|
159
|
-
|
|
160
|
-
for (
|
|
161
|
-
var p = _a[_i];
|
|
142
|
+
let current = array;
|
|
143
|
+
for (const p of path.slice(0, -1)) {
|
|
162
144
|
current[p] = defaultTo(current[p], []);
|
|
163
145
|
current = current[p];
|
|
164
146
|
}
|
|
@@ -175,7 +157,7 @@ var nestedArray = /*#__PURE__*/Object.freeze({
|
|
|
175
157
|
});
|
|
176
158
|
|
|
177
159
|
function callEach(arr) {
|
|
178
|
-
return arr.forEach(
|
|
160
|
+
return arr.forEach(fn => fn());
|
|
179
161
|
}
|
|
180
162
|
|
|
181
163
|
/**
|
|
@@ -222,27 +204,27 @@ function isBoolean(value) {
|
|
|
222
204
|
}
|
|
223
205
|
|
|
224
206
|
function deferThrow(message) {
|
|
225
|
-
setTimeout(
|
|
207
|
+
setTimeout(() => {
|
|
226
208
|
throw new Error(message);
|
|
227
209
|
}, 0);
|
|
228
210
|
}
|
|
229
211
|
|
|
230
212
|
function createBus() {
|
|
231
|
-
|
|
213
|
+
const listeners = {};
|
|
232
214
|
return {
|
|
233
|
-
emit
|
|
234
|
-
listener(event).forEach(
|
|
215
|
+
emit(event, data) {
|
|
216
|
+
listener(event).forEach(handler => {
|
|
235
217
|
handler(data);
|
|
236
218
|
});
|
|
237
219
|
},
|
|
238
|
-
on
|
|
220
|
+
on(event, handler) {
|
|
239
221
|
listeners[event] = listener(event).concat(handler);
|
|
240
222
|
return {
|
|
241
|
-
off
|
|
242
|
-
listeners[event] = listener(event).filter(
|
|
243
|
-
}
|
|
223
|
+
off() {
|
|
224
|
+
listeners[event] = listener(event).filter(h => h !== handler);
|
|
225
|
+
},
|
|
244
226
|
};
|
|
245
|
-
}
|
|
227
|
+
},
|
|
246
228
|
};
|
|
247
229
|
function listener(event) {
|
|
248
230
|
return listeners[event] || [];
|
|
@@ -257,14 +239,15 @@ var bus = /*#__PURE__*/Object.freeze({
|
|
|
257
239
|
/**
|
|
258
240
|
* @returns a unique numeric id.
|
|
259
241
|
*/
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
242
|
+
const seq = genSeq();
|
|
243
|
+
function genSeq(namespace) {
|
|
244
|
+
return ((n) => () => `${namespace ? namespace + '_' : ''}${n++}`)(0);
|
|
245
|
+
}
|
|
263
246
|
|
|
264
247
|
function mapFirst(array, callback) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
for (
|
|
248
|
+
let broke = false;
|
|
249
|
+
let breakoutValue = null;
|
|
250
|
+
for (let i = 0; i < array.length; i++) {
|
|
268
251
|
callback(array[i], breakout, i);
|
|
269
252
|
if (broke) {
|
|
270
253
|
return breakoutValue;
|
|
@@ -290,10 +273,27 @@ function isEmpty(value) {
|
|
|
290
273
|
}
|
|
291
274
|
return false;
|
|
292
275
|
}
|
|
293
|
-
|
|
276
|
+
const isNotEmpty = bindNot(isEmpty);
|
|
294
277
|
|
|
295
278
|
function isPositive(value) {
|
|
296
279
|
return greaterThan(value, 0);
|
|
297
280
|
}
|
|
298
281
|
|
|
299
|
-
|
|
282
|
+
function createTinyState(initialValue) {
|
|
283
|
+
let value;
|
|
284
|
+
resetValue();
|
|
285
|
+
return () => [value, setValue, resetValue];
|
|
286
|
+
function setValue(nextValue) {
|
|
287
|
+
value = optionalFunctionValue(nextValue, value);
|
|
288
|
+
}
|
|
289
|
+
function resetValue() {
|
|
290
|
+
setValue(optionalFunctionValue(initialValue));
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
var tinyState = /*#__PURE__*/Object.freeze({
|
|
295
|
+
__proto__: null,
|
|
296
|
+
createTinyState: createTinyState
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
export { StringObject, asArray, assign, bindNot, bus, createCache as cache, callEach, defaultTo, deferThrow, either, genSeq, greaterThan, hasOwnProperty, invariant, isArray, isBoolean, isEmpty, isFunction, isNotArray, isNotEmpty, isNotNull, isNotNullish, isNotNumeric, isNotUndefined, isNull, isNullish, isNumeric, isPositive, isPromise, isStringValue, isUndefined, last, lengthEquals, lengthNotEquals, longerThan, mapFirst, nestedArray, numberEquals, numberNotEquals, optionalFunctionValue, seq, tinyState };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function n(n){return
|
|
1
|
+
function n(n){return(...t)=>!n(...t)}function t(n){const t=String(n),r=Number(n),e=!isNaN(parseFloat(t))&&!isNaN(Number(n))&&isFinite(r);return Boolean(e)}const r=n(t);function e(n,r){return t(n)&&t(r)&&Number(n)===Number(r)}const o=n(e);function u(n,t){return e(n.length,t)}const c=n(u);function i(n,r){return t(n)&&t(r)&&Number(n)>Number(r)}function f(n,t){return i(n.length,t)}function s(n=1){const t=[],r=(e,o)=>{const u=r.get(e);if(u)return u[1];const c=o();return t.unshift([e.concat(),c]),f(t,n)&&(t.length=n),c};return r.invalidate=n=>{const r=e(n);r>-1&&t.splice(r,1)},r.get=n=>t[e(n)]||null,r;function e(n){return t.findIndex((([t])=>u(n,t.length)&&n.every(((n,r)=>n===t[r]))))}}function a(n){return null===n}const l=n(a);function h(n){return void 0===n}const g=n(h);function b(n){return a(n)||h(n)}const p=n(b);function _(n){return[].concat(n)}function v(n){return"function"==typeof n}function N(n,...t){return v(n)?n(...t):n}function m(n,t){var r;return null!==(r=N(n))&&void 0!==r?r:N(t)}function y(n){return Boolean(Array.isArray(n))}const O=n(y);function j(n){const t=_(n);return t[t.length-1]}function d(n,t){let r=n;for(const n of t.slice(0,-1))r[n]=m(r[n],[]),r=r[n];return r}var w=Object.freeze({__proto__:null,transform:function n(t,r){const e=[];for(const o of t)if(y(o))e.push(n(o,r));else{const n=r(o);l(n)&&e.push(n)}return e},valueAtPath:function(n,t){return d(n,t)[j(t)]},setValueAtPath:function(n,t,r){return d(n,t)[j(t)]=r,n},flatten:function n(t){return _(t).reduce(((t,r)=>y(r)?t.concat(n(r)):_(t).concat(r)),[])},getCurrent:d});function S(n){return n.forEach((n=>n()))}function A(n,t){return Object.prototype.hasOwnProperty.call(n,t)}function E(n){return n&&v(n.then)}var z=Object.assign;function B(n,t){if(!n)throw t instanceof String?t.valueOf():new Error(t?N(t):t)}function P(n){return new String(N(n))}function x(n){return String(n)===n}function F(n,t){return!!n!=!!t}function T(n){return!!n===n}function $(n){setTimeout((()=>{throw new Error(n)}),0)}var k=Object.freeze({__proto__:null,createBus:function(){const n={};return{emit(n,r){t(n).forEach((n=>{n(r)}))},on:(r,e)=>(n[r]=t(r).concat(e),{off(){n[r]=t(r).filter((n=>n!==e))}})};function t(t){return n[t]||[]}}});const C=I();function I(n){return t=0,()=>`${n?n+"_":""}${t++}`;var t}function V(n,t){let r=!1,e=null;for(let u=0;u<n.length;u++)if(t(n[u],o,u),r)return e;function o(n,t){n&&(r=!0,e=t)}}function q(n){return!n||(A(n,"length")?u(n,0):"object"==typeof n&&u(Object.keys(n),0))}const D=n(q);function G(n){return i(n,0)}var H=Object.freeze({__proto__:null,createTinyState:function(n){let t;return e(),()=>[t,r,e];function r(n){t=N(n,t)}function e(){r(N(n))}}});export{P as StringObject,_ as asArray,z as assign,n as bindNot,k as bus,s as cache,S as callEach,m as defaultTo,$ as deferThrow,F as either,I as genSeq,i as greaterThan,A as hasOwnProperty,B as invariant,y as isArray,T as isBoolean,q as isEmpty,v as isFunction,O as isNotArray,D as isNotEmpty,l as isNotNull,p as isNotNullish,r as isNotNumeric,g as isNotUndefined,a as isNull,b as isNullish,t as isNumeric,G as isPositive,E as isPromise,x as isStringValue,h as isUndefined,j as last,u as lengthEquals,c as lengthNotEquals,f as longerThan,V as mapFirst,w as nestedArray,e as numberEquals,o as numberNotEquals,N as optionalFunctionValue,C as seq,H as tinyState};
|