@zthun/helpful-fn 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/index.esm.js +1 -0
- package/dist/lib/index.esm.js.map +1 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -0
- package/package.json +5 -5
package/dist/lib/index.esm.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
1
|
var n,t;function r(n,t,r,o){if(void 0===r&&(r=0),void 0===o&&(o=Infinity),n=Math.max(0,n),t=Math.max(0,t),Number.isNaN(n)||Number.isNaN(t))return NaN;if(0===t)return r;var e=Infinity===n?1:Math.ceil(t/n);return Math.min(o,Math.max(r,e))}let o;!function(n){n.Top="top",n.Middle="middle",n.Bottom="bottom"}(n||(n={})),function(n){n.Left="left",n.Center="center",n.Right="right"}(t||(t={}));const e=new Uint8Array(16);function i(){if(!o&&(o="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!o))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return o(e)}const u=[];for(let n=0;n<256;++n)u.push((n+256).toString(16).slice(1));var a={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)},l=function(n,t,r){if(a.randomUUID&&!t&&!n)return a.randomUUID();const o=(n=n||{}).random||(n.rng||i)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){r=r||0;for(let n=0;n<16;++n)t[r+n]=o[n];return t}return function(n,t=0){return(u[n[t+0]]+u[n[t+1]]+u[n[t+2]]+u[n[t+3]]+"-"+u[n[t+4]]+u[n[t+5]]+"-"+u[n[t+6]]+u[n[t+7]]+"-"+u[n[t+8]]+u[n[t+9]]+"-"+u[n[t+10]]+u[n[t+11]]+u[n[t+12]]+u[n[t+13]]+u[n[t+14]]+u[n[t+15]]).toLowerCase()}(o)};function c(n,t){var r=[].slice.call(arguments,2);if(null!=t)return t;for(var o=0;o<r.length;++o){var e=r[o];if(null!=e)return e}return n}function f(n){return[].slice.call(arguments,1).map(function(n){return n instanceof Array?n[1]?n[0]:null:n}).filter(function(n){return null!=n}).join(n)}var d,m=f.bind(null," "),p=m,s=f.bind(null,","),y=f.bind(null,";"),h=f.bind(null,"|");function v(n,t,r){n(null!=r&&r.length?r[0]:t)}function g(n,t){return void 0===n&&(n=0),void 0===t&&(t=void 0),new Promise(function(r){return setTimeout(function(){return r(t)},n)})}!function(n){n.Horizontal="horizontal",n.Vertical="vertical"}(d||(d={}));export{t as ZHorizontalAnchor,d as ZOrientation,n as ZVerticalAnchor,s as commaJoinDefined,r as countBuckets,l as createGuid,p as cssJoinDefined,c as firstDefined,f as joinDefined,h as pipeJoinDefined,y as semiColonJoinDefined,v as setFirst,g as sleep,m as spaceJoinDefined};
|
|
2
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../src/anchor/anchor.ts","../../src/count-buckets/count-buckets.ts","../../../../node_modules/uuid/dist/esm-browser/rng.js","../../../../node_modules/uuid/dist/esm-browser/stringify.js","../../../../node_modules/uuid/dist/esm-browser/native.js","../../src/create-guid/create-guid.ts","../../../../node_modules/uuid/dist/esm-browser/v4.js","../../src/first-defined/first-defined.ts","../../src/join-defined/join-defined.ts","../../src/orientation/orientation.ts","../../src/set-first/set-first.ts","../../src/sleep/sleep.ts"],"sourcesContent":["/**\n * Represents a vertical anchor.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n */\n Bottom = 'bottom'\n}\n\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point.\n *\n * An anchor point is a point that stays constant while things are\n * resizing.\n */\nexport type ZAnchor = [ZVerticalAnchor, ZHorizontalAnchor];\n\n/**\n * Represents a special type of anchor that excludes the center points.\n */\nexport type ZSideAnchor =\n | ZVerticalAnchor.Top\n | ZVerticalAnchor.Bottom\n | ZHorizontalAnchor.Left\n | ZHorizontalAnchor.Right;\n","/**\n * Calculates the total number of buckets you need to\n * store a number of items where each bucket can hold a\n * maximum weight of items.\n *\n * You can use this function to calculate groupings of\n * items based on total counts and sizes. A good example\n * usage would be to calculate the total number of pages\n * on a paginated list of items given a page size and item\n * count.\n *\n * @param weight -\n * The maximum weight a bucket can store.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight.\n * @param min -\n * The bounded minimum value. If the total number of buckets\n * evaluates to less than this value, then this value is returned.\n * @param max -\n * The bounded maximum value. If the total number of buckets\n * evaluates to more than this value, then this value is returned.\n *\n * @returns\n * The number of buckets you need to store the total number\n * of items given that a single bucket can hold a max weight of items.\n * If either weight or items is NaN, then NaN will be returned regardless\n * of the opposite value. Passing a negative number is the same as\n * passing 0.\n */\nexport function countBuckets(weight: number, items: number, min = 0, max = Infinity) {\n weight = Math.max(0, weight);\n items = Math.max(0, items);\n\n if (Number.isNaN(weight) || Number.isNaN(items)) {\n return NaN;\n }\n\n if (items === 0) {\n return min;\n }\n\n const boxes = weight === Infinity ? 1 : Math.ceil(items / weight);\n return Math.min(max, Math.max(min, boxes));\n}\n","// Unique ID creation requires a high quality random # generator. In the browser we therefore\n// require the crypto API and do not support built-in fallback to lower quality random number\n// generators (like Math.random()).\nlet getRandomValues;\nconst rnds8 = new Uint8Array(16);\nexport default function rng() {\n // lazy load so that environments that need to polyfill have a chance to do so\n if (!getRandomValues) {\n // getRandomValues needs to be invoked in a context where \"this\" is a Crypto implementation.\n getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);\n\n if (!getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n }\n\n return getRandomValues(rnds8);\n}","import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nconst byteToHex = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\n\nexport function unsafeStringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();\n}\n\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;","const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);\nexport default {\n randomUUID\n};","import { v4 } from 'uuid';\n\n/**\n * Creates a globally unique identifier.\n *\n * @returns\n * A new generated globally unique identifier.\n */\nexport const createGuid: () => string = v4;\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\n\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n\n options = options || {};\n const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(rnds);\n}\n\nexport default v4;","/**\n * Returns the first value in args such that args is not null or undefined.\n *\n * @param fallback -\n * The fallback value in the case that all values in args are null/undefined.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n *\n * @returns\n * The first value if it is not null or undefined. If first is undefined or null, then the first item\n * in remaining such that remaining[i] is not null or undefined is returned. If first and all values of\n * remaining are null or undefined, then fallback is returned.\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n if (first != null) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (val != null) {\n return val;\n }\n }\n\n return fallback;\n}\n","export type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to a string join, but filters out null and undefined items.\n *\n * @param delimiter -\n * The delimiter that separates the items.\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n */\nexport function joinDefined<T>(delimiter: string, ...items: JoinListInputParameter<T>[]) {\n return items\n .map((item) => (item instanceof Array ? (item[1] ? item[0] : null) : item))\n .filter((item) => item != null)\n .join(delimiter);\n}\n\n/**\n * Alias to joinList with a string delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n */\nexport const spaceJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ' ');\n\n/**\n * Alias of spaceJoinList.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n */\nexport const cssJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = spaceJoinDefined;\n\n/**\n * Alias of joinList with a comma delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n */\nexport const commaJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ',');\n\n/**\n * Alias of joinList with a semi-colon delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n */\nexport const semiColonJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ';');\n\n/**\n * Alias of joinList with a pipe delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Row orientation.\n *\n * This type of orientation is a row\n * style orientation or flex-row orientation.\n */\n Horizontal = 'horizontal',\n\n /**\n * Vertical orientation.\n *\n * This type of orientation is a column\n * style orientation or block orientation.\n */\n Vertical = 'vertical'\n}\n","/**\n * Represents a setter function for when you want to set a single value, but you have an array instead.\n *\n * This is useful when you want to support lists of items, but you need\n * backwards compatibility for setting a single item.\n *\n * @param setValue -\n * The setter function that takes a single value.\n * @param fallback -\n * The fallback value in the case that there are no values.\n * @param value -\n * The value list to retrieve the first item from.\n */\nexport function setFirst<T>(setValue: (val: T) => any, fallback: T, value: T[] | null | undefined) {\n const _value = value?.length ? value[0] : fallback;\n setValue(_value);\n}\n","/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep(ms?: number): Promise<void>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n * @param val -\n * The value to resolve with.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms: number, val: T): Promise<T>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms = 0, val: T | undefined = undefined): Promise<T | undefined> {\n return new Promise<T | undefined>((resolve) => setTimeout(() => resolve(val), ms));\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","countBuckets","weight","items","min","max","Infinity","Math","Number","isNaN","NaN","boxes","ceil","getRandomValues","rnds8","Uint8Array","rng","crypto","bind","Error","byteToHex","i","push","toString","slice","native","randomUUID","createGuid","options","buf","offset","rnds","random","arr","toLowerCase","unsafeStringify","firstDefined","fallback","first","remaining","call","arguments","length","val","joinDefined","delimiter","map","item","Array","filter","join","ZOrientation","spaceJoinDefined","cssJoinDefined","commaJoinDefined","semiColonJoinDefined","pipeJoinDefined","setFirst","setValue","value","sleep","ms","undefined","Promise","resolve","setTimeout"],"mappings":"AAGY,IAAAA,EAeAC,ECYI,SAAAC,EAAaC,EAAgBC,EAAeC,EAASC,GAInE,QAJ6D,IAAHD,IAAAA,EAAM,QAAM,IAAHC,IAAAA,EAAMC,UACzEJ,EAASK,KAAKF,IAAI,EAAGH,GACrBC,EAAQI,KAAKF,IAAI,EAAGF,GAEhBK,OAAOC,MAAMP,IAAWM,OAAOC,MAAMN,GACvC,OAAOO,IAGT,GAAc,IAAVP,EACF,OAAOC,EAGT,IAAMO,EAAmBL,WAAXJ,EAAsB,EAAIK,KAAKK,KAAKT,EAAQD,GAC1D,OAAOK,KAAKH,IAAIC,EAAKE,KAAKF,IAAID,EAAKO,GACrC,CCzCA,IAAIE,GFAJ,SAAYd,GAIVA,EAAA,IAAA,MAIAA,EAAA,OAAA,SAIAA,EAAA,OAAA,QACD,CAbD,CAAYA,IAAAA,EAaX,KAED,SAAYC,GAIVA,EAAA,KAAA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1
|
var t,n;let r;exports.ZVerticalAnchor=void 0,(t=exports.ZVerticalAnchor||(exports.ZVerticalAnchor={})).Top="top",t.Middle="middle",t.Bottom="bottom",exports.ZHorizontalAnchor=void 0,(n=exports.ZHorizontalAnchor||(exports.ZHorizontalAnchor={})).Left="left",n.Center="center",n.Right="right";const o=new Uint8Array(16);function e(){if(!r&&(r="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!r))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return r(o)}const i=[];for(let t=0;t<256;++t)i.push((t+256).toString(16).slice(1));var u={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function a(t){return[].slice.call(arguments,1).map(function(t){return t instanceof Array?t[1]?t[0]:null:t}).filter(function(t){return null!=t}).join(t)}var l,c=a.bind(null," "),s=c,d=a.bind(null,","),p=a.bind(null,";"),f=a.bind(null,"|");exports.ZOrientation=void 0,(l=exports.ZOrientation||(exports.ZOrientation={})).Horizontal="horizontal",l.Vertical="vertical",exports.commaJoinDefined=d,exports.countBuckets=function(t,n,r,o){if(void 0===r&&(r=0),void 0===o&&(o=Infinity),t=Math.max(0,t),n=Math.max(0,n),Number.isNaN(t)||Number.isNaN(n))return NaN;if(0===n)return r;var e=Infinity===t?1:Math.ceil(n/t);return Math.min(o,Math.max(r,e))},exports.createGuid=function(t,n,r){if(u.randomUUID&&!n&&!t)return u.randomUUID();const o=(t=t||{}).random||(t.rng||e)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,n){r=r||0;for(let t=0;t<16;++t)n[r+t]=o[t];return n}return function(t,n=0){return(i[t[n+0]]+i[t[n+1]]+i[t[n+2]]+i[t[n+3]]+"-"+i[t[n+4]]+i[t[n+5]]+"-"+i[t[n+6]]+i[t[n+7]]+"-"+i[t[n+8]]+i[t[n+9]]+"-"+i[t[n+10]]+i[t[n+11]]+i[t[n+12]]+i[t[n+13]]+i[t[n+14]]+i[t[n+15]]).toLowerCase()}(o)},exports.cssJoinDefined=s,exports.firstDefined=function(t,n){var r=[].slice.call(arguments,2);if(null!=n)return n;for(var o=0;o<r.length;++o){var e=r[o];if(null!=e)return e}return t},exports.joinDefined=a,exports.pipeJoinDefined=f,exports.semiColonJoinDefined=p,exports.setFirst=function(t,n,r){t(null!=r&&r.length?r[0]:n)},exports.sleep=function(t,n){return void 0===t&&(t=0),void 0===n&&(n=void 0),new Promise(function(r){return setTimeout(function(){return r(n)},t)})},exports.spaceJoinDefined=c;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/anchor/anchor.ts","../../../../node_modules/uuid/dist/esm-browser/rng.js","../../../../node_modules/uuid/dist/esm-browser/stringify.js","../../../../node_modules/uuid/dist/esm-browser/native.js","../../src/join-defined/join-defined.ts","../../src/orientation/orientation.ts","../../src/count-buckets/count-buckets.ts","../../../../node_modules/uuid/dist/esm-browser/v4.js","../../src/first-defined/first-defined.ts","../../src/set-first/set-first.ts","../../src/sleep/sleep.ts"],"sourcesContent":["/**\n * Represents a vertical anchor.\n */\nexport enum ZVerticalAnchor {\n /**\n * Top boundary.\n */\n Top = 'top',\n /**\n * Centerpoint between the top and bottom.\n */\n Middle = 'middle',\n /**\n * Bottom boundary.\n */\n Bottom = 'bottom'\n}\n\nexport enum ZHorizontalAnchor {\n /**\n * Left boundary.\n */\n Left = 'left',\n /**\n * Centerpoint between the left and right boundary.\n */\n Center = 'center',\n /**\n * Right boundary.\n */\n Right = 'right'\n}\n\n/**\n * Represents an anchor point.\n *\n * An anchor point is a point that stays constant while things are\n * resizing.\n */\nexport type ZAnchor = [ZVerticalAnchor, ZHorizontalAnchor];\n\n/**\n * Represents a special type of anchor that excludes the center points.\n */\nexport type ZSideAnchor =\n | ZVerticalAnchor.Top\n | ZVerticalAnchor.Bottom\n | ZHorizontalAnchor.Left\n | ZHorizontalAnchor.Right;\n","// Unique ID creation requires a high quality random # generator. In the browser we therefore\n// require the crypto API and do not support built-in fallback to lower quality random number\n// generators (like Math.random()).\nlet getRandomValues;\nconst rnds8 = new Uint8Array(16);\nexport default function rng() {\n // lazy load so that environments that need to polyfill have a chance to do so\n if (!getRandomValues) {\n // getRandomValues needs to be invoked in a context where \"this\" is a Crypto implementation.\n getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);\n\n if (!getRandomValues) {\n throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');\n }\n }\n\n return getRandomValues(rnds8);\n}","import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nconst byteToHex = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).slice(1));\n}\n\nexport function unsafeStringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();\n}\n\nfunction stringify(arr, offset = 0) {\n const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;","const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);\nexport default {\n randomUUID\n};","export type JoinListInputParameter<T> = T | [T, boolean] | null | undefined;\n\n/**\n * Similar to a string join, but filters out null and undefined items.\n *\n * @param delimiter -\n * The delimiter that separates the items.\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by delimiter.\n */\nexport function joinDefined<T>(delimiter: string, ...items: JoinListInputParameter<T>[]) {\n return items\n .map((item) => (item instanceof Array ? (item[1] ? item[0] : null) : item))\n .filter((item) => item != null)\n .join(delimiter);\n}\n\n/**\n * Alias to joinList with a string delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by space delimiter.\n */\nexport const spaceJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ' ');\n\n/**\n * Alias of spaceJoinList.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a space delimiter.\n */\nexport const cssJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = spaceJoinDefined;\n\n/**\n * Alias of joinList with a comma delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a comma delimiter.\n */\nexport const commaJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ',');\n\n/**\n * Alias of joinList with a semi-colon delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a semi-colon delimiter.\n */\nexport const semiColonJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, ';');\n\n/**\n * Alias of joinList with a pipe delimiter.\n *\n * @param items -\n * The items to join.\n *\n * @returns\n * A string that joins the items that are defined, separated by a pipe delimiter.\n */\nexport const pipeJoinDefined: <T>(...items: JoinListInputParameter<T>[]) => string = joinDefined.bind(null, '|');\n","/**\n * Represents a direction orientation.\n */\nexport enum ZOrientation {\n /**\n * Row orientation.\n *\n * This type of orientation is a row\n * style orientation or flex-row orientation.\n */\n Horizontal = 'horizontal',\n\n /**\n * Vertical orientation.\n *\n * This type of orientation is a column\n * style orientation or block orientation.\n */\n Vertical = 'vertical'\n}\n","/**\n * Calculates the total number of buckets you need to\n * store a number of items where each bucket can hold a\n * maximum weight of items.\n *\n * You can use this function to calculate groupings of\n * items based on total counts and sizes. A good example\n * usage would be to calculate the total number of pages\n * on a paginated list of items given a page size and item\n * count.\n *\n * @param weight -\n * The maximum weight a bucket can store.\n * @param items -\n * The total number of items you need to store where each item\n * counts as 1 towards the weight.\n * @param min -\n * The bounded minimum value. If the total number of buckets\n * evaluates to less than this value, then this value is returned.\n * @param max -\n * The bounded maximum value. If the total number of buckets\n * evaluates to more than this value, then this value is returned.\n *\n * @returns\n * The number of buckets you need to store the total number\n * of items given that a single bucket can hold a max weight of items.\n * If either weight or items is NaN, then NaN will be returned regardless\n * of the opposite value. Passing a negative number is the same as\n * passing 0.\n */\nexport function countBuckets(weight: number, items: number, min = 0, max = Infinity) {\n weight = Math.max(0, weight);\n items = Math.max(0, items);\n\n if (Number.isNaN(weight) || Number.isNaN(items)) {\n return NaN;\n }\n\n if (items === 0) {\n return min;\n }\n\n const boxes = weight === Infinity ? 1 : Math.ceil(items / weight);\n return Math.min(max, Math.max(min, boxes));\n}\n","import native from './native.js';\nimport rng from './rng.js';\nimport { unsafeStringify } from './stringify.js';\n\nfunction v4(options, buf, offset) {\n if (native.randomUUID && !buf && !options) {\n return native.randomUUID();\n }\n\n options = options || {};\n const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(rnds);\n}\n\nexport default v4;","/**\n * Returns the first value in args such that args is not null or undefined.\n *\n * @param fallback -\n * The fallback value in the case that all values in args are null/undefined.\n * @param first -\n * The first value to check.\n * @param remaining -\n * The remaining values beyond the first to check.\n *\n * @returns\n * The first value if it is not null or undefined. If first is undefined or null, then the first item\n * in remaining such that remaining[i] is not null or undefined is returned. If first and all values of\n * remaining are null or undefined, then fallback is returned.\n */\nexport function firstDefined<T = any>(\n fallback: T,\n first: T | null | undefined,\n ...remaining: (T | null | undefined)[]\n): T {\n if (first != null) {\n return first;\n }\n\n for (let i = 0; i < remaining.length; ++i) {\n const val = remaining[i];\n\n if (val != null) {\n return val;\n }\n }\n\n return fallback;\n}\n","/**\n * Represents a setter function for when you want to set a single value, but you have an array instead.\n *\n * This is useful when you want to support lists of items, but you need\n * backwards compatibility for setting a single item.\n *\n * @param setValue -\n * The setter function that takes a single value.\n * @param fallback -\n * The fallback value in the case that there are no values.\n * @param value -\n * The value list to retrieve the first item from.\n */\nexport function setFirst<T>(setValue: (val: T) => any, fallback: T, value: T[] | null | undefined) {\n const _value = value?.length ? value[0] : fallback;\n setValue(_value);\n}\n","/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep(ms?: number): Promise<void>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n * @param val -\n * The value to resolve with.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms: number, val: T): Promise<T>;\n\n/**\n * Halts the current thread to invoke an event loop.\n *\n * @param ms -\n * The total number of milliseconds to sleep.\n *\n * @returns\n * A promise that resolves after ms milliseconds.\n */\nexport function sleep<T>(ms = 0, val: T | undefined = undefined): Promise<T | undefined> {\n return new Promise<T | undefined>((resolve) => setTimeout(() => resolve(val), ms));\n}\n"],"names":["ZVerticalAnchor","ZHorizontalAnchor","getRandomValues","rnds8","Uint8Array","rng","crypto","bind","Error","byteToHex","i","push","toString","slice","native","randomUUID","joinDefined","delimiter","call","arguments","map","item","Array","filter","join","ZOrientation","spaceJoinDefined","cssJoinDefined","commaJoinDefined","semiColonJoinDefined","pipeJoinDefined","weight","items","min","max","Infinity","Math","Number","isNaN","NaN","boxes","ceil","options","buf","offset","rnds","random","arr","toLowerCase","unsafeStringify","fallback","first","remaining","length","val","setValue","value","ms","undefined","Promise","resolve","setTimeout"],"mappings":"AAGA,IAAYA,EAeAC,ECfZ,IAAIC,EDAQF,QAAAA,qBAAAA,GAAAA,EAAAA,QAAeA,kBAAfA,QAAeA,gBAa1B,KATC,IAAA,MAIAA,EAAA,OAAA,SAIAA,EAAA,OAAA,SAGUC,QAAAA,uBAAAA,GAAAA,EAAAA,4BAAAA,QAAAA,kBAaX,CAAA,IATC,KAAA,OAIAA,EAAA,OAAA,SAIAA,EAAA,MAAA,QC1BF,MAAME,EAAQ,IAAIC,WAAW,IACd,SAASC,IAEtB,IAAKH,IAEHA,EAAoC,oBAAXI,QAA0BA,OAAOJ,iBAAmBI,OAAOJ,gBAAgBK,KAAKD,SAEpGJ,GACH,MAAM,IAAIM,MAAM,4GAIpB,OAAON,EAAgBC,EACzB,CCXA,MAAMM,EAAY,GAElB,IAAK,IAAIC,EAAI,EAAGA,EAAI,MAAOA,EACzBD,EAAUE,MAAMD,EAAI,KAAOE,SAAS,IAAIC,MAAM,ICRhD,IAAeC,EAAA,CACbC,WAFmC,oBAAXT,QAA0BA,OAAOS,YAAcT,OAAOS,WAAWR,KAAKD,kBCahFU,EAAeC,GAC7B,MAAO,GAAAJ,MAAAK,KAAAC,UACJC,GAAAA,IAAI,SAACC,GAAI,OAAMA,aAAgBC,MAASD,EAAK,GAAKA,EAAK,GAAK,KAAQA,CAAI,GACxEE,OAAO,SAACF,GAAI,OAAa,MAARA,CAAY,GAC7BG,KAAKP,EACV,CAWa,IC1BDQ,ED0BCC,EA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EAAUsC,EAAIH,EAAS,IAAM,IAAMnC,EAAUsC,EAAIH,EAAS,IAAMnC,EAAUsC,EAAIH,EAAS,IAAM,IAAMnC,EAAUsC,EAAIH,EAAS,IAAMnC,EAAUsC,EAAIH,EAAS,IAAM,IAAMnC,EAAUsC,EAAIH,EAAS,KAAOnC,EAAUsC,EAAIH,EAAS,KAAOnC,EAAUsC,EAAIH,EAAS,KAAOnC,EAAUsC,EAAIH,EAAS,KAAOnC,EAAUsC,EAAIH,EAAS,KAAOnC,EAAUsC,EAAIH,EAAS,MAAMI,aACvf,CKSSC,CAAgBJ,EACzB,gDCXgB,SACdK,EACAC,GACG,IAAAC,EAAmC,GAAAvC,MAAAK,KAAAC,UAEtC,GAAA,GAAa,MAATgC,EACF,OAAOA,EAGT,IAAK,IAAIzC,EAAI,EAAGA,EAAI0C,EAAUC,SAAU3C,EAAG,CACzC,IAAM4C,EAAMF,EAAU1C,GAEtB,GAAW,MAAP4C,EACF,OAAOA,CAEV,CAED,OAAOJ,CACT,kGCpBgB,SAAYK,EAA2BL,EAAaM,GAElED,EADoB,MAALC,GAAAA,EAAOH,OAASG,EAAM,GAAKN,EAE5C,yBCiByBO,EAAQH,GAC/B,YADyB,IAAFG,IAAAA,EAAK,YAAGH,IAAAA,OAAqBI,OACzCC,QAAuB,SAACC,UAAYC,WAAW,WAAM,OAAAD,EAAQN,EAAI,EAAEG,EAAG,EACnF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zthun/helpful-fn",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Helpful, isolated pure functions that are not found in other libraries such as lodash.",
|
|
5
5
|
"author": "Anthony Bonta",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"module": "./dist/lib/index.esm.js",
|
|
14
14
|
"types": "./dist/types/index.d.ts",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "microbundle --format esm,cjs --tsconfig tsconfig.prod.json
|
|
16
|
+
"build": "microbundle --format esm,cjs --tsconfig tsconfig.prod.json"
|
|
17
17
|
},
|
|
18
18
|
"publishConfig": {
|
|
19
19
|
"access": "public"
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"microbundle": "^0.15.1",
|
|
23
23
|
"uuid": "^9.0.0",
|
|
24
|
-
"vite": "^4.
|
|
25
|
-
"vitest": "^0.
|
|
24
|
+
"vite": "^4.4.4",
|
|
25
|
+
"vitest": "^0.33.0"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"sideEffects": false,
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "4c3895d2c653d2a30c71cc5f4e07622cfbc9a1c7"
|
|
32
32
|
}
|