vest-utils
Advanced tools
Comparing version 0.1.1 to 1.0.0-next-7526f5
@@ -6,18 +6,12 @@ 'use strict'; | ||
function bindNot(fn) { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return !fn.apply(void 0, args); | ||
}; | ||
return (...args) => !fn(...args); | ||
} | ||
function isNumeric(value) { | ||
var str = String(value); | ||
var num = Number(value); | ||
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num); | ||
const str = String(value); | ||
const num = Number(value); | ||
const result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num); | ||
return Boolean(result); | ||
} | ||
var isNotNumeric = bindNot(isNumeric); | ||
const isNotNumeric = bindNot(isNumeric); | ||
@@ -27,3 +21,3 @@ function numberEquals(value, eq) { | ||
} | ||
var numberNotEquals = bindNot(numberEquals); | ||
const numberNotEquals = bindNot(numberEquals); | ||
@@ -33,3 +27,3 @@ function lengthEquals(value, arg1) { | ||
} | ||
var lengthNotEquals = bindNot(lengthEquals); | ||
const lengthNotEquals = bindNot(lengthEquals); | ||
@@ -47,11 +41,10 @@ function greaterThan(value, gt) { | ||
*/ | ||
function createCache(maxSize) { | ||
if (maxSize === void 0) { maxSize = 1; } | ||
var cacheStorage = []; | ||
var cache = function (deps, cacheAction) { | ||
var cacheHit = cache.get(deps); | ||
function createCache(maxSize = 1) { | ||
const cacheStorage = []; | ||
const cache = (deps, cacheAction) => { | ||
const cacheHit = cache.get(deps); | ||
// cache hit is not null | ||
if (cacheHit) | ||
return cacheHit[1]; | ||
var result = cacheAction(); | ||
const result = cacheAction(); | ||
cacheStorage.unshift([deps.concat(), result]); | ||
@@ -63,4 +56,4 @@ if (longerThan(cacheStorage, maxSize)) | ||
// invalidate an item in the cache by its dependencies | ||
cache.invalidate = function (deps) { | ||
var index = findIndex(deps); | ||
cache.invalidate = (deps) => { | ||
const index = findIndex(deps); | ||
if (index > -1) | ||
@@ -70,12 +63,7 @@ cacheStorage.splice(index, 1); | ||
// Retrieves an item from the cache. | ||
cache.get = function (deps) { | ||
return cacheStorage[findIndex(deps)] || null; | ||
}; | ||
cache.get = (deps) => cacheStorage[findIndex(deps)] || null; | ||
return cache; | ||
function findIndex(deps) { | ||
return cacheStorage.findIndex(function (_a) { | ||
var cachedDeps = _a[0]; | ||
return lengthEquals(deps, cachedDeps.length) && | ||
deps.every(function (dep, i) { return dep === cachedDeps[i]; }); | ||
}); | ||
return cacheStorage.findIndex(([cachedDeps]) => lengthEquals(deps, cachedDeps.length) && | ||
deps.every((dep, i) => dep === cachedDeps[i])); | ||
} | ||
@@ -87,3 +75,3 @@ } | ||
} | ||
var isNotNull = bindNot(isNull); | ||
const isNotNull = bindNot(isNull); | ||
@@ -93,3 +81,3 @@ function isUndefined(value) { | ||
} | ||
var isNotUndefined = bindNot(isUndefined); | ||
const isNotUndefined = bindNot(isUndefined); | ||
@@ -99,3 +87,3 @@ function isNullish(value) { | ||
} | ||
var isNotNullish = bindNot(isNullish); | ||
const isNotNullish = bindNot(isNullish); | ||
@@ -106,88 +94,4 @@ function asArray(possibleArg) { | ||
function isFunction(value) { | ||
return typeof value === 'function'; | ||
} | ||
function optionalFunctionValue(value) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
return isFunction(value) ? value.apply(void 0, args) : value; | ||
} | ||
function defaultTo(value, defaultValue) { | ||
var _a; | ||
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue); | ||
} | ||
// The module is named "isArrayValue" since it | ||
// is conflicting with a nested npm dependency. | ||
// We may need to revisit this in the future. | ||
function isArray(value) { | ||
return Boolean(Array.isArray(value)); | ||
} | ||
var isNotArray = bindNot(isArray); | ||
function last(values) { | ||
var valuesArray = asArray(values); | ||
return valuesArray[valuesArray.length - 1]; | ||
} | ||
// This is kind of a map/filter in one function. | ||
// Normally, behaves like a nested-array map, | ||
// but returning `null` will drop the element from the array | ||
function transform(array, cb) { | ||
var res = []; | ||
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) { | ||
var v = array_1[_i]; | ||
if (isArray(v)) { | ||
res.push(transform(v, cb)); | ||
} | ||
else { | ||
var output = cb(v); | ||
if (isNotNull(output)) { | ||
res.push(output); | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
function valueAtPath(array, path) { | ||
return getCurrent(array, path)[last(path)]; | ||
} | ||
function setValueAtPath(array, path, value) { | ||
var current = getCurrent(array, path); | ||
current[last(path)] = value; | ||
return array; | ||
} | ||
function flatten(values) { | ||
return asArray(values).reduce(function (acc, value) { | ||
if (isArray(value)) { | ||
return acc.concat(flatten(value)); | ||
} | ||
return asArray(acc).concat(value); | ||
}, []); | ||
} | ||
function getCurrent(array, path) { | ||
var current = array; | ||
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) { | ||
var p = _a[_i]; | ||
current[p] = defaultTo(current[p], []); | ||
current = current[p]; | ||
} | ||
return current; | ||
} | ||
var nestedArray = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
transform: transform, | ||
valueAtPath: valueAtPath, | ||
setValueAtPath: setValueAtPath, | ||
flatten: flatten, | ||
getCurrent: getCurrent | ||
}); | ||
function callEach(arr) { | ||
return arr.forEach(function (fn) { return fn(); }); | ||
return arr.forEach(fn => fn()); | ||
} | ||
@@ -202,2 +106,6 @@ | ||
function isFunction(value) { | ||
return typeof value === 'function'; | ||
} | ||
function isPromise(value) { | ||
@@ -207,4 +115,13 @@ return value && isFunction(value.then); | ||
function optionalFunctionValue(value, ...args) { | ||
return isFunction(value) ? value(...args) : value; | ||
} | ||
var assign = Object.assign; | ||
function defaultTo(value, defaultValue) { | ||
var _a; | ||
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue); | ||
} | ||
function invariant(condition, | ||
@@ -240,4 +157,9 @@ // eslint-disable-next-line @typescript-eslint/ban-types | ||
function last(values) { | ||
const valuesArray = asArray(values); | ||
return valuesArray[valuesArray.length - 1]; | ||
} | ||
function deferThrow(message) { | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
throw new Error(message); | ||
@@ -248,17 +170,17 @@ }, 0); | ||
function createBus() { | ||
var listeners = {}; | ||
const listeners = {}; | ||
return { | ||
emit: function (event, data) { | ||
listener(event).forEach(function (handler) { | ||
emit(event, data) { | ||
listener(event).forEach(handler => { | ||
handler(data); | ||
}); | ||
}, | ||
on: function (event, handler) { | ||
on(event, handler) { | ||
listeners[event] = listener(event).concat(handler); | ||
return { | ||
off: function () { | ||
listeners[event] = listener(event).filter(function (h) { return h !== handler; }); | ||
} | ||
off() { | ||
listeners[event] = listener(event).filter(h => h !== handler); | ||
}, | ||
}; | ||
} | ||
}, | ||
}; | ||
@@ -278,13 +200,11 @@ function listener(event) { | ||
*/ | ||
var seq = genSeq(); | ||
const seq = genSeq(); | ||
function genSeq(namespace) { | ||
return (function (n) { return function () { | ||
return "".concat(namespace ? namespace + '_' : '').concat(n++); | ||
}; })(0); | ||
return ((n) => () => `${namespace ? namespace + '_' : ''}${n++}`)(0); | ||
} | ||
function mapFirst(array, callback) { | ||
var broke = false; | ||
var breakoutValue = null; | ||
for (var i = 0; i < array.length; i++) { | ||
let broke = false; | ||
let breakoutValue = null; | ||
for (let i = 0; i < array.length; i++) { | ||
callback(array[i], breakout, i); | ||
@@ -303,2 +223,14 @@ if (broke) { | ||
function isObject(v) { | ||
return typeof v === 'object' && !isNullish(v); | ||
} | ||
// The module is named "isArrayValue" since it | ||
// is conflicting with a nested npm dependency. | ||
// We may need to revisit this in the future. | ||
function isArray(value) { | ||
return Boolean(Array.isArray(value)); | ||
} | ||
const isNotArray = bindNot(isArray); | ||
function isEmpty(value) { | ||
@@ -311,3 +243,3 @@ if (!value) { | ||
} | ||
else if (typeof value === 'object') { | ||
else if (isObject(value)) { | ||
return lengthEquals(Object.keys(value), 0); | ||
@@ -317,3 +249,3 @@ } | ||
} | ||
var isNotEmpty = bindNot(isEmpty); | ||
const isNotEmpty = bindNot(isEmpty); | ||
@@ -324,2 +256,34 @@ function isPositive(value) { | ||
const regexp = /{(.*?)}/g; | ||
function text(str, ...substitutions) { | ||
const first = substitutions[0]; | ||
if (isObject(first)) { | ||
return str.replace(regexp, (placeholder, key) => { | ||
var _a; | ||
return `${(_a = first[key]) !== null && _a !== void 0 ? _a : placeholder}`; | ||
}); | ||
} | ||
const subs = [...substitutions]; | ||
return str.replace(regexp, placeholder => { | ||
return `${isEmpty(subs) ? placeholder : subs.shift()}`; | ||
}); | ||
} | ||
function createTinyState(initialValue) { | ||
let value; | ||
resetValue(); | ||
return () => [value, setValue, resetValue]; | ||
function setValue(nextValue) { | ||
value = optionalFunctionValue(nextValue, value); | ||
} | ||
function resetValue() { | ||
setValue(optionalFunctionValue(initialValue)); | ||
} | ||
} | ||
var tinyState = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
createTinyState: createTinyState | ||
}); | ||
exports.StringObject = StringObject; | ||
@@ -352,2 +316,3 @@ exports.asArray = asArray; | ||
exports.isNumeric = isNumeric; | ||
exports.isObject = isObject; | ||
exports.isPositive = isPositive; | ||
@@ -362,3 +327,2 @@ exports.isPromise = isPromise; | ||
exports.mapFirst = mapFirst; | ||
exports.nestedArray = nestedArray; | ||
exports.numberEquals = numberEquals; | ||
@@ -368,1 +332,3 @@ exports.numberNotEquals = numberNotEquals; | ||
exports.seq = seq; | ||
exports.text = text; | ||
exports.tinyState = tinyState; |
@@ -1,1 +0,1 @@ | ||
"use strict";function r(r){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return!r.apply(void 0,t)}}function t(r){var t=String(r),n=Number(r),e=!isNaN(parseFloat(t))&&!isNaN(Number(r))&&isFinite(n);return Boolean(e)}Object.defineProperty(exports,"__esModule",{value:!0});var n=r(t);function e(r,n){return t(r)&&t(n)&&Number(r)===Number(n)}var o=r(e);function u(r,t){return e(r.length,t)}var i=r(u);function s(r,n){return t(r)&&t(n)&&Number(r)>Number(n)}function c(r,t){return s(r.length,t)}function a(r){return null===r}var f=r(a);function l(r){return void 0===r}var p=r(l);function x(r){return a(r)||l(r)}var v=r(x);function h(r){return[].concat(r)}function g(r){return"function"==typeof r}function N(r){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return g(r)?r.apply(void 0,t):r}function d(r,t){var n;return null!==(n=N(r))&&void 0!==n?n:N(t)}function b(r){return Boolean(Array.isArray(r))}var y=r(b);function m(r){var t=h(r);return t[t.length-1]}function E(r,t){for(var n=r,e=0,o=t.slice(0,-1);e<o.length;e++){var u=o[e];n[u]=d(n[u],[]),n=n[u]}return n}var _=Object.freeze({__proto__:null,transform:function r(t,n){for(var e=[],o=0,u=t;o<u.length;o++){var i=u[o];if(b(i))e.push(r(i,n));else{var s=n(i);f(s)&&e.push(s)}}return e},valueAtPath:function(r,t){return E(r,t)[m(t)]},setValueAtPath:function(r,t,n){return E(r,t)[m(t)]=n,r},flatten:function r(t){return h(t).reduce((function(t,n){return b(n)?t.concat(r(n)):h(t).concat(n)}),[])},getCurrent:E});function O(r,t){return Object.prototype.hasOwnProperty.call(r,t)}var j=Object.assign;var w=Object.freeze({__proto__:null,createBus:function(){var r={};return{emit:function(r,n){t(r).forEach((function(r){r(n)}))},on:function(n,e){return r[n]=t(n).concat(e),{off:function(){r[n]=t(n).filter((function(r){return r!==e}))}}}};function t(t){return r[t]||[]}}}),A=P();function P(r){return t=0,function(){return"".concat(r?r+"_":"").concat(t++)};var t}function S(r){return!r||(O(r,"length")?u(r,0):"object"==typeof r&&u(Object.keys(r),0))}var q=r(S);exports.StringObject=function(r){return new String(N(r))},exports.asArray=h,exports.assign=j,exports.bindNot=r,exports.bus=w,exports.cache=function(r){void 0===r&&(r=1);var t=[],n=function(e,o){var u=n.get(e);if(u)return u[1];var i=o();return t.unshift([e.concat(),i]),c(t,r)&&(t.length=r),i};return n.invalidate=function(r){var n=e(r);n>-1&&t.splice(n,1)},n.get=function(r){return t[e(r)]||null},n;function e(r){return t.findIndex((function(t){var n=t[0];return u(r,n.length)&&r.every((function(r,t){return r===n[t]}))}))}},exports.callEach=function(r){return r.forEach((function(r){return r()}))},exports.defaultTo=d,exports.deferThrow=function(r){setTimeout((function(){throw new Error(r)}),0)},exports.either=function(r,t){return!!r!=!!t},exports.genSeq=P,exports.greaterThan=s,exports.hasOwnProperty=O,exports.invariant=function(r,t){if(!r)throw t instanceof String?t.valueOf():new Error(t?N(t):t)},exports.isArray=b,exports.isBoolean=function(r){return!!r===r},exports.isEmpty=S,exports.isFunction=g,exports.isNotArray=y,exports.isNotEmpty=q,exports.isNotNull=f,exports.isNotNullish=v,exports.isNotNumeric=n,exports.isNotUndefined=p,exports.isNull=a,exports.isNullish=x,exports.isNumeric=t,exports.isPositive=function(r){return s(r,0)},exports.isPromise=function(r){return r&&g(r.then)},exports.isStringValue=function(r){return String(r)===r},exports.isUndefined=l,exports.last=m,exports.lengthEquals=u,exports.lengthNotEquals=i,exports.longerThan=c,exports.mapFirst=function(r,t){for(var n=!1,e=null,o=0;o<r.length;o++)if(t(r[o],u,o),n)return e;function u(r,t){r&&(n=!0,e=t)}},exports.nestedArray=_,exports.numberEquals=e,exports.numberNotEquals=o,exports.optionalFunctionValue=N,exports.seq=A; | ||
"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 s(t,n){return e(t.length,n)}const u=t(s);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 p=t(f);function l(t){return void 0===t}const a=t(l);function x(t){return f(t)||l(t)}const h=t(x);function N(t){return[].concat(t)}function g(t,n){return Object.prototype.hasOwnProperty.call(t,n)}function b(t){return"function"==typeof t}function y(t,...n){return b(t)?t(...n):t}var m=Object.assign;var d=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 v=E();function E(t){return n=0,()=>`${t?t+"_":""}${n++}`;var n}function O(t){return"object"==typeof t&&!x(t)}function _(t){return Boolean(Array.isArray(t))}const j=t(_);function S(t){return!t||(g(t,"length")?s(t,0):!!O(t)&&s(Object.keys(t),0))}const w=t(S);const q=/{(.*?)}/g;var T=Object.freeze({__proto__:null,createTinyState:function(t){let n;return e(),()=>[n,r,e];function r(t){n=y(t,n)}function e(){r(y(t))}}});exports.StringObject=function(t){return new String(y(t))},exports.asArray=N,exports.assign=m,exports.bindNot=t,exports.bus=d,exports.cache=function(t=1){const n=[],r=(e,o)=>{const s=r.get(e);if(s)return s[1];const u=o();return n.unshift([e.concat(),u]),c(n,t)&&(n.length=t),u};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])=>s(t,n.length)&&t.every(((t,r)=>t===n[r]))))}},exports.callEach=function(t){return t.forEach((t=>t()))},exports.defaultTo=function(t,n){var r;return null!==(r=y(t))&&void 0!==r?r:y(n)},exports.deferThrow=function(t){setTimeout((()=>{throw new Error(t)}),0)},exports.either=function(t,n){return!!t!=!!n},exports.genSeq=E,exports.greaterThan=i,exports.hasOwnProperty=g,exports.invariant=function(t,n){if(!t)throw n instanceof String?n.valueOf():new Error(n?y(n):n)},exports.isArray=_,exports.isBoolean=function(t){return!!t===t},exports.isEmpty=S,exports.isFunction=b,exports.isNotArray=j,exports.isNotEmpty=w,exports.isNotNull=p,exports.isNotNullish=h,exports.isNotNumeric=r,exports.isNotUndefined=a,exports.isNull=f,exports.isNullish=x,exports.isNumeric=n,exports.isObject=O,exports.isPositive=function(t){return i(t,0)},exports.isPromise=function(t){return t&&b(t.then)},exports.isStringValue=function(t){return String(t)===t},exports.isUndefined=l,exports.last=function(t){const n=N(t);return n[n.length-1]},exports.lengthEquals=s,exports.lengthNotEquals=u,exports.longerThan=c,exports.mapFirst=function(t,n){let r=!1,e=null;for(let s=0;s<t.length;s++)if(n(t[s],o,s),r)return e;function o(t,n){t&&(r=!0,e=n)}},exports.numberEquals=e,exports.numberNotEquals=o,exports.optionalFunctionValue=y,exports.seq=v,exports.text=function(t,...n){const r=n[0];if(O(r))return t.replace(q,((t,n)=>{var e;return`${null!==(e=r[n])&&void 0!==e?e:t}`}));const e=[...n];return t.replace(q,(t=>`${S(e)?t:e.shift()}`))},exports.tinyState=T; |
function bindNot(fn) { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return !fn.apply(void 0, args); | ||
}; | ||
return (...args) => !fn(...args); | ||
} | ||
function isNumeric(value) { | ||
var str = String(value); | ||
var num = Number(value); | ||
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num); | ||
const str = String(value); | ||
const num = Number(value); | ||
const result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num); | ||
return Boolean(result); | ||
} | ||
var isNotNumeric = bindNot(isNumeric); | ||
const isNotNumeric = bindNot(isNumeric); | ||
@@ -22,3 +16,3 @@ function numberEquals(value, eq) { | ||
} | ||
var numberNotEquals = bindNot(numberEquals); | ||
const numberNotEquals = bindNot(numberEquals); | ||
@@ -28,3 +22,3 @@ function lengthEquals(value, arg1) { | ||
} | ||
var lengthNotEquals = bindNot(lengthEquals); | ||
const lengthNotEquals = bindNot(lengthEquals); | ||
@@ -42,11 +36,10 @@ function greaterThan(value, gt) { | ||
*/ | ||
function createCache(maxSize) { | ||
if (maxSize === void 0) { maxSize = 1; } | ||
var cacheStorage = []; | ||
var cache = function (deps, cacheAction) { | ||
var cacheHit = cache.get(deps); | ||
function createCache(maxSize = 1) { | ||
const cacheStorage = []; | ||
const cache = (deps, cacheAction) => { | ||
const cacheHit = cache.get(deps); | ||
// cache hit is not null | ||
if (cacheHit) | ||
return cacheHit[1]; | ||
var result = cacheAction(); | ||
const result = cacheAction(); | ||
cacheStorage.unshift([deps.concat(), result]); | ||
@@ -58,4 +51,4 @@ if (longerThan(cacheStorage, maxSize)) | ||
// invalidate an item in the cache by its dependencies | ||
cache.invalidate = function (deps) { | ||
var index = findIndex(deps); | ||
cache.invalidate = (deps) => { | ||
const index = findIndex(deps); | ||
if (index > -1) | ||
@@ -65,12 +58,7 @@ cacheStorage.splice(index, 1); | ||
// Retrieves an item from the cache. | ||
cache.get = function (deps) { | ||
return cacheStorage[findIndex(deps)] || null; | ||
}; | ||
cache.get = (deps) => cacheStorage[findIndex(deps)] || null; | ||
return cache; | ||
function findIndex(deps) { | ||
return cacheStorage.findIndex(function (_a) { | ||
var cachedDeps = _a[0]; | ||
return lengthEquals(deps, cachedDeps.length) && | ||
deps.every(function (dep, i) { return dep === cachedDeps[i]; }); | ||
}); | ||
return cacheStorage.findIndex(([cachedDeps]) => lengthEquals(deps, cachedDeps.length) && | ||
deps.every((dep, i) => dep === cachedDeps[i])); | ||
} | ||
@@ -82,3 +70,3 @@ } | ||
} | ||
var isNotNull = bindNot(isNull); | ||
const isNotNull = bindNot(isNull); | ||
@@ -88,3 +76,3 @@ function isUndefined(value) { | ||
} | ||
var isNotUndefined = bindNot(isUndefined); | ||
const isNotUndefined = bindNot(isUndefined); | ||
@@ -94,3 +82,3 @@ function isNullish(value) { | ||
} | ||
var isNotNullish = bindNot(isNullish); | ||
const isNotNullish = bindNot(isNullish); | ||
@@ -101,88 +89,4 @@ function asArray(possibleArg) { | ||
function isFunction(value) { | ||
return typeof value === 'function'; | ||
} | ||
function optionalFunctionValue(value) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
return isFunction(value) ? value.apply(void 0, args) : value; | ||
} | ||
function defaultTo(value, defaultValue) { | ||
var _a; | ||
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue); | ||
} | ||
// The module is named "isArrayValue" since it | ||
// is conflicting with a nested npm dependency. | ||
// We may need to revisit this in the future. | ||
function isArray(value) { | ||
return Boolean(Array.isArray(value)); | ||
} | ||
var isNotArray = bindNot(isArray); | ||
function last(values) { | ||
var valuesArray = asArray(values); | ||
return valuesArray[valuesArray.length - 1]; | ||
} | ||
// This is kind of a map/filter in one function. | ||
// Normally, behaves like a nested-array map, | ||
// but returning `null` will drop the element from the array | ||
function transform(array, cb) { | ||
var res = []; | ||
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) { | ||
var v = array_1[_i]; | ||
if (isArray(v)) { | ||
res.push(transform(v, cb)); | ||
} | ||
else { | ||
var output = cb(v); | ||
if (isNotNull(output)) { | ||
res.push(output); | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
function valueAtPath(array, path) { | ||
return getCurrent(array, path)[last(path)]; | ||
} | ||
function setValueAtPath(array, path, value) { | ||
var current = getCurrent(array, path); | ||
current[last(path)] = value; | ||
return array; | ||
} | ||
function flatten(values) { | ||
return asArray(values).reduce(function (acc, value) { | ||
if (isArray(value)) { | ||
return acc.concat(flatten(value)); | ||
} | ||
return asArray(acc).concat(value); | ||
}, []); | ||
} | ||
function getCurrent(array, path) { | ||
var current = array; | ||
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) { | ||
var p = _a[_i]; | ||
current[p] = defaultTo(current[p], []); | ||
current = current[p]; | ||
} | ||
return current; | ||
} | ||
var nestedArray = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
transform: transform, | ||
valueAtPath: valueAtPath, | ||
setValueAtPath: setValueAtPath, | ||
flatten: flatten, | ||
getCurrent: getCurrent | ||
}); | ||
function callEach(arr) { | ||
return arr.forEach(function (fn) { return fn(); }); | ||
return arr.forEach(fn => fn()); | ||
} | ||
@@ -197,2 +101,6 @@ | ||
function isFunction(value) { | ||
return typeof value === 'function'; | ||
} | ||
function isPromise(value) { | ||
@@ -202,4 +110,13 @@ return value && isFunction(value.then); | ||
function optionalFunctionValue(value, ...args) { | ||
return isFunction(value) ? value(...args) : value; | ||
} | ||
var assign = Object.assign; | ||
function defaultTo(value, defaultValue) { | ||
var _a; | ||
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue); | ||
} | ||
function invariant(condition, | ||
@@ -235,4 +152,9 @@ // eslint-disable-next-line @typescript-eslint/ban-types | ||
function last(values) { | ||
const valuesArray = asArray(values); | ||
return valuesArray[valuesArray.length - 1]; | ||
} | ||
function deferThrow(message) { | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
throw new Error(message); | ||
@@ -243,17 +165,17 @@ }, 0); | ||
function createBus() { | ||
var listeners = {}; | ||
const listeners = {}; | ||
return { | ||
emit: function (event, data) { | ||
listener(event).forEach(function (handler) { | ||
emit(event, data) { | ||
listener(event).forEach(handler => { | ||
handler(data); | ||
}); | ||
}, | ||
on: function (event, handler) { | ||
on(event, handler) { | ||
listeners[event] = listener(event).concat(handler); | ||
return { | ||
off: function () { | ||
listeners[event] = listener(event).filter(function (h) { return h !== handler; }); | ||
} | ||
off() { | ||
listeners[event] = listener(event).filter(h => h !== handler); | ||
}, | ||
}; | ||
} | ||
}, | ||
}; | ||
@@ -273,13 +195,11 @@ function listener(event) { | ||
*/ | ||
var seq = genSeq(); | ||
const seq = genSeq(); | ||
function genSeq(namespace) { | ||
return (function (n) { return function () { | ||
return "".concat(namespace ? namespace + '_' : '').concat(n++); | ||
}; })(0); | ||
return ((n) => () => `${namespace ? namespace + '_' : ''}${n++}`)(0); | ||
} | ||
function mapFirst(array, callback) { | ||
var broke = false; | ||
var breakoutValue = null; | ||
for (var i = 0; i < array.length; i++) { | ||
let broke = false; | ||
let breakoutValue = null; | ||
for (let i = 0; i < array.length; i++) { | ||
callback(array[i], breakout, i); | ||
@@ -298,2 +218,14 @@ if (broke) { | ||
function isObject(v) { | ||
return typeof v === 'object' && !isNullish(v); | ||
} | ||
// The module is named "isArrayValue" since it | ||
// is conflicting with a nested npm dependency. | ||
// We may need to revisit this in the future. | ||
function isArray(value) { | ||
return Boolean(Array.isArray(value)); | ||
} | ||
const isNotArray = bindNot(isArray); | ||
function isEmpty(value) { | ||
@@ -306,3 +238,3 @@ if (!value) { | ||
} | ||
else if (typeof value === 'object') { | ||
else if (isObject(value)) { | ||
return lengthEquals(Object.keys(value), 0); | ||
@@ -312,3 +244,3 @@ } | ||
} | ||
var isNotEmpty = bindNot(isEmpty); | ||
const isNotEmpty = bindNot(isEmpty); | ||
@@ -319,2 +251,34 @@ function isPositive(value) { | ||
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 }; | ||
const regexp = /{(.*?)}/g; | ||
function text(str, ...substitutions) { | ||
const first = substitutions[0]; | ||
if (isObject(first)) { | ||
return str.replace(regexp, (placeholder, key) => { | ||
var _a; | ||
return `${(_a = first[key]) !== null && _a !== void 0 ? _a : placeholder}`; | ||
}); | ||
} | ||
const subs = [...substitutions]; | ||
return str.replace(regexp, placeholder => { | ||
return `${isEmpty(subs) ? placeholder : subs.shift()}`; | ||
}); | ||
} | ||
function createTinyState(initialValue) { | ||
let value; | ||
resetValue(); | ||
return () => [value, setValue, resetValue]; | ||
function setValue(nextValue) { | ||
value = optionalFunctionValue(nextValue, value); | ||
} | ||
function resetValue() { | ||
setValue(optionalFunctionValue(initialValue)); | ||
} | ||
} | ||
var tinyState = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
createTinyState: createTinyState | ||
}); | ||
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, isObject, isPositive, isPromise, isStringValue, isUndefined, last, lengthEquals, lengthNotEquals, longerThan, mapFirst, numberEquals, numberNotEquals, optionalFunctionValue, seq, text, tinyState }; |
@@ -1,1 +0,1 @@ | ||
function n(n){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return!n.apply(void 0,r)}}function r(n){var r=String(n),t=Number(n),u=!isNaN(parseFloat(r))&&!isNaN(Number(n))&&isFinite(t);return Boolean(u)}var t=n(r);function u(n,t){return r(n)&&r(t)&&Number(n)===Number(t)}var e=n(u);function o(n,r){return u(n.length,r)}var c=n(o);function i(n,t){return r(n)&&r(t)&&Number(n)>Number(t)}function f(n,r){return i(n.length,r)}function a(n){void 0===n&&(n=1);var r=[],t=function(u,e){var o=t.get(u);if(o)return o[1];var c=e();return r.unshift([u.concat(),c]),f(r,n)&&(r.length=n),c};return t.invalidate=function(n){var t=u(n);t>-1&&r.splice(t,1)},t.get=function(n){return r[u(n)]||null},t;function u(n){return r.findIndex((function(r){var t=r[0];return o(n,t.length)&&n.every((function(n,r){return n===t[r]}))}))}}function l(n){return null===n}var v=n(l);function h(n){return void 0===n}var s=n(h);function g(n){return l(n)||h(n)}var p=n(g);function b(n){return[].concat(n)}function y(n){return"function"==typeof n}function N(n){for(var r=[],t=1;t<arguments.length;t++)r[t-1]=arguments[t];return y(n)?n.apply(void 0,r):n}function d(n,r){var t;return null!==(t=N(n))&&void 0!==t?t:N(r)}function m(n){return Boolean(Array.isArray(n))}var _=n(m);function O(n){var r=b(n);return r[r.length-1]}function j(n,r){for(var t=n,u=0,e=r.slice(0,-1);u<e.length;u++){var o=e[u];t[o]=d(t[o],[]),t=t[o]}return t}var w=Object.freeze({__proto__:null,transform:function n(r,t){for(var u=[],e=0,o=r;e<o.length;e++){var c=o[e];if(m(c))u.push(n(c,t));else{var i=t(c);v(i)&&u.push(i)}}return u},valueAtPath:function(n,r){return j(n,r)[O(r)]},setValueAtPath:function(n,r,t){return j(n,r)[O(r)]=t,n},flatten:function n(r){return b(r).reduce((function(r,t){return m(t)?r.concat(n(t)):b(r).concat(t)}),[])},getCurrent:j});function A(n){return n.forEach((function(n){return n()}))}function E(n,r){return Object.prototype.hasOwnProperty.call(n,r)}function S(n){return n&&y(n.then)}var B=Object.assign;function P(n,r){if(!n)throw r instanceof String?r.valueOf():new Error(r?N(r):r)}function x(n){return new String(N(n))}function z(n){return String(n)===n}function F(n,r){return!!n!=!!r}function k(n){return!!n===n}function C(n){setTimeout((function(){throw new Error(n)}),0)}var I=Object.freeze({__proto__:null,createBus:function(){var n={};return{emit:function(n,t){r(n).forEach((function(n){n(t)}))},on:function(t,u){return n[t]=r(t).concat(u),{off:function(){n[t]=r(t).filter((function(n){return n!==u}))}}}};function r(r){return n[r]||[]}}}),T=V();function V(n){return r=0,function(){return"".concat(n?n+"_":"").concat(r++)};var r}function q(n,r){for(var t=!1,u=null,e=0;e<n.length;e++)if(r(n[e],o,e),t)return u;function o(n,r){n&&(t=!0,u=r)}}function D(n){return!n||(E(n,"length")?o(n,0):"object"==typeof n&&o(Object.keys(n),0))}var G=n(D);function H(n){return i(n,0)}export{x as StringObject,b as asArray,B as assign,n as bindNot,I as bus,a as cache,A as callEach,d as defaultTo,C as deferThrow,F as either,V as genSeq,i as greaterThan,E as hasOwnProperty,P as invariant,m as isArray,k as isBoolean,D as isEmpty,y as isFunction,_ as isNotArray,G as isNotEmpty,v as isNotNull,p as isNotNullish,t as isNotNumeric,s as isNotUndefined,l as isNull,g as isNullish,r as isNumeric,H as isPositive,S as isPromise,z as isStringValue,h as isUndefined,O as last,o as lengthEquals,c as lengthNotEquals,f as longerThan,q as mapFirst,w as nestedArray,u as numberEquals,e as numberNotEquals,N as optionalFunctionValue,T as seq}; | ||
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 u=n(e);function o(n,t){return e(n.length,t)}const c=n(o);function i(n,r){return t(n)&&t(r)&&Number(n)>Number(r)}function f(n,t){return i(n.length,t)}function l(n=1){const t=[],r=(e,u)=>{const o=r.get(e);if(o)return o[1];const c=u();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])=>o(n,t.length)&&n.every(((n,r)=>n===t[r]))))}}function s(n){return null===n}const a=n(s);function h(n){return void 0===n}const g=n(h);function b(n){return s(n)||h(n)}const p=n(b);function v(n){return[].concat(n)}function N(n){return n.forEach((n=>n()))}function y(n,t){return Object.prototype.hasOwnProperty.call(n,t)}function _(n){return"function"==typeof n}function m(n){return n&&_(n.then)}function O(n,...t){return _(n)?n(...t):n}var d=Object.assign;function j(n,t){var r;return null!==(r=O(n))&&void 0!==r?r:O(t)}function w(n,t){if(!n)throw t instanceof String?t.valueOf():new Error(t?O(t):t)}function S(n){return new String(O(n))}function E(n){return String(n)===n}function $(n,t){return!!n!=!!t}function B(n){return!!n===n}function x(n){const t=v(n);return t[t.length-1]}function z(n){setTimeout((()=>{throw new Error(n)}),0)}var A=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 F=T();function T(n){return t=0,()=>`${n?n+"_":""}${t++}`;var t}function k(n,t){let r=!1,e=null;for(let o=0;o<n.length;o++)if(t(n[o],u,o),r)return e;function u(n,t){n&&(r=!0,e=t)}}function I(n){return"object"==typeof n&&!b(n)}function P(n){return Boolean(Array.isArray(n))}const q=n(P);function C(n){return!n||(y(n,"length")?o(n,0):!!I(n)&&o(Object.keys(n),0))}const D=n(C);function G(n){return i(n,0)}const H=/{(.*?)}/g;function J(n,...t){const r=t[0];if(I(r))return n.replace(H,((n,t)=>{var e;return`${null!==(e=r[t])&&void 0!==e?e:n}`}));const e=[...t];return n.replace(H,(n=>`${C(e)?n:e.shift()}`))}var K=Object.freeze({__proto__:null,createTinyState:function(n){let t;return e(),()=>[t,r,e];function r(n){t=O(n,t)}function e(){r(O(n))}}});export{S as StringObject,v as asArray,d as assign,n as bindNot,A as bus,l as cache,N as callEach,j as defaultTo,z as deferThrow,$ as either,T as genSeq,i as greaterThan,y as hasOwnProperty,w as invariant,P as isArray,B as isBoolean,C as isEmpty,_ as isFunction,q as isNotArray,D as isNotEmpty,a as isNotNull,p as isNotNullish,r as isNotNumeric,g as isNotUndefined,s as isNull,b as isNullish,t as isNumeric,I as isObject,G as isPositive,m as isPromise,E as isStringValue,h as isUndefined,x as last,o as lengthEquals,c as lengthNotEquals,f as longerThan,k as mapFirst,e as numberEquals,u as numberNotEquals,O as optionalFunctionValue,F as seq,J as text,K as tinyState}; |
@@ -8,18 +8,12 @@ (function (global, factory) { | ||
function bindNot(fn) { | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return !fn.apply(void 0, args); | ||
}; | ||
return (...args) => !fn(...args); | ||
} | ||
function isNumeric(value) { | ||
var str = String(value); | ||
var num = Number(value); | ||
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num); | ||
const str = String(value); | ||
const num = Number(value); | ||
const result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num); | ||
return Boolean(result); | ||
} | ||
var isNotNumeric = bindNot(isNumeric); | ||
const isNotNumeric = bindNot(isNumeric); | ||
@@ -29,3 +23,3 @@ function numberEquals(value, eq) { | ||
} | ||
var numberNotEquals = bindNot(numberEquals); | ||
const numberNotEquals = bindNot(numberEquals); | ||
@@ -35,3 +29,3 @@ function lengthEquals(value, arg1) { | ||
} | ||
var lengthNotEquals = bindNot(lengthEquals); | ||
const lengthNotEquals = bindNot(lengthEquals); | ||
@@ -49,11 +43,10 @@ function greaterThan(value, gt) { | ||
*/ | ||
function createCache(maxSize) { | ||
if (maxSize === void 0) { maxSize = 1; } | ||
var cacheStorage = []; | ||
var cache = function (deps, cacheAction) { | ||
var cacheHit = cache.get(deps); | ||
function createCache(maxSize = 1) { | ||
const cacheStorage = []; | ||
const cache = (deps, cacheAction) => { | ||
const cacheHit = cache.get(deps); | ||
// cache hit is not null | ||
if (cacheHit) | ||
return cacheHit[1]; | ||
var result = cacheAction(); | ||
const result = cacheAction(); | ||
cacheStorage.unshift([deps.concat(), result]); | ||
@@ -65,4 +58,4 @@ if (longerThan(cacheStorage, maxSize)) | ||
// invalidate an item in the cache by its dependencies | ||
cache.invalidate = function (deps) { | ||
var index = findIndex(deps); | ||
cache.invalidate = (deps) => { | ||
const index = findIndex(deps); | ||
if (index > -1) | ||
@@ -72,12 +65,7 @@ cacheStorage.splice(index, 1); | ||
// Retrieves an item from the cache. | ||
cache.get = function (deps) { | ||
return cacheStorage[findIndex(deps)] || null; | ||
}; | ||
cache.get = (deps) => cacheStorage[findIndex(deps)] || null; | ||
return cache; | ||
function findIndex(deps) { | ||
return cacheStorage.findIndex(function (_a) { | ||
var cachedDeps = _a[0]; | ||
return lengthEquals(deps, cachedDeps.length) && | ||
deps.every(function (dep, i) { return dep === cachedDeps[i]; }); | ||
}); | ||
return cacheStorage.findIndex(([cachedDeps]) => lengthEquals(deps, cachedDeps.length) && | ||
deps.every((dep, i) => dep === cachedDeps[i])); | ||
} | ||
@@ -89,3 +77,3 @@ } | ||
} | ||
var isNotNull = bindNot(isNull); | ||
const isNotNull = bindNot(isNull); | ||
@@ -95,3 +83,3 @@ function isUndefined(value) { | ||
} | ||
var isNotUndefined = bindNot(isUndefined); | ||
const isNotUndefined = bindNot(isUndefined); | ||
@@ -101,3 +89,3 @@ function isNullish(value) { | ||
} | ||
var isNotNullish = bindNot(isNullish); | ||
const isNotNullish = bindNot(isNullish); | ||
@@ -108,88 +96,4 @@ function asArray(possibleArg) { | ||
function isFunction(value) { | ||
return typeof value === 'function'; | ||
} | ||
function optionalFunctionValue(value) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
return isFunction(value) ? value.apply(void 0, args) : value; | ||
} | ||
function defaultTo(value, defaultValue) { | ||
var _a; | ||
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue); | ||
} | ||
// The module is named "isArrayValue" since it | ||
// is conflicting with a nested npm dependency. | ||
// We may need to revisit this in the future. | ||
function isArray(value) { | ||
return Boolean(Array.isArray(value)); | ||
} | ||
var isNotArray = bindNot(isArray); | ||
function last(values) { | ||
var valuesArray = asArray(values); | ||
return valuesArray[valuesArray.length - 1]; | ||
} | ||
// This is kind of a map/filter in one function. | ||
// Normally, behaves like a nested-array map, | ||
// but returning `null` will drop the element from the array | ||
function transform(array, cb) { | ||
var res = []; | ||
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) { | ||
var v = array_1[_i]; | ||
if (isArray(v)) { | ||
res.push(transform(v, cb)); | ||
} | ||
else { | ||
var output = cb(v); | ||
if (isNotNull(output)) { | ||
res.push(output); | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
function valueAtPath(array, path) { | ||
return getCurrent(array, path)[last(path)]; | ||
} | ||
function setValueAtPath(array, path, value) { | ||
var current = getCurrent(array, path); | ||
current[last(path)] = value; | ||
return array; | ||
} | ||
function flatten(values) { | ||
return asArray(values).reduce(function (acc, value) { | ||
if (isArray(value)) { | ||
return acc.concat(flatten(value)); | ||
} | ||
return asArray(acc).concat(value); | ||
}, []); | ||
} | ||
function getCurrent(array, path) { | ||
var current = array; | ||
for (var _i = 0, _a = path.slice(0, -1); _i < _a.length; _i++) { | ||
var p = _a[_i]; | ||
current[p] = defaultTo(current[p], []); | ||
current = current[p]; | ||
} | ||
return current; | ||
} | ||
var nestedArray = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
transform: transform, | ||
valueAtPath: valueAtPath, | ||
setValueAtPath: setValueAtPath, | ||
flatten: flatten, | ||
getCurrent: getCurrent | ||
}); | ||
function callEach(arr) { | ||
return arr.forEach(function (fn) { return fn(); }); | ||
return arr.forEach(fn => fn()); | ||
} | ||
@@ -204,2 +108,6 @@ | ||
function isFunction(value) { | ||
return typeof value === 'function'; | ||
} | ||
function isPromise(value) { | ||
@@ -209,4 +117,13 @@ return value && isFunction(value.then); | ||
function optionalFunctionValue(value, ...args) { | ||
return isFunction(value) ? value(...args) : value; | ||
} | ||
var assign = Object.assign; | ||
function defaultTo(value, defaultValue) { | ||
var _a; | ||
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue); | ||
} | ||
function invariant(condition, | ||
@@ -242,4 +159,9 @@ // eslint-disable-next-line @typescript-eslint/ban-types | ||
function last(values) { | ||
const valuesArray = asArray(values); | ||
return valuesArray[valuesArray.length - 1]; | ||
} | ||
function deferThrow(message) { | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
throw new Error(message); | ||
@@ -250,17 +172,17 @@ }, 0); | ||
function createBus() { | ||
var listeners = {}; | ||
const listeners = {}; | ||
return { | ||
emit: function (event, data) { | ||
listener(event).forEach(function (handler) { | ||
emit(event, data) { | ||
listener(event).forEach(handler => { | ||
handler(data); | ||
}); | ||
}, | ||
on: function (event, handler) { | ||
on(event, handler) { | ||
listeners[event] = listener(event).concat(handler); | ||
return { | ||
off: function () { | ||
listeners[event] = listener(event).filter(function (h) { return h !== handler; }); | ||
} | ||
off() { | ||
listeners[event] = listener(event).filter(h => h !== handler); | ||
}, | ||
}; | ||
} | ||
}, | ||
}; | ||
@@ -280,13 +202,11 @@ function listener(event) { | ||
*/ | ||
var seq = genSeq(); | ||
const seq = genSeq(); | ||
function genSeq(namespace) { | ||
return (function (n) { return function () { | ||
return "".concat(namespace ? namespace + '_' : '').concat(n++); | ||
}; })(0); | ||
return ((n) => () => `${namespace ? namespace + '_' : ''}${n++}`)(0); | ||
} | ||
function mapFirst(array, callback) { | ||
var broke = false; | ||
var breakoutValue = null; | ||
for (var i = 0; i < array.length; i++) { | ||
let broke = false; | ||
let breakoutValue = null; | ||
for (let i = 0; i < array.length; i++) { | ||
callback(array[i], breakout, i); | ||
@@ -305,2 +225,14 @@ if (broke) { | ||
function isObject(v) { | ||
return typeof v === 'object' && !isNullish(v); | ||
} | ||
// The module is named "isArrayValue" since it | ||
// is conflicting with a nested npm dependency. | ||
// We may need to revisit this in the future. | ||
function isArray(value) { | ||
return Boolean(Array.isArray(value)); | ||
} | ||
const isNotArray = bindNot(isArray); | ||
function isEmpty(value) { | ||
@@ -313,3 +245,3 @@ if (!value) { | ||
} | ||
else if (typeof value === 'object') { | ||
else if (isObject(value)) { | ||
return lengthEquals(Object.keys(value), 0); | ||
@@ -319,3 +251,3 @@ } | ||
} | ||
var isNotEmpty = bindNot(isEmpty); | ||
const isNotEmpty = bindNot(isEmpty); | ||
@@ -326,2 +258,34 @@ function isPositive(value) { | ||
const regexp = /{(.*?)}/g; | ||
function text(str, ...substitutions) { | ||
const first = substitutions[0]; | ||
if (isObject(first)) { | ||
return str.replace(regexp, (placeholder, key) => { | ||
var _a; | ||
return `${(_a = first[key]) !== null && _a !== void 0 ? _a : placeholder}`; | ||
}); | ||
} | ||
const subs = [...substitutions]; | ||
return str.replace(regexp, placeholder => { | ||
return `${isEmpty(subs) ? placeholder : subs.shift()}`; | ||
}); | ||
} | ||
function createTinyState(initialValue) { | ||
let value; | ||
resetValue(); | ||
return () => [value, setValue, resetValue]; | ||
function setValue(nextValue) { | ||
value = optionalFunctionValue(nextValue, value); | ||
} | ||
function resetValue() { | ||
setValue(optionalFunctionValue(initialValue)); | ||
} | ||
} | ||
var tinyState = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
createTinyState: createTinyState | ||
}); | ||
exports.StringObject = StringObject; | ||
@@ -354,2 +318,3 @@ exports.asArray = asArray; | ||
exports.isNumeric = isNumeric; | ||
exports.isObject = isObject; | ||
exports.isPositive = isPositive; | ||
@@ -364,3 +329,2 @@ exports.isPromise = isPromise; | ||
exports.mapFirst = mapFirst; | ||
exports.nestedArray = nestedArray; | ||
exports.numberEquals = numberEquals; | ||
@@ -370,2 +334,4 @@ exports.numberNotEquals = numberNotEquals; | ||
exports.seq = seq; | ||
exports.text = text; | ||
exports.tinyState = tinyState; | ||
@@ -372,0 +338,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self)["vest-utils"]={})}(this,(function(n){"use strict";function t(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function r(n){var t=String(n),r=Number(n),e=!isNaN(parseFloat(t))&&!isNaN(Number(n))&&isFinite(r);return Boolean(e)}var e=t(r);function u(n,t){return r(n)&&r(t)&&Number(n)===Number(t)}var i=t(u);function o(n,t){return u(n.length,t)}var c=t(o);function f(n,t){return r(n)&&r(t)&&Number(n)>Number(t)}function a(n,t){return f(n.length,t)}function l(n){return null===n}var s=t(l);function v(n){return void 0===n}var h=t(v);function g(n){return l(n)||v(n)}var d=t(g);function p(n){return[].concat(n)}function N(n){return"function"==typeof n}function y(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return N(n)?n.apply(void 0,t):n}function b(n,t){var r;return null!==(r=y(n))&&void 0!==r?r:y(t)}function m(n){return Boolean(Array.isArray(n))}var E=t(m);function _(n){var t=p(n);return t[t.length-1]}function O(n,t){for(var r=n,e=0,u=t.slice(0,-1);e<u.length;e++){var i=u[e];r[i]=b(r[i],[]),r=r[i]}return r}var j=Object.freeze({__proto__:null,transform:function n(t,r){for(var e=[],u=0,i=t;u<i.length;u++){var o=i[u];if(m(o))e.push(n(o,r));else{var c=r(o);s(c)&&e.push(c)}}return e},valueAtPath:function(n,t){return O(n,t)[_(t)]},setValueAtPath:function(n,t,r){return O(n,t)[_(t)]=r,n},flatten:function n(t){return p(t).reduce((function(t,r){return m(r)?t.concat(n(r)):p(t).concat(r)}),[])},getCurrent:O});function w(n,t){return Object.prototype.hasOwnProperty.call(n,t)}var A=Object.assign;var P=Object.freeze({__proto__:null,createBus:function(){var n={};return{emit:function(n,r){t(n).forEach((function(n){n(r)}))},on:function(r,e){return n[r]=t(r).concat(e),{off:function(){n[r]=t(r).filter((function(n){return n!==e}))}}}};function t(t){return n[t]||[]}}}),S=T();function T(n){return t=0,function(){return"".concat(n?n+"_":"").concat(t++)};var t}function q(n){return!n||(w(n,"length")?o(n,0):"object"==typeof n&&o(Object.keys(n),0))}var F=t(q);n.StringObject=function(n){return new String(y(n))},n.asArray=p,n.assign=A,n.bindNot=t,n.bus=P,n.cache=function(n){void 0===n&&(n=1);var t=[],r=function(e,u){var i=r.get(e);if(i)return i[1];var o=u();return t.unshift([e.concat(),o]),a(t,n)&&(t.length=n),o};return r.invalidate=function(n){var r=e(n);r>-1&&t.splice(r,1)},r.get=function(n){return t[e(n)]||null},r;function e(n){return t.findIndex((function(t){var r=t[0];return o(n,r.length)&&n.every((function(n,t){return n===r[t]}))}))}},n.callEach=function(n){return n.forEach((function(n){return n()}))},n.defaultTo=b,n.deferThrow=function(n){setTimeout((function(){throw new Error(n)}),0)},n.either=function(n,t){return!!n!=!!t},n.genSeq=T,n.greaterThan=f,n.hasOwnProperty=w,n.invariant=function(n,t){if(!n)throw t instanceof String?t.valueOf():new Error(t?y(t):t)},n.isArray=m,n.isBoolean=function(n){return!!n===n},n.isEmpty=q,n.isFunction=N,n.isNotArray=E,n.isNotEmpty=F,n.isNotNull=s,n.isNotNullish=d,n.isNotNumeric=e,n.isNotUndefined=h,n.isNull=l,n.isNullish=g,n.isNumeric=r,n.isPositive=function(n){return f(n,0)},n.isPromise=function(n){return n&&N(n.then)},n.isStringValue=function(n){return String(n)===n},n.isUndefined=v,n.last=_,n.lengthEquals=o,n.lengthNotEquals=c,n.longerThan=a,n.mapFirst=function(n,t){for(var r=!1,e=null,u=0;u<n.length;u++)if(t(n[u],i,u),r)return e;function i(n,t){n&&(r=!0,e=t)}},n.nestedArray=j,n.numberEquals=u,n.numberNotEquals=i,n.optionalFunctionValue=y,n.seq=S,Object.defineProperty(n,"__esModule",{value:!0})})); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self)["vest-utils"]={})}(this,(function(n){"use strict";function t(n){return(...t)=>!n(...t)}function e(n){const t=String(n),e=Number(n),r=!isNaN(parseFloat(t))&&!isNaN(Number(n))&&isFinite(e);return Boolean(r)}const r=t(e);function o(n,t){return e(n)&&e(t)&&Number(n)===Number(t)}const i=t(o);function u(n,t){return o(n.length,t)}const c=t(u);function s(n,t){return e(n)&&e(t)&&Number(n)>Number(t)}function f(n,t){return s(n.length,t)}function l(n){return null===n}const a=t(l);function h(n){return void 0===n}const g=t(h);function N(n){return l(n)||h(n)}const d=t(N);function p(n){return[].concat(n)}function b(n,t){return Object.prototype.hasOwnProperty.call(n,t)}function y(n){return"function"==typeof n}function m(n,...t){return y(n)?n(...t):n}var v=Object.assign;var E=Object.freeze({__proto__:null,createBus:function(){const n={};return{emit(n,e){t(n).forEach((n=>{n(e)}))},on:(e,r)=>(n[e]=t(e).concat(r),{off(){n[e]=t(e).filter((n=>n!==r))}})};function t(t){return n[t]||[]}}});const O=_();function _(n){return t=0,()=>`${n?n+"_":""}${t++}`;var t}function j(n){return"object"==typeof n&&!N(n)}function S(n){return Boolean(Array.isArray(n))}const w=t(S);function T(n){return!n||(b(n,"length")?u(n,0):!!j(n)&&u(Object.keys(n),0))}const q=t(T);const x=/{(.*?)}/g;var A=Object.freeze({__proto__:null,createTinyState:function(n){let t;return r(),()=>[t,e,r];function e(n){t=m(n,t)}function r(){e(m(n))}}});n.StringObject=function(n){return new String(m(n))},n.asArray=p,n.assign=v,n.bindNot=t,n.bus=E,n.cache=function(n=1){const t=[],e=(r,o)=>{const i=e.get(r);if(i)return i[1];const u=o();return t.unshift([r.concat(),u]),f(t,n)&&(t.length=n),u};return e.invalidate=n=>{const e=r(n);e>-1&&t.splice(e,1)},e.get=n=>t[r(n)]||null,e;function r(n){return t.findIndex((([t])=>u(n,t.length)&&n.every(((n,e)=>n===t[e]))))}},n.callEach=function(n){return n.forEach((n=>n()))},n.defaultTo=function(n,t){var e;return null!==(e=m(n))&&void 0!==e?e:m(t)},n.deferThrow=function(n){setTimeout((()=>{throw new Error(n)}),0)},n.either=function(n,t){return!!n!=!!t},n.genSeq=_,n.greaterThan=s,n.hasOwnProperty=b,n.invariant=function(n,t){if(!n)throw t instanceof String?t.valueOf():new Error(t?m(t):t)},n.isArray=S,n.isBoolean=function(n){return!!n===n},n.isEmpty=T,n.isFunction=y,n.isNotArray=w,n.isNotEmpty=q,n.isNotNull=a,n.isNotNullish=d,n.isNotNumeric=r,n.isNotUndefined=g,n.isNull=l,n.isNullish=N,n.isNumeric=e,n.isObject=j,n.isPositive=function(n){return s(n,0)},n.isPromise=function(n){return n&&y(n.then)},n.isStringValue=function(n){return String(n)===n},n.isUndefined=h,n.last=function(n){const t=p(n);return t[t.length-1]},n.lengthEquals=u,n.lengthNotEquals=c,n.longerThan=f,n.mapFirst=function(n,t){let e=!1,r=null;for(let i=0;i<n.length;i++)if(t(n[i],o,i),e)return r;function o(n,t){n&&(e=!0,r=t)}},n.numberEquals=o,n.numberNotEquals=i,n.optionalFunctionValue=m,n.seq=O,n.text=function(n,...t){const e=t[0];if(j(e))return n.replace(x,((n,t)=>{var r;return`${null!==(r=e[t])&&void 0!==r?r:n}`}));const r=[...t];return n.replace(x,(n=>`${T(r)?n:r.shift()}`))},n.tinyState=A,Object.defineProperty(n,"__esModule",{value:!0})})); |
{ | ||
"version": "0.1.1", | ||
"version": "1.0.0-next-7526f5", | ||
"name": "vest-utils", | ||
@@ -4,0 +4,0 @@ "author": "ealush", |
@@ -20,16 +20,2 @@ /** | ||
}; | ||
declare function isNullish(value: any): value is null | undefined; | ||
declare const isNotNullish: (value: any) => boolean; | ||
declare namespace nestedArray { | ||
type NestedArray<T> = Array<NestedArray<T> | T>; | ||
// This is kind of a map/filter in one function. | ||
// Normally, behaves like a nested-array map, | ||
// but returning `null` will drop the element from the array | ||
function transform<T>(array: NestedArray<T>, cb: (value: T) => NestedArray<T> | T | null): NestedArray<T>; | ||
function valueAtPath<T>(array: NestedArray<T>, path: number[]): T | NestedArray<T>; | ||
function setValueAtPath<T>(array: NestedArray<T>, path: number[], value: NestedArray<T> | T): NestedArray<T>; | ||
function flatten<T>(values: NestedArray<T> | T): T[]; | ||
function getCurrent<T>(array: NestedArray<T>, path: number[]): NestedArray<T>; | ||
} | ||
declare function asArray<T>(possibleArg: T | T[]): T[]; | ||
type DropFirst<T extends unknown[]> = T extends [ | ||
@@ -42,2 +28,17 @@ unknown, | ||
type ValueOf<T> = T[keyof T]; | ||
type OnReturn = { | ||
off: () => void; | ||
}; | ||
type BusType = { | ||
on: (event: string, handler: CB) => OnReturn; | ||
emit: (event: string, ...args: any[]) => void; | ||
}; | ||
type TinyState<S> = () => [ | ||
value: S, | ||
setValue: (next: S | ((prev: S) => S)) => void, | ||
resetValue: () => void | ||
]; | ||
declare function isNullish(value: any): value is null | undefined; | ||
declare const isNotNullish: (value: any) => boolean; | ||
declare function asArray<T>(possibleArg: T | T[]): T[]; | ||
declare function callEach(arr: CB[]): void; | ||
@@ -56,3 +57,3 @@ /** | ||
}; | ||
declare function defaultTo<T>(value: T | ((...args: any[]) => T), defaultValue: T | (() => T)): T; | ||
declare function defaultTo<T>(value: T | void | null | ((...args: any[]) => T | void | null), defaultValue: T | (() => T)): T; | ||
declare function invariant(condition: any, | ||
@@ -77,9 +78,10 @@ // eslint-disable-next-line @typescript-eslint/ban-types | ||
type ValueOf<T> = T[keyof T]; | ||
function createBus(): { | ||
function createBus(): BusType; | ||
type OnReturn = { | ||
off: () => void; | ||
}; | ||
type BusType = { | ||
on: (event: string, handler: CB) => OnReturn; | ||
emit: (event: string, ...args: any[]) => void; | ||
}; | ||
type OnReturn = { | ||
off: () => void; | ||
}; | ||
} | ||
@@ -97,2 +99,3 @@ /** | ||
declare const isNotNumeric: (value: string | number) => boolean; | ||
declare function isObject(v: any): v is Record<any, any>; | ||
declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean; | ||
@@ -114,4 +117,13 @@ declare const lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean; | ||
declare function isPositive(value: number | string): boolean; | ||
export { createCache as cache, CacheApi, isNullish, isNotNullish, nestedArray, asArray, callEach, hasOwnProperty, isPromise, optionalFunctionValue, _default as assign, defaultTo, invariant, StringObject, isStringValue, bindNot, either, isBoolean, last, deferThrow, bus, seq, genSeq, isFunction, mapFirst, greaterThan, longerThan, isNumeric, isNotNumeric, lengthEquals, lengthNotEquals, numberEquals, numberNotEquals, isNull, isNotNull, isUndefined, isNotUndefined, isArray, isNotArray, isEmpty, isNotEmpty, isPositive }; | ||
declare function text(str: string, ...substitutions: Array<unknown>): string; | ||
declare namespace tinyState { | ||
function createTinyState<S>(initialValue: S | (() => S)): TinyState<S>; | ||
type TinyState<S> = () => [ | ||
value: S, | ||
setValue: (next: S | ((prev: S) => S)) => void, | ||
resetValue: () => void | ||
]; | ||
} | ||
export { createCache as cache, CacheApi, BusType, TinyState, isNullish, isNotNullish, asArray, callEach, hasOwnProperty, isPromise, optionalFunctionValue, _default as assign, defaultTo, invariant, StringObject, isStringValue, bindNot, either, isBoolean, last, deferThrow, bus, seq, genSeq, isFunction, mapFirst, greaterThan, longerThan, isNumeric, isNotNumeric, isObject, lengthEquals, lengthNotEquals, numberEquals, numberNotEquals, isNull, isNotNull, isUndefined, isNotUndefined, isArray, isNotArray, isEmpty, isNotEmpty, isPositive, text, tinyState }; | ||
export type { DropFirst, Stringable, CB, ValueOf }; | ||
//# sourceMappingURL=vest-utils.d.ts.map |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
43977
14
953
1