@vielzeug/toolkit 1.0.11 → 1.0.13
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/array/chunk.cjs +1 -1
- package/dist/array/chunk.cjs.map +1 -1
- package/dist/array/chunk.js +15 -12
- package/dist/array/chunk.js.map +1 -1
- package/dist/array/group.cjs +1 -1
- package/dist/array/group.cjs.map +1 -1
- package/dist/array/group.js +9 -9
- package/dist/array/group.js.map +1 -1
- package/dist/array/list.cjs +1 -1
- package/dist/array/list.cjs.map +1 -1
- package/dist/array/list.js +28 -24
- package/dist/array/list.js.map +1 -1
- package/dist/array/pick.cjs.map +1 -1
- package/dist/array/pick.js.map +1 -1
- package/dist/date/timeDiff.cjs +1 -1
- package/dist/date/timeDiff.cjs.map +1 -1
- package/dist/date/timeDiff.js +10 -12
- package/dist/date/timeDiff.js.map +1 -1
- package/dist/function/curry.cjs +1 -1
- package/dist/function/curry.cjs.map +1 -1
- package/dist/function/curry.js +3 -3
- package/dist/function/curry.js.map +1 -1
- package/dist/function/debounce.cjs +1 -1
- package/dist/function/debounce.cjs.map +1 -1
- package/dist/function/debounce.js +22 -5
- package/dist/function/debounce.js.map +1 -1
- package/dist/function/memo.cjs +1 -1
- package/dist/function/memo.cjs.map +1 -1
- package/dist/function/memo.js +14 -13
- package/dist/function/memo.js.map +1 -1
- package/dist/function/retry.cjs +1 -1
- package/dist/function/retry.cjs.map +1 -1
- package/dist/function/retry.js +12 -12
- package/dist/function/retry.js.map +1 -1
- package/dist/function/sleep.cjs +1 -1
- package/dist/function/sleep.cjs.map +1 -1
- package/dist/function/sleep.js +8 -3
- package/dist/function/sleep.js.map +1 -1
- package/dist/function/throttle.cjs +1 -1
- package/dist/function/throttle.cjs.map +1 -1
- package/dist/function/throttle.js +33 -6
- package/dist/function/throttle.js.map +1 -1
- package/dist/index.d.ts +62 -51
- package/dist/logit/dist/logit.cjs +1 -1
- package/dist/logit/dist/logit.cjs.map +1 -1
- package/dist/logit/dist/logit.js +64 -62
- package/dist/logit/dist/logit.js.map +1 -1
- package/dist/math/average.cjs +1 -1
- package/dist/math/average.cjs.map +1 -1
- package/dist/math/average.js +18 -12
- package/dist/math/average.js.map +1 -1
- package/dist/math/median.cjs.map +1 -1
- package/dist/math/median.js.map +1 -1
- package/dist/math/range.cjs +1 -1
- package/dist/math/range.cjs.map +1 -1
- package/dist/math/range.js +14 -6
- package/dist/math/range.js.map +1 -1
- package/dist/math/sum.cjs +1 -1
- package/dist/math/sum.cjs.map +1 -1
- package/dist/math/sum.js +11 -18
- package/dist/math/sum.js.map +1 -1
- package/dist/object/clone.cjs +1 -1
- package/dist/object/clone.cjs.map +1 -1
- package/dist/object/clone.js +13 -3
- package/dist/object/clone.js.map +1 -1
- package/dist/object/merge.cjs +1 -1
- package/dist/object/merge.cjs.map +1 -1
- package/dist/object/merge.js +11 -15
- package/dist/object/merge.js.map +1 -1
- package/dist/object/seek.cjs +1 -1
- package/dist/object/seek.cjs.map +1 -1
- package/dist/object/seek.js +8 -6
- package/dist/object/seek.js.map +1 -1
- package/dist/random/uuid.cjs +1 -1
- package/dist/random/uuid.cjs.map +1 -1
- package/dist/random/uuid.js +6 -3
- package/dist/random/uuid.js.map +1 -1
- package/dist/string/camelCase.cjs +1 -1
- package/dist/string/camelCase.cjs.map +1 -1
- package/dist/string/camelCase.js +3 -3
- package/dist/string/camelCase.js.map +1 -1
- package/dist/string/similarity.cjs +1 -1
- package/dist/string/similarity.cjs.map +1 -1
- package/dist/string/similarity.js +24 -21
- package/dist/string/similarity.js.map +1 -1
- package/dist/string/truncate.cjs +1 -1
- package/dist/string/truncate.cjs.map +1 -1
- package/dist/string/truncate.js +14 -5
- package/dist/string/truncate.js.map +1 -1
- package/dist/typed/is.cjs +1 -1
- package/dist/typed/is.cjs.map +1 -1
- package/dist/typed/is.js +30 -31
- package/dist/typed/is.js.map +1 -1
- package/dist/typed/isEmpty.cjs +1 -1
- package/dist/typed/isEmpty.cjs.map +1 -1
- package/dist/typed/isEmpty.js +6 -6
- package/dist/typed/isEmpty.js.map +1 -1
- package/dist/typed/isEqual.cjs +1 -1
- package/dist/typed/isEqual.cjs.map +1 -1
- package/dist/typed/isEqual.js +22 -17
- package/dist/typed/isEqual.js.map +1 -1
- package/package.json +1 -1
package/dist/math/sum.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sum.js","sources":["../../src/math/sum.ts"],"sourcesContent":["/**\n * Sum numbers in an array or numbers mapped by a callback function.\n *\n * @example\n * ```ts\n * sum([1, 2, 3]) // 6\n * sum([{value: 1}, {value: 2}, {value: 3}], (item) => item.value) // 6\n * sum(['apple', 'banana', 'cherry']) // TypeError\n *
|
|
1
|
+
{"version":3,"file":"sum.js","sources":["../../src/math/sum.ts"],"sourcesContent":["/**\n * Sum numbers in an array or numbers mapped by a callback function.\n *\n * @example\n * ```ts\n * sum([1, 2, 3]) // 6\n * sum([{value: 1}, {value: 2}, {value: 3}], (item) => item.value) // 6\n * sum(['apple', 'banana', 'cherry']) // TypeError\n * ```\n *\n * @param array - The array to sum.\n * @param callback - An optional callback function to map the values.\n *\n * @returns The sum of the numbers in the array or the sum of the mapped values.\n */\nexport function sum<T>(array: T[], callback?: (item: T) => number): number | undefined {\n if (array.length === 0) return undefined;\n\n return array.reduce<number>((acc, item) => {\n const val = callback ? callback(item) : item;\n if (typeof val !== 'number') {\n throw new TypeError(`Expected number, got ${typeof val}`);\n }\n if (Number.isNaN(val)) {\n throw new TypeError('Cannot sum NaN values');\n }\n return acc + val;\n }, 0);\n}\n"],"names":["sum","array","callback","acc","item","val"],"mappings":"AAeO,SAASA,EAAOC,GAAYC,GAAoD;AACrF,MAAID,EAAM,WAAW;AAErB,WAAOA,EAAM,OAAe,CAACE,GAAKC,MAAS;AACzC,YAAMC,IAAMH,IAAWA,EAASE,CAAI,IAAIA;AACxC,UAAI,OAAOC,KAAQ;AACjB,cAAM,IAAI,UAAU,wBAAwB,OAAOA,CAAG,EAAE;AAE1D,UAAI,OAAO,MAAMA,CAAG;AAClB,cAAM,IAAI,UAAU,uBAAuB;AAE7C,aAAOF,IAAME;AAAA,IACf,GAAG,CAAC;AACN;"}
|
package/dist/object/clone.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e){return structuredClone(e)}exports.clone=t;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e){if(typeof structuredClone=="function")try{return structuredClone(e)}catch(r){throw new Error(`Failed to clone item: ${r instanceof Error?r.message:String(r)}`)}try{return JSON.parse(JSON.stringify(e))}catch(r){throw new Error(`Failed to clone item using JSON: ${r instanceof Error?r.message:String(r)}`)}}exports.clone=t;
|
|
2
2
|
//# sourceMappingURL=clone.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clone.cjs","sources":["../../src/object/clone.ts"],"sourcesContent":["/**\n * Creates a deep copy of the provided data using the structuredClone algorithm.\n *\n * @example\n * ```ts\n * const obj = { a: 1, b: { c: 2 } };\n * const dup = clone(obj);\n *\n * dup.b.c = 3;\n * console.log(obj.b.c); // logs 2\n * console.log(dup.b.c); // logs 3\n * ```\n *\n * @param item - The data to clone.\n *\n * @returns A deep copy of the provided data.\n */\nexport function clone<T>(item: T): T {\n return structuredClone(item);\n}\n"],"names":["clone","item"],"mappings":"
|
|
1
|
+
{"version":3,"file":"clone.cjs","sources":["../../src/object/clone.ts"],"sourcesContent":["/**\n * Creates a deep copy of the provided data using the structuredClone algorithm.\n *\n * @example\n * ```ts\n * const obj = { a: 1, b: { c: 2 } };\n * const dup = clone(obj);\n *\n * dup.b.c = 3;\n * console.log(obj.b.c); // logs 2\n * console.log(dup.b.c); // logs 3\n * ```\n *\n * @param item - The data to clone.\n *\n * @returns A deep copy of the provided data.\n *\n * @throws {Error} If the item cannot be cloned.\n */\nexport function clone<T>(item: T): T {\n if (typeof structuredClone === 'function') {\n try {\n return structuredClone(item);\n } catch (error) {\n throw new Error(`Failed to clone item: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n try {\n return JSON.parse(JSON.stringify(item));\n } catch (error) {\n throw new Error(`Failed to clone item using JSON: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n"],"names":["clone","item","error"],"mappings":"gFAmBO,SAASA,EAASC,EAAY,CACnC,GAAI,OAAO,iBAAoB,WAC7B,GAAI,CACF,OAAO,gBAAgBA,CAAI,CAC7B,OAASC,EAAO,CACd,MAAM,IAAI,MAAM,yBAAyBA,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,CAAC,EAAE,CACnG,CAEF,GAAI,CACF,OAAO,KAAK,MAAM,KAAK,UAAUD,CAAI,CAAC,CACxC,OAASC,EAAO,CACd,MAAM,IAAI,MAAM,oCAAoCA,aAAiB,MAAQA,EAAM,QAAU,OAAOA,CAAK,CAAC,EAAE,CAC9G,CACF"}
|
package/dist/object/clone.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
1
|
+
function t(e) {
|
|
2
|
+
if (typeof structuredClone == "function")
|
|
3
|
+
try {
|
|
4
|
+
return structuredClone(e);
|
|
5
|
+
} catch (r) {
|
|
6
|
+
throw new Error(`Failed to clone item: ${r instanceof Error ? r.message : String(r)}`);
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(JSON.stringify(e));
|
|
10
|
+
} catch (r) {
|
|
11
|
+
throw new Error(`Failed to clone item using JSON: ${r instanceof Error ? r.message : String(r)}`);
|
|
12
|
+
}
|
|
3
13
|
}
|
|
4
14
|
export {
|
|
5
|
-
|
|
15
|
+
t as clone
|
|
6
16
|
};
|
|
7
17
|
//# sourceMappingURL=clone.js.map
|
package/dist/object/clone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clone.js","sources":["../../src/object/clone.ts"],"sourcesContent":["/**\n * Creates a deep copy of the provided data using the structuredClone algorithm.\n *\n * @example\n * ```ts\n * const obj = { a: 1, b: { c: 2 } };\n * const dup = clone(obj);\n *\n * dup.b.c = 3;\n * console.log(obj.b.c); // logs 2\n * console.log(dup.b.c); // logs 3\n * ```\n *\n * @param item - The data to clone.\n *\n * @returns A deep copy of the provided data.\n */\nexport function clone<T>(item: T): T {\n return structuredClone(item);\n}\n"],"names":["clone","item"],"mappings":"
|
|
1
|
+
{"version":3,"file":"clone.js","sources":["../../src/object/clone.ts"],"sourcesContent":["/**\n * Creates a deep copy of the provided data using the structuredClone algorithm.\n *\n * @example\n * ```ts\n * const obj = { a: 1, b: { c: 2 } };\n * const dup = clone(obj);\n *\n * dup.b.c = 3;\n * console.log(obj.b.c); // logs 2\n * console.log(dup.b.c); // logs 3\n * ```\n *\n * @param item - The data to clone.\n *\n * @returns A deep copy of the provided data.\n *\n * @throws {Error} If the item cannot be cloned.\n */\nexport function clone<T>(item: T): T {\n if (typeof structuredClone === 'function') {\n try {\n return structuredClone(item);\n } catch (error) {\n throw new Error(`Failed to clone item: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n try {\n return JSON.parse(JSON.stringify(item));\n } catch (error) {\n throw new Error(`Failed to clone item using JSON: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n"],"names":["clone","item","error"],"mappings":"AAmBO,SAASA,EAASC,GAAY;AACnC,MAAI,OAAO,mBAAoB;AAC7B,QAAI;AACF,aAAO,gBAAgBA,CAAI;AAAA,IAC7B,SAASC,GAAO;AACd,YAAM,IAAI,MAAM,yBAAyBA,aAAiB,QAAQA,EAAM,UAAU,OAAOA,CAAK,CAAC,EAAE;AAAA,IACnG;AAEF,MAAI;AACF,WAAO,KAAK,MAAM,KAAK,UAAUD,CAAI,CAAC;AAAA,EACxC,SAASC,GAAO;AACd,UAAM,IAAI,MAAM,oCAAoCA,aAAiB,QAAQA,EAAM,UAAU,OAAOA,CAAK,CAAC,EAAE;AAAA,EAC9G;AACF;"}
|
package/dist/object/merge.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../typed/isArray.cjs"),f=require("../typed/isObject.cjs");function a(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../typed/isArray.cjs"),f=require("../typed/isObject.cjs");function a(i="deep",...n){return n.length===0?{}:i==="shallow"?Object.assign({},...n):n.reduce((e,r)=>l(e,r,i),{})}function l(i,n,e){if(!f.isObject(n))return n;const r={...i};for(const c in n){if(!Object.hasOwn(n,c))continue;const t=n[c],u=r[c];r[c]=o.isArray(t)&&o.isArray(u)?b(u,t,e):f.isObject(t)&&f.isObject(u)?l(u,t,e):O(u,t,e)}return r}function b(i,n,e){return i?e==="arrayConcat"?i.concat(n):e==="arrayReplace"?n:Array.from(new Set([...i,...n])):n}function O(i,n,e){return typeof e=="function"?e(i,n):e==="lastWins"||n!==void 0?n:i}exports.merge=a;
|
|
2
2
|
//# sourceMappingURL=merge.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.cjs","sources":["../../src/object/merge.ts"],"sourcesContent":["import { isArray } from '../typed/isArray';\nimport { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype MergeStrategy =\n | 'deep'\n | 'shallow'\n | 'lastWins'\n | 'arrayConcat'\n | 'arrayReplace'\n // biome-ignore lint/suspicious/noExplicitAny: -\n | ((target: any, source: any) => any);\n\ntype DeepMerge<T, U> = T extends Obj\n ? U extends Obj\n ? {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<T[K], U[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : U\n : U;\n\ntype Merge<T extends Obj[]> = T extends [infer First, ...infer Rest]\n ? First extends Obj\n ? Rest extends Obj[]\n ? DeepMerge<First, Merge<Rest>>\n : First\n : Obj\n : Obj;\n\n/**\n * Merges multiple objects based on a specified merge strategy.\n *\n * @example\n * ```ts\n * const obj1 = { a: 1, b: { x: 10, y: \"hello\" }, c: [1] };\n * const obj2 = { b: { y: 20, z: true }, c: [2] };\n * const obj3 = { d: false, c: [3] };\n *\n * merge(\"deep\", obj1, obj2, obj3); // { a: 1, b: { x: 10, y: 20, z: true }, c: [1, 2, 3], d: false }\n * merge(\"shallow\", obj1, obj2, obj3); // { a: 1, b: { y: 20, z: true }, c: [3], d: false }\n * ```\n *\n * @param [strategy='deep'] - The merging strategy to use.\n * @param items - The objects to merge.\n * @returns A new merged object.\n */\nexport function merge<T extends Obj[]>(strategy: MergeStrategy = 'deep', ...items: [...T]): Merge<T> {\n if (items.length === 0) return {} as Merge<T>;\n\n if (strategy === 'shallow') {\n return Object.assign({}, ...items) as Merge<T>;\n }\n\n
|
|
1
|
+
{"version":3,"file":"merge.cjs","sources":["../../src/object/merge.ts"],"sourcesContent":["import { isArray } from '../typed/isArray';\nimport { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype MergeStrategy =\n | 'deep'\n | 'shallow'\n | 'lastWins'\n | 'arrayConcat'\n | 'arrayReplace'\n // biome-ignore lint/suspicious/noExplicitAny: -\n | ((target: any, source: any) => any);\n\ntype DeepMerge<T, U> = T extends Obj\n ? U extends Obj\n ? {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<T[K], U[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : U\n : U;\n\ntype Merge<T extends Obj[]> = T extends [infer First, ...infer Rest]\n ? First extends Obj\n ? Rest extends Obj[]\n ? DeepMerge<First, Merge<Rest>>\n : First\n : Obj\n : Obj;\n\n/**\n * Merges multiple objects based on a specified merge strategy.\n *\n * @example\n * ```ts\n * const obj1 = { a: 1, b: { x: 10, y: \"hello\" }, c: [1] };\n * const obj2 = { b: { y: 20, z: true }, c: [2] };\n * const obj3 = { d: false, c: [3] };\n *\n * merge(\"deep\", obj1, obj2, obj3); // { a: 1, b: { x: 10, y: 20, z: true }, c: [1, 2, 3], d: false }\n * merge(\"shallow\", obj1, obj2, obj3); // { a: 1, b: { y: 20, z: true }, c: [3], d: false }\n * ```\n *\n * @param [strategy='deep'] - The merging strategy to use.\n * @param items - The objects to merge.\n * @returns A new merged object.\n */\nexport function merge<T extends Obj[]>(strategy: MergeStrategy = 'deep', ...items: [...T]): Merge<T> {\n if (items.length === 0) return {} as Merge<T>;\n\n if (strategy === 'shallow') {\n return Object.assign({}, ...items) as Merge<T>;\n }\n\n return items.reduce((acc, obj) => deepMerge(acc, obj, strategy) as unknown as Merge<T>, {} as Merge<T>);\n}\n\n/**\n * Deeply merges two objects based on the provided strategy.\n *\n * - Uses **direct property access** for performance.\n * - **Avoids redundant deep merging** where unnecessary.\n * - Optimized **array merging strategies**.\n *\n * @param target - The target object.\n * @param source - The source object.\n * @param strategy - The merge strategy.\n * @returns A new merged object.\n */\nfunction deepMerge<T extends Obj, U extends Obj>(target: T, source: U, strategy: MergeStrategy): DeepMerge<T, U> {\n if (!isObject(source)) return source as DeepMerge<T, U>;\n\n const result = { ...target } as DeepMerge<T, U>;\n\n for (const key in source) {\n if (!Object.hasOwn(source, key)) continue; // Prevent prototype pollution\n\n const sourceValue = source[key];\n const targetValue = result[key];\n\n // biome-ignore lint/suspicious/noExplicitAny: -\n (result as any)[key] =\n isArray(sourceValue) && isArray(targetValue)\n ? handleArrayMerge(targetValue, sourceValue, strategy)\n : isObject(sourceValue) && isObject(targetValue)\n ? deepMerge(targetValue, sourceValue, strategy)\n : applyMergeStrategy(targetValue, sourceValue, strategy);\n }\n\n return result;\n}\n\n/**\n * Optimized array merge based on strategy.\n *\n * - `\"arrayConcat\"` → Concatenates arrays.\n * - `\"arrayReplace\"` → Replaces the existing array.\n * - Default: **Unique merge** (Set-based optimization).\n */\nfunction handleArrayMerge<T, U>(targetArray: T[] | undefined, sourceArray: U[], strategy: MergeStrategy): (T | U)[] {\n if (!targetArray) return sourceArray;\n // biome-ignore lint/suspicious/noExplicitAny: -\n if (strategy === 'arrayConcat') return targetArray.concat(sourceArray as any);\n if (strategy === 'arrayReplace') return sourceArray;\n return Array.from(new Set([...targetArray, ...sourceArray])); // Unique merge\n}\n\n/**\n * Determines the appropriate value to assign based on the merge strategy.\n *\n * - `\"lastWins\"` → Overwrites with the latest value.\n * - Custom functions → Allows user-defined behavior.\n */\nfunction applyMergeStrategy<T, U>(target: T, source: U, strategy: MergeStrategy): T | U {\n if (typeof strategy === 'function') return strategy(target, source);\n return strategy === 'lastWins' || source !== undefined ? source : target;\n}\n"],"names":["merge","strategy","items","acc","obj","deepMerge","target","source","isObject","result","key","sourceValue","targetValue","isArray","handleArrayMerge","applyMergeStrategy","targetArray","sourceArray"],"mappings":"2JAoDO,SAASA,EAAuBC,EAA0B,UAAWC,EAAyB,CACnG,OAAIA,EAAM,SAAW,EAAU,CAAA,EAE3BD,IAAa,UACR,OAAO,OAAO,CAAA,EAAI,GAAGC,CAAK,EAG5BA,EAAM,OAAO,CAACC,EAAKC,IAAQC,EAAUF,EAAKC,EAAKH,CAAQ,EAA0B,EAAc,CACxG,CAcA,SAASI,EAAwCC,EAAWC,EAAWN,EAA0C,CAC/G,GAAI,CAACO,EAAAA,SAASD,CAAM,EAAG,OAAOA,EAE9B,MAAME,EAAS,CAAE,GAAGH,CAAA,EAEpB,UAAWI,KAAOH,EAAQ,CACxB,GAAI,CAAC,OAAO,OAAOA,EAAQG,CAAG,EAAG,SAEjC,MAAMC,EAAcJ,EAAOG,CAAG,EACxBE,EAAcH,EAAOC,CAAG,EAG7BD,EAAeC,CAAG,EACjBG,EAAAA,QAAQF,CAAW,GAAKE,EAAAA,QAAQD,CAAW,EACvCE,EAAiBF,EAAaD,EAAaV,CAAQ,EACnDO,EAAAA,SAASG,CAAW,GAAKH,EAAAA,SAASI,CAAW,EAC3CP,EAAUO,EAAaD,EAAaV,CAAQ,EAC5Cc,EAAmBH,EAAaD,EAAaV,CAAQ,CAC/D,CAEA,OAAOQ,CACT,CASA,SAASK,EAAuBE,EAA8BC,EAAkBhB,EAAoC,CAClH,OAAKe,EAEDf,IAAa,cAAsBe,EAAY,OAAOC,CAAkB,EACxEhB,IAAa,eAAuBgB,EACjC,MAAM,KAAK,IAAI,IAAI,CAAC,GAAGD,EAAa,GAAGC,CAAW,CAAC,CAAC,EAJlCA,CAK3B,CAQA,SAASF,EAAyBT,EAAWC,EAAWN,EAAgC,CACtF,OAAI,OAAOA,GAAa,WAAmBA,EAASK,EAAQC,CAAM,EAC3DN,IAAa,YAAcM,IAAW,OAAYA,EAASD,CACpE"}
|
package/dist/object/merge.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
import { isArray as c } from "../typed/isArray.js";
|
|
2
2
|
import { isObject as u } from "../typed/isObject.js";
|
|
3
|
-
function m(
|
|
4
|
-
return n.length === 0 ? {} :
|
|
5
|
-
// @ts-expect-error
|
|
6
|
-
(e, i) => l(e, i, r),
|
|
7
|
-
{}
|
|
8
|
-
);
|
|
3
|
+
function m(i = "deep", ...n) {
|
|
4
|
+
return n.length === 0 ? {} : i === "shallow" ? Object.assign({}, ...n) : n.reduce((e, r) => l(e, r, i), {});
|
|
9
5
|
}
|
|
10
|
-
function l(
|
|
6
|
+
function l(i, n, e) {
|
|
11
7
|
if (!u(n)) return n;
|
|
12
|
-
const
|
|
8
|
+
const r = { ...i };
|
|
13
9
|
for (const o in n) {
|
|
14
10
|
if (!Object.hasOwn(n, o)) continue;
|
|
15
|
-
const
|
|
16
|
-
|
|
11
|
+
const f = n[o], t = r[o];
|
|
12
|
+
r[o] = c(f) && c(t) ? p(t, f, e) : u(f) && u(t) ? l(t, f, e) : a(t, f, e);
|
|
17
13
|
}
|
|
18
|
-
return
|
|
14
|
+
return r;
|
|
19
15
|
}
|
|
20
|
-
function p(
|
|
21
|
-
return
|
|
16
|
+
function p(i, n, e) {
|
|
17
|
+
return i ? e === "arrayConcat" ? i.concat(n) : e === "arrayReplace" ? n : Array.from(/* @__PURE__ */ new Set([...i, ...n])) : n;
|
|
22
18
|
}
|
|
23
|
-
function a(
|
|
24
|
-
return typeof e == "function" ? e(
|
|
19
|
+
function a(i, n, e) {
|
|
20
|
+
return typeof e == "function" ? e(i, n) : e === "lastWins" || n !== void 0 ? n : i;
|
|
25
21
|
}
|
|
26
22
|
export {
|
|
27
23
|
m as merge
|
package/dist/object/merge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.js","sources":["../../src/object/merge.ts"],"sourcesContent":["import { isArray } from '../typed/isArray';\nimport { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype MergeStrategy =\n | 'deep'\n | 'shallow'\n | 'lastWins'\n | 'arrayConcat'\n | 'arrayReplace'\n // biome-ignore lint/suspicious/noExplicitAny: -\n | ((target: any, source: any) => any);\n\ntype DeepMerge<T, U> = T extends Obj\n ? U extends Obj\n ? {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<T[K], U[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : U\n : U;\n\ntype Merge<T extends Obj[]> = T extends [infer First, ...infer Rest]\n ? First extends Obj\n ? Rest extends Obj[]\n ? DeepMerge<First, Merge<Rest>>\n : First\n : Obj\n : Obj;\n\n/**\n * Merges multiple objects based on a specified merge strategy.\n *\n * @example\n * ```ts\n * const obj1 = { a: 1, b: { x: 10, y: \"hello\" }, c: [1] };\n * const obj2 = { b: { y: 20, z: true }, c: [2] };\n * const obj3 = { d: false, c: [3] };\n *\n * merge(\"deep\", obj1, obj2, obj3); // { a: 1, b: { x: 10, y: 20, z: true }, c: [1, 2, 3], d: false }\n * merge(\"shallow\", obj1, obj2, obj3); // { a: 1, b: { y: 20, z: true }, c: [3], d: false }\n * ```\n *\n * @param [strategy='deep'] - The merging strategy to use.\n * @param items - The objects to merge.\n * @returns A new merged object.\n */\nexport function merge<T extends Obj[]>(strategy: MergeStrategy = 'deep', ...items: [...T]): Merge<T> {\n if (items.length === 0) return {} as Merge<T>;\n\n if (strategy === 'shallow') {\n return Object.assign({}, ...items) as Merge<T>;\n }\n\n
|
|
1
|
+
{"version":3,"file":"merge.js","sources":["../../src/object/merge.ts"],"sourcesContent":["import { isArray } from '../typed/isArray';\nimport { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype MergeStrategy =\n | 'deep'\n | 'shallow'\n | 'lastWins'\n | 'arrayConcat'\n | 'arrayReplace'\n // biome-ignore lint/suspicious/noExplicitAny: -\n | ((target: any, source: any) => any);\n\ntype DeepMerge<T, U> = T extends Obj\n ? U extends Obj\n ? {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<T[K], U[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : U\n : U;\n\ntype Merge<T extends Obj[]> = T extends [infer First, ...infer Rest]\n ? First extends Obj\n ? Rest extends Obj[]\n ? DeepMerge<First, Merge<Rest>>\n : First\n : Obj\n : Obj;\n\n/**\n * Merges multiple objects based on a specified merge strategy.\n *\n * @example\n * ```ts\n * const obj1 = { a: 1, b: { x: 10, y: \"hello\" }, c: [1] };\n * const obj2 = { b: { y: 20, z: true }, c: [2] };\n * const obj3 = { d: false, c: [3] };\n *\n * merge(\"deep\", obj1, obj2, obj3); // { a: 1, b: { x: 10, y: 20, z: true }, c: [1, 2, 3], d: false }\n * merge(\"shallow\", obj1, obj2, obj3); // { a: 1, b: { y: 20, z: true }, c: [3], d: false }\n * ```\n *\n * @param [strategy='deep'] - The merging strategy to use.\n * @param items - The objects to merge.\n * @returns A new merged object.\n */\nexport function merge<T extends Obj[]>(strategy: MergeStrategy = 'deep', ...items: [...T]): Merge<T> {\n if (items.length === 0) return {} as Merge<T>;\n\n if (strategy === 'shallow') {\n return Object.assign({}, ...items) as Merge<T>;\n }\n\n return items.reduce((acc, obj) => deepMerge(acc, obj, strategy) as unknown as Merge<T>, {} as Merge<T>);\n}\n\n/**\n * Deeply merges two objects based on the provided strategy.\n *\n * - Uses **direct property access** for performance.\n * - **Avoids redundant deep merging** where unnecessary.\n * - Optimized **array merging strategies**.\n *\n * @param target - The target object.\n * @param source - The source object.\n * @param strategy - The merge strategy.\n * @returns A new merged object.\n */\nfunction deepMerge<T extends Obj, U extends Obj>(target: T, source: U, strategy: MergeStrategy): DeepMerge<T, U> {\n if (!isObject(source)) return source as DeepMerge<T, U>;\n\n const result = { ...target } as DeepMerge<T, U>;\n\n for (const key in source) {\n if (!Object.hasOwn(source, key)) continue; // Prevent prototype pollution\n\n const sourceValue = source[key];\n const targetValue = result[key];\n\n // biome-ignore lint/suspicious/noExplicitAny: -\n (result as any)[key] =\n isArray(sourceValue) && isArray(targetValue)\n ? handleArrayMerge(targetValue, sourceValue, strategy)\n : isObject(sourceValue) && isObject(targetValue)\n ? deepMerge(targetValue, sourceValue, strategy)\n : applyMergeStrategy(targetValue, sourceValue, strategy);\n }\n\n return result;\n}\n\n/**\n * Optimized array merge based on strategy.\n *\n * - `\"arrayConcat\"` → Concatenates arrays.\n * - `\"arrayReplace\"` → Replaces the existing array.\n * - Default: **Unique merge** (Set-based optimization).\n */\nfunction handleArrayMerge<T, U>(targetArray: T[] | undefined, sourceArray: U[], strategy: MergeStrategy): (T | U)[] {\n if (!targetArray) return sourceArray;\n // biome-ignore lint/suspicious/noExplicitAny: -\n if (strategy === 'arrayConcat') return targetArray.concat(sourceArray as any);\n if (strategy === 'arrayReplace') return sourceArray;\n return Array.from(new Set([...targetArray, ...sourceArray])); // Unique merge\n}\n\n/**\n * Determines the appropriate value to assign based on the merge strategy.\n *\n * - `\"lastWins\"` → Overwrites with the latest value.\n * - Custom functions → Allows user-defined behavior.\n */\nfunction applyMergeStrategy<T, U>(target: T, source: U, strategy: MergeStrategy): T | U {\n if (typeof strategy === 'function') return strategy(target, source);\n return strategy === 'lastWins' || source !== undefined ? source : target;\n}\n"],"names":["merge","strategy","items","acc","obj","deepMerge","target","source","isObject","result","key","sourceValue","targetValue","isArray","handleArrayMerge","applyMergeStrategy","targetArray","sourceArray"],"mappings":";;AAoDO,SAASA,EAAuBC,IAA0B,WAAWC,GAAyB;AACnG,SAAIA,EAAM,WAAW,IAAU,CAAA,IAE3BD,MAAa,YACR,OAAO,OAAO,CAAA,GAAI,GAAGC,CAAK,IAG5BA,EAAM,OAAO,CAACC,GAAKC,MAAQC,EAAUF,GAAKC,GAAKH,CAAQ,GAA0B,EAAc;AACxG;AAcA,SAASI,EAAwCC,GAAWC,GAAWN,GAA0C;AAC/G,MAAI,CAACO,EAASD,CAAM,EAAG,QAAOA;AAE9B,QAAME,IAAS,EAAE,GAAGH,EAAA;AAEpB,aAAWI,KAAOH,GAAQ;AACxB,QAAI,CAAC,OAAO,OAAOA,GAAQG,CAAG,EAAG;AAEjC,UAAMC,IAAcJ,EAAOG,CAAG,GACxBE,IAAcH,EAAOC,CAAG;AAG7B,IAAAD,EAAeC,CAAG,IACjBG,EAAQF,CAAW,KAAKE,EAAQD,CAAW,IACvCE,EAAiBF,GAAaD,GAAaV,CAAQ,IACnDO,EAASG,CAAW,KAAKH,EAASI,CAAW,IAC3CP,EAAUO,GAAaD,GAAaV,CAAQ,IAC5Cc,EAAmBH,GAAaD,GAAaV,CAAQ;AAAA,EAC/D;AAEA,SAAOQ;AACT;AASA,SAASK,EAAuBE,GAA8BC,GAAkBhB,GAAoC;AAClH,SAAKe,IAEDf,MAAa,gBAAsBe,EAAY,OAAOC,CAAkB,IACxEhB,MAAa,iBAAuBgB,IACjC,MAAM,KAAK,oBAAI,IAAI,CAAC,GAAGD,GAAa,GAAGC,CAAW,CAAC,CAAC,IAJlCA;AAK3B;AAQA,SAASF,EAAyBT,GAAWC,GAAWN,GAAgC;AACtF,SAAI,OAAOA,KAAa,aAAmBA,EAASK,GAAQC,CAAM,IAC3DN,MAAa,cAAcM,MAAW,SAAYA,IAASD;AACpE;"}
|
package/dist/object/seek.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../function/assert.cjs"),l=require("../string/similarity.cjs"),s=require("../typed/is.cjs"),a=require("../typed/isWithin.cjs");function t(r,n,i=1){return u.assert(a.isWithin(i,0,1),a.IS_WITHIN_ERROR_MSG,{args:{max:1,min:0,tone:i},type:TypeError}),s.is("nil",r)?!1:s.is("string",r)||s.is("number",r)?l.similarity(r,n)>=i:s.is("array",r)?r.some(e=>t(e,n,i)):s.is("object",r)?Object.values(r).some(e=>s.is("nil",e)?!1:t(e,n,i)):!1}exports.seek=t;
|
|
2
2
|
//# sourceMappingURL=seek.cjs.map
|
package/dist/object/seek.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seek.cjs","sources":["../../src/object/seek.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { similarity } from '../string/similarity';\nimport { is } from '../typed/is';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Recursively checks if an object contains a value similar to the search string.\n *\n * @example\n * ```ts\n * const obj = { a: 'hello', b: { c: 'world' }, d: [1, 2, 3] };\n *\n * seek(obj, 'hello'); // true\n * seek(obj, 'world'); // true\n * seek(obj, 'foo'); // false\n * seek(obj, 'hello', 0.5); // true\n * seek(obj, 'hello', 0.8); // true\n * seek(obj, 'hello', 1); // true\n * seek(obj, 'hello', 1.5); // false\n * seek(obj, 'hello', -1); // false\n * seek(obj, 'hello', 0); // false\n * ```\n *\n * @param item - The object to search within.\n * @param query - The search string.\n * @param [tone=1] - The similarity threshold.\n *\n * @returns Whether the object contains a matching value.\n */\nexport function seek<T>(item: T, query: string, tone = 1): boolean {\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (is('string', item) || is('number', item)) {\n // Lowercase both sides for case-insensitive comparison\n return similarity(item, query) >= tone;\n }\n\n
|
|
1
|
+
{"version":3,"file":"seek.cjs","sources":["../../src/object/seek.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { similarity } from '../string/similarity';\nimport { is } from '../typed/is';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Recursively checks if an object contains a value similar to the search string.\n *\n * @example\n * ```ts\n * const obj = { a: 'hello', b: { c: 'world' }, d: [1, 2, 3] };\n *\n * seek(obj, 'hello'); // true\n * seek(obj, 'world'); // true\n * seek(obj, 'foo'); // false\n * seek(obj, 'hello', 0.5); // true\n * seek(obj, 'hello', 0.8); // true\n * seek(obj, 'hello', 1); // true\n * seek(obj, 'hello', 1.5); // false\n * seek(obj, 'hello', -1); // false\n * seek(obj, 'hello', 0); // false\n * ```\n *\n * @param item - The object to search within.\n * @param query - The search string.\n * @param [tone=1] - The similarity threshold.\n *\n * @returns Whether the object contains a matching value.\n */\nexport function seek<T>(item: T, query: string, tone = 1): boolean {\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (is('nil', item)) return false;\n\n if (is('string', item) || is('number', item)) {\n // Lowercase both sides for case-insensitive comparison\n return similarity(item, query) >= tone;\n }\n\n // Handle arrays\n if (is('array', item)) {\n return (item as unknown[]).some((value) => seek(value, query, tone));\n }\n\n // Handle objects but skip dates/regex/etc which are technically objects\n if (is('object', item)) {\n return Object.values(item as Record<string, unknown>).some((value) =>\n is('nil', value) ? false : seek(value, query, tone),\n );\n }\n\n return false;\n}\n"],"names":["seek","item","query","tone","assert","isWithin","IS_WITHIN_ERROR_MSG","is","similarity","value"],"mappings":"gOA6BO,SAASA,EAAQC,EAASC,EAAeC,EAAO,EAAY,CAGjE,OAFAC,EAAAA,OAAOC,EAAAA,SAASF,EAAM,EAAG,CAAC,EAAGG,EAAAA,oBAAqB,CAAE,KAAM,CAAE,IAAK,EAAG,IAAK,EAAG,KAAAH,GAAQ,KAAM,UAAW,EAEjGI,KAAG,MAAON,CAAI,EAAU,GAExBM,EAAAA,GAAG,SAAUN,CAAI,GAAKM,EAAAA,GAAG,SAAUN,CAAI,EAElCO,aAAWP,EAAMC,CAAK,GAAKC,EAIhCI,EAAAA,GAAG,QAASN,CAAI,EACVA,EAAmB,KAAMQ,GAAUT,EAAKS,EAAOP,EAAOC,CAAI,CAAC,EAIjEI,EAAAA,GAAG,SAAUN,CAAI,EACZ,OAAO,OAAOA,CAA+B,EAAE,KAAMQ,GAC1DF,KAAG,MAAOE,CAAK,EAAI,GAAQT,EAAKS,EAAOP,EAAOC,CAAI,CAAA,EAI/C,EACT"}
|
package/dist/object/seek.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
import { similarity as
|
|
1
|
+
import { assert as n } from "../function/assert.js";
|
|
2
|
+
import { similarity as m } from "../string/similarity.js";
|
|
3
3
|
import { is as s } from "../typed/is.js";
|
|
4
|
-
import { IS_WITHIN_ERROR_MSG as
|
|
5
|
-
function
|
|
6
|
-
return
|
|
4
|
+
import { IS_WITHIN_ERROR_MSG as p, isWithin as t } from "../typed/isWithin.js";
|
|
5
|
+
function a(r, o, i = 1) {
|
|
6
|
+
return n(t(i, 0, 1), p, { args: { max: 1, min: 0, tone: i }, type: TypeError }), s("nil", r) ? !1 : s("string", r) || s("number", r) ? m(r, o) >= i : s("array", r) ? r.some((f) => a(f, o, i)) : s("object", r) ? Object.values(r).some(
|
|
7
|
+
(f) => s("nil", f) ? !1 : a(f, o, i)
|
|
8
|
+
) : !1;
|
|
7
9
|
}
|
|
8
10
|
export {
|
|
9
|
-
|
|
11
|
+
a as seek
|
|
10
12
|
};
|
|
11
13
|
//# sourceMappingURL=seek.js.map
|
package/dist/object/seek.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seek.js","sources":["../../src/object/seek.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { similarity } from '../string/similarity';\nimport { is } from '../typed/is';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Recursively checks if an object contains a value similar to the search string.\n *\n * @example\n * ```ts\n * const obj = { a: 'hello', b: { c: 'world' }, d: [1, 2, 3] };\n *\n * seek(obj, 'hello'); // true\n * seek(obj, 'world'); // true\n * seek(obj, 'foo'); // false\n * seek(obj, 'hello', 0.5); // true\n * seek(obj, 'hello', 0.8); // true\n * seek(obj, 'hello', 1); // true\n * seek(obj, 'hello', 1.5); // false\n * seek(obj, 'hello', -1); // false\n * seek(obj, 'hello', 0); // false\n * ```\n *\n * @param item - The object to search within.\n * @param query - The search string.\n * @param [tone=1] - The similarity threshold.\n *\n * @returns Whether the object contains a matching value.\n */\nexport function seek<T>(item: T, query: string, tone = 1): boolean {\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (is('string', item) || is('number', item)) {\n // Lowercase both sides for case-insensitive comparison\n return similarity(item, query) >= tone;\n }\n\n
|
|
1
|
+
{"version":3,"file":"seek.js","sources":["../../src/object/seek.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { similarity } from '../string/similarity';\nimport { is } from '../typed/is';\nimport { IS_WITHIN_ERROR_MSG, isWithin } from '../typed/isWithin';\n\n/**\n * Recursively checks if an object contains a value similar to the search string.\n *\n * @example\n * ```ts\n * const obj = { a: 'hello', b: { c: 'world' }, d: [1, 2, 3] };\n *\n * seek(obj, 'hello'); // true\n * seek(obj, 'world'); // true\n * seek(obj, 'foo'); // false\n * seek(obj, 'hello', 0.5); // true\n * seek(obj, 'hello', 0.8); // true\n * seek(obj, 'hello', 1); // true\n * seek(obj, 'hello', 1.5); // false\n * seek(obj, 'hello', -1); // false\n * seek(obj, 'hello', 0); // false\n * ```\n *\n * @param item - The object to search within.\n * @param query - The search string.\n * @param [tone=1] - The similarity threshold.\n *\n * @returns Whether the object contains a matching value.\n */\nexport function seek<T>(item: T, query: string, tone = 1): boolean {\n assert(isWithin(tone, 0, 1), IS_WITHIN_ERROR_MSG, { args: { max: 1, min: 0, tone }, type: TypeError });\n\n if (is('nil', item)) return false;\n\n if (is('string', item) || is('number', item)) {\n // Lowercase both sides for case-insensitive comparison\n return similarity(item, query) >= tone;\n }\n\n // Handle arrays\n if (is('array', item)) {\n return (item as unknown[]).some((value) => seek(value, query, tone));\n }\n\n // Handle objects but skip dates/regex/etc which are technically objects\n if (is('object', item)) {\n return Object.values(item as Record<string, unknown>).some((value) =>\n is('nil', value) ? false : seek(value, query, tone),\n );\n }\n\n return false;\n}\n"],"names":["seek","item","query","tone","assert","isWithin","IS_WITHIN_ERROR_MSG","is","similarity","value"],"mappings":";;;;AA6BO,SAASA,EAAQC,GAASC,GAAeC,IAAO,GAAY;AAGjE,SAFAC,EAAOC,EAASF,GAAM,GAAG,CAAC,GAAGG,GAAqB,EAAE,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,MAAAH,KAAQ,MAAM,WAAW,GAEjGI,EAAG,OAAON,CAAI,IAAU,KAExBM,EAAG,UAAUN,CAAI,KAAKM,EAAG,UAAUN,CAAI,IAElCO,EAAWP,GAAMC,CAAK,KAAKC,IAIhCI,EAAG,SAASN,CAAI,IACVA,EAAmB,KAAK,CAACQ,MAAUT,EAAKS,GAAOP,GAAOC,CAAI,CAAC,IAIjEI,EAAG,UAAUN,CAAI,IACZ,OAAO,OAAOA,CAA+B,EAAE;AAAA,IAAK,CAACQ,MAC1DF,EAAG,OAAOE,CAAK,IAAI,KAAQT,EAAKS,GAAOP,GAAOC,CAAI;AAAA,EAAA,IAI/C;AACT;"}
|
package/dist/random/uuid.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(){return typeof crypto<"u"&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/x/g,r=>{const x=Math.random()*16|0;return(r==="x"?x:x&3|8).toString(16)})}exports.uuid=t;
|
|
2
2
|
//# sourceMappingURL=uuid.cjs.map
|
package/dist/random/uuid.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.cjs","sources":["../../src/random/uuid.ts"],"sourcesContent":["/**\n * Generates a unique identifier.\n *\n * @example\n * ```ts\n * uuid(); // a unique identifier, e.g., '22a746d0-08be-4aff-bbc2-4deddf0914e0'\n * ```\n *\n * @returns A unique identifier.\n */\nexport function uuid(): string {\n
|
|
1
|
+
{"version":3,"file":"uuid.cjs","sources":["../../src/random/uuid.ts"],"sourcesContent":["/**\n * Generates a unique identifier.\n *\n * @example\n * ```ts\n * uuid(); // a unique identifier, e.g., '22a746d0-08be-4aff-bbc2-4deddf0914e0'\n * ```\n *\n * @returns A unique identifier.\n */\nexport function uuid(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n\n return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/x/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n"],"names":["uuid","c","r"],"mappings":"gFAUO,SAASA,GAAe,CAC7B,OAAI,OAAO,OAAW,KAAe,OAAO,WACnC,OAAO,WAAA,EAGT,uCAAuC,QAAQ,KAAOC,GAAM,CACjE,MAAMC,EAAK,KAAK,OAAA,EAAW,GAAM,EAEjC,OADUD,IAAM,IAAMC,EAAKA,EAAI,EAAO,GAC7B,SAAS,EAAE,CACtB,CAAC,CACH"}
|
package/dist/random/uuid.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
function
|
|
2
|
-
return crypto
|
|
1
|
+
function n() {
|
|
2
|
+
return typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/x/g, (r) => {
|
|
3
|
+
const x = Math.random() * 16 | 0;
|
|
4
|
+
return (r === "x" ? x : x & 3 | 8).toString(16);
|
|
5
|
+
});
|
|
3
6
|
}
|
|
4
7
|
export {
|
|
5
|
-
|
|
8
|
+
n as uuid
|
|
6
9
|
};
|
|
7
10
|
//# sourceMappingURL=uuid.js.map
|
package/dist/random/uuid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.js","sources":["../../src/random/uuid.ts"],"sourcesContent":["/**\n * Generates a unique identifier.\n *\n * @example\n * ```ts\n * uuid(); // a unique identifier, e.g., '22a746d0-08be-4aff-bbc2-4deddf0914e0'\n * ```\n *\n * @returns A unique identifier.\n */\nexport function uuid(): string {\n
|
|
1
|
+
{"version":3,"file":"uuid.js","sources":["../../src/random/uuid.ts"],"sourcesContent":["/**\n * Generates a unique identifier.\n *\n * @example\n * ```ts\n * uuid(); // a unique identifier, e.g., '22a746d0-08be-4aff-bbc2-4deddf0914e0'\n * ```\n *\n * @returns A unique identifier.\n */\nexport function uuid(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n\n return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/x/g, (c) => {\n const r = (Math.random() * 16) | 0;\n const v = c === 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n}\n"],"names":["uuid","c","r"],"mappings":"AAUO,SAASA,IAAe;AAC7B,SAAI,OAAO,SAAW,OAAe,OAAO,aACnC,OAAO,WAAA,IAGT,uCAAuC,QAAQ,MAAM,CAACC,MAAM;AACjE,UAAMC,IAAK,KAAK,OAAA,IAAW,KAAM;AAEjC,YADUD,MAAM,MAAMC,IAAKA,IAAI,IAAO,GAC7B,SAAS,EAAE;AAAA,EACtB,CAAC;AACH;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./_caseUtils.cjs");function o(a){return t.normalizeCase(a," ").replace(/[^a-zA-Z0-9]+(.)/g,(e,r)=>r.toUpperCase()).replace(/^./,e=>e.toLowerCase())}exports.camelCase=o;
|
|
2
2
|
//# sourceMappingURL=camelCase.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camelCase.cjs","sources":["../../src/string/camelCase.ts"],"sourcesContent":["import { normalizeCase } from './_caseUtils';\n\n/**\n * Converts a string to camel case.\n *\n * @example\n * ```ts\n * const text = 'hello world';\n * camelCase(text); // 'helloWorld'\n * ```\n *\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport function camelCase(str: string): string {\n return normalizeCase(str, ' ')\n .replace(/(
|
|
1
|
+
{"version":3,"file":"camelCase.cjs","sources":["../../src/string/camelCase.ts"],"sourcesContent":["import { normalizeCase } from './_caseUtils';\n\n/**\n * Converts a string to camel case.\n *\n * @example\n * ```ts\n * const text = 'hello world';\n * camelCase(text); // 'helloWorld'\n * ```\n *\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport function camelCase(str: string): string {\n return normalizeCase(str, ' ')\n .replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()) // Basic split by non-alphanumeric\n .replace(/^./, (char) => char.toLowerCase());\n}\n"],"names":["camelCase","str","normalizeCase","_","char"],"mappings":"oHAcO,SAASA,EAAUC,EAAqB,CAC7C,OAAOC,EAAAA,cAAcD,EAAK,GAAG,EAC1B,QAAQ,oBAAqB,CAACE,EAAGC,IAASA,EAAK,YAAA,CAAa,EAC5D,QAAQ,KAAOA,GAASA,EAAK,aAAa,CAC/C"}
|
package/dist/string/camelCase.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { normalizeCase as o } from "./_caseUtils.js";
|
|
2
|
-
function
|
|
3
|
-
return o(r, " ").replace(/(
|
|
2
|
+
function t(r) {
|
|
3
|
+
return o(r, " ").replace(/[^a-zA-Z0-9]+(.)/g, (e, a) => a.toUpperCase()).replace(/^./, (e) => e.toLowerCase());
|
|
4
4
|
}
|
|
5
5
|
export {
|
|
6
|
-
|
|
6
|
+
t as camelCase
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=camelCase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camelCase.js","sources":["../../src/string/camelCase.ts"],"sourcesContent":["import { normalizeCase } from './_caseUtils';\n\n/**\n * Converts a string to camel case.\n *\n * @example\n * ```ts\n * const text = 'hello world';\n * camelCase(text); // 'helloWorld'\n * ```\n *\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport function camelCase(str: string): string {\n return normalizeCase(str, ' ')\n .replace(/(
|
|
1
|
+
{"version":3,"file":"camelCase.js","sources":["../../src/string/camelCase.ts"],"sourcesContent":["import { normalizeCase } from './_caseUtils';\n\n/**\n * Converts a string to camel case.\n *\n * @example\n * ```ts\n * const text = 'hello world';\n * camelCase(text); // 'helloWorld'\n * ```\n *\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport function camelCase(str: string): string {\n return normalizeCase(str, ' ')\n .replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()) // Basic split by non-alphanumeric\n .replace(/^./, (char) => char.toLowerCase());\n}\n"],"names":["camelCase","str","normalizeCase","_","char"],"mappings":";AAcO,SAASA,EAAUC,GAAqB;AAC7C,SAAOC,EAAcD,GAAK,GAAG,EAC1B,QAAQ,qBAAqB,CAACE,GAAGC,MAASA,EAAK,YAAA,CAAa,EAC5D,QAAQ,MAAM,CAACA,MAASA,EAAK,aAAa;AAC/C;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../function/assert.cjs");function y(l,g){f.assert(["string","number"].includes(typeof l)&&["string","number"].includes(typeof g),"Invalid arguments",{args:{str1:l,str2:g},type:TypeError});const n=String(l).toLowerCase(),t=String(g).toLowerCase();if(n===t)return 1;if(n.length===0)return t.length===0?1:0;if(t.length===0)return 0;const[a,c]=n.length<t.length?[n,t]:[t,n],s=a.length,h=c.length;let r=Array.from({length:s+1},(i,e)=>e),o=new Array(s+1);for(let i=1;i<=h;i++){o[0]=i;for(let e=1;e<=s;e++){const u=c[i-1]===a[e-1]?0:1;o[e]=Math.min(o[e-1]+1,r[e]+1,r[e-1]+u)}[r,o]=[o,r]}return 1-r[s]/Math.max(n.length,t.length)}exports.similarity=y;
|
|
2
2
|
//# sourceMappingURL=similarity.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"similarity.cjs","sources":["../../src/string/similarity.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Calculate the similarity between two strings using the Levenshtein distance algorithm.\n *\n * @example\n * ```ts\n * similarity('abc', 'abc') // 1\n * similarity('a', 'b') // 0\n * similarity('ab', 'ac') // 0.5\n * similarity('doe', 'John Doe') // 0.25\n * similarity('abc', 'axc') // 0.6666666666666667\n * similarity('kitten', 'sitting') // 0.5714285714285714\n * ```\n *\n * @param str1 - The first string.\n * @param str2 - The second string.\n *\n * @returns A number between 0 and 1 representing the similarity between the two strings.\n */\nexport function similarity(str1: unknown, str2: unknown): number {\n assert(\n ['string', 'number'].includes(typeof str1) && ['string', 'number'].includes(typeof str2),\n 'Invalid arguments',\n {\n args: { str1, str2 },\n type: TypeError,\n },\n );\n\n const a = String(str1).toLowerCase();\n const b = String(str2).toLowerCase();\n\n if (a === b) return 1;\n if (
|
|
1
|
+
{"version":3,"file":"similarity.cjs","sources":["../../src/string/similarity.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Calculate the similarity between two strings using the Levenshtein distance algorithm.\n *\n * @example\n * ```ts\n * similarity('abc', 'abc') // 1\n * similarity('a', 'b') // 0\n * similarity('ab', 'ac') // 0.5\n * similarity('doe', 'John Doe') // 0.25\n * similarity('abc', 'axc') // 0.6666666666666667\n * similarity('kitten', 'sitting') // 0.5714285714285714\n * ```\n *\n * @param str1 - The first string.\n * @param str2 - The second string.\n *\n * @returns A number between 0 and 1 representing the similarity between the two strings.\n */\nexport function similarity(str1: unknown, str2: unknown): number {\n assert(\n ['string', 'number'].includes(typeof str1) && ['string', 'number'].includes(typeof str2),\n 'Invalid arguments',\n {\n args: { str1, str2 },\n type: TypeError,\n },\n );\n\n const a = String(str1).toLowerCase();\n const b = String(str2).toLowerCase();\n\n if (a === b) return 1;\n if (a.length === 0) return b.length === 0 ? 1 : 0;\n if (b.length === 0) return 0;\n\n // Swap to ensure we use the smaller string for columns (O(min(A,B)) space)\n const [shorter, longer] = a.length < b.length ? [a, b] : [b, a];\n const shorterLength = shorter.length;\n const longerLength = longer.length;\n\n let prevRow = Array.from({ length: shorterLength + 1 }, (_, i) => i);\n let currRow = new Array(shorterLength + 1);\n\n for (let i = 1; i <= longerLength; i++) {\n currRow[0] = i;\n for (let j = 1; j <= shorterLength; j++) {\n const cost = longer[i - 1] === shorter[j - 1] ? 0 : 1;\n currRow[j] = Math.min(\n currRow[j - 1] + 1, // insertion\n prevRow[j] + 1, // deletion\n prevRow[j - 1] + cost, // substitution\n );\n }\n // Swap rows for the next iteration (avoid allocation)\n [prevRow, currRow] = [currRow, prevRow];\n }\n\n // After the loop, a result is in prevRow because of the swap\n const distance = prevRow[shorterLength];\n\n return 1 - distance / Math.max(a.length, b.length);\n}\n"],"names":["similarity","str1","str2","assert","a","b","shorter","longer","shorterLength","longerLength","prevRow","_","i","currRow","j","cost"],"mappings":"0HAoBO,SAASA,EAAWC,EAAeC,EAAuB,CAC/DC,EAAAA,OACE,CAAC,SAAU,QAAQ,EAAE,SAAS,OAAOF,CAAI,GAAK,CAAC,SAAU,QAAQ,EAAE,SAAS,OAAOC,CAAI,EACvF,oBACA,CACE,KAAM,CAAE,KAAAD,EAAM,KAAAC,CAAA,EACd,KAAM,SAAA,CACR,EAGF,MAAME,EAAI,OAAOH,CAAI,EAAE,YAAA,EACjBI,EAAI,OAAOH,CAAI,EAAE,YAAA,EAEvB,GAAIE,IAAMC,EAAG,MAAO,GACpB,GAAID,EAAE,SAAW,SAAUC,EAAE,SAAW,EAAI,EAAI,EAChD,GAAIA,EAAE,SAAW,EAAG,MAAO,GAG3B,KAAM,CAACC,EAASC,CAAM,EAAIH,EAAE,OAASC,EAAE,OAAS,CAACD,EAAGC,CAAC,EAAI,CAACA,EAAGD,CAAC,EACxDI,EAAgBF,EAAQ,OACxBG,EAAeF,EAAO,OAE5B,IAAIG,EAAU,MAAM,KAAK,CAAE,OAAQF,EAAgB,GAAK,CAACG,EAAGC,IAAMA,CAAC,EAC/DC,EAAU,IAAI,MAAML,EAAgB,CAAC,EAEzC,QAAS,EAAI,EAAG,GAAKC,EAAc,IAAK,CACtCI,EAAQ,CAAC,EAAI,EACb,QAASC,EAAI,EAAGA,GAAKN,EAAeM,IAAK,CACvC,MAAMC,EAAOR,EAAO,EAAI,CAAC,IAAMD,EAAQQ,EAAI,CAAC,EAAI,EAAI,EACpDD,EAAQC,CAAC,EAAI,KAAK,IAChBD,EAAQC,EAAI,CAAC,EAAI,EACjBJ,EAAQI,CAAC,EAAI,EACbJ,EAAQI,EAAI,CAAC,EAAIC,CAAA,CAErB,CAEA,CAACL,EAASG,CAAO,EAAI,CAACA,EAASH,CAAO,CACxC,CAKA,MAAO,GAFUA,EAAQF,CAAa,EAEhB,KAAK,IAAIJ,EAAE,OAAQC,EAAE,MAAM,CACnD"}
|
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
import { assert as
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
["string", "number"].includes(typeof
|
|
1
|
+
import { assert as f } from "../function/assert.js";
|
|
2
|
+
function y(i, s) {
|
|
3
|
+
f(
|
|
4
|
+
["string", "number"].includes(typeof i) && ["string", "number"].includes(typeof s),
|
|
5
5
|
"Invalid arguments",
|
|
6
6
|
{
|
|
7
|
-
args: { str1:
|
|
7
|
+
args: { str1: i, str2: s },
|
|
8
8
|
type: TypeError
|
|
9
9
|
}
|
|
10
10
|
);
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
for (let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
e[t][n - 1] + 1,
|
|
11
|
+
const n = String(i).toLowerCase(), e = String(s).toLowerCase();
|
|
12
|
+
if (n === e) return 1;
|
|
13
|
+
if (n.length === 0) return e.length === 0 ? 1 : 0;
|
|
14
|
+
if (e.length === 0) return 0;
|
|
15
|
+
const [h, a] = n.length < e.length ? [n, e] : [e, n], l = h.length, c = a.length;
|
|
16
|
+
let r = Array.from({ length: l + 1 }, (g, t) => t), o = new Array(l + 1);
|
|
17
|
+
for (let g = 1; g <= c; g++) {
|
|
18
|
+
o[0] = g;
|
|
19
|
+
for (let t = 1; t <= l; t++) {
|
|
20
|
+
const u = a[g - 1] === h[t - 1] ? 0 : 1;
|
|
21
|
+
o[t] = Math.min(
|
|
22
|
+
o[t - 1] + 1,
|
|
24
23
|
// insertion
|
|
25
|
-
|
|
24
|
+
r[t] + 1,
|
|
25
|
+
// deletion
|
|
26
|
+
r[t - 1] + u
|
|
26
27
|
// substitution
|
|
27
28
|
);
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
+
[r, o] = [o, r];
|
|
31
|
+
}
|
|
32
|
+
return 1 - r[l] / Math.max(n.length, e.length);
|
|
30
33
|
}
|
|
31
34
|
export {
|
|
32
|
-
|
|
35
|
+
y as similarity
|
|
33
36
|
};
|
|
34
37
|
//# sourceMappingURL=similarity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"similarity.js","sources":["../../src/string/similarity.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Calculate the similarity between two strings using the Levenshtein distance algorithm.\n *\n * @example\n * ```ts\n * similarity('abc', 'abc') // 1\n * similarity('a', 'b') // 0\n * similarity('ab', 'ac') // 0.5\n * similarity('doe', 'John Doe') // 0.25\n * similarity('abc', 'axc') // 0.6666666666666667\n * similarity('kitten', 'sitting') // 0.5714285714285714\n * ```\n *\n * @param str1 - The first string.\n * @param str2 - The second string.\n *\n * @returns A number between 0 and 1 representing the similarity between the two strings.\n */\nexport function similarity(str1: unknown, str2: unknown): number {\n assert(\n ['string', 'number'].includes(typeof str1) && ['string', 'number'].includes(typeof str2),\n 'Invalid arguments',\n {\n args: { str1, str2 },\n type: TypeError,\n },\n );\n\n const a = String(str1).toLowerCase();\n const b = String(str2).toLowerCase();\n\n if (a === b) return 1;\n if (
|
|
1
|
+
{"version":3,"file":"similarity.js","sources":["../../src/string/similarity.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Calculate the similarity between two strings using the Levenshtein distance algorithm.\n *\n * @example\n * ```ts\n * similarity('abc', 'abc') // 1\n * similarity('a', 'b') // 0\n * similarity('ab', 'ac') // 0.5\n * similarity('doe', 'John Doe') // 0.25\n * similarity('abc', 'axc') // 0.6666666666666667\n * similarity('kitten', 'sitting') // 0.5714285714285714\n * ```\n *\n * @param str1 - The first string.\n * @param str2 - The second string.\n *\n * @returns A number between 0 and 1 representing the similarity between the two strings.\n */\nexport function similarity(str1: unknown, str2: unknown): number {\n assert(\n ['string', 'number'].includes(typeof str1) && ['string', 'number'].includes(typeof str2),\n 'Invalid arguments',\n {\n args: { str1, str2 },\n type: TypeError,\n },\n );\n\n const a = String(str1).toLowerCase();\n const b = String(str2).toLowerCase();\n\n if (a === b) return 1;\n if (a.length === 0) return b.length === 0 ? 1 : 0;\n if (b.length === 0) return 0;\n\n // Swap to ensure we use the smaller string for columns (O(min(A,B)) space)\n const [shorter, longer] = a.length < b.length ? [a, b] : [b, a];\n const shorterLength = shorter.length;\n const longerLength = longer.length;\n\n let prevRow = Array.from({ length: shorterLength + 1 }, (_, i) => i);\n let currRow = new Array(shorterLength + 1);\n\n for (let i = 1; i <= longerLength; i++) {\n currRow[0] = i;\n for (let j = 1; j <= shorterLength; j++) {\n const cost = longer[i - 1] === shorter[j - 1] ? 0 : 1;\n currRow[j] = Math.min(\n currRow[j - 1] + 1, // insertion\n prevRow[j] + 1, // deletion\n prevRow[j - 1] + cost, // substitution\n );\n }\n // Swap rows for the next iteration (avoid allocation)\n [prevRow, currRow] = [currRow, prevRow];\n }\n\n // After the loop, a result is in prevRow because of the swap\n const distance = prevRow[shorterLength];\n\n return 1 - distance / Math.max(a.length, b.length);\n}\n"],"names":["similarity","str1","str2","assert","a","b","shorter","longer","shorterLength","longerLength","prevRow","_","i","currRow","j","cost"],"mappings":";AAoBO,SAASA,EAAWC,GAAeC,GAAuB;AAC/D,EAAAC;AAAA,IACE,CAAC,UAAU,QAAQ,EAAE,SAAS,OAAOF,CAAI,KAAK,CAAC,UAAU,QAAQ,EAAE,SAAS,OAAOC,CAAI;AAAA,IACvF;AAAA,IACA;AAAA,MACE,MAAM,EAAE,MAAAD,GAAM,MAAAC,EAAA;AAAA,MACd,MAAM;AAAA,IAAA;AAAA,EACR;AAGF,QAAME,IAAI,OAAOH,CAAI,EAAE,YAAA,GACjBI,IAAI,OAAOH,CAAI,EAAE,YAAA;AAEvB,MAAIE,MAAMC,EAAG,QAAO;AACpB,MAAID,EAAE,WAAW,UAAUC,EAAE,WAAW,IAAI,IAAI;AAChD,MAAIA,EAAE,WAAW,EAAG,QAAO;AAG3B,QAAM,CAACC,GAASC,CAAM,IAAIH,EAAE,SAASC,EAAE,SAAS,CAACD,GAAGC,CAAC,IAAI,CAACA,GAAGD,CAAC,GACxDI,IAAgBF,EAAQ,QACxBG,IAAeF,EAAO;AAE5B,MAAIG,IAAU,MAAM,KAAK,EAAE,QAAQF,IAAgB,KAAK,CAACG,GAAGC,MAAMA,CAAC,GAC/DC,IAAU,IAAI,MAAML,IAAgB,CAAC;AAEzC,WAASI,IAAI,GAAGA,KAAKH,GAAcG,KAAK;AACtC,IAAAC,EAAQ,CAAC,IAAID;AACb,aAASE,IAAI,GAAGA,KAAKN,GAAeM,KAAK;AACvC,YAAMC,IAAOR,EAAOK,IAAI,CAAC,MAAMN,EAAQQ,IAAI,CAAC,IAAI,IAAI;AACpD,MAAAD,EAAQC,CAAC,IAAI,KAAK;AAAA,QAChBD,EAAQC,IAAI,CAAC,IAAI;AAAA;AAAA,QACjBJ,EAAQI,CAAC,IAAI;AAAA;AAAA,QACbJ,EAAQI,IAAI,CAAC,IAAIC;AAAA;AAAA,MAAA;AAAA,IAErB;AAEA,KAACL,GAASG,CAAO,IAAI,CAACA,GAASH,CAAO;AAAA,EACxC;AAKA,SAAO,IAFUA,EAAQF,CAAa,IAEhB,KAAK,IAAIJ,EAAE,QAAQC,EAAE,MAAM;AACnD;"}
|
package/dist/string/truncate.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../function/assert.cjs");function o(t,e=25,s=!1,u="…"){if(n.assert(typeof t=="string","First argument must be a string",{args:{str:t},type:TypeError}),n.assert(typeof e=="number"&&e>=0&&Number.isFinite(e),"Limit must be a non-negative finite number",{args:{limit:e},type:TypeError}),t.length<=e)return t;const r=s?t.substring(0,e).lastIndexOf(" "):e,a=r>0?r:e;return`${t.substring(0,a).trim()}${u}`}exports.truncate=o;
|
|
2
2
|
//# sourceMappingURL=truncate.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"truncate.cjs","sources":["../../src/string/truncate.ts"],"sourcesContent":["/**\n * Truncates a string if it is longer than the given maximum string length. The last characters of the truncated string are replaced with the ellipsis sign \"…\".\n *\n * @example\n * ```ts\n * const text = 'Hello World';\n * truncate(text, 5); // 'Hello…'\n * truncate(text, 3, true); // 'Hello…'\n * truncate(text, 5, true, '...'); // 'Hello...'\n * ```\n *\n * @param str - The string to truncate.\n * @param limit - The maximum string length.\n * @param completeWords - If true, the string is truncated to the nearest word, instead of character.\n * @param ellipsis - The characters to end the truncated string with.\n *\n * @returns The truncated string.\n */\nexport function truncate(str: string, limit = 25, completeWords = false, ellipsis = '…'): string {\n if (str.length <= limit) return str;\n\n const _limit = completeWords ? str.substring(0, limit).lastIndexOf(' ') : limit;\n const effectiveLimit = _limit > 0 ? _limit : limit;\n\n return `${str.substring(0, effectiveLimit).trim()}${ellipsis}`;\n}\n"],"names":["truncate","str","limit","completeWords","ellipsis","_limit","effectiveLimit"],"mappings":"
|
|
1
|
+
{"version":3,"file":"truncate.cjs","sources":["../../src/string/truncate.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Truncates a string if it is longer than the given maximum string length. The last characters of the truncated string are replaced with the ellipsis sign \"…\".\n *\n * @example\n * ```ts\n * const text = 'Hello World';\n * truncate(text, 5); // 'Hello…'\n * truncate(text, 3, true); // 'Hello…'\n * truncate(text, 5, true, '...'); // 'Hello...'\n * ```\n *\n * @param str - The string to truncate.\n * @param limit - The maximum string length.\n * @param completeWords - If true, the string is truncated to the nearest word, instead of character.\n * @param ellipsis - The characters to end the truncated string with.\n *\n * @returns The truncated string.\n *\n * @throws {TypeError} If str is not a string or limit is not a positive number.\n */\nexport function truncate(str: string, limit = 25, completeWords = false, ellipsis = '…'): string {\n assert(typeof str === 'string', 'First argument must be a string', {\n args: { str },\n type: TypeError,\n });\n assert(\n typeof limit === 'number' && limit >= 0 && Number.isFinite(limit),\n 'Limit must be a non-negative finite number',\n { args: { limit }, type: TypeError },\n );\n\n if (str.length <= limit) {\n return str;\n }\n\n const _limit = completeWords ? str.substring(0, limit).lastIndexOf(' ') : limit;\n const effectiveLimit = _limit > 0 ? _limit : limit;\n\n return `${str.substring(0, effectiveLimit).trim()}${ellipsis}`;\n}\n"],"names":["truncate","str","limit","completeWords","ellipsis","assert","_limit","effectiveLimit"],"mappings":"0HAsBO,SAASA,EAASC,EAAaC,EAAQ,GAAIC,EAAgB,GAAOC,EAAW,IAAa,CAW/F,GAVAC,EAAAA,OAAO,OAAOJ,GAAQ,SAAU,kCAAmC,CACjE,KAAM,CAAE,IAAAA,CAAA,EACR,KAAM,SAAA,CACP,EACDI,EAAAA,OACE,OAAOH,GAAU,UAAYA,GAAS,GAAK,OAAO,SAASA,CAAK,EAChE,6CACA,CAAE,KAAM,CAAE,MAAAA,CAAA,EAAS,KAAM,SAAA,CAAU,EAGjCD,EAAI,QAAUC,EAChB,OAAOD,EAGT,MAAMK,EAASH,EAAgBF,EAAI,UAAU,EAAGC,CAAK,EAAE,YAAY,GAAG,EAAIA,EACpEK,EAAiBD,EAAS,EAAIA,EAASJ,EAE7C,MAAO,GAAGD,EAAI,UAAU,EAAGM,CAAc,EAAE,KAAA,CAAM,GAAGH,CAAQ,EAC9D"}
|
package/dist/string/truncate.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { assert as t } from "../function/assert.js";
|
|
2
|
+
function f(r, e = 25, s = !1, u = "…") {
|
|
3
|
+
if (t(typeof r == "string", "First argument must be a string", {
|
|
4
|
+
args: { str: r },
|
|
5
|
+
type: TypeError
|
|
6
|
+
}), t(
|
|
7
|
+
typeof e == "number" && e >= 0 && Number.isFinite(e),
|
|
8
|
+
"Limit must be a non-negative finite number",
|
|
9
|
+
{ args: { limit: e }, type: TypeError }
|
|
10
|
+
), r.length <= e)
|
|
11
|
+
return r;
|
|
12
|
+
const n = s ? r.substring(0, e).lastIndexOf(" ") : e, o = n > 0 ? n : e;
|
|
13
|
+
return `${r.substring(0, o).trim()}${u}`;
|
|
5
14
|
}
|
|
6
15
|
export {
|
|
7
|
-
|
|
16
|
+
f as truncate
|
|
8
17
|
};
|
|
9
18
|
//# sourceMappingURL=truncate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"truncate.js","sources":["../../src/string/truncate.ts"],"sourcesContent":["/**\n * Truncates a string if it is longer than the given maximum string length. The last characters of the truncated string are replaced with the ellipsis sign \"…\".\n *\n * @example\n * ```ts\n * const text = 'Hello World';\n * truncate(text, 5); // 'Hello…'\n * truncate(text, 3, true); // 'Hello…'\n * truncate(text, 5, true, '...'); // 'Hello...'\n * ```\n *\n * @param str - The string to truncate.\n * @param limit - The maximum string length.\n * @param completeWords - If true, the string is truncated to the nearest word, instead of character.\n * @param ellipsis - The characters to end the truncated string with.\n *\n * @returns The truncated string.\n */\nexport function truncate(str: string, limit = 25, completeWords = false, ellipsis = '…'): string {\n if (str.length <= limit) return str;\n\n const _limit = completeWords ? str.substring(0, limit).lastIndexOf(' ') : limit;\n const effectiveLimit = _limit > 0 ? _limit : limit;\n\n return `${str.substring(0, effectiveLimit).trim()}${ellipsis}`;\n}\n"],"names":["truncate","str","limit","completeWords","ellipsis","_limit","effectiveLimit"],"mappings":"
|
|
1
|
+
{"version":3,"file":"truncate.js","sources":["../../src/string/truncate.ts"],"sourcesContent":["import { assert } from '../function/assert';\n\n/**\n * Truncates a string if it is longer than the given maximum string length. The last characters of the truncated string are replaced with the ellipsis sign \"…\".\n *\n * @example\n * ```ts\n * const text = 'Hello World';\n * truncate(text, 5); // 'Hello…'\n * truncate(text, 3, true); // 'Hello…'\n * truncate(text, 5, true, '...'); // 'Hello...'\n * ```\n *\n * @param str - The string to truncate.\n * @param limit - The maximum string length.\n * @param completeWords - If true, the string is truncated to the nearest word, instead of character.\n * @param ellipsis - The characters to end the truncated string with.\n *\n * @returns The truncated string.\n *\n * @throws {TypeError} If str is not a string or limit is not a positive number.\n */\nexport function truncate(str: string, limit = 25, completeWords = false, ellipsis = '…'): string {\n assert(typeof str === 'string', 'First argument must be a string', {\n args: { str },\n type: TypeError,\n });\n assert(\n typeof limit === 'number' && limit >= 0 && Number.isFinite(limit),\n 'Limit must be a non-negative finite number',\n { args: { limit }, type: TypeError },\n );\n\n if (str.length <= limit) {\n return str;\n }\n\n const _limit = completeWords ? str.substring(0, limit).lastIndexOf(' ') : limit;\n const effectiveLimit = _limit > 0 ? _limit : limit;\n\n return `${str.substring(0, effectiveLimit).trim()}${ellipsis}`;\n}\n"],"names":["truncate","str","limit","completeWords","ellipsis","assert","_limit","effectiveLimit"],"mappings":";AAsBO,SAASA,EAASC,GAAaC,IAAQ,IAAIC,IAAgB,IAAOC,IAAW,KAAa;AAW/F,MAVAC,EAAO,OAAOJ,KAAQ,UAAU,mCAAmC;AAAA,IACjE,MAAM,EAAE,KAAAA,EAAA;AAAA,IACR,MAAM;AAAA,EAAA,CACP,GACDI;AAAA,IACE,OAAOH,KAAU,YAAYA,KAAS,KAAK,OAAO,SAASA,CAAK;AAAA,IAChE;AAAA,IACA,EAAE,MAAM,EAAE,OAAAA,EAAA,GAAS,MAAM,UAAA;AAAA,EAAU,GAGjCD,EAAI,UAAUC;AAChB,WAAOD;AAGT,QAAMK,IAASH,IAAgBF,EAAI,UAAU,GAAGC,CAAK,EAAE,YAAY,GAAG,IAAIA,GACpEK,IAAiBD,IAAS,IAAIA,IAASJ;AAE7C,SAAO,GAAGD,EAAI,UAAU,GAAGM,CAAc,EAAE,KAAA,CAAM,GAAGH,CAAQ;AAC9D;"}
|
package/dist/typed/is.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./ge.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../function/assert.cjs"),n=require("./ge.cjs"),o=require("./gt.cjs"),c=require("./isDefined.cjs"),u=require("./isEmpty.cjs"),r=require("./isEqual.cjs"),q=require("./isEven.cjs"),a=require("./isMatch.cjs"),l=require("./isNegative.cjs"),d=require("./isNil.cjs"),g=require("./isOdd.cjs"),v=require("./isPositive.cjs"),p=require("./isRegex.cjs"),m=require("./isWithin.cjs"),E=require("./isZero.cjs"),f=require("./le.cjs"),h=require("./lt.cjs"),y=require("./typeOf.cjs");function O(i,s){return t.assert(!!i,"Type must be provided",{args:{type:i},type:Error}),{defined:c.isDefined,empty:u.isEmpty,eq:e=>r.isEqual(...e),even:q.isEven,ge:e=>n.ge(...e),gt:e=>o.gt(...e),le:e=>f.le(...e),lt:e=>h.lt(...e),match:e=>a.isMatch(...e),ne:e=>!r.isEqual(...e),negative:l.isNegative,nil:d.isNil,odd:g.isOdd,positive:v.isPositive,regex:p.isRegex,within:e=>m.isWithin(...e),zero:E.isZero}[i]?.(s)??y.typeOf(s)===i}exports.is=O;
|
|
2
2
|
//# sourceMappingURL=is.cjs.map
|
package/dist/typed/is.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is.cjs","sources":["../../src/typed/is.ts"],"sourcesContent":["import { ge } from './ge';\nimport { gt } from './gt';\nimport { isDefined } from './isDefined';\nimport { isEmpty } from './isEmpty';\nimport { isEqual } from './isEqual';\nimport { isEven } from './isEven';\nimport { isMatch } from './isMatch';\nimport { isNegative } from './isNegative';\nimport { isNil } from './isNil';\nimport { isOdd } from './isOdd';\nimport { isPositive } from './isPositive';\nimport { isRegex } from './isRegex';\nimport { isWithin } from './isWithin';\nimport { isZero } from './isZero';\nimport { le } from './le';\nimport { lt } from './lt';\nimport { type ArgType, typeOf } from './typeOf';\n\ntype isType =\n | ArgType\n | 'defined'\n | 'empty'\n | 'eq'\n | 'even'\n | 'ge'\n | 'gt'\n | 'le'\n | 'lt'\n | 'match'\n | 'ne'\n | 'negative'\n | 'nil'\n | 'odd'\n | 'positive'\n | 'regex'\n | 'within'\n | 'zero';\n\n/**\n * @description\n * Checks if the value type of argument.\n *\n * @example\n * ```ts\n * is('array', []);\n * is('boolean', true);\n * is('date', new Date());\n * is('defined', 123);\n * is('empty', []);\n * is('even', 2);\n * is('function', () => {});\n * is('match', { a: 1, b: 2 }, { a: 1 });\n * is('nan', Number.NaN);\n * is('negative', -123);\n * is('nil', null);\n * is('null', null);\n * is('number', 123);\n * is('object', {});\n * is('odd', 3);\n * is('positive', 123);\n * is('string', 'hello');\n * is('symbol', Symbol('test'));\n * is('regex', /abc/);\n * is('string', 'hello world');\n * is('undefined', undefined);\n * is('within', 1, 2, 3);\n * is('zero', 0);\n * is('eq', [1, 2, 3], [1, 2, 3]);\n * is('ne', [1, 2, 3], [1, 2]);\n * is('ge', 5, 5);\n * is('gt', 5, 3);\n * is('le', 5, 5);\n * is('lt', 3, 5);\n * ```\n *\n * @param type - The type to check against.\n * @param args - The argument to be checked.\n *\n * @returns `true` if the value is of the specified type, else `false`.\n */\nexport function is(type: 'within', ...args: Parameters<typeof isWithin>): boolean;\nexport function is(type: 'eq', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'ne', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'gt', ...args: Parameters<typeof gt>): boolean;\nexport function is(type: 'ge', ...args: Parameters<typeof ge>): boolean;\nexport function is(type: 'lt', ...args: Parameters<typeof lt>): boolean;\nexport function is(type: 'le', ...args: Parameters<typeof le>): boolean;\nexport function is(type: 'match', ...args: Parameters<typeof isMatch>): boolean;\nexport function is(type: 'empty', ...args: Parameters<typeof isEmpty>): boolean;\nexport function is(type: 'array', arg: unknown): arg is Array<unknown>;\nexport function is(type: 'string', arg: unknown): arg is string;\nexport function is(type: 'number', arg: unknown): arg is number;\nexport function is(type: 'object', arg: unknown): arg is object;\nexport function is(type: 'nil', arg: unknown): arg is null | undefined;\nexport function is(type: 'primitive', arg: unknown): arg is string | number | boolean;\nexport function is(type: isType, arg: unknown): boolean;\nexport function is(type: string, arg: unknown): boolean {\n
|
|
1
|
+
{"version":3,"file":"is.cjs","sources":["../../src/typed/is.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { ge } from './ge';\nimport { gt } from './gt';\nimport { isDefined } from './isDefined';\nimport { isEmpty } from './isEmpty';\nimport { isEqual } from './isEqual';\nimport { isEven } from './isEven';\nimport { isMatch } from './isMatch';\nimport { isNegative } from './isNegative';\nimport { isNil } from './isNil';\nimport { isOdd } from './isOdd';\nimport { isPositive } from './isPositive';\nimport { isRegex } from './isRegex';\nimport { isWithin } from './isWithin';\nimport { isZero } from './isZero';\nimport { le } from './le';\nimport { lt } from './lt';\nimport { type ArgType, typeOf } from './typeOf';\n\ntype isType =\n | ArgType\n | 'defined'\n | 'empty'\n | 'eq'\n | 'even'\n | 'ge'\n | 'gt'\n | 'le'\n | 'lt'\n | 'match'\n | 'ne'\n | 'negative'\n | 'nil'\n | 'odd'\n | 'positive'\n | 'regex'\n | 'within'\n | 'zero';\n\n/**\n * @description\n * Checks if the value type of argument.\n *\n * @example\n * ```ts\n * is('array', []);\n * is('boolean', true);\n * is('date', new Date());\n * is('defined', 123);\n * is('empty', []);\n * is('even', 2);\n * is('function', () => {});\n * is('match', { a: 1, b: 2 }, { a: 1 });\n * is('nan', Number.NaN);\n * is('negative', -123);\n * is('nil', null);\n * is('null', null);\n * is('number', 123);\n * is('object', {});\n * is('odd', 3);\n * is('positive', 123);\n * is('string', 'hello');\n * is('symbol', Symbol('test'));\n * is('regex', /abc/);\n * is('string', 'hello world');\n * is('undefined', undefined);\n * is('within', 1, 2, 3);\n * is('zero', 0);\n * is('eq', [1, 2, 3], [1, 2, 3]);\n * is('ne', [1, 2, 3], [1, 2]);\n * is('ge', 5, 5);\n * is('gt', 5, 3);\n * is('le', 5, 5);\n * is('lt', 3, 5);\n * ```\n *\n * @param type - The type to check against.\n * @param args - The argument to be checked.\n *\n * @returns `true` if the value is of the specified type, else `false`.\n */\nexport function is(type: 'within', ...args: Parameters<typeof isWithin>): boolean;\nexport function is(type: 'eq', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'ne', ...args: Parameters<typeof isEqual>): boolean;\nexport function is(type: 'gt', ...args: Parameters<typeof gt>): boolean;\nexport function is(type: 'ge', ...args: Parameters<typeof ge>): boolean;\nexport function is(type: 'lt', ...args: Parameters<typeof lt>): boolean;\nexport function is(type: 'le', ...args: Parameters<typeof le>): boolean;\nexport function is(type: 'match', ...args: Parameters<typeof isMatch>): boolean;\nexport function is(type: 'empty', ...args: Parameters<typeof isEmpty>): boolean;\nexport function is(type: 'array', arg: unknown): arg is Array<unknown>;\nexport function is(type: 'string', arg: unknown): arg is string;\nexport function is(type: 'number', arg: unknown): arg is number;\nexport function is(type: 'object', arg: unknown): arg is object;\nexport function is(type: 'nil', arg: unknown): arg is null | undefined;\nexport function is(type: 'primitive', arg: unknown): arg is string | number | boolean;\nexport function is(type: isType, arg: unknown): boolean;\nexport function is(type: string, arg: unknown): boolean {\n assert(Boolean(type), 'Type must be provided', { args: { type }, type: Error });\n\n const compare = {\n defined: isDefined,\n empty: isEmpty,\n eq: (args: Parameters<typeof isEqual>) => isEqual(...args),\n even: isEven,\n ge: (args: Parameters<typeof ge>) => ge(...args),\n gt: (args: Parameters<typeof gt>) => gt(...args),\n le: (args: Parameters<typeof le>) => le(...args),\n lt: (args: Parameters<typeof lt>) => lt(...args),\n match: (args: Parameters<typeof isMatch>) => isMatch(...args),\n ne: (args: Parameters<typeof isEqual>) => !isEqual(...args),\n negative: isNegative,\n nil: isNil,\n odd: isOdd,\n positive: isPositive,\n regex: isRegex,\n within: (args: Parameters<typeof isWithin>) => isWithin(...args),\n zero: isZero,\n };\n\n return compare[type as keyof typeof compare]?.(arg) ?? typeOf(arg) === type;\n}\n"],"names":["is","type","arg","assert","isDefined","isEmpty","args","isEqual","isEven","ge","gt","le","lt","isMatch","isNegative","isNil","isOdd","isPositive","isRegex","isWithin","isZero","typeOf"],"mappings":"mjBAiGO,SAASA,EAAGC,EAAcC,EAAuB,CACtDC,OAAAA,EAAAA,OAAO,EAAQF,EAAO,wBAAyB,CAAE,KAAM,CAAE,KAAAA,CAAA,EAAQ,KAAM,MAAO,EAE9D,CACd,QAASG,EAAAA,UACT,MAAOC,EAAAA,QACP,GAAKC,GAAqCC,EAAAA,QAAQ,GAAGD,CAAI,EACzD,KAAME,EAAAA,OACN,GAAKF,GAAgCG,EAAAA,GAAG,GAAGH,CAAI,EAC/C,GAAKA,GAAgCI,EAAAA,GAAG,GAAGJ,CAAI,EAC/C,GAAKA,GAAgCK,EAAAA,GAAG,GAAGL,CAAI,EAC/C,GAAKA,GAAgCM,EAAAA,GAAG,GAAGN,CAAI,EAC/C,MAAQA,GAAqCO,EAAAA,QAAQ,GAAGP,CAAI,EAC5D,GAAKA,GAAqC,CAACC,EAAAA,QAAQ,GAAGD,CAAI,EAC1D,SAAUQ,EAAAA,WACV,IAAKC,EAAAA,MACL,IAAKC,EAAAA,MACL,SAAUC,EAAAA,WACV,MAAOC,EAAAA,QACP,OAASZ,GAAsCa,EAAAA,SAAS,GAAGb,CAAI,EAC/D,KAAMc,EAAAA,MAAA,EAGOnB,CAA4B,IAAIC,CAAG,GAAKmB,EAAAA,OAAOnB,CAAG,IAAMD,CACzE"}
|