@vielzeug/arsenal 2.1.0 → 3.0.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/README.md +5 -18
- package/dist/array/chunk.cjs.map +1 -1
- package/dist/array/chunk.d.ts +1 -1
- package/dist/array/chunk.d.ts.map +1 -1
- package/dist/array/chunk.js.map +1 -1
- package/dist/array/compact.cjs.map +1 -1
- package/dist/array/compact.d.ts +1 -1
- package/dist/array/compact.d.ts.map +1 -1
- package/dist/array/compact.js.map +1 -1
- package/dist/array/contains.cjs.map +1 -1
- package/dist/array/contains.d.ts +1 -1
- package/dist/array/contains.d.ts.map +1 -1
- package/dist/array/contains.js.map +1 -1
- package/dist/array/countBy.cjs.map +1 -1
- package/dist/array/countBy.d.ts +1 -1
- package/dist/array/countBy.d.ts.map +1 -1
- package/dist/array/countBy.js.map +1 -1
- package/dist/array/difference.cjs.map +1 -1
- package/dist/array/difference.d.ts +4 -2
- package/dist/array/difference.d.ts.map +1 -1
- package/dist/array/difference.js.map +1 -1
- package/dist/array/drop.cjs.map +1 -1
- package/dist/array/drop.d.ts +1 -1
- package/dist/array/drop.d.ts.map +1 -1
- package/dist/array/drop.js.map +1 -1
- package/dist/array/dropLast.cjs.map +1 -1
- package/dist/array/dropLast.d.ts +1 -1
- package/dist/array/dropLast.d.ts.map +1 -1
- package/dist/array/dropLast.js.map +1 -1
- package/dist/array/filterMap.cjs.map +1 -1
- package/dist/array/filterMap.d.ts +3 -1
- package/dist/array/filterMap.d.ts.map +1 -1
- package/dist/array/filterMap.js.map +1 -1
- package/dist/array/first.cjs.map +1 -1
- package/dist/array/first.d.ts +1 -1
- package/dist/array/first.d.ts.map +1 -1
- package/dist/array/first.js.map +1 -1
- package/dist/array/groupBy.cjs.map +1 -1
- package/dist/array/groupBy.d.ts +1 -1
- package/dist/array/groupBy.d.ts.map +1 -1
- package/dist/array/groupBy.js.map +1 -1
- package/dist/array/index.cjs +1 -1
- package/dist/array/index.d.ts +0 -1
- package/dist/array/index.d.ts.map +1 -1
- package/dist/array/index.js +17 -18
- package/dist/array/indexBy.cjs.map +1 -1
- package/dist/array/indexBy.d.ts +1 -1
- package/dist/array/indexBy.d.ts.map +1 -1
- package/dist/array/indexBy.js.map +1 -1
- package/dist/array/intersection.cjs.map +1 -1
- package/dist/array/intersection.d.ts +4 -2
- package/dist/array/intersection.d.ts.map +1 -1
- package/dist/array/intersection.js.map +1 -1
- package/dist/array/last.cjs.map +1 -1
- package/dist/array/last.d.ts +1 -1
- package/dist/array/last.d.ts.map +1 -1
- package/dist/array/last.js.map +1 -1
- package/dist/array/partition.cjs.map +1 -1
- package/dist/array/partition.d.ts +3 -1
- package/dist/array/partition.d.ts.map +1 -1
- package/dist/array/partition.js.map +1 -1
- package/dist/array/replace.cjs.map +1 -1
- package/dist/array/replace.d.ts +2 -15
- package/dist/array/replace.d.ts.map +1 -1
- package/dist/array/replace.js.map +1 -1
- package/dist/array/rotate.cjs.map +1 -1
- package/dist/array/rotate.d.ts +5 -17
- package/dist/array/rotate.d.ts.map +1 -1
- package/dist/array/rotate.js.map +1 -1
- package/dist/array/sort.cjs.map +1 -1
- package/dist/array/sort.d.ts +2 -2
- package/dist/array/sort.d.ts.map +1 -1
- package/dist/array/sort.js.map +1 -1
- package/dist/array/take.cjs.map +1 -1
- package/dist/array/take.d.ts +1 -1
- package/dist/array/take.d.ts.map +1 -1
- package/dist/array/take.js.map +1 -1
- package/dist/array/takeLast.cjs.map +1 -1
- package/dist/array/takeLast.d.ts +1 -1
- package/dist/array/takeLast.d.ts.map +1 -1
- package/dist/array/takeLast.js.map +1 -1
- package/dist/array/toggle.cjs.map +1 -1
- package/dist/array/toggle.d.ts +1 -1
- package/dist/array/toggle.d.ts.map +1 -1
- package/dist/array/toggle.js.map +1 -1
- package/dist/array/union.cjs.map +1 -1
- package/dist/array/union.d.ts +4 -2
- package/dist/array/union.d.ts.map +1 -1
- package/dist/array/union.js.map +1 -1
- package/dist/array/uniq.cjs.map +1 -1
- package/dist/array/uniq.d.ts +1 -1
- package/dist/array/uniq.d.ts.map +1 -1
- package/dist/array/uniq.js.map +1 -1
- package/dist/array/zip.cjs.map +1 -1
- package/dist/array/zip.d.ts +1 -1
- package/dist/array/zip.d.ts.map +1 -1
- package/dist/array/zip.js.map +1 -1
- package/dist/arsenal.cjs +1 -1
- package/dist/arsenal.cjs.map +1 -1
- package/dist/arsenal.iife.js +1 -1
- package/dist/arsenal.iife.js.map +1 -1
- package/dist/arsenal.js +1 -1
- package/dist/arsenal.js.map +1 -1
- package/dist/async/abortError.cjs +1 -1
- package/dist/async/abortError.cjs.map +1 -1
- package/dist/async/abortError.d.ts +3 -2
- package/dist/async/abortError.d.ts.map +1 -1
- package/dist/async/abortError.js +2 -2
- package/dist/async/abortError.js.map +1 -1
- package/dist/cache/cache.cjs +1 -1
- package/dist/cache/cache.cjs.map +1 -1
- package/dist/cache/cache.d.ts +1 -0
- package/dist/cache/cache.d.ts.map +1 -1
- package/dist/cache/cache.js +1 -0
- package/dist/cache/cache.js.map +1 -1
- package/dist/function/assert.cjs.map +1 -1
- package/dist/function/assert.d.ts +1 -1
- package/dist/function/assert.js.map +1 -1
- package/dist/guards/index.cjs +1 -1
- package/dist/guards/index.js +7 -7
- package/dist/guards/isEmpty.cjs +1 -1
- package/dist/guards/isEmpty.cjs.map +1 -1
- package/dist/guards/isEmpty.d.ts.map +1 -1
- package/dist/guards/isEmpty.js +4 -5
- package/dist/guards/isEmpty.js.map +1 -1
- package/dist/guards/isFunction.cjs.map +1 -1
- package/dist/guards/isFunction.d.ts +1 -1
- package/dist/guards/isFunction.d.ts.map +1 -1
- package/dist/guards/isFunction.js.map +1 -1
- package/dist/guards/isPrimitive.cjs +1 -1
- package/dist/guards/isPrimitive.cjs.map +1 -1
- package/dist/guards/isPrimitive.d.ts +4 -17
- package/dist/guards/isPrimitive.d.ts.map +1 -1
- package/dist/guards/isPrimitive.js +1 -2
- package/dist/guards/isPrimitive.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -22
- package/dist/math/average.cjs +1 -1
- package/dist/math/average.cjs.map +1 -1
- package/dist/math/average.d.ts +3 -2
- package/dist/math/average.d.ts.map +1 -1
- package/dist/math/average.js +1 -6
- package/dist/math/average.js.map +1 -1
- package/dist/math/gcd.cjs +1 -1
- package/dist/math/gcd.cjs.map +1 -1
- package/dist/math/gcd.d.ts.map +1 -1
- package/dist/math/gcd.js +1 -0
- package/dist/math/gcd.js.map +1 -1
- package/dist/math/index.cjs +1 -1
- package/dist/math/index.d.ts +0 -1
- package/dist/math/index.d.ts.map +1 -1
- package/dist/math/index.js +7 -8
- package/dist/math/lcm.cjs +1 -1
- package/dist/math/lcm.cjs.map +1 -1
- package/dist/math/lcm.d.ts.map +1 -1
- package/dist/math/lcm.js +5 -1
- package/dist/math/lcm.js.map +1 -1
- package/dist/math/linspace.cjs +1 -1
- package/dist/math/linspace.cjs.map +1 -1
- package/dist/math/linspace.d.ts.map +1 -1
- package/dist/math/linspace.js +2 -1
- package/dist/math/linspace.js.map +1 -1
- package/dist/math/median.cjs.map +1 -1
- package/dist/math/median.d.ts +1 -1
- package/dist/math/median.d.ts.map +1 -1
- package/dist/math/median.js.map +1 -1
- package/dist/math/standardDeviation.cjs.map +1 -1
- package/dist/math/standardDeviation.d.ts +1 -1
- package/dist/math/standardDeviation.d.ts.map +1 -1
- package/dist/math/standardDeviation.js.map +1 -1
- package/dist/math/sum.cjs +1 -1
- package/dist/math/sum.cjs.map +1 -1
- package/dist/math/sum.d.ts +1 -1
- package/dist/math/sum.d.ts.map +1 -1
- package/dist/math/sum.js +1 -1
- package/dist/math/sum.js.map +1 -1
- package/dist/math/variance.cjs.map +1 -1
- package/dist/math/variance.d.ts +1 -1
- package/dist/math/variance.d.ts.map +1 -1
- package/dist/math/variance.js.map +1 -1
- package/dist/object/diff.cjs.map +1 -1
- package/dist/object/diff.d.ts +1 -1
- package/dist/object/diff.d.ts.map +1 -1
- package/dist/object/diff.js.map +1 -1
- package/dist/object/prune.cjs +1 -1
- package/dist/object/prune.cjs.map +1 -1
- package/dist/object/prune.d.ts.map +1 -1
- package/dist/object/prune.js +16 -17
- package/dist/object/prune.js.map +1 -1
- package/dist/random/_index.cjs +1 -1
- package/dist/random/_index.cjs.map +1 -1
- package/dist/random/_index.d.ts +1 -1
- package/dist/random/_index.d.ts.map +1 -1
- package/dist/random/_index.js +4 -5
- package/dist/random/_index.js.map +1 -1
- package/dist/random/index.cjs +1 -1
- package/dist/random/index.d.ts +0 -1
- package/dist/random/index.d.ts.map +1 -1
- package/dist/random/index.js +2 -2
- package/dist/random/source.cjs +2 -0
- package/dist/random/source.cjs.map +1 -0
- package/dist/random/source.d.ts +2 -0
- package/dist/random/source.d.ts.map +1 -1
- package/dist/random/source.js +10 -0
- package/dist/random/source.js.map +1 -0
- package/dist/string/index.cjs +1 -1
- package/dist/string/index.d.ts +1 -1
- package/dist/string/index.d.ts.map +1 -1
- package/dist/string/index.js +2 -2
- package/dist/string/{pad.cjs → padCenter.cjs} +2 -2
- package/dist/string/padCenter.cjs.map +1 -0
- package/dist/string/padCenter.d.ts +3 -0
- package/dist/string/padCenter.d.ts.map +1 -0
- package/dist/string/{pad.js → padCenter.js} +3 -3
- package/dist/string/padCenter.js.map +1 -0
- package/package.json +7 -7
- package/dist/array/flatten.cjs +0 -2
- package/dist/array/flatten.cjs.map +0 -1
- package/dist/array/flatten.d.ts +0 -5
- package/dist/array/flatten.d.ts.map +0 -1
- package/dist/array/flatten.js +0 -11
- package/dist/array/flatten.js.map +0 -1
- package/dist/math/percent.cjs +0 -2
- package/dist/math/percent.cjs.map +0 -1
- package/dist/math/percent.d.ts +0 -19
- package/dist/math/percent.d.ts.map +0 -1
- package/dist/math/percent.js +0 -8
- package/dist/math/percent.js.map +0 -1
- package/dist/random/uuid.cjs +0 -2
- package/dist/random/uuid.cjs.map +0 -1
- package/dist/random/uuid.d.ts +0 -12
- package/dist/random/uuid.d.ts.map +0 -1
- package/dist/random/uuid.js +0 -8
- package/dist/random/uuid.js.map +0 -1
- package/dist/string/pad.cjs.map +0 -1
- package/dist/string/pad.d.ts +0 -5
- package/dist/string/pad.d.ts.map +0 -1
- package/dist/string/pad.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variance.cjs","names":[],"sources":["../../src/math/variance.ts"],"sourcesContent":["import { average } from './average';\n\n/**\n * Computes the population variance (average squared deviation from the mean) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * variance([2, 4, 4, 4, 5, 5, 7, 9]); // 4\n * variance([{ n: 1 }, { n: 3 }], (item) => item.n); // 1\n * variance([]); // 0\n * ```\n *\n * @param array - The array to compute variance over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population variance, or `0` for an empty array.\n */\nexport function variance<T>(array: T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n const values = callback ? array.map(callback) : (array as unknown as number[]);\n const mean = average(values) ?? 0;\n\n return average(values.map((value) => (value - mean) ** 2)) ?? 0;\n}\n"],"mappings":"iCAiBA,SAAgB,EAAY,
|
|
1
|
+
{"version":3,"file":"variance.cjs","names":[],"sources":["../../src/math/variance.ts"],"sourcesContent":["import { average } from './average';\n\n/**\n * Computes the population variance (average squared deviation from the mean) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * variance([2, 4, 4, 4, 5, 5, 7, 9]); // 4\n * variance([{ n: 1 }, { n: 3 }], (item) => item.n); // 1\n * variance([]); // 0\n * ```\n *\n * @param array - The array to compute variance over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population variance, or `0` for an empty array.\n */\nexport function variance<T>(array: readonly T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n const values = callback ? array.map(callback) : (array as unknown as number[]);\n const mean = average(values) ?? 0;\n\n return average(values.map((value) => (value - mean) ** 2)) ?? 0;\n}\n"],"mappings":"iCAiBA,SAAgB,EAAY,EAAqB,EAAwC,CACvF,GAAI,EAAM,SAAW,EAAG,MAAO,GAE/B,IAAM,EAAS,EAAW,EAAM,IAAI,CAAQ,EAAK,EAC3C,EAAO,EAAA,QAAQ,CAAM,GAAK,EAEhC,OAAO,EAAA,QAAQ,EAAO,IAAK,IAAW,EAAQ,IAAS,CAAC,CAAC,GAAK,CAChE"}
|
package/dist/math/variance.d.ts
CHANGED
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
* @param callback - An optional callback to map each item to a number.
|
|
14
14
|
* @returns The population variance, or `0` for an empty array.
|
|
15
15
|
*/
|
|
16
|
-
export declare function variance<T>(array: T[], callback?: (item: T) => number): number;
|
|
16
|
+
export declare function variance<T>(array: readonly T[], callback?: (item: T) => number): number;
|
|
17
17
|
//# sourceMappingURL=variance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variance.d.ts","sourceRoot":"","sources":["../../src/math/variance.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"variance.d.ts","sourceRoot":"","sources":["../../src/math/variance.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,CAOvF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variance.js","names":[],"sources":["../../src/math/variance.ts"],"sourcesContent":["import { average } from './average';\n\n/**\n * Computes the population variance (average squared deviation from the mean) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * variance([2, 4, 4, 4, 5, 5, 7, 9]); // 4\n * variance([{ n: 1 }, { n: 3 }], (item) => item.n); // 1\n * variance([]); // 0\n * ```\n *\n * @param array - The array to compute variance over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population variance, or `0` for an empty array.\n */\nexport function variance<T>(array: T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n const values = callback ? array.map(callback) : (array as unknown as number[]);\n const mean = average(values) ?? 0;\n\n return average(values.map((value) => (value - mean) ** 2)) ?? 0;\n}\n"],"mappings":";;AAiBA,SAAgB,EAAY,
|
|
1
|
+
{"version":3,"file":"variance.js","names":[],"sources":["../../src/math/variance.ts"],"sourcesContent":["import { average } from './average';\n\n/**\n * Computes the population variance (average squared deviation from the mean) of an array of\n * numbers, or of values mapped by a callback.\n *\n * @example\n * ```ts\n * variance([2, 4, 4, 4, 5, 5, 7, 9]); // 4\n * variance([{ n: 1 }, { n: 3 }], (item) => item.n); // 1\n * variance([]); // 0\n * ```\n *\n * @param array - The array to compute variance over.\n * @param callback - An optional callback to map each item to a number.\n * @returns The population variance, or `0` for an empty array.\n */\nexport function variance<T>(array: readonly T[], callback?: (item: T) => number): number {\n if (array.length === 0) return 0;\n\n const values = callback ? array.map(callback) : (array as unknown as number[]);\n const mean = average(values) ?? 0;\n\n return average(values.map((value) => (value - mean) ** 2)) ?? 0;\n}\n"],"mappings":";;AAiBA,SAAgB,EAAY,GAAqB,GAAwC;CACvF,IAAI,EAAM,WAAW,GAAG,OAAO;CAE/B,IAAM,IAAS,IAAW,EAAM,IAAI,CAAQ,IAAK,GAC3C,IAAO,EAAQ,CAAM,KAAK;CAEhC,OAAO,EAAQ,EAAO,KAAK,OAAW,IAAQ,MAAS,CAAC,CAAC,KAAK;AAChE"}
|
package/dist/object/diff.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.cjs","names":[],"sources":["../../src/object/diff.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isEqual } from '../guards/isEqual';\nimport type { Obj } from '../types';\n\nexport type DiffResult<T extends Obj> = {\n /** Keys present in `after` but not in `before`. */\n added: Array<keyof T & string>;\n /** Keys present in both objects whose values differ. Maps key → `{ before, after }`. */\n changed: { [K in keyof T]?: { after: T[K]; before: T[K] } };\n /** Keys present in `before` but not in `after`. */\n removed: Array<keyof T & string>;\n};\n\n/**\n * Computes the structural difference between two plain objects.\n * Returns an `{ added, removed, changed }` result — no sentinel symbols needed.\n * Dangerous keys (`__proto__`, `constructor`, `prototype`) are omitted from `changed`.\n *\n * @example\n * ```ts\n * diff({ a: 1, b: 2, c: 3 }, { a: 1, b: 99 });\n * // { added: [], removed: ['c'], changed: { b: { before: 2, after: 99 } } }\n *\n * diff({ x: { n: 1 } }, { x: { n: 2 } });\n * // { added: [], removed: [], changed: { x: { before: { n: 1 }, after: { n: 2 } } } }\n * ```\n *\n * @param before - The original object.\n * @param after - The updated object.\n * @param compareFn - Custom equality function. Defaults to deep `isEqual`.\n */\nexport function diff<T extends Obj>(\n before: T = {} as T,\n after: T = {} as T,\n compareFn: (a: unknown, b: unknown) => boolean = isEqual,\n): DiffResult<T> {\n const added: Array<keyof T & string> = [];\n const removed: Array<keyof T & string> = [];\n const changed: Record<string, { after: unknown; before: unknown }> = {};\n\n const beforeKeys = new Set(Object.keys(before));\n const afterKeys = new Set(Object.keys(after));\n\n for (const key of afterKeys) {\n if (!beforeKeys.has(key)) {\n added.push(key as keyof T & string);\n } else if (!isUnsafeKey(key) && !compareFn(before[key], after[key])) {\n changed[key] = { after: after[key], before: before[key] };\n }\n }\n\n for (const key of beforeKeys) {\n if (!afterKeys.has(key)) {\n removed.push(key as keyof T & string);\n }\n }\n\n return { added, changed: changed as DiffResult<T>['changed'], removed };\n}\n\nexport type ArrayDiff<T> = {\n added: T[];\n removed: T[];\n};\n\nexport type ArrayDiffOptions<T> = {\n compareFn?: (a: T, b: T) => boolean;\n};\n\n/**\n * Computes the set-difference between two arrays.\n * Items present in `after` but not `before` are `added`.\n * Items present in `before` but not `after` are `removed`.\n * Order-independent; uses deep equality by default.\n *\n * @example\n * ```ts\n * diffArrays([1, 2, 3], [2, 3, 4]); // { added: [4], removed: [1] }\n * diffArrays(\n * [{ id: 1 }, { id: 2 }],\n * [{ id: 2 }, { id: 3 }],\n * { compareFn: (a, b) => a.id === b.id },\n * ); // { added: [{ id: 3 }], removed: [{ id: 1 }] }\n * ```\n *\n * @param before - The original array.\n * @param after - The updated array.\n * @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.\n * @returns An object with `added` and `removed` arrays.\n */\nexport function diffArrays<T>(before: T[], after: T[], options?: ArrayDiffOptions<T>): ArrayDiff<T> {\n const compareFn = options?.compareFn ?? ((a: T, b: T) => isEqual(a, b));\n\n return {\n added: after.filter((item) => !before.some((b) => compareFn(b, item))),\n removed: before.filter((item) => !after.some((a) => compareFn(item, a))),\n };\n}\n"],"mappings":"iFA+BA,SAAgB,EACd,EAAY,CAAC,EACb,EAAW,CAAC,EACZ,EAAiD,EAAA,QAClC,CACf,IAAM,EAAiC,CAAC,EAClC,EAAmC,CAAC,EACpC,EAA+D,CAAC,EAEhE,EAAa,IAAI,IAAI,OAAO,KAAK,CAAM,CAAC,EACxC,EAAY,IAAI,IAAI,OAAO,KAAK,CAAK,CAAC,EAE5C,IAAK,IAAM,KAAO,EACX,EAAW,IAAI,CAAG,EAEZ,CAAC,EAAA,YAAY,CAAG,GAAK,CAAC,EAAU,EAAO,GAAM,EAAM,EAAI,IAChE,EAAQ,GAAO,CAAE,MAAO,EAAM,GAAM,OAAQ,EAAO,EAAK,GAFxD,EAAM,KAAK,CAAuB,EAMtC,IAAK,IAAM,KAAO,EACX,EAAU,IAAI,CAAG,GACpB,EAAQ,KAAK,CAAuB,EAIxC,MAAO,CAAE,QAAgB,UAAqC,SAAQ,CACxE,CAgCA,SAAgB,EAAc,
|
|
1
|
+
{"version":3,"file":"diff.cjs","names":[],"sources":["../../src/object/diff.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isEqual } from '../guards/isEqual';\nimport type { Obj } from '../types';\n\nexport type DiffResult<T extends Obj> = {\n /** Keys present in `after` but not in `before`. */\n added: Array<keyof T & string>;\n /** Keys present in both objects whose values differ. Maps key → `{ before, after }`. */\n changed: { [K in keyof T]?: { after: T[K]; before: T[K] } };\n /** Keys present in `before` but not in `after`. */\n removed: Array<keyof T & string>;\n};\n\n/**\n * Computes the structural difference between two plain objects.\n * Returns an `{ added, removed, changed }` result — no sentinel symbols needed.\n * Dangerous keys (`__proto__`, `constructor`, `prototype`) are omitted from `changed`.\n *\n * @example\n * ```ts\n * diff({ a: 1, b: 2, c: 3 }, { a: 1, b: 99 });\n * // { added: [], removed: ['c'], changed: { b: { before: 2, after: 99 } } }\n *\n * diff({ x: { n: 1 } }, { x: { n: 2 } });\n * // { added: [], removed: [], changed: { x: { before: { n: 1 }, after: { n: 2 } } } }\n * ```\n *\n * @param before - The original object.\n * @param after - The updated object.\n * @param compareFn - Custom equality function. Defaults to deep `isEqual`.\n */\nexport function diff<T extends Obj>(\n before: T = {} as T,\n after: T = {} as T,\n compareFn: (a: unknown, b: unknown) => boolean = isEqual,\n): DiffResult<T> {\n const added: Array<keyof T & string> = [];\n const removed: Array<keyof T & string> = [];\n const changed: Record<string, { after: unknown; before: unknown }> = {};\n\n const beforeKeys = new Set(Object.keys(before));\n const afterKeys = new Set(Object.keys(after));\n\n for (const key of afterKeys) {\n if (!beforeKeys.has(key)) {\n added.push(key as keyof T & string);\n } else if (!isUnsafeKey(key) && !compareFn(before[key], after[key])) {\n changed[key] = { after: after[key], before: before[key] };\n }\n }\n\n for (const key of beforeKeys) {\n if (!afterKeys.has(key)) {\n removed.push(key as keyof T & string);\n }\n }\n\n return { added, changed: changed as DiffResult<T>['changed'], removed };\n}\n\nexport type ArrayDiff<T> = {\n added: T[];\n removed: T[];\n};\n\nexport type ArrayDiffOptions<T> = {\n compareFn?: (a: T, b: T) => boolean;\n};\n\n/**\n * Computes the set-difference between two arrays.\n * Items present in `after` but not `before` are `added`.\n * Items present in `before` but not `after` are `removed`.\n * Order-independent; uses deep equality by default.\n *\n * @example\n * ```ts\n * diffArrays([1, 2, 3], [2, 3, 4]); // { added: [4], removed: [1] }\n * diffArrays(\n * [{ id: 1 }, { id: 2 }],\n * [{ id: 2 }, { id: 3 }],\n * { compareFn: (a, b) => a.id === b.id },\n * ); // { added: [{ id: 3 }], removed: [{ id: 1 }] }\n * ```\n *\n * @param before - The original array.\n * @param after - The updated array.\n * @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.\n * @returns An object with `added` and `removed` arrays.\n */\nexport function diffArrays<T>(before: readonly T[], after: readonly T[], options?: ArrayDiffOptions<T>): ArrayDiff<T> {\n const compareFn = options?.compareFn ?? ((a: T, b: T) => isEqual(a, b));\n\n return {\n added: after.filter((item) => !before.some((b) => compareFn(b, item))),\n removed: before.filter((item) => !after.some((a) => compareFn(item, a))),\n };\n}\n"],"mappings":"iFA+BA,SAAgB,EACd,EAAY,CAAC,EACb,EAAW,CAAC,EACZ,EAAiD,EAAA,QAClC,CACf,IAAM,EAAiC,CAAC,EAClC,EAAmC,CAAC,EACpC,EAA+D,CAAC,EAEhE,EAAa,IAAI,IAAI,OAAO,KAAK,CAAM,CAAC,EACxC,EAAY,IAAI,IAAI,OAAO,KAAK,CAAK,CAAC,EAE5C,IAAK,IAAM,KAAO,EACX,EAAW,IAAI,CAAG,EAEZ,CAAC,EAAA,YAAY,CAAG,GAAK,CAAC,EAAU,EAAO,GAAM,EAAM,EAAI,IAChE,EAAQ,GAAO,CAAE,MAAO,EAAM,GAAM,OAAQ,EAAO,EAAK,GAFxD,EAAM,KAAK,CAAuB,EAMtC,IAAK,IAAM,KAAO,EACX,EAAU,IAAI,CAAG,GACpB,EAAQ,KAAK,CAAuB,EAIxC,MAAO,CAAE,QAAgB,UAAqC,SAAQ,CACxE,CAgCA,SAAgB,EAAc,EAAsB,EAAqB,EAA6C,CACpH,IAAM,EAAY,GAAS,aAAe,EAAM,IAAS,EAAA,QAAQ,EAAG,CAAC,GAErE,MAAO,CACL,MAAO,EAAM,OAAQ,GAAS,CAAC,EAAO,KAAM,GAAM,EAAU,EAAG,CAAI,CAAC,CAAC,EACrE,QAAS,EAAO,OAAQ,GAAS,CAAC,EAAM,KAAM,GAAM,EAAU,EAAM,CAAC,CAAC,CAAC,CACzE,CACF"}
|
package/dist/object/diff.d.ts
CHANGED
|
@@ -59,5 +59,5 @@ export type ArrayDiffOptions<T> = {
|
|
|
59
59
|
* @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.
|
|
60
60
|
* @returns An object with `added` and `removed` arrays.
|
|
61
61
|
*/
|
|
62
|
-
export declare function diffArrays<T>(before: T[], after: T[], options?: ArrayDiffOptions<T>): ArrayDiff<T>;
|
|
62
|
+
export declare function diffArrays<T>(before: readonly T[], after: readonly T[], options?: ArrayDiffOptions<T>): ArrayDiff<T>;
|
|
63
63
|
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/object/diff.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,IAAI;IACtC,mDAAmD;IACnD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAC/B,wFAAwF;IACxF,OAAO,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE;YAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;SAAE;KAAE,CAAC;IAC5D,mDAAmD;IACnD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,GAAG,EAChC,MAAM,GAAE,CAAW,EACnB,KAAK,GAAE,CAAW,EAClB,SAAS,GAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAiB,GACvD,UAAU,CAAC,CAAC,CAAC,CAuBf;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,OAAO,EAAE,CAAC,EAAE,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAChC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../src/object/diff.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,IAAI;IACtC,mDAAmD;IACnD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAC/B,wFAAwF;IACxF,OAAO,EAAE;SAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE;YAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;SAAE;KAAE,CAAC;IAC5D,mDAAmD;IACnD,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,GAAG,EAChC,MAAM,GAAE,CAAW,EACnB,KAAK,GAAE,CAAW,EAClB,SAAS,GAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAiB,GACvD,UAAU,CAAC,CAAC,CAAC,CAuBf;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,OAAO,EAAE,CAAC,EAAE,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI;IAChC,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAOpH"}
|
package/dist/object/diff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","names":[],"sources":["../../src/object/diff.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isEqual } from '../guards/isEqual';\nimport type { Obj } from '../types';\n\nexport type DiffResult<T extends Obj> = {\n /** Keys present in `after` but not in `before`. */\n added: Array<keyof T & string>;\n /** Keys present in both objects whose values differ. Maps key → `{ before, after }`. */\n changed: { [K in keyof T]?: { after: T[K]; before: T[K] } };\n /** Keys present in `before` but not in `after`. */\n removed: Array<keyof T & string>;\n};\n\n/**\n * Computes the structural difference between two plain objects.\n * Returns an `{ added, removed, changed }` result — no sentinel symbols needed.\n * Dangerous keys (`__proto__`, `constructor`, `prototype`) are omitted from `changed`.\n *\n * @example\n * ```ts\n * diff({ a: 1, b: 2, c: 3 }, { a: 1, b: 99 });\n * // { added: [], removed: ['c'], changed: { b: { before: 2, after: 99 } } }\n *\n * diff({ x: { n: 1 } }, { x: { n: 2 } });\n * // { added: [], removed: [], changed: { x: { before: { n: 1 }, after: { n: 2 } } } }\n * ```\n *\n * @param before - The original object.\n * @param after - The updated object.\n * @param compareFn - Custom equality function. Defaults to deep `isEqual`.\n */\nexport function diff<T extends Obj>(\n before: T = {} as T,\n after: T = {} as T,\n compareFn: (a: unknown, b: unknown) => boolean = isEqual,\n): DiffResult<T> {\n const added: Array<keyof T & string> = [];\n const removed: Array<keyof T & string> = [];\n const changed: Record<string, { after: unknown; before: unknown }> = {};\n\n const beforeKeys = new Set(Object.keys(before));\n const afterKeys = new Set(Object.keys(after));\n\n for (const key of afterKeys) {\n if (!beforeKeys.has(key)) {\n added.push(key as keyof T & string);\n } else if (!isUnsafeKey(key) && !compareFn(before[key], after[key])) {\n changed[key] = { after: after[key], before: before[key] };\n }\n }\n\n for (const key of beforeKeys) {\n if (!afterKeys.has(key)) {\n removed.push(key as keyof T & string);\n }\n }\n\n return { added, changed: changed as DiffResult<T>['changed'], removed };\n}\n\nexport type ArrayDiff<T> = {\n added: T[];\n removed: T[];\n};\n\nexport type ArrayDiffOptions<T> = {\n compareFn?: (a: T, b: T) => boolean;\n};\n\n/**\n * Computes the set-difference between two arrays.\n * Items present in `after` but not `before` are `added`.\n * Items present in `before` but not `after` are `removed`.\n * Order-independent; uses deep equality by default.\n *\n * @example\n * ```ts\n * diffArrays([1, 2, 3], [2, 3, 4]); // { added: [4], removed: [1] }\n * diffArrays(\n * [{ id: 1 }, { id: 2 }],\n * [{ id: 2 }, { id: 3 }],\n * { compareFn: (a, b) => a.id === b.id },\n * ); // { added: [{ id: 3 }], removed: [{ id: 1 }] }\n * ```\n *\n * @param before - The original array.\n * @param after - The updated array.\n * @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.\n * @returns An object with `added` and `removed` arrays.\n */\nexport function diffArrays<T>(before: T[], after: T[], options?: ArrayDiffOptions<T>): ArrayDiff<T> {\n const compareFn = options?.compareFn ?? ((a: T, b: T) => isEqual(a, b));\n\n return {\n added: after.filter((item) => !before.some((b) => compareFn(b, item))),\n removed: before.filter((item) => !after.some((a) => compareFn(item, a))),\n };\n}\n"],"mappings":";;;AA+BA,SAAgB,EACd,IAAY,CAAC,GACb,IAAW,CAAC,GACZ,IAAiD,GAClC;CACf,IAAM,IAAiC,CAAC,GAClC,IAAmC,CAAC,GACpC,IAA+D,CAAC,GAEhE,IAAa,IAAI,IAAI,OAAO,KAAK,CAAM,CAAC,GACxC,IAAY,IAAI,IAAI,OAAO,KAAK,CAAK,CAAC;CAE5C,KAAK,IAAM,KAAO,GAChB,AAAK,EAAW,IAAI,CAAG,IAEZ,CAAC,EAAY,CAAG,KAAK,CAAC,EAAU,EAAO,IAAM,EAAM,EAAI,MAChE,EAAQ,KAAO;EAAE,OAAO,EAAM;EAAM,QAAQ,EAAO;CAAK,KAFxD,EAAM,KAAK,CAAuB;CAMtC,KAAK,IAAM,KAAO,GAChB,AAAK,EAAU,IAAI,CAAG,KACpB,EAAQ,KAAK,CAAuB;CAIxC,OAAO;EAAE;EAAgB;EAAqC;CAAQ;AACxE;AAgCA,SAAgB,EAAc,
|
|
1
|
+
{"version":3,"file":"diff.js","names":[],"sources":["../../src/object/diff.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { isEqual } from '../guards/isEqual';\nimport type { Obj } from '../types';\n\nexport type DiffResult<T extends Obj> = {\n /** Keys present in `after` but not in `before`. */\n added: Array<keyof T & string>;\n /** Keys present in both objects whose values differ. Maps key → `{ before, after }`. */\n changed: { [K in keyof T]?: { after: T[K]; before: T[K] } };\n /** Keys present in `before` but not in `after`. */\n removed: Array<keyof T & string>;\n};\n\n/**\n * Computes the structural difference between two plain objects.\n * Returns an `{ added, removed, changed }` result — no sentinel symbols needed.\n * Dangerous keys (`__proto__`, `constructor`, `prototype`) are omitted from `changed`.\n *\n * @example\n * ```ts\n * diff({ a: 1, b: 2, c: 3 }, { a: 1, b: 99 });\n * // { added: [], removed: ['c'], changed: { b: { before: 2, after: 99 } } }\n *\n * diff({ x: { n: 1 } }, { x: { n: 2 } });\n * // { added: [], removed: [], changed: { x: { before: { n: 1 }, after: { n: 2 } } } }\n * ```\n *\n * @param before - The original object.\n * @param after - The updated object.\n * @param compareFn - Custom equality function. Defaults to deep `isEqual`.\n */\nexport function diff<T extends Obj>(\n before: T = {} as T,\n after: T = {} as T,\n compareFn: (a: unknown, b: unknown) => boolean = isEqual,\n): DiffResult<T> {\n const added: Array<keyof T & string> = [];\n const removed: Array<keyof T & string> = [];\n const changed: Record<string, { after: unknown; before: unknown }> = {};\n\n const beforeKeys = new Set(Object.keys(before));\n const afterKeys = new Set(Object.keys(after));\n\n for (const key of afterKeys) {\n if (!beforeKeys.has(key)) {\n added.push(key as keyof T & string);\n } else if (!isUnsafeKey(key) && !compareFn(before[key], after[key])) {\n changed[key] = { after: after[key], before: before[key] };\n }\n }\n\n for (const key of beforeKeys) {\n if (!afterKeys.has(key)) {\n removed.push(key as keyof T & string);\n }\n }\n\n return { added, changed: changed as DiffResult<T>['changed'], removed };\n}\n\nexport type ArrayDiff<T> = {\n added: T[];\n removed: T[];\n};\n\nexport type ArrayDiffOptions<T> = {\n compareFn?: (a: T, b: T) => boolean;\n};\n\n/**\n * Computes the set-difference between two arrays.\n * Items present in `after` but not `before` are `added`.\n * Items present in `before` but not `after` are `removed`.\n * Order-independent; uses deep equality by default.\n *\n * @example\n * ```ts\n * diffArrays([1, 2, 3], [2, 3, 4]); // { added: [4], removed: [1] }\n * diffArrays(\n * [{ id: 1 }, { id: 2 }],\n * [{ id: 2 }, { id: 3 }],\n * { compareFn: (a, b) => a.id === b.id },\n * ); // { added: [{ id: 3 }], removed: [{ id: 1 }] }\n * ```\n *\n * @param before - The original array.\n * @param after - The updated array.\n * @param [options.compareFn] - Custom equality function. Defaults to deep `isEqual`.\n * @returns An object with `added` and `removed` arrays.\n */\nexport function diffArrays<T>(before: readonly T[], after: readonly T[], options?: ArrayDiffOptions<T>): ArrayDiff<T> {\n const compareFn = options?.compareFn ?? ((a: T, b: T) => isEqual(a, b));\n\n return {\n added: after.filter((item) => !before.some((b) => compareFn(b, item))),\n removed: before.filter((item) => !after.some((a) => compareFn(item, a))),\n };\n}\n"],"mappings":";;;AA+BA,SAAgB,EACd,IAAY,CAAC,GACb,IAAW,CAAC,GACZ,IAAiD,GAClC;CACf,IAAM,IAAiC,CAAC,GAClC,IAAmC,CAAC,GACpC,IAA+D,CAAC,GAEhE,IAAa,IAAI,IAAI,OAAO,KAAK,CAAM,CAAC,GACxC,IAAY,IAAI,IAAI,OAAO,KAAK,CAAK,CAAC;CAE5C,KAAK,IAAM,KAAO,GAChB,AAAK,EAAW,IAAI,CAAG,IAEZ,CAAC,EAAY,CAAG,KAAK,CAAC,EAAU,EAAO,IAAM,EAAM,EAAI,MAChE,EAAQ,KAAO;EAAE,OAAO,EAAM;EAAM,QAAQ,EAAO;CAAK,KAFxD,EAAM,KAAK,CAAuB;CAMtC,KAAK,IAAM,KAAO,GAChB,AAAK,EAAU,IAAI,CAAG,KACpB,EAAQ,KAAK,CAAuB;CAIxC,OAAO;EAAE;EAAgB;EAAqC;CAAQ;AACxE;AAgCA,SAAgB,EAAc,GAAsB,GAAqB,GAA6C;CACpH,IAAM,IAAY,GAAS,eAAe,GAAM,MAAS,EAAQ,GAAG,CAAC;CAErE,OAAO;EACL,OAAO,EAAM,QAAQ,MAAS,CAAC,EAAO,MAAM,MAAM,EAAU,GAAG,CAAI,CAAC,CAAC;EACrE,SAAS,EAAO,QAAQ,MAAS,CAAC,EAAM,MAAM,MAAM,EAAU,GAAM,CAAC,CAAC,CAAC;CACzE;AACF"}
|
package/dist/object/prune.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../_common/unsafePaths.cjs"),t=require("../array/filterMap.cjs"),n=require("../guards/
|
|
1
|
+
const e=require("../_common/unsafePaths.cjs"),t=require("../array/filterMap.cjs"),n=require("../guards/isPlainObject.cjs"),r=require("../guards/isEmpty.cjs");function i(a){if(a!=null){if(typeof a==`string`){let e=a.trim();return e===``?void 0:e}if(Array.isArray(a)){let e=t.filterMap(a,e=>{let t=i(e);return r.isEmpty(t)?void 0:t});return e.length===0?void 0:e}if(n.isPlainObject(a)){let t={};for(let[n,o]of Object.entries(a)){if(e.isUnsafeKey(n))continue;let a=i(o);r.isEmpty(a)||(t[n]=a)}return Object.keys(t).length===0?void 0:t}return a}}exports.prune=i;
|
|
2
2
|
//# sourceMappingURL=prune.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prune.cjs","names":[],"sources":["../../src/object/prune.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { filterMap } from '../array/filterMap';\nimport { isEmpty } from '../guards/isEmpty';\nimport {
|
|
1
|
+
{"version":3,"file":"prune.cjs","names":[],"sources":["../../src/object/prune.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { filterMap } from '../array/filterMap';\nimport { isEmpty } from '../guards/isEmpty';\nimport { isPlainObject } from '../guards/isPlainObject';\n\n/**\n * Removes all nullable and empty values from strings, arrays, or objects.\n *\n * - For strings: trims whitespace and returns `undefined` if the result is empty.\n * - For arrays: recursively removes `null`, `undefined`, empty strings, and empty objects/arrays.\n * - For objects: recursively removes properties whose pruned value is empty. Dangerous keys\n * (`__proto__`, `constructor`, `prototype`) are always skipped.\n * - For any other type: returns the value unchanged.\n *\n * @example\n * ```ts\n * prune(' hello '); // 'hello'\n * prune(' '); // undefined\n * prune([1, null, '', 2, undefined, 3]); // [1, 2, 3]\n * prune({ a: 1, b: null, c: '', d: 2 }); // { a: 1, d: 2 }\n * prune({ a: { b: null, c: '' }, d: 1 }); // { d: 1 }\n * ```\n *\n * @param value - The value to prune.\n * @returns The pruned value, or `undefined` if the result would be empty.\n */\nexport function prune(value: string): string | undefined;\nexport function prune<T>(value: T[]): Array<NonNullable<T>> | undefined;\nexport function prune<T extends Record<string, unknown>>(value: T): Partial<T> | undefined;\nexport function prune<T>(value: T): T | undefined;\nexport function prune<T>(value: T): T | undefined {\n if (value === null || value === undefined) return undefined;\n\n if (typeof value === 'string') {\n const trimmed = value.trim();\n\n return (trimmed === '' ? undefined : trimmed) as T | undefined;\n }\n\n if (Array.isArray(value)) {\n const cleaned = filterMap(value as unknown[], (item) => {\n const pruned = prune(item);\n\n return isEmpty(pruned) ? undefined : (pruned as unknown);\n });\n\n return (cleaned.length === 0 ? undefined : cleaned) as T | undefined;\n }\n\n if (isPlainObject(value)) {\n const cleaned: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(value)) {\n if (isUnsafeKey(key)) continue;\n\n const cleanedValue = prune(val);\n\n if (!isEmpty(cleanedValue)) {\n cleaned[key] = cleanedValue;\n }\n }\n\n return (Object.keys(cleaned).length === 0 ? undefined : cleaned) as T | undefined;\n }\n\n return value;\n}\n"],"mappings":"8JA8BA,SAAgB,EAAS,EAAyB,CAC5C,MAAU,KAEd,IAAI,OAAO,GAAU,SAAU,CAC7B,IAAM,EAAU,EAAM,KAAK,EAE3B,OAAQ,IAAY,GAAK,IAAA,GAAY,CACvC,CAEA,GAAI,MAAM,QAAQ,CAAK,EAAG,CACxB,IAAM,EAAU,EAAA,UAAU,EAAqB,GAAS,CACtD,IAAM,EAAS,EAAM,CAAI,EAEzB,OAAO,EAAA,QAAQ,CAAM,EAAI,IAAA,GAAa,CACxC,CAAC,EAED,OAAQ,EAAQ,SAAW,EAAI,IAAA,GAAY,CAC7C,CAEA,GAAI,EAAA,cAAc,CAAK,EAAG,CACxB,IAAM,EAAmC,CAAC,EAE1C,IAAK,GAAM,CAAC,EAAK,KAAQ,OAAO,QAAQ,CAAK,EAAG,CAC9C,GAAI,EAAA,YAAY,CAAG,EAAG,SAEtB,IAAM,EAAe,EAAM,CAAG,EAEzB,EAAA,QAAQ,CAAY,IACvB,EAAQ,GAAO,EAEnB,CAEA,OAAQ,OAAO,KAAK,CAAO,CAAC,CAAC,SAAW,EAAI,IAAA,GAAY,CAC1D,CAEA,OAAO,CA5BP,CA6BF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../src/object/prune.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../src/object/prune.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AACzD,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AACxE,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;AAC3F,wBAAgB,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC"}
|
package/dist/object/prune.js
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
import { isUnsafeKey as e } from "../_common/unsafePaths.js";
|
|
2
2
|
import { filterMap as t } from "../array/filterMap.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { isEmpty as i } from "../guards/isEmpty.js";
|
|
3
|
+
import { isPlainObject as n } from "../guards/isPlainObject.js";
|
|
4
|
+
import { isEmpty as r } from "../guards/isEmpty.js";
|
|
6
5
|
//#region src/object/prune.ts
|
|
7
|
-
function a
|
|
8
|
-
if (
|
|
9
|
-
if (typeof
|
|
10
|
-
let e =
|
|
6
|
+
function i(a) {
|
|
7
|
+
if (a != null) {
|
|
8
|
+
if (typeof a == "string") {
|
|
9
|
+
let e = a.trim();
|
|
11
10
|
return e === "" ? void 0 : e;
|
|
12
11
|
}
|
|
13
|
-
if (Array.isArray(
|
|
14
|
-
let e = t(
|
|
15
|
-
let t =
|
|
16
|
-
return
|
|
12
|
+
if (Array.isArray(a)) {
|
|
13
|
+
let e = t(a, (e) => {
|
|
14
|
+
let t = i(e);
|
|
15
|
+
return r(t) ? void 0 : t;
|
|
17
16
|
});
|
|
18
17
|
return e.length === 0 ? void 0 : e;
|
|
19
18
|
}
|
|
20
|
-
if (
|
|
19
|
+
if (n(a)) {
|
|
21
20
|
let t = {};
|
|
22
|
-
for (let [n,
|
|
21
|
+
for (let [n, o] of Object.entries(a)) {
|
|
23
22
|
if (e(n)) continue;
|
|
24
|
-
let
|
|
25
|
-
|
|
23
|
+
let a = i(o);
|
|
24
|
+
r(a) || (t[n] = a);
|
|
26
25
|
}
|
|
27
26
|
return Object.keys(t).length === 0 ? void 0 : t;
|
|
28
27
|
}
|
|
29
|
-
return
|
|
28
|
+
return a;
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
//#endregion
|
|
33
|
-
export {
|
|
32
|
+
export { i as prune };
|
|
34
33
|
|
|
35
34
|
//# sourceMappingURL=prune.js.map
|
package/dist/object/prune.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prune.js","names":[],"sources":["../../src/object/prune.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { filterMap } from '../array/filterMap';\nimport { isEmpty } from '../guards/isEmpty';\nimport {
|
|
1
|
+
{"version":3,"file":"prune.js","names":[],"sources":["../../src/object/prune.ts"],"sourcesContent":["import { isUnsafeKey } from '../_common/unsafePaths';\nimport { filterMap } from '../array/filterMap';\nimport { isEmpty } from '../guards/isEmpty';\nimport { isPlainObject } from '../guards/isPlainObject';\n\n/**\n * Removes all nullable and empty values from strings, arrays, or objects.\n *\n * - For strings: trims whitespace and returns `undefined` if the result is empty.\n * - For arrays: recursively removes `null`, `undefined`, empty strings, and empty objects/arrays.\n * - For objects: recursively removes properties whose pruned value is empty. Dangerous keys\n * (`__proto__`, `constructor`, `prototype`) are always skipped.\n * - For any other type: returns the value unchanged.\n *\n * @example\n * ```ts\n * prune(' hello '); // 'hello'\n * prune(' '); // undefined\n * prune([1, null, '', 2, undefined, 3]); // [1, 2, 3]\n * prune({ a: 1, b: null, c: '', d: 2 }); // { a: 1, d: 2 }\n * prune({ a: { b: null, c: '' }, d: 1 }); // { d: 1 }\n * ```\n *\n * @param value - The value to prune.\n * @returns The pruned value, or `undefined` if the result would be empty.\n */\nexport function prune(value: string): string | undefined;\nexport function prune<T>(value: T[]): Array<NonNullable<T>> | undefined;\nexport function prune<T extends Record<string, unknown>>(value: T): Partial<T> | undefined;\nexport function prune<T>(value: T): T | undefined;\nexport function prune<T>(value: T): T | undefined {\n if (value === null || value === undefined) return undefined;\n\n if (typeof value === 'string') {\n const trimmed = value.trim();\n\n return (trimmed === '' ? undefined : trimmed) as T | undefined;\n }\n\n if (Array.isArray(value)) {\n const cleaned = filterMap(value as unknown[], (item) => {\n const pruned = prune(item);\n\n return isEmpty(pruned) ? undefined : (pruned as unknown);\n });\n\n return (cleaned.length === 0 ? undefined : cleaned) as T | undefined;\n }\n\n if (isPlainObject(value)) {\n const cleaned: Record<string, unknown> = {};\n\n for (const [key, val] of Object.entries(value)) {\n if (isUnsafeKey(key)) continue;\n\n const cleanedValue = prune(val);\n\n if (!isEmpty(cleanedValue)) {\n cleaned[key] = cleanedValue;\n }\n }\n\n return (Object.keys(cleaned).length === 0 ? undefined : cleaned) as T | undefined;\n }\n\n return value;\n}\n"],"mappings":";;;;;AA8BA,SAAgB,EAAS,GAAyB;CAC5C,SAAU,MAEd;MAAI,OAAO,KAAU,UAAU;GAC7B,IAAM,IAAU,EAAM,KAAK;GAE3B,OAAQ,MAAY,KAAK,KAAA,IAAY;EACvC;EAEA,IAAI,MAAM,QAAQ,CAAK,GAAG;GACxB,IAAM,IAAU,EAAU,IAAqB,MAAS;IACtD,IAAM,IAAS,EAAM,CAAI;IAEzB,OAAO,EAAQ,CAAM,IAAI,KAAA,IAAa;GACxC,CAAC;GAED,OAAQ,EAAQ,WAAW,IAAI,KAAA,IAAY;EAC7C;EAEA,IAAI,EAAc,CAAK,GAAG;GACxB,IAAM,IAAmC,CAAC;GAE1C,KAAK,IAAM,CAAC,GAAK,MAAQ,OAAO,QAAQ,CAAK,GAAG;IAC9C,IAAI,EAAY,CAAG,GAAG;IAEtB,IAAM,IAAe,EAAM,CAAG;IAE9B,AAAK,EAAQ,CAAY,MACvB,EAAQ,KAAO;GAEnB;GAEA,OAAQ,OAAO,KAAK,CAAO,CAAC,CAAC,WAAW,IAAI,KAAA,IAAY;EAC1D;EAEA,OAAO;CA5BP;AA6BF"}
|
package/dist/random/_index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require("./source.cjs");function t(t,n){return Math.floor(e.randomFloat(n)*t)}exports.randomIndex=t;
|
|
2
2
|
//# sourceMappingURL=_index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_index.cjs","names":[],"sources":["../../src/random/_index.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"_index.cjs","names":[],"sources":["../../src/random/_index.ts"],"sourcesContent":["import { type RandomSource, randomFloat } from './source';\n\nexport function randomIndex(exclusiveMax: number, source?: RandomSource): number {\n return Math.floor(randomFloat(source) * exclusiveMax);\n}\n"],"mappings":"gCAEA,SAAgB,EAAY,EAAsB,EAA+B,CAC/E,OAAO,KAAK,MAAM,EAAA,YAAY,CAAM,EAAI,CAAY,CACtD"}
|
package/dist/random/_index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_index.d.ts","sourceRoot":"","sources":["../../src/random/_index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"_index.d.ts","sourceRoot":"","sources":["../../src/random/_index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,UAAU,CAAC;AAE1D,wBAAgB,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,MAAM,CAE/E"}
|
package/dist/random/_index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { randomFloat as e } from "./source.js";
|
|
1
2
|
//#region src/random/_index.ts
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
if (!Number.isFinite(n) || n < 0 || n >= 1) throw RangeError("random source must return a finite number in [0, 1)");
|
|
5
|
-
return Math.floor(n * e);
|
|
3
|
+
function t(t, n) {
|
|
4
|
+
return Math.floor(e(n) * t);
|
|
6
5
|
}
|
|
7
6
|
//#endregion
|
|
8
|
-
export {
|
|
7
|
+
export { t as randomIndex };
|
|
9
8
|
|
|
10
9
|
//# sourceMappingURL=_index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_index.js","names":[],"sources":["../../src/random/_index.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"file":"_index.js","names":[],"sources":["../../src/random/_index.ts"],"sourcesContent":["import { type RandomSource, randomFloat } from './source';\n\nexport function randomIndex(exclusiveMax: number, source?: RandomSource): number {\n return Math.floor(randomFloat(source) * exclusiveMax);\n}\n"],"mappings":";;AAEA,SAAgB,EAAY,GAAsB,GAA+B;CAC/E,OAAO,KAAK,MAAM,EAAY,CAAM,IAAI,CAAY;AACtD"}
|
package/dist/random/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./source.cjs"),t=require("./random.cjs"),n=require("./draw.cjs"),r=require("./shuffle.cjs");exports.draw=n.draw,exports.drawMany=n.drawMany,exports.random=t.random,exports.randomFloat=e.randomFloat,exports.shuffle=r.shuffle;
|
package/dist/random/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/random/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/random/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
package/dist/random/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomFloat as e } from "./source.js";
|
|
2
2
|
import { random as t } from "./random.js";
|
|
3
3
|
import { draw as n, drawMany as r } from "./draw.js";
|
|
4
4
|
import { shuffle as i } from "./shuffle.js";
|
|
5
|
-
export { n as draw, r as drawMany, t as random,
|
|
5
|
+
export { n as draw, r as drawMany, t as random, e as randomFloat, i as shuffle };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.cjs","names":[],"sources":["../../src/random/source.ts"],"sourcesContent":["export type RandomSource = {\n next(): number;\n};\n\n/** Returns a validated random float in `[0, 1)`. */\nexport function randomFloat(source?: RandomSource): number {\n const value = source?.next() ?? crypto.getRandomValues(new Uint32Array(1))[0]! / 0x100000000;\n\n if (!Number.isFinite(value) || value < 0 || value >= 1) {\n throw new RangeError('random source must return a finite number in [0, 1)');\n }\n\n return value;\n}\n"],"mappings":"AAKA,SAAgB,EAAY,EAA+B,CACzD,IAAM,EAAQ,GAAQ,KAAK,GAAK,OAAO,gBAAgB,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,GAAM,WAEjF,GAAI,CAAC,OAAO,SAAS,CAAK,GAAK,EAAQ,GAAK,GAAS,EACnD,MAAU,WAAW,qDAAqD,EAG5E,OAAO,CACT"}
|
package/dist/random/source.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/random/source.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,IAAI,MAAM,CAAC;CAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/random/source.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,IAAI,MAAM,CAAC;CAChB,CAAC;AAEF,oDAAoD;AACpD,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,MAAM,CAQzD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/random/source.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = e?.next() ?? crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0] / 4294967296;
|
|
4
|
+
if (!Number.isFinite(t) || t < 0 || t >= 1) throw RangeError("random source must return a finite number in [0, 1)");
|
|
5
|
+
return t;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { e as randomFloat };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","names":[],"sources":["../../src/random/source.ts"],"sourcesContent":["export type RandomSource = {\n next(): number;\n};\n\n/** Returns a validated random float in `[0, 1)`. */\nexport function randomFloat(source?: RandomSource): number {\n const value = source?.next() ?? crypto.getRandomValues(new Uint32Array(1))[0]! / 0x100000000;\n\n if (!Number.isFinite(value) || value < 0 || value >= 1) {\n throw new RangeError('random source must return a finite number in [0, 1)');\n }\n\n return value;\n}\n"],"mappings":";AAKA,SAAgB,EAAY,GAA+B;CACzD,IAAM,IAAQ,GAAQ,KAAK,KAAK,OAAO,gCAAgB,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,KAAM;CAEjF,IAAI,CAAC,OAAO,SAAS,CAAK,KAAK,IAAQ,KAAK,KAAS,GACnD,MAAU,WAAW,qDAAqD;CAG5E,OAAO;AACT"}
|
package/dist/string/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./similarity.cjs"),t=require("./camelCase.cjs"),n=require("./escape.cjs"),r=require("./kebabCase.cjs"),i=require("./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./similarity.cjs"),t=require("./camelCase.cjs"),n=require("./escape.cjs"),r=require("./kebabCase.cjs"),i=require("./padCenter.cjs"),a=require("./pascalCase.cjs"),o=require("./snakeCase.cjs"),s=require("./words.cjs"),c=require("./titleCase.cjs"),l=require("./truncate.cjs"),u=require("./unescape.cjs");exports.camelCase=t.camelCase,exports.escape=n.escape,exports.kebabCase=r.kebabCase,exports.padCenter=i.padCenter,exports.pascalCase=a.pascalCase,exports.similarity=e.similarity,exports.snakeCase=o.snakeCase,exports.titleCase=c.titleCase,exports.truncate=l.truncate,exports.unescape=u.unescape,exports.words=s.words;
|
package/dist/string/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
package/dist/string/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import { similarity as e } from "./similarity.js";
|
|
|
2
2
|
import { camelCase as t } from "./camelCase.js";
|
|
3
3
|
import { escape as n } from "./escape.js";
|
|
4
4
|
import { kebabCase as r } from "./kebabCase.js";
|
|
5
|
-
import {
|
|
5
|
+
import { padCenter as i } from "./padCenter.js";
|
|
6
6
|
import { pascalCase as a } from "./pascalCase.js";
|
|
7
7
|
import { snakeCase as o } from "./snakeCase.js";
|
|
8
8
|
import { words as s } from "./words.js";
|
|
9
9
|
import { titleCase as c } from "./titleCase.js";
|
|
10
10
|
import { truncate as l } from "./truncate.js";
|
|
11
11
|
import { unescape as u } from "./unescape.js";
|
|
12
|
-
export { t as camelCase, n as escape, r as kebabCase, i as
|
|
12
|
+
export { t as camelCase, n as escape, r as kebabCase, i as padCenter, a as pascalCase, e as similarity, o as snakeCase, c as titleCase, l as truncate, u as unescape, s as words };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t,n=` `){if(t<=e.length)return e;let r=t-e.length,i=Math.floor(r/2);return e.padStart(e.length+i,n).padEnd(t,n)}exports.
|
|
2
|
-
//# sourceMappingURL=
|
|
1
|
+
function e(e,t,n=` `){if(t<=e.length)return e;let r=t-e.length,i=Math.floor(r/2);return e.padStart(e.length+i,n).padEnd(t,n)}exports.padCenter=e;
|
|
2
|
+
//# sourceMappingURL=padCenter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"padCenter.cjs","names":[],"sources":["../../src/string/padCenter.ts"],"sourcesContent":["/** Pads both sides of a string to reach `targetLength`. */\nexport function padCenter(value: string, targetLength: number, fill = ' '): string {\n if (targetLength <= value.length) return value;\n\n const total = targetLength - value.length;\n const left = Math.floor(total / 2);\n\n return value.padStart(value.length + left, fill).padEnd(targetLength, fill);\n}\n"],"mappings":"AACA,SAAgB,EAAU,EAAe,EAAsB,EAAO,IAAa,CACjF,GAAI,GAAgB,EAAM,OAAQ,OAAO,EAEzC,IAAM,EAAQ,EAAe,EAAM,OAC7B,EAAO,KAAK,MAAM,EAAQ,CAAC,EAEjC,OAAO,EAAM,SAAS,EAAM,OAAS,EAAM,CAAI,CAAC,CAAC,OAAO,EAAc,CAAI,CAC5E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"padCenter.d.ts","sourceRoot":"","sources":["../../src/string/padCenter.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,MAAM,CAOjF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
//#region src/string/
|
|
1
|
+
//#region src/string/padCenter.ts
|
|
2
2
|
function e(e, t, n = " ") {
|
|
3
3
|
if (t <= e.length) return e;
|
|
4
4
|
let r = t - e.length, i = Math.floor(r / 2);
|
|
5
5
|
return e.padStart(e.length + i, n).padEnd(t, n);
|
|
6
6
|
}
|
|
7
7
|
//#endregion
|
|
8
|
-
export { e as
|
|
8
|
+
export { e as padCenter };
|
|
9
9
|
|
|
10
|
-
//# sourceMappingURL=
|
|
10
|
+
//# sourceMappingURL=padCenter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"padCenter.js","names":[],"sources":["../../src/string/padCenter.ts"],"sourcesContent":["/** Pads both sides of a string to reach `targetLength`. */\nexport function padCenter(value: string, targetLength: number, fill = ' '): string {\n if (targetLength <= value.length) return value;\n\n const total = targetLength - value.length;\n const left = Math.floor(total / 2);\n\n return value.padStart(value.length + left, fill).padEnd(targetLength, fill);\n}\n"],"mappings":";AACA,SAAgB,EAAU,GAAe,GAAsB,IAAO,KAAa;CACjF,IAAI,KAAgB,EAAM,QAAQ,OAAO;CAEzC,IAAM,IAAQ,IAAe,EAAM,QAC7B,IAAO,KAAK,MAAM,IAAQ,CAAC;CAEjC,OAAO,EAAM,SAAS,EAAM,SAAS,GAAM,CAAI,CAAC,CAAC,OAAO,GAAc,CAAI;AAC5E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vielzeug/arsenal",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Tree-shakeable TypeScript utility library — array, object, string, async, cache, math, and more",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -106,21 +106,21 @@
|
|
|
106
106
|
"registry": "https://registry.npmjs.org/"
|
|
107
107
|
},
|
|
108
108
|
"scripts": {
|
|
109
|
-
"build": "pnpm run verify:exports && vite build && pnpm run build:bundle && pnpm run build:types",
|
|
109
|
+
"build": "pnpm --silent run verify:exports && vite build && pnpm --silent run build:bundle && pnpm --silent run build:types",
|
|
110
110
|
"build:bundle": "vite build --config vite.bundle.config.ts",
|
|
111
111
|
"build:types": "tsc -p tsconfig.declarations.json",
|
|
112
112
|
"fix": "biome check --write src",
|
|
113
113
|
"lint": "biome ci src",
|
|
114
|
-
"prepublishOnly": "pnpm run build",
|
|
114
|
+
"prepublishOnly": "pnpm --silent run build",
|
|
115
115
|
"preview": "vite preview",
|
|
116
116
|
"sync:exports": "node ./scripts/sync-exports.mjs",
|
|
117
|
-
"test": "pnpm run verify:exports && vitest",
|
|
117
|
+
"test": "pnpm --silent run verify:exports && vitest",
|
|
118
118
|
"verify:exports": "node ./scripts/sync-exports.mjs --check"
|
|
119
119
|
},
|
|
120
120
|
"devDependencies": {
|
|
121
|
-
"@types/node": "^26.
|
|
121
|
+
"@types/node": "^26.4.1",
|
|
122
122
|
"typescript": "^6.0.3",
|
|
123
|
-
"vite": "^8.2.
|
|
124
|
-
"vitest": "^
|
|
123
|
+
"vite": "^8.2.2",
|
|
124
|
+
"vitest": "^5.0.0"
|
|
125
125
|
}
|
|
126
126
|
}
|
package/dist/array/flatten.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.cjs","names":[],"sources":["../../src/array/flatten.ts"],"sourcesContent":["/**\n * Flattens nested arrays up to the provided depth.\n */\nexport function flatten<T>(array: unknown[], depth = 1): T[] {\n if (depth < 1) return [...array] as T[];\n\n const out: unknown[] = [];\n\n for (const item of array) {\n if (Array.isArray(item)) {\n out.push(...flatten(item, depth - 1));\n } else {\n out.push(item);\n }\n }\n\n return out as T[];\n}\n"],"mappings":"AAGA,SAAgB,EAAW,EAAkB,EAAQ,EAAQ,CAC3D,GAAI,EAAQ,EAAG,MAAO,CAAC,GAAG,CAAK,EAE/B,IAAM,EAAiB,CAAC,EAExB,IAAK,IAAM,KAAQ,EACb,MAAM,QAAQ,CAAI,EACpB,EAAI,KAAK,GAAG,EAAQ,EAAM,EAAQ,CAAC,CAAC,EAEpC,EAAI,KAAK,CAAI,EAIjB,OAAO,CACT"}
|
package/dist/array/flatten.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.d.ts","sourceRoot":"","sources":["../../src/array/flatten.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,SAAI,GAAG,CAAC,EAAE,CAc3D"}
|
package/dist/array/flatten.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/array/flatten.ts
|
|
2
|
-
function e(t, n = 1) {
|
|
3
|
-
if (n < 1) return [...t];
|
|
4
|
-
let r = [];
|
|
5
|
-
for (let i of t) Array.isArray(i) ? r.push(...e(i, n - 1)) : r.push(i);
|
|
6
|
-
return r;
|
|
7
|
-
}
|
|
8
|
-
//#endregion
|
|
9
|
-
export { e as flatten };
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=flatten.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.js","names":[],"sources":["../../src/array/flatten.ts"],"sourcesContent":["/**\n * Flattens nested arrays up to the provided depth.\n */\nexport function flatten<T>(array: unknown[], depth = 1): T[] {\n if (depth < 1) return [...array] as T[];\n\n const out: unknown[] = [];\n\n for (const item of array) {\n if (Array.isArray(item)) {\n out.push(...flatten(item, depth - 1));\n } else {\n out.push(item);\n }\n }\n\n return out as T[];\n}\n"],"mappings":";AAGA,SAAgB,EAAW,GAAkB,IAAQ,GAAQ;CAC3D,IAAI,IAAQ,GAAG,OAAO,CAAC,GAAG,CAAK;CAE/B,IAAM,IAAiB,CAAC;CAExB,KAAK,IAAM,KAAQ,GACjB,AAAI,MAAM,QAAQ,CAAI,IACpB,EAAI,KAAK,GAAG,EAAQ,GAAM,IAAQ,CAAC,CAAC,IAEpC,EAAI,KAAK,CAAI;CAIjB,OAAO;AACT"}
|
package/dist/math/percent.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"percent.cjs","names":[],"sources":["../../src/math/percent.ts"],"sourcesContent":["/**\n * Calculates what percentage `value` is of `total`.\n *\n * @example\n * ```ts\n * percent(25, 100); // 25\n * percent(1, 3); // 33.333...\n * percent(50, 200); // 25\n * percent(0, 100); // 0\n * percent(5, 0); // 0\n * ```\n *\n * @param value - The partial value.\n * @param total - The total value.\n *\n * @returns The percentage (0–100 scale). Returns 0 when `total` is 0.\n */\nexport function percent(value: number, total: number): number {\n if (total === 0) return 0;\n\n return (value / total) * 100;\n}\n"],"mappings":"AAiBA,SAAgB,EAAQ,EAAe,EAAuB,CAG5D,OAFI,IAAU,EAAU,EAEhB,EAAQ,EAAS,GAC3B"}
|
package/dist/math/percent.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculates what percentage `value` is of `total`.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* percent(25, 100); // 25
|
|
7
|
-
* percent(1, 3); // 33.333...
|
|
8
|
-
* percent(50, 200); // 25
|
|
9
|
-
* percent(0, 100); // 0
|
|
10
|
-
* percent(5, 0); // 0
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* @param value - The partial value.
|
|
14
|
-
* @param total - The total value.
|
|
15
|
-
*
|
|
16
|
-
* @returns The percentage (0–100 scale). Returns 0 when `total` is 0.
|
|
17
|
-
*/
|
|
18
|
-
export declare function percent(value: number, total: number): number;
|
|
19
|
-
//# sourceMappingURL=percent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../src/math/percent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI5D"}
|
package/dist/math/percent.js
DELETED
package/dist/math/percent.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"percent.js","names":[],"sources":["../../src/math/percent.ts"],"sourcesContent":["/**\n * Calculates what percentage `value` is of `total`.\n *\n * @example\n * ```ts\n * percent(25, 100); // 25\n * percent(1, 3); // 33.333...\n * percent(50, 200); // 25\n * percent(0, 100); // 0\n * percent(5, 0); // 0\n * ```\n *\n * @param value - The partial value.\n * @param total - The total value.\n *\n * @returns The percentage (0–100 scale). Returns 0 when `total` is 0.\n */\nexport function percent(value: number, total: number): number {\n if (total === 0) return 0;\n\n return (value / total) * 100;\n}\n"],"mappings":";AAiBA,SAAgB,EAAQ,GAAe,GAAuB;CAG5D,OAFI,MAAU,IAAU,IAEhB,IAAQ,IAAS;AAC3B"}
|
package/dist/random/uuid.cjs
DELETED
package/dist/random/uuid.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.cjs","names":[],"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 return crypto.randomUUID();\n}\n"],"mappings":"AAUA,SAAgB,GAAe,CAC7B,OAAO,OAAO,WAAW,CAC3B"}
|
package/dist/random/uuid.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a unique identifier.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* uuid(); // a unique identifier, e.g., '22a746d0-08be-4aff-bbc2-4deddf0914e0'
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* @returns A unique identifier.
|
|
10
|
-
*/
|
|
11
|
-
export declare function uuid(): string;
|
|
12
|
-
//# sourceMappingURL=uuid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/random/uuid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,IAAI,IAAI,MAAM,CAE7B"}
|
package/dist/random/uuid.js
DELETED
package/dist/random/uuid.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uuid.js","names":[],"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 return crypto.randomUUID();\n}\n"],"mappings":";AAUA,SAAgB,IAAe;CAC7B,OAAO,OAAO,WAAW;AAC3B"}
|
package/dist/string/pad.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pad.cjs","names":[],"sources":["../../src/string/pad.ts"],"sourcesContent":["/**\n * Pads a string on both sides to reach the target length.\n */\nexport function pad(str: string, targetLength: number, fillString = ' '): string {\n if (targetLength <= str.length) return str;\n\n const total = targetLength - str.length;\n const left = Math.floor(total / 2);\n\n return str.padStart(str.length + left, fillString).padEnd(targetLength, fillString);\n}\n"],"mappings":"AAGA,SAAgB,EAAI,EAAa,EAAsB,EAAa,IAAa,CAC/E,GAAI,GAAgB,EAAI,OAAQ,OAAO,EAEvC,IAAM,EAAQ,EAAe,EAAI,OAC3B,EAAO,KAAK,MAAM,EAAQ,CAAC,EAEjC,OAAO,EAAI,SAAS,EAAI,OAAS,EAAM,CAAU,CAAC,CAAC,OAAO,EAAc,CAAU,CACpF"}
|
package/dist/string/pad.d.ts
DELETED
package/dist/string/pad.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pad.d.ts","sourceRoot":"","sources":["../../src/string/pad.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,SAAM,GAAG,MAAM,CAO/E"}
|
package/dist/string/pad.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pad.js","names":[],"sources":["../../src/string/pad.ts"],"sourcesContent":["/**\n * Pads a string on both sides to reach the target length.\n */\nexport function pad(str: string, targetLength: number, fillString = ' '): string {\n if (targetLength <= str.length) return str;\n\n const total = targetLength - str.length;\n const left = Math.floor(total / 2);\n\n return str.padStart(str.length + left, fillString).padEnd(targetLength, fillString);\n}\n"],"mappings":";AAGA,SAAgB,EAAI,GAAa,GAAsB,IAAa,KAAa;CAC/E,IAAI,KAAgB,EAAI,QAAQ,OAAO;CAEvC,IAAM,IAAQ,IAAe,EAAI,QAC3B,IAAO,KAAK,MAAM,IAAQ,CAAC;CAEjC,OAAO,EAAI,SAAS,EAAI,SAAS,GAAM,CAAU,CAAC,CAAC,OAAO,GAAc,CAAU;AACpF"}
|