vest-utils
Advanced tools
Comparing version 1.0.0-dev-9c596e to 1.0.0-dev-ae6b14
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function bindNot(fn) { | ||
@@ -253,2 +251,36 @@ return (...args) => !fn(...args); | ||
const STATE_WILD_CARD = '*'; | ||
function StateMachine(machine) { | ||
let state = machine.initial; | ||
const api = { getState, transition }; | ||
return api; | ||
function getState() { | ||
return state; | ||
} | ||
// eslint-disable-next-line complexity | ||
function transition(action, payload) { | ||
var _a, _b, _c; | ||
const transitionTo = (_b = (_a = machine.states[state]) === null || _a === void 0 ? void 0 : _a[action]) !== null && _b !== void 0 ? _b : | ||
// @ts-expect-error - This is a valid state | ||
(_c = machine.states[STATE_WILD_CARD]) === null || _c === void 0 ? void 0 : _c[action]; | ||
let target = transitionTo; | ||
if (Array.isArray(target)) { | ||
const [, conditional] = target; | ||
if (!conditional(payload)) { | ||
return; | ||
} | ||
target = target[0]; | ||
} | ||
if (!target || target === state) { | ||
return; | ||
} | ||
state = target; | ||
} | ||
} | ||
function nonnullish(value, error) { | ||
invariant(!isNullish(value), error); | ||
return value; | ||
} | ||
function createTinyState(initialValue) { | ||
@@ -271,2 +303,3 @@ let value; | ||
exports.StateMachine = StateMachine; | ||
exports.StringObject = StringObject; | ||
@@ -309,2 +342,3 @@ exports.asArray = asArray; | ||
exports.mapFirst = mapFirst; | ||
exports.nonnullish = nonnullish; | ||
exports.numberEquals = numberEquals; | ||
@@ -311,0 +345,0 @@ exports.numberNotEquals = numberNotEquals; |
@@ -1,1 +0,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 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; | ||
"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)}const r=t(n);function e(t,r){return n(t)&&n(r)&&Number(t)===Number(r)}const o=t(e);function i(t,n){return e(t.length,n)}const u=t(i);function s(t,r){return n(t)&&n(r)&&Number(t)>Number(r)}function c(t,n){return s(t.length,n)}function f(t){return null===t}const l=t(f);function a(t){return void 0===t}const p=t(a);function x(t){return f(t)||a(t)}const h=t(x);function N(t){return[].concat(t)}function g(t,n){return Object.prototype.hasOwnProperty.call(t,n)}function v(t){return"function"==typeof t}function b(t,...n){return v(t)?t(...n):t}var d=Object.assign;function y(t,n){if(!t)throw n instanceof String?n.valueOf():new Error(n?b(n):n)}var m=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 E=S();function S(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 w(t){return!t||(g(t,"length")?i(t,0):!!O(t)&&i(Object.keys(t),0))}const A=t(w);const q=/{(.*?)}/g;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.StateMachine=function(t){let n=t.initial;return{getState:function(){return n},transition:function(r,e){var o,i,u;let s=null!==(i=null===(o=t.states[n])||void 0===o?void 0:o[r])&&void 0!==i?i:null===(u=t.states["*"])||void 0===u?void 0:u[r];if(Array.isArray(s)){const[,t]=s;if(!t(e))return;s=s[0]}if(!s||s===n)return;n=s}}},exports.StringObject=function(t){return new String(b(t))},exports.asArray=N,exports.assign=d,exports.bindNot=t,exports.bus=m,exports.cache=function(t=1){const n=[],r=(e,o)=>{const i=r.get(e);if(i)return i[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])=>i(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=b(t))&&void 0!==r?r:b(n)},exports.deferThrow=function(t){setTimeout((()=>{throw new Error(t)}),0)},exports.either=function(t,n){return!!t!=!!n},exports.genSeq=S,exports.greaterThan=s,exports.hasOwnProperty=g,exports.invariant=y,exports.isArray=_,exports.isBoolean=function(t){return!!t===t},exports.isEmpty=w,exports.isFunction=v,exports.isNotArray=j,exports.isNotEmpty=A,exports.isNotNull=l,exports.isNotNullish=h,exports.isNotNumeric=r,exports.isNotUndefined=p,exports.isNull=f,exports.isNullish=x,exports.isNumeric=n,exports.isObject=O,exports.isPositive=function(t){return s(t,0)},exports.isPromise=function(t){return t&&v(t.then)},exports.isStringValue=function(t){return String(t)===t},exports.isUndefined=a,exports.last=function(t){const n=N(t);return n[n.length-1]},exports.lengthEquals=i,exports.lengthNotEquals=u,exports.longerThan=c,exports.mapFirst=function(t,n){let r=!1,e=null;for(let i=0;i<t.length;i++)if(n(t[i],o,i),r)return e;function o(t,n){t&&(r=!0,e=n)}},exports.nonnullish=function(t,n){return y(!x(t),n),t},exports.numberEquals=e,exports.numberNotEquals=o,exports.optionalFunctionValue=b,exports.seq=E,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=>`${w(e)?t:e.shift()}`))},exports.tinyState=T; |
@@ -249,2 +249,36 @@ function bindNot(fn) { | ||
const STATE_WILD_CARD = '*'; | ||
function StateMachine(machine) { | ||
let state = machine.initial; | ||
const api = { getState, transition }; | ||
return api; | ||
function getState() { | ||
return state; | ||
} | ||
// eslint-disable-next-line complexity | ||
function transition(action, payload) { | ||
var _a, _b, _c; | ||
const transitionTo = (_b = (_a = machine.states[state]) === null || _a === void 0 ? void 0 : _a[action]) !== null && _b !== void 0 ? _b : | ||
// @ts-expect-error - This is a valid state | ||
(_c = machine.states[STATE_WILD_CARD]) === null || _c === void 0 ? void 0 : _c[action]; | ||
let target = transitionTo; | ||
if (Array.isArray(target)) { | ||
const [, conditional] = target; | ||
if (!conditional(payload)) { | ||
return; | ||
} | ||
target = target[0]; | ||
} | ||
if (!target || target === state) { | ||
return; | ||
} | ||
state = target; | ||
} | ||
} | ||
function nonnullish(value, error) { | ||
invariant(!isNullish(value), error); | ||
return value; | ||
} | ||
function createTinyState(initialValue) { | ||
@@ -267,2 +301,2 @@ let 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, isObject, isPositive, isPromise, isStringValue, isUndefined, last, lengthEquals, lengthNotEquals, longerThan, mapFirst, numberEquals, numberNotEquals, optionalFunctionValue, seq, text, tinyState }; | ||
export { StateMachine, 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, nonnullish, numberEquals, numberNotEquals, optionalFunctionValue, seq, text, tinyState }; |
@@ -1,1 +0,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 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}; | ||
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 v(n){return void 0===n}const g=n(v);function h(n){return s(n)||v(n)}const b=n(h);function p(n){return[].concat(n)}function d(n){return n.forEach((n=>n()))}function y(n,t){return Object.prototype.hasOwnProperty.call(n,t)}function N(n){return"function"==typeof n}function _(n){return n&&N(n.then)}function m(n,...t){return N(n)?n(...t):n}var O=Object.assign;function j(n,t){var r;return null!==(r=m(n))&&void 0!==r?r:m(t)}function w(n,t){if(!n)throw t instanceof String?t.valueOf():new Error(t?m(t):t)}function S(n){return new String(m(n))}function A(n){return String(n)===n}function E(n,t){return!!n!=!!t}function $(n){return!!n===n}function B(n){const t=p(n);return t[t.length-1]}function x(n){setTimeout((()=>{throw new Error(n)}),0)}var z=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&&!h(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()}`))}function K(n){let t=n.initial;return{getState:function(){return t},transition:function(r,e){var u,o,c;let i=null!==(o=null===(u=n.states[t])||void 0===u?void 0:u[r])&&void 0!==o?o:null===(c=n.states["*"])||void 0===c?void 0:c[r];if(Array.isArray(i)){const[,n]=i;if(!n(e))return;i=i[0]}if(!i||i===t)return;t=i}}}function L(n,t){return w(!h(n),t),n}var M=Object.freeze({__proto__:null,createTinyState:function(n){let t;return e(),()=>[t,r,e];function r(n){t=m(n,t)}function e(){r(m(n))}}});export{K as StateMachine,S as StringObject,p as asArray,O as assign,n as bindNot,z as bus,l as cache,d as callEach,j as defaultTo,x as deferThrow,E as either,T as genSeq,i as greaterThan,y as hasOwnProperty,w as invariant,P as isArray,$ as isBoolean,C as isEmpty,N as isFunction,q as isNotArray,D as isNotEmpty,a as isNotNull,b as isNotNullish,r as isNotNumeric,g as isNotUndefined,s as isNull,h as isNullish,t as isNumeric,I as isObject,G as isPositive,_ as isPromise,A as isStringValue,v as isUndefined,B as last,o as lengthEquals,c as lengthNotEquals,f as longerThan,k as mapFirst,L as nonnullish,e as numberEquals,u as numberNotEquals,m as optionalFunctionValue,F as seq,J as text,M as tinyState}; |
@@ -255,2 +255,36 @@ (function (global, factory) { | ||
const STATE_WILD_CARD = '*'; | ||
function StateMachine(machine) { | ||
let state = machine.initial; | ||
const api = { getState, transition }; | ||
return api; | ||
function getState() { | ||
return state; | ||
} | ||
// eslint-disable-next-line complexity | ||
function transition(action, payload) { | ||
var _a, _b, _c; | ||
const transitionTo = (_b = (_a = machine.states[state]) === null || _a === void 0 ? void 0 : _a[action]) !== null && _b !== void 0 ? _b : | ||
// @ts-expect-error - This is a valid state | ||
(_c = machine.states[STATE_WILD_CARD]) === null || _c === void 0 ? void 0 : _c[action]; | ||
let target = transitionTo; | ||
if (Array.isArray(target)) { | ||
const [, conditional] = target; | ||
if (!conditional(payload)) { | ||
return; | ||
} | ||
target = target[0]; | ||
} | ||
if (!target || target === state) { | ||
return; | ||
} | ||
state = target; | ||
} | ||
} | ||
function nonnullish(value, error) { | ||
invariant(!isNullish(value), error); | ||
return value; | ||
} | ||
function createTinyState(initialValue) { | ||
@@ -273,2 +307,3 @@ let value; | ||
exports.StateMachine = StateMachine; | ||
exports.StringObject = StringObject; | ||
@@ -311,2 +346,3 @@ exports.asArray = asArray; | ||
exports.mapFirst = mapFirst; | ||
exports.nonnullish = nonnullish; | ||
exports.numberEquals = numberEquals; | ||
@@ -319,4 +355,2 @@ exports.numberNotEquals = numberNotEquals; | ||
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(...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})})); | ||
!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 i(n,t){return e(n)&&e(t)&&Number(n)===Number(t)}const o=t(i);function u(n,t){return i(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 d=t(h);function g(n){return l(n)||h(n)}const N=t(g);function p(n){return[].concat(n)}function y(n,t){return Object.prototype.hasOwnProperty.call(n,t)}function b(n){return"function"==typeof n}function v(n,...t){return b(n)?n(...t):n}var m=Object.assign;function E(n,t){if(!n)throw t instanceof String?t.valueOf():new Error(t?v(t):t)}var S=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=j();function j(n){return t=0,()=>`${n?n+"_":""}${t++}`;var t}function _(n){return"object"==typeof n&&!g(n)}function w(n){return Boolean(Array.isArray(n))}const T=t(w);function A(n){return!n||(y(n,"length")?u(n,0):!!_(n)&&u(Object.keys(n),0))}const q=t(A);const x=/{(.*?)}/g;var F=Object.freeze({__proto__:null,createTinyState:function(n){let t;return r(),()=>[t,e,r];function e(n){t=v(n,t)}function r(){e(v(n))}}});n.StateMachine=function(n){let t=n.initial;return{getState:function(){return t},transition:function(e,r){var i,o,u;let c=null!==(o=null===(i=n.states[t])||void 0===i?void 0:i[e])&&void 0!==o?o:null===(u=n.states["*"])||void 0===u?void 0:u[e];if(Array.isArray(c)){const[,n]=c;if(!n(r))return;c=c[0]}if(!c||c===t)return;t=c}}},n.StringObject=function(n){return new String(v(n))},n.asArray=p,n.assign=m,n.bindNot=t,n.bus=S,n.cache=function(n=1){const t=[],e=(r,i)=>{const o=e.get(r);if(o)return o[1];const u=i();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=v(n))&&void 0!==e?e:v(t)},n.deferThrow=function(n){setTimeout((()=>{throw new Error(n)}),0)},n.either=function(n,t){return!!n!=!!t},n.genSeq=j,n.greaterThan=s,n.hasOwnProperty=y,n.invariant=E,n.isArray=w,n.isBoolean=function(n){return!!n===n},n.isEmpty=A,n.isFunction=b,n.isNotArray=T,n.isNotEmpty=q,n.isNotNull=a,n.isNotNullish=N,n.isNotNumeric=r,n.isNotUndefined=d,n.isNull=l,n.isNullish=g,n.isNumeric=e,n.isObject=_,n.isPositive=function(n){return s(n,0)},n.isPromise=function(n){return n&&b(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 o=0;o<n.length;o++)if(t(n[o],i,o),e)return r;function i(n,t){n&&(e=!0,r=t)}},n.nonnullish=function(n,t){return E(!g(n),t),n},n.numberEquals=i,n.numberNotEquals=o,n.optionalFunctionValue=v,n.seq=O,n.text=function(n,...t){const e=t[0];if(_(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=>`${A(r)?n:r.shift()}`))},n.tinyState=F})); |
{ | ||
"version": "1.0.0-dev-9c596e", | ||
"version": "1.0.0-dev-ae6b14", | ||
"name": "vest-utils", | ||
@@ -47,2 +47,2 @@ "author": "ealush", | ||
} | ||
} | ||
} |
@@ -113,2 +113,20 @@ /** | ||
declare function text(str: string, ...substitutions: Array<unknown>): string; | ||
declare const STATE_WILD_CARD = "*"; | ||
type TStateWildCard = typeof STATE_WILD_CARD; | ||
type TStateMachine<S extends string, A extends string> = { | ||
initial: S; | ||
states: Partial<{ | ||
[key in S & TStateWildCard]: { | ||
[key in A]?: S | [ | ||
S, | ||
(payload?: any) => boolean | ||
]; | ||
}; | ||
}>; | ||
}; | ||
declare function StateMachine<S extends string, A extends string>(machine: TStateMachine<S, A>): { | ||
getState: () => S; | ||
transition: (action: A, payload?: any) => void; | ||
}; | ||
declare function nonnullish<T>(value: T | null | undefined, error?: string): T; | ||
declare namespace tinyState { | ||
@@ -122,4 +140,4 @@ function createTinyState<S>(initialValue: S | (() => S)): TinyState<S>; | ||
} | ||
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 { 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, TStateMachine, StateMachine, nonnullish, 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
48998
1073
0