vest-utils 0.0.2-rc → 0.0.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.
Files changed (65) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/package.json +1 -0
  4. package/dist/cjs/vest-utils.development.js +342 -0
  5. package/dist/cjs/vest-utils.js +7 -0
  6. package/dist/cjs/vest-utils.production.js +1 -0
  7. package/dist/es/package.json +1 -0
  8. package/dist/es/vest-utils.development.js +299 -0
  9. package/dist/es/vest-utils.production.js +1 -0
  10. package/dist/umd/vest-utils.development.js +348 -0
  11. package/dist/umd/vest-utils.production.js +1 -0
  12. package/package.json +4 -662
  13. package/src/__tests__/bindNot.test.ts +37 -0
  14. package/src/__tests__/bus.test.ts +81 -0
  15. package/src/__tests__/cache.test.ts +113 -0
  16. package/src/__tests__/defaultTo.test.ts +50 -0
  17. package/src/__tests__/deferThrow.test.ts +24 -0
  18. package/src/__tests__/greaterThan.test.ts +59 -0
  19. package/src/__tests__/invariant.test.ts +45 -0
  20. package/src/__tests__/isArray.test.ts +15 -0
  21. package/src/__tests__/isNull.test.ts +25 -0
  22. package/src/__tests__/isNumeric.test.ts +26 -0
  23. package/src/__tests__/isUndefined.test.ts +26 -0
  24. package/src/__tests__/lengthEquals.test.ts +56 -0
  25. package/src/__tests__/longerThan.test.ts +56 -0
  26. package/src/__tests__/mapFirst.test.ts +29 -0
  27. package/src/__tests__/numberEquals.test.ts +59 -0
  28. package/src/__tests__/optionalFunctionValue.test.ts +27 -0
  29. package/src/__tests__/seq.test.ts +12 -0
  30. package/src/asArray.ts +3 -0
  31. package/src/assign.ts +1 -0
  32. package/src/bindNot.ts +3 -0
  33. package/src/bus.ts +32 -0
  34. package/src/cache.ts +49 -0
  35. package/src/callEach.ts +5 -0
  36. package/src/defaultTo.ts +8 -0
  37. package/src/deferThrow.ts +5 -0
  38. package/src/either.ts +3 -0
  39. package/src/globals.d.ts +3 -0
  40. package/src/greaterThan.ts +8 -0
  41. package/src/hasOwnProperty.ts +9 -0
  42. package/src/invariant.ts +24 -0
  43. package/src/isArrayValue.ts +11 -0
  44. package/src/isBooleanValue.ts +3 -0
  45. package/src/isEmpty.ts +17 -0
  46. package/src/isFunction.ts +5 -0
  47. package/src/isNull.ts +7 -0
  48. package/src/isNullish.ts +9 -0
  49. package/src/isNumeric.ts +11 -0
  50. package/src/isPositive.ts +5 -0
  51. package/src/isPromise.ts +5 -0
  52. package/src/isStringValue.ts +3 -0
  53. package/src/isUndefined.ts +7 -0
  54. package/src/last.ts +7 -0
  55. package/src/lengthEquals.ts +11 -0
  56. package/src/longerThan.ts +8 -0
  57. package/src/mapFirst.ts +25 -0
  58. package/src/nestedArray.ts +69 -0
  59. package/src/numberEquals.ts +11 -0
  60. package/src/optionalFunctionValue.ts +8 -0
  61. package/src/seq.ts +10 -0
  62. package/src/utilityTypes.ts +9 -0
  63. package/src/vest-utils.ts +31 -0
  64. package/tsconfig.json +3 -1
  65. package/types/vest-utils.d.ts +92 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 ealush
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # vest-utils
2
+
3
+ Set of shared functions used by the different components of Vest validations framefork. You probably do not need to use this package directly.
4
+
5
+ The modules in this package are considered internal and are likely to change in the future.
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,342 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function bindNot(fn) {
6
+ return function () {
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
+ };
13
+ }
14
+
15
+ function isNumeric(value) {
16
+ var str = String(value);
17
+ var num = Number(value);
18
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
19
+ return Boolean(result);
20
+ }
21
+ var isNotNumeric = bindNot(isNumeric);
22
+
23
+ function numberEquals(value, eq) {
24
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
25
+ }
26
+ var numberNotEquals = bindNot(numberEquals);
27
+
28
+ function lengthEquals(value, arg1) {
29
+ return numberEquals(value.length, arg1);
30
+ }
31
+ var lengthNotEquals = bindNot(lengthEquals);
32
+
33
+ function greaterThan(value, gt) {
34
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
35
+ }
36
+
37
+ function longerThan(value, arg1) {
38
+ return greaterThan(value.length, arg1);
39
+ }
40
+
41
+ /**
42
+ * Creates a cache function
43
+ */
44
+ function createCache(maxSize) {
45
+ if (maxSize === void 0) { maxSize = 1; }
46
+ var cacheStorage = [];
47
+ var cache = function (deps, cacheAction) {
48
+ var cacheHit = cache.get(deps);
49
+ // cache hit is not null
50
+ if (cacheHit)
51
+ return cacheHit[1];
52
+ var result = cacheAction();
53
+ cacheStorage.unshift([deps.concat(), result]);
54
+ if (longerThan(cacheStorage, maxSize))
55
+ cacheStorage.length = maxSize;
56
+ return result;
57
+ };
58
+ // invalidate an item in the cache by its dependencies
59
+ cache.invalidate = function (deps) {
60
+ var index = findIndex(deps);
61
+ if (index > -1)
62
+ cacheStorage.splice(index, 1);
63
+ };
64
+ // Retrieves an item from the cache.
65
+ cache.get = function (deps) {
66
+ return cacheStorage[findIndex(deps)] || null;
67
+ };
68
+ return cache;
69
+ function findIndex(deps) {
70
+ return cacheStorage.findIndex(function (_a) {
71
+ var cachedDeps = _a[0];
72
+ return lengthEquals(deps, cachedDeps.length) &&
73
+ deps.every(function (dep, i) { return dep === cachedDeps[i]; });
74
+ });
75
+ }
76
+ }
77
+
78
+ function isNull(value) {
79
+ return value === null;
80
+ }
81
+ var isNotNull = bindNot(isNull);
82
+
83
+ function isUndefined(value) {
84
+ return value === undefined;
85
+ }
86
+ var isNotUndefined = bindNot(isUndefined);
87
+
88
+ function isNullish(value) {
89
+ return isNull(value) || isUndefined(value);
90
+ }
91
+ var isNotNullish = bindNot(isNullish);
92
+
93
+ function asArray(possibleArg) {
94
+ return [].concat(possibleArg);
95
+ }
96
+
97
+ function isFunction(value) {
98
+ return typeof value === 'function';
99
+ }
100
+
101
+ function optionalFunctionValue(value) {
102
+ var args = [];
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;
107
+ }
108
+
109
+ function defaultTo(value, defaultValue) {
110
+ var _a;
111
+ return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
112
+ }
113
+
114
+ // The module is named "isArrayValue" since it
115
+ // is conflicting with a nested npm dependency.
116
+ // We may need to revisit this in the future.
117
+ function isArray(value) {
118
+ return Boolean(Array.isArray(value));
119
+ }
120
+ var isNotArray = bindNot(isArray);
121
+
122
+ function last(values) {
123
+ var valuesArray = asArray(values);
124
+ return valuesArray[valuesArray.length - 1];
125
+ }
126
+
127
+ // This is kind of a map/filter in one function.
128
+ // Normally, behaves like a nested-array map,
129
+ // but returning `null` will drop the element from the array
130
+ function transform(array, cb) {
131
+ var res = [];
132
+ for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
133
+ var v = array_1[_i];
134
+ if (isArray(v)) {
135
+ res.push(transform(v, cb));
136
+ }
137
+ else {
138
+ var output = cb(v);
139
+ if (isNotNull(output)) {
140
+ res.push(output);
141
+ }
142
+ }
143
+ }
144
+ return res;
145
+ }
146
+ function valueAtPath(array, path) {
147
+ return getCurrent(array, path)[last(path)];
148
+ }
149
+ function setValueAtPath(array, path, value) {
150
+ var current = getCurrent(array, path);
151
+ current[last(path)] = value;
152
+ return array;
153
+ }
154
+ function flatten(values) {
155
+ return asArray(values).reduce(function (acc, value) {
156
+ if (isArray(value)) {
157
+ return acc.concat(flatten(value));
158
+ }
159
+ return asArray(acc).concat(value);
160
+ }, []);
161
+ }
162
+ function getCurrent(array, path) {
163
+ var current = array;
164
+ for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
165
+ var p = _a[_i];
166
+ current[p] = defaultTo(current[p], []);
167
+ current = current[p];
168
+ }
169
+ return current;
170
+ }
171
+
172
+ var nestedArray = /*#__PURE__*/Object.freeze({
173
+ __proto__: null,
174
+ transform: transform,
175
+ valueAtPath: valueAtPath,
176
+ setValueAtPath: setValueAtPath,
177
+ flatten: flatten,
178
+ getCurrent: getCurrent
179
+ });
180
+
181
+ function callEach(arr) {
182
+ return arr.forEach(function (fn) { return fn(); });
183
+ }
184
+
185
+ /**
186
+ * A safe hasOwnProperty access
187
+ */
188
+ function hasOwnProperty(obj, key) {
189
+ return Object.prototype.hasOwnProperty.call(obj, key);
190
+ }
191
+
192
+ function isPromise(value) {
193
+ return value && isFunction(value.then);
194
+ }
195
+
196
+ var assign = Object.assign;
197
+
198
+ function invariant(condition,
199
+ // eslint-disable-next-line @typescript-eslint/ban-types
200
+ message) {
201
+ if (condition) {
202
+ return;
203
+ }
204
+ // If message is a string object (rather than string literal)
205
+ // Throw the value directly as a string
206
+ // Alternatively, throw an error with the message
207
+ throw message instanceof String
208
+ ? message.valueOf()
209
+ : new Error(message ? optionalFunctionValue(message) : message);
210
+ }
211
+ // eslint-disable-next-line @typescript-eslint/ban-types
212
+ function StringObject(value) {
213
+ return new String(optionalFunctionValue(value));
214
+ }
215
+
216
+ function isStringValue(v) {
217
+ return String(v) === v;
218
+ }
219
+
220
+ function either(a, b) {
221
+ return !!a !== !!b;
222
+ }
223
+
224
+ function isBoolean(value) {
225
+ return !!value === value;
226
+ }
227
+
228
+ function deferThrow(message) {
229
+ setTimeout(function () {
230
+ throw new Error(message);
231
+ }, 0);
232
+ }
233
+
234
+ function createBus() {
235
+ var listeners = {};
236
+ return {
237
+ emit: function (event, data) {
238
+ listener(event).forEach(function (handler) {
239
+ handler(data);
240
+ });
241
+ },
242
+ on: function (event, handler) {
243
+ listeners[event] = listener(event).concat(handler);
244
+ return {
245
+ off: function () {
246
+ listeners[event] = listener(event).filter(function (h) { return h !== handler; });
247
+ }
248
+ };
249
+ }
250
+ };
251
+ function listener(event) {
252
+ return listeners[event] || [];
253
+ }
254
+ }
255
+
256
+ var bus = /*#__PURE__*/Object.freeze({
257
+ __proto__: null,
258
+ createBus: createBus
259
+ });
260
+
261
+ /**
262
+ * @returns a unique numeric id.
263
+ */
264
+ var seq = (function (n) { return function () {
265
+ return "".concat(n++);
266
+ }; })(0);
267
+
268
+ function mapFirst(array, callback) {
269
+ var broke = false;
270
+ var breakoutValue = null;
271
+ for (var i = 0; i < array.length; i++) {
272
+ callback(array[i], breakout, i);
273
+ if (broke) {
274
+ return breakoutValue;
275
+ }
276
+ }
277
+ function breakout(conditional, value) {
278
+ if (conditional) {
279
+ broke = true;
280
+ breakoutValue = value;
281
+ }
282
+ }
283
+ }
284
+
285
+ function isEmpty(value) {
286
+ if (!value) {
287
+ return true;
288
+ }
289
+ else if (hasOwnProperty(value, 'length')) {
290
+ return lengthEquals(value, 0);
291
+ }
292
+ else if (typeof value === 'object') {
293
+ return lengthEquals(Object.keys(value), 0);
294
+ }
295
+ return false;
296
+ }
297
+ var isNotEmpty = bindNot(isEmpty);
298
+
299
+ function isPositive(value) {
300
+ return greaterThan(value, 0);
301
+ }
302
+
303
+ exports.StringObject = StringObject;
304
+ exports.asArray = asArray;
305
+ exports.assign = assign;
306
+ exports.bindNot = bindNot;
307
+ exports.bus = bus;
308
+ exports.cache = createCache;
309
+ exports.callEach = callEach;
310
+ exports.defaultTo = defaultTo;
311
+ exports.deferThrow = deferThrow;
312
+ exports.either = either;
313
+ exports.greaterThan = greaterThan;
314
+ exports.hasOwnProperty = hasOwnProperty;
315
+ exports.invariant = invariant;
316
+ exports.isArray = isArray;
317
+ exports.isBoolean = isBoolean;
318
+ exports.isEmpty = isEmpty;
319
+ exports.isFunction = isFunction;
320
+ exports.isNotArray = isNotArray;
321
+ exports.isNotEmpty = isNotEmpty;
322
+ exports.isNotNull = isNotNull;
323
+ exports.isNotNullish = isNotNullish;
324
+ exports.isNotNumeric = isNotNumeric;
325
+ exports.isNotUndefined = isNotUndefined;
326
+ exports.isNull = isNull;
327
+ exports.isNullish = isNullish;
328
+ exports.isNumeric = isNumeric;
329
+ exports.isPositive = isPositive;
330
+ exports.isPromise = isPromise;
331
+ exports.isStringValue = isStringValue;
332
+ exports.isUndefined = isUndefined;
333
+ exports.last = last;
334
+ exports.lengthEquals = lengthEquals;
335
+ exports.lengthNotEquals = lengthNotEquals;
336
+ exports.longerThan = longerThan;
337
+ exports.mapFirst = mapFirst;
338
+ exports.nestedArray = nestedArray;
339
+ exports.numberEquals = numberEquals;
340
+ exports.numberNotEquals = numberNotEquals;
341
+ exports.optionalFunctionValue = optionalFunctionValue;
342
+ exports.seq = seq;
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ if (process.env.NODE_ENV === 'production') {
4
+ module.exports = require('./vest-utils.production.js');
5
+ } else {
6
+ module.exports = require('./vest-utils.development.js');
7
+ }
@@ -0,0 +1 @@
1
+ "use strict";function t(t){return function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return!t.apply(void 0,r)}}function r(t){var r=Number(t);return!(isNaN(parseFloat(String(t)))||isNaN(Number(t))||!isFinite(r))}Object.defineProperty(exports,"__esModule",{value:!0});var n=t(r);function e(t,n){return r(t)&&r(n)&&Number(t)===Number(n)}var o=t(e);function u(t,r){return e(t.length,r)}var i=t(u);function s(t,n){return r(t)&&r(n)&&Number(t)>Number(n)}function c(t,r){return s(t.length,r)}function a(t){return null===t}var f=t(a);function p(t){return void 0===t}var l=t(p);function x(t){return a(t)||p(t)}var v=t(x);function h(t){return[].concat(t)}function g(t){return"function"==typeof t}function N(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return g(t)?t.apply(void 0,r):t}function d(t,r){var n;return null!==(n=N(t))&&void 0!==n?n:N(r)}function b(t){return!!Array.isArray(t)}var y=t(b);function m(t){return(t=h(t))[t.length-1]}function E(t,r){var n=0;for(r=r.slice(0,-1);n<r.length;n++){var e=r[n];t[e]=d(t[e],[]),t=t[e]}return t}var O=Object.freeze({__proto__:null,transform:function t(r,n){for(var e=[],o=0;o<r.length;o++){var u=r[o];b(u)?e.push(t(u,n)):(u=n(u),f(u)&&e.push(u))}return e},valueAtPath:function(t,r){return E(t,r)[m(r)]},setValueAtPath:function(t,r,n){return E(t,r)[m(r)]=n,t},flatten:function t(r){return h(r).reduce((function(r,n){return b(n)?r.concat(t(n)):h(r).concat(n)}),[])},getCurrent:E});function _(t,r){return Object.prototype.hasOwnProperty.call(t,r)}var j=Object.assign;var A,P=Object.freeze({__proto__:null,createBus:function(){var t={};return{emit:function(r,n){(t[r]||[]).forEach((function(t){t(n)}))},on:function(r,n){return t[r]=(t[r]||[]).concat(n),{off:function(){t[r]=(t[r]||[]).filter((function(t){return t!==n}))}}}}}}),w=(A=0,function(){return"".concat(A++)});function S(t){return!t||(_(t,"length")?u(t,0):"object"==typeof t&&u(Object.keys(t),0))}var q=t(S);exports.StringObject=function(t){return new String(N(t))},exports.asArray=h,exports.assign=j,exports.bindNot=t,exports.bus=P,exports.cache=function(t){function r(t){return n.findIndex((function(r){var n=r[0];return u(t,n.length)&&t.every((function(t,r){return t===n[r]}))}))}void 0===t&&(t=1);var n=[],e=function(r,o){var u=e.get(r);return u?u[1]:(o=o(),n.unshift([r.concat(),o]),c(n,t)&&(n.length=t),o)};return e.invalidate=function(t){-1<(t=r(t))&&n.splice(t,1)},e.get=function(t){return n[r(t)]||null},e},exports.callEach=function(t){return t.forEach((function(t){return t()}))},exports.defaultTo=d,exports.deferThrow=function(t){setTimeout((function(){throw Error(t)}),0)},exports.either=function(t,r){return!!t!=!!r},exports.greaterThan=s,exports.hasOwnProperty=_,exports.invariant=function(t,r){if(!t)throw r instanceof String?r.valueOf():Error(r?N(r):r)},exports.isArray=b,exports.isBoolean=function(t){return!!t===t},exports.isEmpty=S,exports.isFunction=g,exports.isNotArray=y,exports.isNotEmpty=q,exports.isNotNull=f,exports.isNotNullish=v,exports.isNotNumeric=n,exports.isNotUndefined=l,exports.isNull=a,exports.isNullish=x,exports.isNumeric=r,exports.isPositive=function(t){return s(t,0)},exports.isPromise=function(t){return t&&g(t.then)},exports.isStringValue=function(t){return String(t)===t},exports.isUndefined=p,exports.last=m,exports.lengthEquals=u,exports.lengthNotEquals=i,exports.longerThan=c,exports.mapFirst=function(t,r){function n(t,r){t&&(e=!0,o=r)}for(var e=!1,o=null,u=0;u<t.length;u++)if(r(t[u],n,u),e)return o},exports.nestedArray=O,exports.numberEquals=e,exports.numberNotEquals=o,exports.optionalFunctionValue=N,exports.seq=w;
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,299 @@
1
+ function bindNot(fn) {
2
+ return function () {
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
+ };
9
+ }
10
+
11
+ function isNumeric(value) {
12
+ var str = String(value);
13
+ var num = Number(value);
14
+ var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
15
+ return Boolean(result);
16
+ }
17
+ var isNotNumeric = bindNot(isNumeric);
18
+
19
+ function numberEquals(value, eq) {
20
+ return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
21
+ }
22
+ var numberNotEquals = bindNot(numberEquals);
23
+
24
+ function lengthEquals(value, arg1) {
25
+ return numberEquals(value.length, arg1);
26
+ }
27
+ var lengthNotEquals = bindNot(lengthEquals);
28
+
29
+ function greaterThan(value, gt) {
30
+ return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
31
+ }
32
+
33
+ function longerThan(value, arg1) {
34
+ return greaterThan(value.length, arg1);
35
+ }
36
+
37
+ /**
38
+ * Creates a cache function
39
+ */
40
+ function createCache(maxSize) {
41
+ if (maxSize === void 0) { maxSize = 1; }
42
+ var cacheStorage = [];
43
+ var cache = function (deps, cacheAction) {
44
+ var cacheHit = cache.get(deps);
45
+ // cache hit is not null
46
+ if (cacheHit)
47
+ return cacheHit[1];
48
+ var result = cacheAction();
49
+ cacheStorage.unshift([deps.concat(), result]);
50
+ if (longerThan(cacheStorage, maxSize))
51
+ cacheStorage.length = maxSize;
52
+ return result;
53
+ };
54
+ // invalidate an item in the cache by its dependencies
55
+ cache.invalidate = function (deps) {
56
+ var index = findIndex(deps);
57
+ if (index > -1)
58
+ cacheStorage.splice(index, 1);
59
+ };
60
+ // Retrieves an item from the cache.
61
+ cache.get = function (deps) {
62
+ return cacheStorage[findIndex(deps)] || null;
63
+ };
64
+ return cache;
65
+ function findIndex(deps) {
66
+ return cacheStorage.findIndex(function (_a) {
67
+ var cachedDeps = _a[0];
68
+ return lengthEquals(deps, cachedDeps.length) &&
69
+ deps.every(function (dep, i) { return dep === cachedDeps[i]; });
70
+ });
71
+ }
72
+ }
73
+
74
+ function isNull(value) {
75
+ return value === null;
76
+ }
77
+ var isNotNull = bindNot(isNull);
78
+
79
+ function isUndefined(value) {
80
+ return value === undefined;
81
+ }
82
+ var isNotUndefined = bindNot(isUndefined);
83
+
84
+ function isNullish(value) {
85
+ return isNull(value) || isUndefined(value);
86
+ }
87
+ var isNotNullish = bindNot(isNullish);
88
+
89
+ function asArray(possibleArg) {
90
+ return [].concat(possibleArg);
91
+ }
92
+
93
+ function isFunction(value) {
94
+ return typeof value === 'function';
95
+ }
96
+
97
+ function optionalFunctionValue(value) {
98
+ var args = [];
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;
103
+ }
104
+
105
+ function defaultTo(value, defaultValue) {
106
+ var _a;
107
+ return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
108
+ }
109
+
110
+ // The module is named "isArrayValue" since it
111
+ // is conflicting with a nested npm dependency.
112
+ // We may need to revisit this in the future.
113
+ function isArray(value) {
114
+ return Boolean(Array.isArray(value));
115
+ }
116
+ var isNotArray = bindNot(isArray);
117
+
118
+ function last(values) {
119
+ var valuesArray = asArray(values);
120
+ return valuesArray[valuesArray.length - 1];
121
+ }
122
+
123
+ // This is kind of a map/filter in one function.
124
+ // Normally, behaves like a nested-array map,
125
+ // but returning `null` will drop the element from the array
126
+ function transform(array, cb) {
127
+ var res = [];
128
+ for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
129
+ var v = array_1[_i];
130
+ if (isArray(v)) {
131
+ res.push(transform(v, cb));
132
+ }
133
+ else {
134
+ var output = cb(v);
135
+ if (isNotNull(output)) {
136
+ res.push(output);
137
+ }
138
+ }
139
+ }
140
+ return res;
141
+ }
142
+ function valueAtPath(array, path) {
143
+ return getCurrent(array, path)[last(path)];
144
+ }
145
+ function setValueAtPath(array, path, value) {
146
+ var current = getCurrent(array, path);
147
+ current[last(path)] = value;
148
+ return array;
149
+ }
150
+ function flatten(values) {
151
+ return asArray(values).reduce(function (acc, value) {
152
+ if (isArray(value)) {
153
+ return acc.concat(flatten(value));
154
+ }
155
+ return asArray(acc).concat(value);
156
+ }, []);
157
+ }
158
+ function getCurrent(array, path) {
159
+ var current = array;
160
+ for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) {
161
+ var p = _a[_i];
162
+ current[p] = defaultTo(current[p], []);
163
+ current = current[p];
164
+ }
165
+ return current;
166
+ }
167
+
168
+ var nestedArray = /*#__PURE__*/Object.freeze({
169
+ __proto__: null,
170
+ transform: transform,
171
+ valueAtPath: valueAtPath,
172
+ setValueAtPath: setValueAtPath,
173
+ flatten: flatten,
174
+ getCurrent: getCurrent
175
+ });
176
+
177
+ function callEach(arr) {
178
+ return arr.forEach(function (fn) { return fn(); });
179
+ }
180
+
181
+ /**
182
+ * A safe hasOwnProperty access
183
+ */
184
+ function hasOwnProperty(obj, key) {
185
+ return Object.prototype.hasOwnProperty.call(obj, key);
186
+ }
187
+
188
+ function isPromise(value) {
189
+ return value && isFunction(value.then);
190
+ }
191
+
192
+ var assign = Object.assign;
193
+
194
+ function invariant(condition,
195
+ // eslint-disable-next-line @typescript-eslint/ban-types
196
+ message) {
197
+ if (condition) {
198
+ return;
199
+ }
200
+ // If message is a string object (rather than string literal)
201
+ // Throw the value directly as a string
202
+ // Alternatively, throw an error with the message
203
+ throw message instanceof String
204
+ ? message.valueOf()
205
+ : new Error(message ? optionalFunctionValue(message) : message);
206
+ }
207
+ // eslint-disable-next-line @typescript-eslint/ban-types
208
+ function StringObject(value) {
209
+ return new String(optionalFunctionValue(value));
210
+ }
211
+
212
+ function isStringValue(v) {
213
+ return String(v) === v;
214
+ }
215
+
216
+ function either(a, b) {
217
+ return !!a !== !!b;
218
+ }
219
+
220
+ function isBoolean(value) {
221
+ return !!value === value;
222
+ }
223
+
224
+ function deferThrow(message) {
225
+ setTimeout(function () {
226
+ throw new Error(message);
227
+ }, 0);
228
+ }
229
+
230
+ function createBus() {
231
+ var listeners = {};
232
+ return {
233
+ emit: function (event, data) {
234
+ listener(event).forEach(function (handler) {
235
+ handler(data);
236
+ });
237
+ },
238
+ on: function (event, handler) {
239
+ listeners[event] = listener(event).concat(handler);
240
+ return {
241
+ off: function () {
242
+ listeners[event] = listener(event).filter(function (h) { return h !== handler; });
243
+ }
244
+ };
245
+ }
246
+ };
247
+ function listener(event) {
248
+ return listeners[event] || [];
249
+ }
250
+ }
251
+
252
+ var bus = /*#__PURE__*/Object.freeze({
253
+ __proto__: null,
254
+ createBus: createBus
255
+ });
256
+
257
+ /**
258
+ * @returns a unique numeric id.
259
+ */
260
+ var seq = (function (n) { return function () {
261
+ return "".concat(n++);
262
+ }; })(0);
263
+
264
+ function mapFirst(array, callback) {
265
+ var broke = false;
266
+ var breakoutValue = null;
267
+ for (var i = 0; i < array.length; i++) {
268
+ callback(array[i], breakout, i);
269
+ if (broke) {
270
+ return breakoutValue;
271
+ }
272
+ }
273
+ function breakout(conditional, value) {
274
+ if (conditional) {
275
+ broke = true;
276
+ breakoutValue = value;
277
+ }
278
+ }
279
+ }
280
+
281
+ function isEmpty(value) {
282
+ if (!value) {
283
+ return true;
284
+ }
285
+ else if (hasOwnProperty(value, 'length')) {
286
+ return lengthEquals(value, 0);
287
+ }
288
+ else if (typeof value === 'object') {
289
+ return lengthEquals(Object.keys(value), 0);
290
+ }
291
+ return false;
292
+ }
293
+ var isNotEmpty = bindNot(isEmpty);
294
+
295
+ function isPositive(value) {
296
+ return greaterThan(value, 0);
297
+ }
298
+
299
+ export { StringObject, asArray, assign, bindNot, bus, createCache as cache, callEach, defaultTo, deferThrow, either, 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 };
@@ -0,0 +1 @@
1
+ function n(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function t(n){var t=Number(n);return!(isNaN(parseFloat(String(n)))||isNaN(Number(n))||!isFinite(t))}var r=n(t);function u(n,r){return t(n)&&t(r)&&Number(n)===Number(r)}var e=n(u);function o(n,t){return u(n.length,t)}var i=n(o);function a(n,r){return t(n)&&t(r)&&Number(n)>Number(r)}function c(n,t){return a(n.length,t)}function f(n){return null===n}var s=n(f);function l(n){return void 0===n}var v=n(l);function h(n){return null===n||l(n)}var N=n(h);function g(n){return[].concat(n)}function p(n){return"function"==typeof n}function b(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return p(n)?n.apply(void 0,t):n}function d(n,t){var r;return null!==(r=b(n))&&void 0!==r?r:b(t)}function y(n){return!!Array.isArray(n)}var m=n(y);function E(n){return(n=g(n))[n.length-1]}function A(n,t){var r=0;for(t=t.slice(0,-1);r<t.length;r++){var u=t[r];n[u]=d(n[u],[]),n=n[u]}return n}var _=Object.freeze({__proto__:null,transform:function n(t,r){for(var u=[],e=0;e<t.length;e++){var o=t[e];y(o)?u.push(n(o,r)):(o=r(o),s(o)&&u.push(o))}return u},valueAtPath:function(n,t){return A(n,t)[E(t)]},setValueAtPath:function(n,t,r){return A(n,t)[E(t)]=r,n},flatten:function n(t){return g(t).reduce((function(t,r){return y(r)?t.concat(n(r)):g(t).concat(r)}),[])},getCurrent:A});function O(n,t){return Object.prototype.hasOwnProperty.call(n,t)}var j,q=Object.assign,w=Object.freeze({__proto__:null,createBus:function(){var n={};return{emit:function(t,r){(n[t]||[]).forEach((function(n){n(r)}))},on:function(t,r){return n[t]=(n[t]||[]).concat(r),{off:function(){n[t]=(n[t]||[]).filter((function(n){return n!==r}))}}}}}}),F=(j=0,function(){return"".concat(j++)});function S(n){return!n||(O(n,"length")?o(n,0):"object"==typeof n&&o(Object.keys(n),0))}var T=n(S);function P(n){return new String(b(n))}function x(n){function t(r,e){var o=t.get(r);return o?o[1]:(e=e(),u.unshift([r.concat(),e]),c(u,n)&&(u.length=n),e)}function r(n){return u.findIndex((function(t){var r=t[0];return o(n,r.length)&&n.every((function(n,t){return n===r[t]}))}))}void 0===n&&(n=1);var u=[];return t.invalidate=function(n){-1<(n=r(n))&&u.splice(n,1)},t.get=function(n){return u[r(n)]||null},t}function z(n){return n.forEach((function(n){return n()}))}function U(n){setTimeout((function(){throw Error(n)}),0)}function V(n,t){return!!n!=!!t}function k(n,t){if(!n)throw t instanceof String?t.valueOf():Error(t?b(t):t)}function B(n){return!!n===n}function C(n){return a(n,0)}function I(n){return n&&p(n.then)}function D(n){return String(n)===n}function G(n,t){function r(n,t){n&&(u=!0,e=t)}for(var u=!1,e=null,o=0;o<n.length;o++)if(t(n[o],r,o),u)return e}export{P as StringObject,g as asArray,q as assign,n as bindNot,w as bus,x as cache,z as callEach,d as defaultTo,U as deferThrow,V as either,a as greaterThan,O as hasOwnProperty,k as invariant,y as isArray,B as isBoolean,S as isEmpty,p as isFunction,m as isNotArray,T as isNotEmpty,s as isNotNull,N as isNotNullish,r as isNotNumeric,v as isNotUndefined,f as isNull,h as isNullish,t as isNumeric,C as isPositive,I as isPromise,D as isStringValue,l as isUndefined,E as last,o as lengthEquals,i as lengthNotEquals,c as longerThan,G as mapFirst,_ as nestedArray,u as numberEquals,e as numberNotEquals,b as optionalFunctionValue,F as seq};