@absoluteui/helpers 0.0.0-stage → 0.13.1
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/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +47 -2
- package/SECURITY.md +102 -0
- package/dist/array/compare.d.ts +8 -0
- package/dist/array/compare.js +2 -0
- package/dist/array/index.d.ts +328 -0
- package/dist/array/index.js +2 -0
- package/dist/array/tree.d.ts +48 -0
- package/dist/array/tree.js +2 -0
- package/dist/async/batch.d.ts +103 -0
- package/dist/async/batch.js +2 -0
- package/dist/async/concurrency.d.ts +92 -0
- package/dist/async/concurrency.js +2 -0
- package/dist/async/control.d.ts +77 -0
- package/dist/async/control.js +2 -0
- package/dist/async/index.d.ts +8 -0
- package/dist/async/index.js +2 -0
- package/dist/async/signal.d.ts +95 -0
- package/dist/async/signal.js +2 -0
- package/dist/boolean/index.d.ts +83 -0
- package/dist/boolean/index.js +2 -0
- package/dist/business-calendar/days.d.ts +397 -0
- package/dist/business-calendar/days.js +2 -0
- package/dist/business-calendar/describe.d.ts +45 -0
- package/dist/business-calendar/describe.js +2 -0
- package/dist/business-calendar/engine.d.ts +305 -0
- package/dist/business-calendar/engine.js +2 -0
- package/dist/business-calendar/hours.d.ts +96 -0
- package/dist/business-calendar/hours.js +2 -0
- package/dist/business-calendar/index.d.ts +29 -0
- package/dist/business-calendar/index.js +2 -0
- package/dist/business-calendar/internal.d.ts +44 -0
- package/dist/business-calendar/internal.js +2 -0
- package/dist/business-calendar/rules.d.ts +260 -0
- package/dist/business-calendar/rules.js +2 -0
- package/dist/color/index.d.ts +200 -0
- package/dist/color/index.js +2 -0
- package/dist/color/named.d.ts +4 -0
- package/dist/color/named.js +2 -0
- package/dist/compare/index.d.ts +186 -0
- package/dist/compare/index.js +2 -0
- package/dist/convert/index.d.ts +152 -0
- package/dist/convert/index.js +2 -0
- package/dist/csv/index.d.ts +6 -0
- package/dist/csv/index.js +2 -0
- package/dist/csv/parse.d.ts +85 -0
- package/dist/csv/parse.js +12 -0
- package/dist/csv/stringify.d.ts +48 -0
- package/dist/csv/stringify.js +5 -0
- package/dist/date/calendar.d.ts +339 -0
- package/dist/date/calendar.js +2 -0
- package/dist/date/format.d.ts +66 -0
- package/dist/date/format.js +2 -0
- package/dist/date/index.d.ts +26 -0
- package/dist/date/index.js +2 -0
- package/dist/date/intervals.d.ts +110 -0
- package/dist/date/intervals.js +2 -0
- package/dist/date/intl-cache.d.ts +10 -0
- package/dist/date/intl-cache.js +2 -0
- package/dist/date/locale.d.ts +58 -0
- package/dist/date/locale.js +2 -0
- package/dist/date/plain-date.d.ts +105 -0
- package/dist/date/plain-date.js +2 -0
- package/dist/date/plain-time.d.ts +121 -0
- package/dist/date/plain-time.js +2 -0
- package/dist/date/zone.d.ts +121 -0
- package/dist/date/zone.js +2 -0
- package/dist/decimal/index.d.ts +149 -0
- package/dist/decimal/index.js +2 -0
- package/dist/ds/avl.d.ts +50 -0
- package/dist/ds/avl.js +2 -0
- package/dist/ds/bitset.d.ts +46 -0
- package/dist/ds/bitset.js +2 -0
- package/dist/ds/bloom.d.ts +41 -0
- package/dist/ds/bloom.js +2 -0
- package/dist/ds/caches.d.ts +141 -0
- package/dist/ds/caches.js +2 -0
- package/dist/ds/disjoint-set.d.ts +38 -0
- package/dist/ds/disjoint-set.js +2 -0
- package/dist/ds/emitter.d.ts +53 -0
- package/dist/ds/emitter.js +2 -0
- package/dist/ds/graph.d.ts +84 -0
- package/dist/ds/graph.js +2 -0
- package/dist/ds/heap.d.ts +49 -0
- package/dist/ds/heap.js +2 -0
- package/dist/ds/index.d.ts +20 -0
- package/dist/ds/index.js +2 -0
- package/dist/ds/internal.d.ts +19 -0
- package/dist/ds/internal.js +2 -0
- package/dist/ds/interval-tree.d.ts +49 -0
- package/dist/ds/interval-tree.js +2 -0
- package/dist/ds/linked-list.d.ts +54 -0
- package/dist/ds/linked-list.js +2 -0
- package/dist/ds/maps.d.ts +89 -0
- package/dist/ds/maps.js +2 -0
- package/dist/ds/ring.d.ts +99 -0
- package/dist/ds/ring.js +2 -0
- package/dist/ds/sorted.d.ts +104 -0
- package/dist/ds/sorted.js +2 -0
- package/dist/ds/stack.d.ts +28 -0
- package/dist/ds/stack.js +2 -0
- package/dist/ds/trie.d.ts +84 -0
- package/dist/ds/trie.js +2 -0
- package/dist/duration/index.d.ts +146 -0
- package/dist/duration/index.js +2 -0
- package/dist/encoding/index.d.ts +144 -0
- package/dist/encoding/index.js +2 -0
- package/dist/error/index.d.ts +316 -0
- package/dist/error/index.js +2 -0
- package/dist/fn/index.d.ts +129 -0
- package/dist/fn/index.js +2 -0
- package/dist/fn/memo.d.ts +46 -0
- package/dist/fn/memo.js +2 -0
- package/dist/fn/timing.d.ts +64 -0
- package/dist/fn/timing.js +2 -0
- package/dist/http/headers.d.ts +160 -0
- package/dist/http/headers.js +2 -0
- package/dist/http/index.d.ts +10 -0
- package/dist/http/index.js +2 -0
- package/dist/http/problem.d.ts +37 -0
- package/dist/http/problem.js +2 -0
- package/dist/http/response.d.ts +43 -0
- package/dist/http/response.js +2 -0
- package/dist/http/status.d.ts +169 -0
- package/dist/http/status.js +2 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +2 -0
- package/dist/internal/keys.d.ts +6 -0
- package/dist/internal/keys.js +2 -0
- package/dist/is/index.d.ts +219 -0
- package/dist/is/index.js +2 -0
- package/dist/json/index.d.ts +9 -0
- package/dist/json/index.js +2 -0
- package/dist/json/internal.d.ts +12 -0
- package/dist/json/internal.js +2 -0
- package/dist/json/ndjson.d.ts +28 -0
- package/dist/json/ndjson.js +4 -0
- package/dist/json/parse.d.ts +45 -0
- package/dist/json/parse.js +2 -0
- package/dist/json/patch.d.ts +62 -0
- package/dist/json/patch.js +2 -0
- package/dist/json/pointer.d.ts +43 -0
- package/dist/json/pointer.js +2 -0
- package/dist/json/stringify.d.ts +42 -0
- package/dist/json/stringify.js +2 -0
- package/dist/linq/enumerable.d.ts +208 -0
- package/dist/linq/enumerable.js +2 -0
- package/dist/linq/index.d.ts +6 -0
- package/dist/linq/index.js +2 -0
- package/dist/linq/operators.d.ts +503 -0
- package/dist/linq/operators.js +2 -0
- package/dist/number/core.d.ts +164 -0
- package/dist/number/core.js +2 -0
- package/dist/number/format.d.ts +80 -0
- package/dist/number/format.js +2 -0
- package/dist/number/index.d.ts +12 -0
- package/dist/number/index.js +2 -0
- package/dist/number/internal.d.ts +18 -0
- package/dist/number/internal.js +2 -0
- package/dist/number/parse.d.ts +45 -0
- package/dist/number/parse.js +2 -0
- package/dist/number/words.d.ts +19 -0
- package/dist/number/words.js +2 -0
- package/dist/object/basic.d.ts +130 -0
- package/dist/object/basic.js +2 -0
- package/dist/object/deep.d.ts +90 -0
- package/dist/object/deep.js +2 -0
- package/dist/object/diff.d.ts +57 -0
- package/dist/object/diff.js +2 -0
- package/dist/object/index.d.ts +8 -0
- package/dist/object/index.js +2 -0
- package/dist/object/internal.d.ts +21 -0
- package/dist/object/internal.js +2 -0
- package/dist/object/path.d.ts +17 -0
- package/dist/object/path.js +2 -0
- package/dist/random/core.d.ts +14 -0
- package/dist/random/core.js +2 -0
- package/dist/random/index.d.ts +167 -0
- package/dist/random/index.js +2 -0
- package/dist/random/seeded.d.ts +27 -0
- package/dist/random/seeded.js +2 -0
- package/dist/sanitize/index.d.ts +8 -0
- package/dist/sanitize/index.js +2 -0
- package/dist/sanitize/pii.d.ts +48 -0
- package/dist/sanitize/pii.js +2 -0
- package/dist/sanitize/records.d.ts +100 -0
- package/dist/sanitize/records.js +2 -0
- package/dist/sanitize/text.d.ts +101 -0
- package/dist/sanitize/text.js +2 -0
- package/dist/set/index.d.ts +162 -0
- package/dist/set/index.js +2 -0
- package/dist/stats/index.d.ts +190 -0
- package/dist/stats/index.js +2 -0
- package/dist/string/index.d.ts +494 -0
- package/dist/string/index.js +8 -0
- package/dist/string/internal.d.ts +33 -0
- package/dist/string/internal.js +2 -0
- package/dist/string/words.d.ts +14 -0
- package/dist/string/words.js +2 -0
- package/dist/timezone/index.d.ts +76 -0
- package/dist/timezone/index.js +2 -0
- package/dist/url/index.d.ts +178 -0
- package/dist/url/index.js +2 -0
- package/dist/validate/builders.d.ts +6 -0
- package/dist/validate/builders.js +2 -0
- package/dist/validate/formats.d.ts +237 -0
- package/dist/validate/formats.js +2 -0
- package/dist/validate/index.d.ts +13 -0
- package/dist/validate/index.js +2 -0
- package/dist/validate/schema.d.ts +220 -0
- package/dist/validate/schema.js +2 -0
- package/dist/zip/index.d.ts +8 -0
- package/dist/zip/index.js +2 -0
- package/dist/zip/internal.d.ts +69 -0
- package/dist/zip/internal.js +2 -0
- package/dist/zip/reader.d.ts +56 -0
- package/dist/zip/reader.js +2 -0
- package/dist/zip/writer.d.ts +65 -0
- package/dist/zip/writer.js +2 -0
- package/package.json +150 -4
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type Path } from './path.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reads a nested own property. Returns `fallback` when the path is missing or resolves to `undefined`.
|
|
4
|
+
* Never traverses into prototypes (`deepGet({}, 'constructor')` is `fallback`).
|
|
5
|
+
* @example deepGet({ a: [{ b: 1 }] }, 'a[0].b') // => 1
|
|
6
|
+
*/
|
|
7
|
+
export declare function deepGet(obj: unknown, path: Path, fallback?: unknown): unknown;
|
|
8
|
+
/**
|
|
9
|
+
* True when every segment of the path is an own property.
|
|
10
|
+
* @example deepHas({ a: { b: undefined } }, 'a.b') // => true
|
|
11
|
+
*/
|
|
12
|
+
export declare function deepHas(obj: unknown, path: Path): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a copy with the value set at `path`, copying only the containers along the path.
|
|
15
|
+
* Missing or primitive intermediates become `[]` (numeric next segment) or `{}`.
|
|
16
|
+
* Throws `HLP_UNSAFE_KEY` for `__proto__`/`constructor`/`prototype` segments and
|
|
17
|
+
* `HLP_OBJECT_PATH_BLOCKED` when the path crosses a non-plain object (Date, Map, class instance).
|
|
18
|
+
* @example deepSet({}, 'a.list[1]', 'x') // => { a: { list: [undefined, 'x'] } } // index 0 is a hole
|
|
19
|
+
*/
|
|
20
|
+
export declare function deepSet<T>(obj: T, path: Path, value: unknown): T;
|
|
21
|
+
/**
|
|
22
|
+
* Sets the value at `path`, mutating `obj` and creating missing containers. Returns `obj`.
|
|
23
|
+
* @example
|
|
24
|
+
* const o = {};
|
|
25
|
+
* deepSetInPlace(o, 'a.b', 1);
|
|
26
|
+
* o; // => { a: { b: 1 } }
|
|
27
|
+
*/
|
|
28
|
+
export declare function deepSetInPlace<T extends object>(obj: T, path: Path, value: unknown): T;
|
|
29
|
+
/**
|
|
30
|
+
* Returns a copy without the property at `path` (array elements are spliced out).
|
|
31
|
+
* Returns `obj` itself when the path does not exist.
|
|
32
|
+
* @example deepUnset({ a: { b: 1, c: 2 } }, 'a.b') // => { a: { c: 2 } }
|
|
33
|
+
*/
|
|
34
|
+
export declare function deepUnset<T>(obj: T, path: Path): T;
|
|
35
|
+
export interface DeepMergeOptions {
|
|
36
|
+
/** How arrays combine. Default `'replace'`. `'union'` appends source items not already present (SameValueZero). */
|
|
37
|
+
readonly arrays?: 'replace' | 'concat' | 'merge-by-index' | 'union';
|
|
38
|
+
/** `'skip'` (default) ignores `undefined` source values; `'overwrite'` writes them. */
|
|
39
|
+
readonly undefinedValues?: 'skip' | 'overwrite';
|
|
40
|
+
/** `'error'` (default) throws `HLP_UNSAFE_KEY` on `__proto__`/`constructor`/`prototype` source keys; `'skip'` drops them. */
|
|
41
|
+
readonly unsafeKeys?: 'error' | 'skip';
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Deep-merges plain objects into a new object. Only plain objects merge; other values
|
|
45
|
+
* (class instances, dates, maps) replace. Prototypes are never merged or modified.
|
|
46
|
+
* @example deepMerge({ a: { x: 1 } }, { a: { y: 2 } }) // => { a: { x: 1, y: 2 } }
|
|
47
|
+
*/
|
|
48
|
+
export declare function deepMerge<A extends object, B extends object>(target: A, source: B, options?: DeepMergeOptions): A & B;
|
|
49
|
+
/**
|
|
50
|
+
* Deep-merges several objects left to right into a new object.
|
|
51
|
+
* @example deepMergeAll([{ a: 1 }, { b: 2 }, { a: 3 }]) // => { a: 3, b: 2 }
|
|
52
|
+
*/
|
|
53
|
+
export declare function deepMergeAll(objects: readonly object[], options?: DeepMergeOptions): Record<string, unknown>;
|
|
54
|
+
export interface DeepCloneOptions {
|
|
55
|
+
/**
|
|
56
|
+
* `'auto'` (default) uses `structuredClone` when available and falls back to a manual clone
|
|
57
|
+
* for values it cannot clone (functions, symbols). Like the platform, class instances then become
|
|
58
|
+
* plain objects. `'manual'` always uses the manual clone, which keeps prototypes and symbol keys.
|
|
59
|
+
*/
|
|
60
|
+
readonly strategy?: 'auto' | 'manual';
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Deep copy supporting Date, RegExp, Map, Set, ArrayBuffer, typed arrays, DataView and cycles.
|
|
64
|
+
* Functions are copied by reference.
|
|
65
|
+
* @example const b = deepClone({ d: new Date(0), s: new Set([1]) });
|
|
66
|
+
*/
|
|
67
|
+
export declare function deepClone<T>(value: T, options?: DeepCloneOptions): T;
|
|
68
|
+
/** Recursively readonly view of `T`. */
|
|
69
|
+
export type DeepReadonly<T> = T extends (...args: never[]) => unknown ? T : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepReadonly<U>> : T extends object ? {
|
|
70
|
+
readonly [P in keyof T]: DeepReadonly<T[P]>;
|
|
71
|
+
} : T;
|
|
72
|
+
/**
|
|
73
|
+
* Freezes `value` and everything reachable through own properties, map/set entries (cycle-safe).
|
|
74
|
+
* Typed arrays cannot be frozen and are left as is. Mutates (freezes) the input and returns it.
|
|
75
|
+
* @example
|
|
76
|
+
* const cfg = deepFreeze({ a: { b: 1 } });
|
|
77
|
+
* Object.isFrozen(cfg.a); // => true // assigning cfg.a.b throws in strict mode
|
|
78
|
+
*/
|
|
79
|
+
export declare function deepFreeze<T>(value: T): DeepReadonly<T>;
|
|
80
|
+
export interface DeepEqualOptions {
|
|
81
|
+
/** Treat `+0` and `-0` as different (`Object.is`). Default false. `NaN` always equals `NaN`. */
|
|
82
|
+
readonly distinguishZero?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Structural equality: key-order independent; handles NaN, Date, RegExp, Map, Set,
|
|
86
|
+
* ArrayBuffer, typed arrays, DataView, boxed primitives, errors and cycles.
|
|
87
|
+
* Objects must share a prototype.
|
|
88
|
+
* @example deepEqual({ a: [1, { b: NaN }] }, { a: [1, { b: NaN }] }) // => true
|
|
89
|
+
*/
|
|
90
|
+
export declare function deepEqual(a: unknown, b: unknown, options?: DeepEqualOptions): boolean;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{ValidationError as O}from"../error/index.js";import{isArray as D,isPlainObject as M}from"../is/index.js";import{assertSafeKey as B,hasOwn as N,isUnsafeKey as K}from"../internal/keys.js";import{MISSING as R,at as T,circular as _,copyContainer as z,copyPlain as H,isContainer as q,ownEnumerableKeys as S,ownValue as A,put as P}from"./internal.js";import{parsePath as j}from"./path.js";function X(e,s,i){let r=e;for(const o of j(s))if(r=A(r,o),r===R)return i;return r===void 0?i:r}function F(e,s){let i=e;for(const r of j(s))if(i=A(i,r),i===R)return!1;return!0}function E(e){const s=j(e);for(const i of s)B(i);return s}const V=()=>{throw new O("HLP_OBJECT_PATH_BLOCKED","Cannot write a path through a non-plain object.")};function C(e,s){return q(e)?z(e):typeof e=="object"&&e!==null||typeof e=="function"?V():typeof s=="number"?[]:{}}function Y(e,s,i){const r=E(s);if(r.length===0)return i;const o=(f,l)=>{const c=T(r,l),g=C(f,c),d=A(f,c);return g[c]=l===r.length-1?i:o(d===R?void 0:d,l+1),g};return o(e,0)}function $(e,s,i){const r=E(s);if(r.length===0)throw new O("HLP_OBJECT_INVALID_PATH","The property path is not valid.");let o=e;for(let f=0;f<r.length-1;f++){const l=T(r,f),c=A(o,l);if(typeof c=="object"&&c!==null||typeof c=="function")o=c;else{const g=typeof r[f+1]=="number"?[]:{};o[l]=g,o=g}}return o[T(r,r.length-1)]=i,e}function x(e,s){const i=j(s);if(i.length===0)throw new O("HLP_OBJECT_INVALID_PATH","The property path is not valid.");if(!F(e,i))return e;const r=(o,f)=>{const l=T(i,f),c=C(o,l);return f===i.length-1?Array.isArray(c)&&typeof l=="number"?c.splice(l,1):Reflect.deleteProperty(c,l):P(c,l,r(A(o,l),f+1)),c};return r(e,0)}function I(e){const{arrays:s="replace",undefinedValues:i="skip",unsafeKeys:r="error"}=e,o=i==="skip",f=new Set,l=d=>{f.has(d)&&_(),f.add(d)},c=d=>g(void 0,d),g=(d,n)=>{if(M(n)){l(n);const t=M(d)?H(d):{};for(const a of Object.keys(n)){if(K(a)){if(r==="skip")continue;B(a)}const y=n[a];y===void 0&&o||(t[a]=N(t,a)?g(t[a],y):c(y))}return f.delete(n),t}if(D(n)){l(n);let t;if(!D(d)||s==="replace")t=n.map(c);else if(s==="concat")t=[...d,...n.map(c)];else if(s==="union"){t=[...d];const a=new Set(d);for(const y of n)a.has(y)||(a.add(y),t.push(c(y)))}else{t=d.slice();for(let a=0;a<n.length;a++){const y=n[a];y===void 0&&o&&a<d.length||(t[a]=a<d.length?g(d[a],y):c(y))}}return f.delete(n),t}return n};return g}function v(e,s,i={}){return I(i)(e,s)}function ee(e,s={}){const i=I(s);let r={};for(const o of e)r=i(r,o);return r}function m(e,s){if(typeof e!="object"||e===null)return e;const i=s.get(e);if(i!==void 0)return i;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp){const o=new RegExp(e.source,e.flags);return o.lastIndex=e.lastIndex,o}if(e instanceof ArrayBuffer)return e.slice(0);if(e instanceof DataView)return new DataView(e.buffer.slice(0),e.byteOffset,e.byteLength);if(ArrayBuffer.isView(e))return e.slice();if(e instanceof Map){const o=new Map;s.set(e,o);for(const[f,l]of e)o.set(m(f,s),m(l,s));return o}if(e instanceof Set){const o=new Set;s.set(e,o);for(const f of e)o.add(m(f,s));return o}if(e instanceof Number||e instanceof String||e instanceof Boolean)return Object(e.valueOf());if(Array.isArray(e)){const o=new Array(e.length);s.set(e,o);for(let f=0;f<e.length;f++)f in e&&(o[f]=m(e[f],s));return o}const r=Object.create(Object.getPrototypeOf(e));s.set(e,r),e instanceof Error&&(P(r,"message",e.message),e.stack!==void 0&&Object.defineProperty(r,"stack",{value:e.stack,writable:!0,configurable:!0}));for(const o of S(e))P(r,o,m(e[o],s));return r}function ne(e,s={}){if(typeof e!="object"||e===null)return e;if((s.strategy??"auto")==="auto"&&typeof globalThis.structuredClone=="function")try{return globalThis.structuredClone(e)}catch{}return m(e,new Map)}function te(e){const s=new WeakSet,i=r=>{if(!(typeof r!="object"&&typeof r!="function"||r===null||s.has(r))&&(s.add(r),!ArrayBuffer.isView(r))){if(r instanceof Map)for(const[o,f]of r)i(o),i(f);else if(r instanceof Set)for(const o of r)i(o);Object.freeze(r);for(const o of Reflect.ownKeys(r)){const f=Object.getOwnPropertyDescriptor(r,o);f&&"value"in f&&i(f.value)}}};return i(e),e}function re(e,s,i={}){const r=i.distinguishZero??!1,o=new Map,f=(n,t)=>n===t?!r||Object.is(n,t):Number.isNaN(n)&&Number.isNaN(t),l=(n,t)=>{if(n.byteLength!==t.byteLength)return!1;const a=new Uint8Array(n.buffer,n.byteOffset,n.byteLength),y=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);for(let u=0;u<a.length;u++)if(a[u]!==y[u])return!1;return!0},c=(n,t)=>{if(typeof n=="number"&&typeof t=="number")return f(n,t);if(n===t)return!0;if(typeof n!="object"||typeof t!="object"||n===null||t===null||Object.getPrototypeOf(n)!==Object.getPrototypeOf(t))return!1;let a=o.get(n);if(a?.has(t))return!0;a||(a=new Set,o.set(n,a)),a.add(t);const y=d(n,t);return a.delete(t),y},g=(n,t,a,y)=>{for(let u=0;u<t.length;u++)if(!(a.has(u)||!c(n,t[u])||!y(u)))return a.add(u),!0;return!1},d=(n,t)=>{if(n instanceof Date)return f(n.getTime(),t.getTime());if(n instanceof RegExp)return n.source===t.source&&n.flags===t.flags;if(n instanceof Number||n instanceof String||n instanceof Boolean)return c(n.valueOf(),t.valueOf());if(n instanceof ArrayBuffer)return l(new Uint8Array(n),new Uint8Array(t));if(n instanceof DataView)return l(n,t);if(ArrayBuffer.isView(n)){const u=n,w=t;if(u.length!==w.length)return!1;for(let p=0;p<u.length;p++){const b=u[p],k=w[p];if(typeof b=="number"&&typeof k=="number"?!f(b,k):b!==k)return!1}return!0}if(Array.isArray(n)){const u=t;if(n.length!==u.length)return!1;for(let w=0;w<n.length;w++)if(!c(n[w],u[w]))return!1;return!0}if(n instanceof Map){const u=t;if(n.size!==u.size)return!1;let w;for(const[p,b]of n)if(u.has(p)&&(typeof p!="object"||p===null)){if(!c(b,u.get(p)))return!1}else if(typeof p=="object"&&p!==null)(w??=[]).push([p,b]);else return!1;if(w){const p=[...u].filter(([h])=>typeof h=="object"&&h!==null),b=p.map(([h])=>h),k=new Set;for(const[h,U]of w)if(!g(h,b,k,L=>c(U,p[L]?.[1])))return!1}return!0}if(n instanceof Set){const u=t;if(n.size!==u.size)return!1;const w=[];for(const p of n)if(!u.has(p)){if(typeof p!="object"||p===null)return!1;w.push(p)}if(w.length){const p=[...u].filter(k=>typeof k=="object"&&k!==null&&!n.has(k)),b=new Set;for(const k of w)if(!g(k,p,b,()=>!0))return!1}return!0}if(n instanceof Error&&(n.name!==t.name||n.message!==t.message))return!1;const a=S(n),y=S(t);if(a.length!==y.length)return!1;for(const u of a)if(!Object.prototype.propertyIsEnumerable.call(t,u)||!c(n[u],t[u]))return!1;return!0};return c(e,s)}export{ne as deepClone,re as deepEqual,te as deepFreeze,X as deepGet,F as deepHas,v as deepMerge,ee as deepMergeAll,Y as deepSet,$ as deepSetInPlace,x as deepUnset};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { PathSegment } from './path.js';
|
|
2
|
+
/** One change produced by `diff`. Paths are segment arrays; `[]` is the root. */
|
|
3
|
+
export type DiffChange = {
|
|
4
|
+
readonly op: 'add';
|
|
5
|
+
readonly path: readonly PathSegment[];
|
|
6
|
+
readonly value: unknown;
|
|
7
|
+
} | {
|
|
8
|
+
readonly op: 'remove';
|
|
9
|
+
readonly path: readonly PathSegment[];
|
|
10
|
+
readonly from: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
readonly op: 'replace';
|
|
13
|
+
readonly path: readonly PathSegment[];
|
|
14
|
+
readonly from: unknown;
|
|
15
|
+
readonly value: unknown;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Lists the changes that turn `a` into `b`. Plain objects and arrays are compared recursively
|
|
19
|
+
* (arrays by index: appended items are `add`s in ascending order, dropped tail items are `remove`s
|
|
20
|
+
* in descending order); other values are compared with `deepEqual` and reported as `replace`.
|
|
21
|
+
* @example diff({ a: 1 }, { a: 2, b: 3 }) // => [{ op: 'replace', path: ['a'], from: 1, value: 2 }, { op: 'add', path: ['b'], value: 3 }]
|
|
22
|
+
*/
|
|
23
|
+
export declare function diff(a: unknown, b: unknown): DiffChange[];
|
|
24
|
+
/**
|
|
25
|
+
* Applies `diff` changes and returns a new value; the input is never mutated and only
|
|
26
|
+
* containers on changed paths are copied. `add` inserts into arrays (index <= length);
|
|
27
|
+
* `remove` splices arrays. Throws `HLP_OBJECT_PATH_NOT_FOUND` for missing paths and
|
|
28
|
+
* `HLP_UNSAFE_KEY` for unsafe segments.
|
|
29
|
+
* @example applyDiff({ a: 1 }, diff({ a: 1 }, { a: 2 })) // => { a: 2 }
|
|
30
|
+
*/
|
|
31
|
+
export declare function applyDiff<T>(obj: T, changes: readonly DiffChange[]): T;
|
|
32
|
+
export interface FlattenOptions {
|
|
33
|
+
/** Key separator. Default `'.'`. */
|
|
34
|
+
readonly separator?: string;
|
|
35
|
+
/** Flatten arrays with index keys (`a.0`). Default true; false keeps arrays as values. */
|
|
36
|
+
readonly arrays?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Flattens nested plain objects (and arrays) to one level with joined keys.
|
|
40
|
+
* Empty objects and arrays are kept as values so `unflattenObject` restores them.
|
|
41
|
+
* @example flattenObject({ a: { b: 1, c: [2] } }) // => { 'a.b': 1, 'a.c.0': 2 }
|
|
42
|
+
*/
|
|
43
|
+
export declare function flattenObject(obj: object, options?: FlattenOptions): Record<string, unknown>;
|
|
44
|
+
export interface UnflattenOptions {
|
|
45
|
+
/** Key separator. Default `'.'`. */
|
|
46
|
+
readonly separator?: string;
|
|
47
|
+
/** Canonical digit segments create arrays. Default true. */
|
|
48
|
+
readonly arrays?: boolean;
|
|
49
|
+
/** Largest array index accepted (larger throws `HLP_OBJECT_ARRAY_INDEX_LIMIT`). Default 10000. */
|
|
50
|
+
readonly maxArrayIndex?: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Rebuilds nested objects from joined keys. Every segment is checked with `assertSafeKey`,
|
|
54
|
+
* so `{ '__proto__.x': 1 }` throws `HLP_UNSAFE_KEY`. Later keys win on conflicts.
|
|
55
|
+
* @example unflattenObject({ 'a.b': 1, 'a.c.0': 2 }) // => { a: { b: 1, c: [2] } }
|
|
56
|
+
*/
|
|
57
|
+
export declare function unflattenObject(flat: Readonly<Record<string, unknown>>, options?: UnflattenOptions): Record<string, unknown>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{LimitError as _,ValidationError as y}from"../error/index.js";import{isPlainObject as w}from"../is/index.js";import{assertSafeKey as b,hasOwn as h}from"../internal/keys.js";import{at as g,circular as k,copyContainer as I,isContainer as O,put as R}from"./internal.js";import{deepEqual as P}from"./deep.js";function E(u,p){const s=[],c=new Set,i=(e,r,o)=>{if(Array.isArray(e)&&Array.isArray(r)){c.has(e)&&k(),c.add(e);const n=Math.min(e.length,r.length);for(let t=0;t<n;t++)i(e[t],r[t],[...o,t]);for(let t=n;t<r.length;t++)s.push({op:"add",path:[...o,t],value:r[t]});for(let t=e.length-1;t>=n;t--)s.push({op:"remove",path:[...o,t],from:e[t]});c.delete(e);return}if(w(e)&&w(r)){c.has(e)&&k(),c.add(e);for(const n of Object.keys(e))h(r,n)?i(e[n],r[n],[...o,n]):s.push({op:"remove",path:[...o,n],from:e[n]});for(const n of Object.keys(r))h(e,n)||s.push({op:"add",path:[...o,n],value:r[n]});c.delete(e);return}P(e,r)||s.push({op:"replace",path:o,from:e,value:r})};return i(u,p,[]),s}const m=()=>{throw new y("HLP_OBJECT_PATH_NOT_FOUND","A change refers to a path that does not exist.")};function F(u,p){const s=new WeakSet,c=e=>{if(!O(e))return m();if(s.has(e))return e;const r=I(e);return s.add(r),r};let i=u;for(const e of p){const r=e.path;if(!Array.isArray(r))throw new y("HLP_OBJECT_DIFF_INVALID","A change is not valid.");for(const l of r){if(typeof l!="string"&&(typeof l!="number"||!Number.isSafeInteger(l)||l<0))throw new y("HLP_OBJECT_DIFF_INVALID","A change is not valid.");b(l)}const o=r;if(o.length===0){i=e.op==="remove"?void 0:e.value;continue}i=c(i);let n=i;for(let l=0;l<o.length-1;l++){const f=g(o,l);h(n,f)||m();const A=c(n[f]);n[f]=A,n=A}const t=g(o,o.length-1),a=Array.isArray(n)&&typeof t=="number",d=n;switch(e.op){case"add":a?(t>d.length&&m(),d.splice(t,0,e.value)):n[t]=e.value;break;case"remove":h(n,t)||m(),a?d.splice(t,1):Reflect.deleteProperty(n,t);break;case"replace":h(n,t)||m(),n[t]=e.value;break;default:throw new y("HLP_OBJECT_DIFF_INVALID","A change is not valid.")}}return i}function v(u,p={}){const{separator:s=".",arrays:c=!0}=p,i={},e=new Set,r=(o,n)=>{const t=w(o)||c&&Array.isArray(o);if(!t||n!==void 0&&Object.keys(o).length===0){n!==void 0&&R(i,n,t?Array.isArray(o)?[]:{}:o);return}e.has(o)&&k(),e.add(o);for(const a of Object.keys(o))r(o[a],n===void 0?a:`${n}${s}${a}`);e.delete(o)};return r(u,void 0),i}const T=/^(?:0|[1-9]\d{0,14})$/;function N(u,p={}){const{separator:s=".",arrays:c=!0,maxArrayIndex:i=1e4}=p;if(s==="")throw new y("HLP_OBJECT_INVALID_SEPARATOR","The separator must not be empty.");const e={};for(const[r,o]of Object.entries(u)){const n=r.split(s).map(a=>{if(b(a),!c||!T.test(a))return a;const d=Number(a);if(d>i)throw new _("HLP_OBJECT_ARRAY_INDEX_LIMIT","An array index exceeds the limit.");return d});let t=e;for(let a=0;a<n.length-1;a++){const d=g(n,a),l=g(n,a+1);let f=h(t,d)?t[d]:void 0;Array.isArray(f)&&typeof l=="string"?f=Object.assign({},f):O(f)||(f=typeof l=="number"?[]:{}),t[d]=f,t=f}t[g(n,n.length-1)]=o}return e}export{F as applyDiff,E as diff,v as flattenObject,N as unflattenObject};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object helpers (docs/PLAN-HELPERS.md section 2 `object`): shallow transforms, deep paths,
|
|
3
|
+
* merge, clone, freeze, equality, diff/apply and flatten. Prototype-pollution safe (section 5).
|
|
4
|
+
*/
|
|
5
|
+
export { type Path, type PathSegment, MAX_PATH_LENGTH, parsePath, formatPath } from './path.js';
|
|
6
|
+
export { pick, omit, pickBy, omitBy, mapKeys, mapValues, mapEntries, filterKeys, filterValues, invert, invertBy, renameKeys, type CompactObjectOptions, compactObject, defaults, typedKeys, typedValues, typedEntries, typedFromEntries, isShallowEqual, getOwn, size, countValuesBy, type SortKeysOptions, sortKeys, objectToMap, mapToObject, } from './basic.js';
|
|
7
|
+
export { deepGet, deepHas, deepSet, deepSetInPlace, deepUnset, type DeepMergeOptions, deepMerge, deepMergeAll, type DeepCloneOptions, deepClone, type DeepReadonly, deepFreeze, type DeepEqualOptions, deepEqual, } from './deep.js';
|
|
8
|
+
export { type DiffChange, diff, applyDiff, type FlattenOptions, flattenObject, type UnflattenOptions, unflattenObject } from './diff.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{MAX_PATH_LENGTH as p,parsePath as a,formatPath as o}from"./path.js";import{pick as s,omit as y,pickBy as r,omitBy as i,mapKeys as l,mapValues as d,mapEntries as f,filterKeys as m,filterValues as c,invert as O,invertBy as u,renameKeys as E,compactObject as b,defaults as g,typedKeys as h,typedValues as j,typedEntries as D,typedFromEntries as K,isShallowEqual as P,getOwn as M,size as S,countValuesBy as x,sortKeys as B,objectToMap as C,mapToObject as T}from"./basic.js";import{deepGet as q,deepHas as A,deepSet as F,deepSetInPlace as H,deepUnset as k,deepMerge as v,deepMergeAll as w,deepClone as z,deepFreeze as G,deepEqual as U}from"./deep.js";import{diff as I,applyDiff as L,flattenObject as N,unflattenObject as R}from"./diff.js";export{p as MAX_PATH_LENGTH,L as applyDiff,b as compactObject,x as countValuesBy,z as deepClone,U as deepEqual,G as deepFreeze,q as deepGet,A as deepHas,v as deepMerge,w as deepMergeAll,F as deepSet,H as deepSetInPlace,k as deepUnset,g as defaults,I as diff,m as filterKeys,c as filterValues,N as flattenObject,o as formatPath,M as getOwn,O as invert,u as invertBy,P as isShallowEqual,f as mapEntries,l as mapKeys,T as mapToObject,d as mapValues,C as objectToMap,y as omit,i as omitBy,a as parsePath,s as pick,r as pickBy,E as renameKeys,S as size,B as sortKeys,D as typedEntries,K as typedFromEntries,h as typedKeys,j as typedValues,R as unflattenObject};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type AnyRecord = Record<PropertyKey, unknown>;
|
|
2
|
+
/** Sentinel for "no own property". */
|
|
3
|
+
export declare const MISSING: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* Copies a key onto a fresh object without invoking the `__proto__` setter,
|
|
6
|
+
* so copying an own `__proto__` data property can never change a prototype.
|
|
7
|
+
*/
|
|
8
|
+
export declare function put(target: object, key: PropertyKey, value: unknown): void;
|
|
9
|
+
/** Own property value or `MISSING`; never reads through the prototype chain. */
|
|
10
|
+
export declare function ownValue(obj: unknown, key: PropertyKey): unknown;
|
|
11
|
+
/** Shallow copy of a plain object, keeping a null prototype. */
|
|
12
|
+
export declare function copyPlain(obj: Record<string, unknown>): Record<string, unknown>;
|
|
13
|
+
/** Plain object or array. */
|
|
14
|
+
export declare function isContainer(value: unknown): value is Record<string, unknown> | unknown[];
|
|
15
|
+
/** Shallow copy of a container. */
|
|
16
|
+
export declare function copyContainer(value: Record<string, unknown> | unknown[]): Record<string, unknown> | unknown[];
|
|
17
|
+
export declare const circular: () => never;
|
|
18
|
+
/** Own enumerable string and symbol keys. */
|
|
19
|
+
export declare function ownEnumerableKeys(obj: object): PropertyKey[];
|
|
20
|
+
/** Element at a known-valid index (keeps `noUncheckedIndexedAccess` honest without `!`). */
|
|
21
|
+
export declare function at<T>(items: readonly T[], index: number): T;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{ValidationError as o}from"../error/index.js";import{isPlainObject as c}from"../is/index.js";const t=Symbol("missing");function s(n,r,e){r==="__proto__"?Object.defineProperty(n,r,{value:e,writable:!0,enumerable:!0,configurable:!0}):n[r]=e}function y(n,r){return typeof n!="object"&&typeof n!="function"||n===null?t:Object.prototype.hasOwnProperty.call(n,r)?n[r]:t}function u(n){return Object.getPrototypeOf(n)===null?Object.assign(Object.create(null),n):{...n}}function a(n){return Array.isArray(n)||c(n)}function l(n){return Array.isArray(n)?n.slice():u(n)}const f=()=>{throw new o("HLP_OBJECT_CIRCULAR","The value contains a circular reference.")};function w(n){const r=Object.keys(n);for(const e of Object.getOwnPropertySymbols(n))Object.prototype.propertyIsEnumerable.call(n,e)&&r.push(e);return r}function O(n,r){if(r<0||r>=n.length)throw new o("HLP_OBJECT_INVALID_PATH","The property path is not valid.");return n[r]}export{t as MISSING,O as at,f as circular,l as copyContainer,u as copyPlain,a as isContainer,w as ownEnumerableKeys,y as ownValue,s as put};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** One path step: a property name or an array index. */
|
|
2
|
+
export type PathSegment = string | number;
|
|
3
|
+
/** A dotted/bracketed path string or an array of segments. */
|
|
4
|
+
export type Path = string | readonly PathSegment[];
|
|
5
|
+
/** Maximum path length in characters (string paths) or segments (array paths). */
|
|
6
|
+
export declare const MAX_PATH_LENGTH = 4096;
|
|
7
|
+
/**
|
|
8
|
+
* Parses a path into segments. Canonical digit segments (`0`, `12`) become numbers;
|
|
9
|
+
* quoted brackets (`["a.b"]`) keep any characters, with `\` escaping.
|
|
10
|
+
* @example parsePath('a.b[0]["x.y"]') // => ['a', 'b', 0, 'x.y']
|
|
11
|
+
*/
|
|
12
|
+
export declare function parsePath(path: Path): PathSegment[];
|
|
13
|
+
/**
|
|
14
|
+
* Formats segments as a path string that `parsePath` reads back exactly.
|
|
15
|
+
* @example formatPath(['a', 0, 'x.y']) // => 'a[0]["x.y"]'
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatPath(segments: readonly PathSegment[]): string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{LimitError as g,ValidationError as m}from"../error/index.js";const c=4096,o=()=>{throw new m("HLP_OBJECT_INVALID_PATH","The property path is not valid.")},h=e=>e>=48&&e<=57;function d(e){if(!(e.length===0||e.length>15)){for(let t=0;t<e.length;t++)if(!h(e.charCodeAt(t)))return;if(!(e.length>1&&e.startsWith("0")))return Number(e)}}function T(e){if(typeof e!="string"){if(e.length>c)throw new g("HLP_OBJECT_PATH_TOO_LONG","The property path is too long.");const l=[];for(const i of e)typeof i=="number"?((!Number.isSafeInteger(i)||i<0)&&o(),l.push(i)):typeof i=="string"?l.push(i):o();return l}if(e.length>c)throw new g("HLP_OBJECT_PATH_TOO_LONG","The property path is too long.");const t=[],r=e.length;let s=0,n=0;for(;n<r;){const l=e[n];if(l==="["){s===1&&o(),n++;const i=e[n];if(i==='"'||i==="'"){n++;let f="";for(;;){n>=r&&o();const u=e[n];if(u==="\\")n+1>=r&&o(),f+=e[n+1]??"",n+=2;else if(u===i){n++;break}else f+=u??"",n++}e[n]!=="]"&&o(),t.push(f)}else{const f=n;for(;n<r&&h(e.charCodeAt(n));)n++;e[n]!=="]"&&o();const u=d(e.slice(f,n));u===void 0?o():t.push(u)}n++,s=2}else if(l===".")s!==2&&o(),n++,s=1;else{s===2&&o();const i=n;for(;n<r&&e[n]!=="."&&e[n]!=="[";)e[n]==="]"&&o(),n++;const f=e.slice(i,n);t.push(d(f)??f),s=2}}return s===1&&o(),t}const P=/^[A-Z_$][\w$]*$/i;function _(e){let t="";for(const r of e)typeof r=="number"?t+=`[${r}]`:P.test(r)?t+=t===""?r:`.${r}`:t+=`["${r.replace(/["\\]/g,s=>`\\${s}`)}"]`;return t}export{c as MAX_PATH_LENGTH,_ as formatPath,T as parsePath};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Fills `bytes` in 64 KiB chunks. */
|
|
2
|
+
export declare function fillRandom(bytes: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
3
|
+
/** Source of uniform 32-bit words. */
|
|
4
|
+
export type U32Source = () => number;
|
|
5
|
+
/** Buffered crypto word source for one operation (no shared global state). */
|
|
6
|
+
export declare function cryptoSource(expected?: number): U32Source;
|
|
7
|
+
/** Uniform integer in `[0, n)` for `1 <= n <= 2^53` by masked rejection sampling (no modulo bias). */
|
|
8
|
+
export declare function uniformBelow(next: U32Source, n: number): number;
|
|
9
|
+
/** Uniform float in `[0, 1)` with 53 random bits. */
|
|
10
|
+
export declare function unitFloat(next: U32Source): number;
|
|
11
|
+
/** Validates an inclusive integer range whose size is at most 2^53 and returns that size. */
|
|
12
|
+
export declare function rangeSize(min: number, max: number): number;
|
|
13
|
+
/** In-place Fisher-Yates using `next`. */
|
|
14
|
+
export declare function fisherYates<T>(arr: T[], next: U32Source): T[];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{HelperError as m,ValidationError as u}from"../error/index.js";const i=65536,c=4294967296;function s(){const e=globalThis.crypto;if(typeof e?.getRandomValues!="function")throw new m("HLP_RANDOM_UNAVAILABLE","A cryptographic random source (crypto.getRandomValues) is not available.",{kind:"unsupported"});return e}function h(e){const r=s();for(let t=0;t<e.length;t+=i)r.getRandomValues(e.subarray(t,Math.min(e.length,t+i)));return e}function _(e=1){const r=Math.max(1,Math.min(i/4,e)),t=s(),n=new Uint32Array(r);let o=r;return()=>(o>=r&&(t.getRandomValues(n),o=0),n[o++]??0)}function l(e,r){if(r<=1)return 0;if(r<=c){let o=0;for(;2**o<r;)o++;const a=o>=32?4294967295:2**o-1;for(;;){const f=(e()&a)>>>0;if(f<r)return f}}let t=0;for(;2**t*c<r;)t++;const n=2**t-1;for(;;){const o=(e()&n)*c+e();if(o<r)return o}}function A(e){return((e()>>>5)*67108864+(e()>>>6))/9007199254740992}function g(e,r){if(!Number.isSafeInteger(e)||!Number.isSafeInteger(r))throw new u("HLP_RANDOM_RANGE","Bounds must be safe integers.");if(e>r)throw new u("HLP_RANDOM_RANGE","The minimum must not exceed the maximum.");const t=r-e+1;if(t>2**53)throw new u("HLP_RANDOM_RANGE","The range must not exceed 2^53 values.");return t}function b(e,r){for(let t=e.length-1;t>0;t--){const n=l(r,t+1),o=e[t];e[t]=e[n],e[n]=o}return e}export{_ as cryptoSource,h as fillRandom,b as fisherYates,g as rangeSize,l as uniformBelow,A as unitFloat};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export { createSeededRandom } from './seeded.js';
|
|
2
|
+
export type { SeededRandom } from './seeded.js';
|
|
3
|
+
/** Largest `randomBytes` request. */
|
|
4
|
+
export declare const MAX_RANDOM_BYTES: number;
|
|
5
|
+
/** Longest `randomId` / `randomString` / `generatePassword` result. */
|
|
6
|
+
export declare const MAX_RANDOM_LENGTH = 65536;
|
|
7
|
+
/**
|
|
8
|
+
* Uniform integer in `[min, max]` (inclusive); the range may span up to 2^53 values.
|
|
9
|
+
* @example
|
|
10
|
+
* const roll = randomInt(1, 6); // e.g. 4
|
|
11
|
+
* roll >= 1 && roll <= 6 && Number.isInteger(roll); // => true
|
|
12
|
+
*/
|
|
13
|
+
export declare function randomInt(min: number, max: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Uniform float in `[min, max)` with 53 bits of randomness.
|
|
16
|
+
* @example
|
|
17
|
+
* const pct = randomFloat(0, 100); // e.g. 42.1937
|
|
18
|
+
* pct >= 0 && pct < 100; // => true
|
|
19
|
+
*/
|
|
20
|
+
export declare function randomFloat(min?: number, max?: number): number;
|
|
21
|
+
/**
|
|
22
|
+
* `true` with the given probability (default 0.5).
|
|
23
|
+
* @example
|
|
24
|
+
* randomBool(0.1); // e.g. false (true about 10% of the time)
|
|
25
|
+
* randomBool(1); // => true
|
|
26
|
+
*/
|
|
27
|
+
export declare function randomBool(probability?: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Cryptographically random bytes (chunked past the 64 KiB `getRandomValues` limit).
|
|
30
|
+
* @example
|
|
31
|
+
* randomBytes(16).length; // => 16
|
|
32
|
+
*/
|
|
33
|
+
export declare function randomBytes(length: number): Uint8Array<ArrayBuffer>;
|
|
34
|
+
/**
|
|
35
|
+
* Uniformly chosen element, or `undefined` for an empty array. (Named `randomPick` so it
|
|
36
|
+
* does not clash with the object module's `pick`.)
|
|
37
|
+
* @example
|
|
38
|
+
* randomPick(['red', 'green', 'blue']); // e.g. 'green'
|
|
39
|
+
* randomPick([]); // => undefined
|
|
40
|
+
*/
|
|
41
|
+
export declare function randomPick<T>(items: readonly T[]): T | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Element chosen with probability proportional to its weight. Weights must be finite and
|
|
44
|
+
* non-negative with a positive total. `undefined` for empty input.
|
|
45
|
+
* @example
|
|
46
|
+
* randomPickWeighted(['common', 'rare'], [9, 1]); // e.g. 'common' (90% of the time)
|
|
47
|
+
* randomPickWeighted(['common', 'rare'], [1, 0]); // => 'common'
|
|
48
|
+
*/
|
|
49
|
+
export declare function randomPickWeighted<T>(items: readonly T[], weights: readonly number[]): T | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* `k` distinct elements in random order (partial Fisher-Yates on a copy). Throws when `k > length`.
|
|
52
|
+
* @example
|
|
53
|
+
* const picked = sample([1, 2, 3, 4, 5], 2); // e.g. [4, 1]
|
|
54
|
+
* new Set(picked).size; // => 2
|
|
55
|
+
* sample([1, 2], 3); // => throws HLP_RANDOM_SAMPLE_SIZE
|
|
56
|
+
*/
|
|
57
|
+
export declare function sample<T>(items: readonly T[], k: number): T[];
|
|
58
|
+
/**
|
|
59
|
+
* Shuffled copy (unbiased Fisher-Yates); the input is not modified.
|
|
60
|
+
* @example
|
|
61
|
+
* const deck = [1, 2, 3];
|
|
62
|
+
* const mixed = shuffle(deck); // e.g. [3, 1, 2]
|
|
63
|
+
* [...mixed].sort(); // => [1, 2, 3]
|
|
64
|
+
* deck; // => [1, 2, 3] // input unchanged
|
|
65
|
+
*/
|
|
66
|
+
export declare function shuffle<T>(items: readonly T[]): T[];
|
|
67
|
+
/**
|
|
68
|
+
* Shuffles `items` in place and returns it.
|
|
69
|
+
* @example
|
|
70
|
+
* const deck = ['A', 'K', 'Q', 'J'];
|
|
71
|
+
* shuffleInPlace(deck) === deck; // => true
|
|
72
|
+
* deck; // e.g. ['Q', 'A', 'J', 'K']
|
|
73
|
+
*/
|
|
74
|
+
export declare function shuffleInPlace<T>(items: T[]): T[];
|
|
75
|
+
/**
|
|
76
|
+
* Random UUID version 4 (`crypto.randomUUID` when available, e.g. in secure contexts).
|
|
77
|
+
* @example
|
|
78
|
+
* const id = uuidV4(); // e.g. '3b241101-e2bb-4255-8caf-4136c566a962'
|
|
79
|
+
* isUuid(id, 4); // => true
|
|
80
|
+
*/
|
|
81
|
+
export declare function uuidV4(): string;
|
|
82
|
+
/**
|
|
83
|
+
* Time-ordered UUID version 7 (RFC 9562): 48-bit Unix ms timestamp, then 74 random bits.
|
|
84
|
+
* Stateless: two ids in the same millisecond are unordered; use `createUuidV7Generator` for strict order.
|
|
85
|
+
* @example
|
|
86
|
+
* uuidV7(); // e.g. '01922e6a-7c3b-7d4e-9f12-4c1d2e3f4a5b'
|
|
87
|
+
* uuidV7(1700000000000).slice(0, 13); // => '018bcfe5-6800'
|
|
88
|
+
*/
|
|
89
|
+
export declare function uuidV7(timestamp?: number): string;
|
|
90
|
+
/**
|
|
91
|
+
* Returns a UUID v7 generator that is strictly monotonic (RFC 9562 section 6.2 method 1): within one
|
|
92
|
+
* millisecond, or when the clock moves backwards, the 12-bit `rand_a` field is used as a counter.
|
|
93
|
+
* @example const next = createUuidV7Generator(); next() < next() // => true
|
|
94
|
+
*/
|
|
95
|
+
export declare function createUuidV7Generator(clock?: () => number): () => string;
|
|
96
|
+
/**
|
|
97
|
+
* Millisecond timestamp embedded in a UUID v7, or `undefined` for other strings.
|
|
98
|
+
* @example uuidV7Timestamp(uuidV7(1700000000000)) // => 1700000000000
|
|
99
|
+
*/
|
|
100
|
+
export declare function uuidV7Timestamp(uuid: string): number | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* True for an RFC 9562 UUID string (versions 1-8, variant 10xx), optionally of a given version.
|
|
103
|
+
* Without a version, the nil and max UUIDs are also accepted.
|
|
104
|
+
* @example isUuid('01922e6a-7c3b-7d4e-9f12-0123456789ab', 7) // => true
|
|
105
|
+
*/
|
|
106
|
+
export declare function isUuid(value: unknown, version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8): boolean;
|
|
107
|
+
/** URL-safe 64-character alphabet used by `randomId`. */
|
|
108
|
+
export declare const URL_ALPHABET = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
109
|
+
/**
|
|
110
|
+
* Unbiased random id (nanoid-style mask and rejection). Default: 21 URL-safe characters (~126 bits).
|
|
111
|
+
* @example
|
|
112
|
+
* randomId(); // e.g. 'V1StGXR8_Z5jdHi6B-myT'
|
|
113
|
+
* randomId(8, '0123456789abcdef').length; // => 8
|
|
114
|
+
*/
|
|
115
|
+
export declare function randomId(length?: number, alphabet?: string): string;
|
|
116
|
+
declare const CHARSETS: {
|
|
117
|
+
readonly alpha: string;
|
|
118
|
+
readonly numeric: "0123456789";
|
|
119
|
+
readonly alphanumeric: string;
|
|
120
|
+
readonly hex: "0123456789abcdef";
|
|
121
|
+
};
|
|
122
|
+
export interface RandomStringOptions {
|
|
123
|
+
/** Preset character set. Default `alphanumeric`. */
|
|
124
|
+
readonly charset?: keyof typeof CHARSETS;
|
|
125
|
+
/** Custom alphabet (2-256 unique characters); overrides `charset`. */
|
|
126
|
+
readonly alphabet?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Unbiased random string from a preset or custom character set.
|
|
130
|
+
* @example
|
|
131
|
+
* const token = randomString(8, { charset: 'hex' }); // e.g. '9f86d081'
|
|
132
|
+
* /^[0-9a-f]{8}$/.test(token); // => true
|
|
133
|
+
*/
|
|
134
|
+
export declare function randomString(length: number, options?: RandomStringOptions): string;
|
|
135
|
+
/** Characters dropped by `generatePassword({ excludeAmbiguous: true })`. */
|
|
136
|
+
export declare const AMBIGUOUS_CHARACTERS = "Il1|O0o`'\"";
|
|
137
|
+
export interface PasswordOptions {
|
|
138
|
+
/** Default 16; at least 4. */
|
|
139
|
+
readonly length?: number;
|
|
140
|
+
/** Include a-z. Default true. */
|
|
141
|
+
readonly lower?: boolean;
|
|
142
|
+
/** Include A-Z. Default true. */
|
|
143
|
+
readonly upper?: boolean;
|
|
144
|
+
/** Include 0-9. Default true. */
|
|
145
|
+
readonly digits?: boolean;
|
|
146
|
+
/** Include symbols; `true` (default) uses a built-in set, a string supplies your own. */
|
|
147
|
+
readonly symbols?: boolean | string;
|
|
148
|
+
/** Drop look-alike characters (I l 1 | O 0 o and quotes). Default false. */
|
|
149
|
+
readonly excludeAmbiguous?: boolean;
|
|
150
|
+
/** Minimum characters from each enabled class. Default 1. */
|
|
151
|
+
readonly minEach?: number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Password meeting a character-class policy: `minEach` characters from every enabled class,
|
|
155
|
+
* the rest from their union, then an unbiased shuffle.
|
|
156
|
+
* @example
|
|
157
|
+
* const pw = generatePassword({ length: 20, symbols: false }); // e.g. 'q7GmT2xkR4bNw9LpZs3H'
|
|
158
|
+
* pw.length; // => 20
|
|
159
|
+
*/
|
|
160
|
+
export declare function generatePassword(options?: PasswordOptions): string;
|
|
161
|
+
/**
|
|
162
|
+
* Numeric one-time code with uniformly random digits (leading zeros kept), 4-12 digits.
|
|
163
|
+
* @example
|
|
164
|
+
* const code = randomOtp(); // e.g. '042917'
|
|
165
|
+
* /^[0-9]{6}$/.test(code); // => true
|
|
166
|
+
*/
|
|
167
|
+
export declare function randomOtp(digits?: number): string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{LimitError as N,ValidationError as s}from"../error/index.js";import{cryptoSource as l,fillRandom as d,fisherYates as A,rangeSize as D,uniformBelow as m,unitFloat as T}from"./core.js";import{createSeededRandom as ue}from"./seeded.js";const E=16*1024*1024,H=65536;function z(e,n){const t=D(e,n);return e+m(l(2),t)}function X(e=0,n=1){if(!Number.isFinite(e)||!Number.isFinite(n)||!(e<n)||!Number.isFinite(n-e))throw new s("HLP_RANDOM_RANGE","Expected finite bounds with min < max.");const t=l(4);for(;;){const r=e+T(t)*(n-e);if(r<n)return r}}function Y(e=.5){if(!(e>=0&&e<=1))throw new s("HLP_RANDOM_PROBABILITY","The probability must be between 0 and 1.");return T(l(2))<e}function j(e){if(!Number.isInteger(e)||e<0)throw new s("HLP_RANDOM_LENGTH","The length must be a non-negative integer.");if(e>E)throw new N("HLP_RANDOM_TOO_LARGE","The requested byte count exceeds the limit.");return d(new Uint8Array(e))}function k(e){return e.length?e[m(l(2),e.length)]:void 0}function Z(e,n){if(e.length!==n.length)throw new s("HLP_RANDOM_WEIGHTS","Items and weights must have the same length.");if(!e.length)return;let t=0;for(const i of n){if(!Number.isFinite(i)||i<0)throw new s("HLP_RANDOM_WEIGHTS","Weights must be finite and non-negative.");t+=i}if(!(t>0)||!Number.isFinite(t))throw new s("HLP_RANDOM_WEIGHTS","The total weight must be positive and finite.");const r=T(l(2))*t;let o=0,f=-1;for(let i=0;i<n.length;i++){const u=n[i]??0;if(!(u<=0)&&(o+=u,f=i,r<o))return e[i]}return e[f]}function J(e,n){if(!Number.isInteger(n)||n<0||n>e.length)throw new s("HLP_RANDOM_SAMPLE_SIZE","The sample size must be an integer between 0 and the array length.");const t=e.slice(),r=l(n*2);for(let o=0;o<n;o++){const f=o+m(r,t.length-o),i=t[o];t[o]=t[f],t[f]=i}return t.length=n,t}function K(e){return A(e.slice(),l(e.length))}function Q(e){return A(e,l(e.length))}const I=Array.from({length:256},(e,n)=>n.toString(16).padStart(2,"0"));function P(e){let n="";for(let t=0;t<16;t++)(t===4||t===6||t===8||t===10)&&(n+="-"),n+=I[e[t]??0]??"00";return n}function $(){const e=globalThis.crypto;if(typeof e?.randomUUID=="function")return e.randomUUID();const n=d(new Uint8Array(16));return n[6]=(n[6]??0)&15|64,n[8]=(n[8]??0)&63|128,P(n)}const U=2**48-1;function L(e,n,t){const r=new Uint8Array(16);let o=e;for(let f=5;f>=0;f--)r[f]=o%256,o=Math.floor(o/256);return r[6]=112|n>>>8&15,r[7]=n&255,r.set(t.subarray(0,8),8),r[8]=(r[8]??0)&63|128,P(r)}function _(e){if(!Number.isInteger(e)||e<0||e>U)throw new s("HLP_RANDOM_TIMESTAMP","The timestamp must be an integer millisecond value within 48 bits.")}function ee(e=Date.now()){_(e);const n=d(new Uint8Array(10));return L(e,(n[8]??0)<<8|(n[9]??0),n)}function ne(e=Date.now){let n=-1,t=0;return()=>{let r=e();_(r);const o=d(new Uint8Array(10));return r>n?t=((o[8]??0)<<8|(o[9]??0))&2047:(r=n,t++,t>4095&&(r=n+1,t=((o[8]??0)<<8|(o[9]??0))&2047,_(r))),n=r,L(r,t,o)}}function te(e){if(B(e,7))return Number.parseInt(e.slice(0,8)+e.slice(9,13),16)}const G=/^[\da-f]{8}-[\da-f]{4}-([1-8])[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;function B(e,n){if(typeof e!="string"||e.length!==36)return!1;if(n===void 0&&(e==="00000000-0000-0000-0000-000000000000"||e.toLowerCase()==="ffffffff-ffff-ffff-ffff-ffffffffffff"))return!0;const t=G.exec(e);return t!==null&&(n===void 0||Number(t[1])===n)}const W="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";function y(e){if(!Number.isInteger(e)||e<0)throw new s("HLP_RANDOM_LENGTH","The length must be a non-negative integer.");if(e>H)throw new N("HLP_RANDOM_TOO_LARGE","The requested length exceeds the limit.")}function M(e){const n=Array.from(e);if(n.length<2||n.length>256||new Set(n).size!==n.length)throw new s("HLP_RANDOM_ALPHABET","The alphabet must have 2 to 256 unique characters.");return n}function x(e,n){let t=0;for(;2**t<e.length;)t++;const r=2**t-1,o=Math.min(65536,Math.ceil(1.6*r*n/e.length)+8);let f="",i=0;for(;i<n;){const u=d(new Uint8Array(o));for(let c=0;c<o&&i<n;c++){const a=e[(u[c]??0)&r];a!==void 0&&(f+=a,i++)}}return f}function re(e=21,n=W){return y(e),x(M(n),e)}const R="abcdefghijklmnopqrstuvwxyz",O="ABCDEFGHIJKLMNOPQRSTUVWXYZ",p="0123456789",F={alpha:R+O,numeric:p,alphanumeric:p+O+R,hex:"0123456789abcdef"};function oe(e,n={}){return y(e),x(M(n.alphabet??F[n.charset??"alphanumeric"]),e)}const C="Il1|O0o`'\"",V="!@#$%^&*()-_=+[]{};:,.<>?/~";function ie(e={}){const{length:n=16,lower:t=!0,upper:r=!0,digits:o=!0,symbols:f=!0,excludeAmbiguous:i=!1,minEach:u=1}=e;if(y(n),n<4)throw new s("HLP_RANDOM_PASSWORD","The password length must be at least 4.");if(!Number.isInteger(u)||u<0)throw new s("HLP_RANDOM_PASSWORD","minEach must be a non-negative integer.");const c=h=>Array.from(new Set(Array.from(h))).filter(b=>!i||!C.includes(b)),a=[];if(t&&a.push(c(R)),r&&a.push(c(O)),o&&a.push(c(p)),f!==!1&&a.push(c(f===!0?V:f)),!a.length||a.some(h=>h.length===0))throw new s("HLP_RANDOM_PASSWORD","Enable at least one non-empty character class.");if(u*a.length>n)throw new s("HLP_RANDOM_PASSWORD","The length is too short for the required characters.");const S=Array.from(new Set(a.flat())),w=l(n*3),g=[];for(const h of a)for(let b=0;b<u;b++)g.push(h[m(w,h.length)]??"");for(;g.length<n;)g.push(S[m(w,S.length)]??"");return A(g,w).join("")}function fe(e=6){if(!Number.isInteger(e)||e<4||e>12)throw new s("HLP_RANDOM_OTP","OTP length must be an integer between 4 and 12.");return x(Array.from(p),e)}export{C as AMBIGUOUS_CHARACTERS,E as MAX_RANDOM_BYTES,H as MAX_RANDOM_LENGTH,W as URL_ALPHABET,ue as createSeededRandom,ne as createUuidV7Generator,ie as generatePassword,B as isUuid,Y as randomBool,j as randomBytes,X as randomFloat,re as randomId,z as randomInt,fe as randomOtp,k as randomPick,Z as randomPickWeighted,oe as randomString,J as sample,K as shuffle,Q as shuffleInPlace,$ as uuidV4,ee as uuidV7,te as uuidV7Timestamp};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Seeded, NON-cryptographic generator returned by `createSeededRandom`. */
|
|
2
|
+
export interface SeededRandom {
|
|
3
|
+
/** Float in `[0, 1)` with 53 bits. */
|
|
4
|
+
next(): number;
|
|
5
|
+
/** Raw 32-bit unsigned output. */
|
|
6
|
+
nextUint32(): number;
|
|
7
|
+
/** Unbiased integer in `[min, max]` (inclusive, up to 2^53 values). */
|
|
8
|
+
int(min: number, max: number): number;
|
|
9
|
+
/** Float in `[min, max)`. Default `[0, 1)`. */
|
|
10
|
+
float(min?: number, max?: number): number;
|
|
11
|
+
/** `true` with the given probability (default 0.5). */
|
|
12
|
+
bool(probability?: number): boolean;
|
|
13
|
+
/** Uniform element or `undefined` for an empty array. */
|
|
14
|
+
pick<T>(items: readonly T[]): T | undefined;
|
|
15
|
+
/** Shuffled copy. */
|
|
16
|
+
shuffle<T>(items: readonly T[]): T[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* xoshiro128** generator seeded through splitmix32 from a number or string.
|
|
20
|
+
* NOT for security: output is predictable from the seed or a few outputs.
|
|
21
|
+
* @example
|
|
22
|
+
* const a = createSeededRandom('demo');
|
|
23
|
+
* const b = createSeededRandom('demo');
|
|
24
|
+
* a.int(1, 6) === b.int(1, 6); // => true // same seed, same sequence
|
|
25
|
+
* a.shuffle([1, 2, 3, 4, 5]); // => [5, 2, 4, 1, 3] // identical on every run for this seed
|
|
26
|
+
*/
|
|
27
|
+
export declare function createSeededRandom(seed: number | string): SeededRandom;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{ValidationError as b}from"../error/index.js";import{fisherYates as h,rangeSize as T,uniformBelow as s,unitFloat as a}from"./core.js";function d(r){let i=r>>>0;return()=>{i=i+2654435769>>>0;let n=i;return n=Math.imul(n^n>>>16,2246822507),n=Math.imul(n^n>>>13,3266489909),(n^n>>>16)>>>0}}function x(r){if(typeof r=="string"){let n=2166136261;for(let o=0;o<r.length;o++)n=Math.imul(n^r.charCodeAt(o),16777619);return n>>>0}if(!Number.isFinite(r))throw new b("HLP_RANDOM_SEED","The seed must be a finite number or a string.");const i=Math.floor(r/4294967296);return r>>>0^d(i>>>0)()}function M(r){const i=d(x(r));let n=i(),o=i(),l=i(),m=i();(n|o|l|m)===0&&(n=1);const f=(e,t)=>e<<t|e>>>32-t,u=()=>{const e=Math.imul(f(Math.imul(o,5),7),9)>>>0,t=o<<9;return l^=n,m^=o,o^=l,n^=m,l^=t,m=f(m,11),e};return{next:()=>a(u),nextUint32:u,int:(e,t)=>e+s(u,T(e,t)),float:(e=0,t=1)=>{if(!Number.isFinite(e)||!Number.isFinite(t)||!(e<t))throw new b("HLP_RANDOM_RANGE","Expected finite bounds with min < max.");for(;;){const c=e+a(u)*(t-e);if(c<t)return c}},bool:(e=.5)=>{if(!(e>=0&&e<=1))throw new b("HLP_RANDOM_PROBABILITY","The probability must be between 0 and 1.");return a(u)<e},pick:e=>e.length?e[s(u,e.length)]:void 0,shuffle:e=>h(e.slice(),u)}}export{M as createSeededRandom};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data cleaning: record normalization, de-duplication, type coercion, invisible-character and
|
|
3
|
+
* file-name sanitizing, PII masking and redaction (docs/PLAN-HELPERS.md section 2, section 5).
|
|
4
|
+
* HTML sanitizing is out of scope; it stays in `@absoluteui/core`.
|
|
5
|
+
*/
|
|
6
|
+
export { trimStrings, removeNullish, removeEmpty, normalizeRecord, dedupeBy, cleanRecords, coerceRecordTypes, type DeepOptions, type RemoveEmptyOptions, type NormalizeRecordRules, type DedupeOptions, type CleanRecordsOptions, type CoerceType, type CoerceOptions, } from './records.js';
|
|
7
|
+
export { stripInvisible, stripControl, normalizeUnicode, collapseWhitespace, safeFileName, normalizeEmail, normalizePhone, sanitizeSearchQuery, truncateForLog, type StripInvisibleOptions, type SafeFileNameOptions, type NormalizeEmailOptions, type NormalizePhoneOptions, type SanitizeSearchQueryOptions, } from './text.js';
|
|
8
|
+
export { maskPii, redact, DEFAULT_REDACT_KEYS, type MaskPiiOptions, type RedactOptions } from './pii.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{trimStrings as t,removeNullish as i,removeEmpty as p,normalizeRecord as r,dedupeBy as n,cleanRecords as s,coerceRecordTypes as a}from"./records.js";import{stripInvisible as m,stripControl as y,normalizeUnicode as c,collapseWhitespace as O,safeFileName as d,normalizeEmail as z,normalizePhone as R,sanitizeSearchQuery as u,truncateForLog as E}from"./text.js";import{maskPii as h,redact as N,DEFAULT_REDACT_KEYS as f}from"./pii.js";export{f as DEFAULT_REDACT_KEYS,s as cleanRecords,a as coerceRecordTypes,O as collapseWhitespace,n as dedupeBy,h as maskPii,z as normalizeEmail,R as normalizePhone,r as normalizeRecord,c as normalizeUnicode,N as redact,p as removeEmpty,i as removeNullish,d as safeFileName,u as sanitizeSearchQuery,y as stripControl,m as stripInvisible,t as trimStrings,E as truncateForLog};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface MaskPiiOptions {
|
|
2
|
+
/** Mask e-mail addresses (`j***@example.com`). Default true. */
|
|
3
|
+
readonly email?: boolean;
|
|
4
|
+
/** Mask phone numbers of 7-15 digits, keeping the last 2. Default true. */
|
|
5
|
+
readonly phone?: boolean;
|
|
6
|
+
/** Mask Luhn-valid card numbers, keeping the last 4. Default true. */
|
|
7
|
+
readonly card?: boolean;
|
|
8
|
+
/** Mask checksum-valid IBANs, keeping the country code and last 4. Default true. */
|
|
9
|
+
readonly iban?: boolean;
|
|
10
|
+
/** Mask `123-45-6789`-shaped numbers, keeping the last 4. Default true. */
|
|
11
|
+
readonly ssn?: boolean;
|
|
12
|
+
/** Mask character. Default `'*'`. */
|
|
13
|
+
readonly maskChar?: string;
|
|
14
|
+
/** Input longer than this is truncated before masking (bounded work). Default 1 000 000. */
|
|
15
|
+
readonly maxLength?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Masks e-mail addresses, phone numbers, card numbers, IBANs and SSN-shaped numbers in free
|
|
19
|
+
* text (for logs, support tickets, previews). Heuristic: never a substitute for not logging PII.
|
|
20
|
+
* @example maskPii('Mail ada@example.com, card 4111 1111 1111 1111') // => 'Mail a***@example.com, card **** **** **** 1111'
|
|
21
|
+
*/
|
|
22
|
+
export declare function maskPii(text: string, options?: MaskPiiOptions): string;
|
|
23
|
+
/**
|
|
24
|
+
* Default secret-looking key pattern for {@link redact}.
|
|
25
|
+
* @example
|
|
26
|
+
* redact({ name: 'Ada', ssn: '123-45-6789', apiKey: 'k1' }, { keys: [...DEFAULT_REDACT_KEYS, /ssn/i] }); // => { name: 'Ada', ssn: '[REDACTED]', apiKey: '[REDACTED]' }
|
|
27
|
+
*/
|
|
28
|
+
export declare const DEFAULT_REDACT_KEYS: readonly RegExp[];
|
|
29
|
+
export interface RedactOptions {
|
|
30
|
+
/** Key patterns (RegExp) or exact names (case-insensitive) to redact. Default {@link DEFAULT_REDACT_KEYS}. */
|
|
31
|
+
readonly keys?: readonly (RegExp | string)[];
|
|
32
|
+
/** Replacement value. Default `'[REDACTED]'`. */
|
|
33
|
+
readonly replacement?: unknown;
|
|
34
|
+
/** Recurse into nested objects, arrays and Maps. Default true. */
|
|
35
|
+
readonly deep?: boolean;
|
|
36
|
+
/** Deeper values become `'[Truncated]'`. Default 20. */
|
|
37
|
+
readonly maxDepth?: number;
|
|
38
|
+
/** Also run {@link maskPii} on string values. Default false. */
|
|
39
|
+
readonly maskStrings?: boolean | MaskPiiOptions;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns a copy with values under secret-looking keys replaced (for logs and telemetry).
|
|
43
|
+
* Plain objects, arrays and Maps are copied; other objects are kept by reference. Cycles become
|
|
44
|
+
* `'[Circular]'`; unsafe keys (`__proto__`...) are dropped.
|
|
45
|
+
* @example redact({ user: 'ada', password: 'x', headers: { Authorization: 'Bearer t' } })
|
|
46
|
+
* // { user: 'ada', password: '[REDACTED]', headers: { Authorization: '[REDACTED]' } }
|
|
47
|
+
*/
|
|
48
|
+
export declare function redact<T>(value: T, options?: RedactOptions): T;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{isUnsafeKey as x}from"../internal/keys.js";import{isPlainObject as C}from"../is/index.js";const E=/[\w%+.-]{1,64}@[a-z\d-]{1,63}(?:\.[a-z\d-]{1,63}){1,10}/gi,O=/\b[A-Z]{2}\d{2}[A-Z\d]{11,30}\b/g,D=/\b[A-Z]{2}\d{2}(?: [A-Z\d]{4}){2,7}(?: [A-Z\d]{1,4})?\b/g,R=/\b\d(?:[ -]?\d){11,18}\b/g,M=/\b\d{3}-\d{2}-\d{4}\b/g,P=/(?<![\w+])\+?(?:\(\d{1,4}\)|\d)(?:[ ().-]{0,2}\d){6,16}\b/g;function S(c){let u=0,r=!1;for(let a=c.length-1;a>=0;a--){let o=c.charCodeAt(a)-48;r&&(o*=2,o>9&&(o-=9)),u+=o,r=!r}return u%10===0}function T(c){const u=c.slice(4)+c.slice(0,4);let r=0;for(const a of u){const o=a.charCodeAt(0),l=o>=65?o-55:o-48;r=l>9?(r*100+l)%97:(r*10+l)%97}return r===1}function h(c,u,r){let a=0;for(const i of c)i>="0"&&i<="9"&&a++;let o=0,l="";for(const i of c)i>="0"&&i<="9"?(o++,l+=o>a-u?i:r):l+=i;return l}function _(c,u={}){const{email:r=!0,phone:a=!0,card:o=!0,iban:l=!0,ssn:i=!0,maskChar:b="*",maxLength:k=1e6}=u,d=b===""?"*":Array.from(b)[0]??"*";let t=c;if(t.length>k&&(t=t.slice(0,k)),r&&(t=t.replace(E,n=>{const s=n.indexOf("@");return`${Array.from(n.slice(0,s))[0]??""}${d.repeat(3)}${n.slice(s)}`})),l){const n=s=>{const e=s.replaceAll(" ","");if(!T(e))return s;let f=0,y="";const m=e.length;for(const g of s){if(g===" "){y+=g;continue}f++,y+=f<=2||f>m-4?g:d}return y};t=t.replace(D,n).replace(O,n)}return o&&(t=t.replace(R,n=>S(n.replace(/\D/g,""))?h(n,4,d):n)),i&&(t=t.replace(M,n=>h(n,4,d))),a&&(t=t.replace(P,n=>{const s=n.replace(/\D/g,"").length;return s>=7&&s<=15?h(n,2,d):n})),t}const L=[/pass|pwd|secret|token|authori[sz]ation|api[-_]?key|cookie|session|credential|private[-_]?key/i];function I(c,u={}){const{keys:r=L,replacement:a="[REDACTED]",deep:o=!0,maxDepth:l=20,maskStrings:i=!1}=u,b=new Set(r.filter(e=>typeof e=="string").map(e=>e.toLowerCase())),k=r.filter(e=>e instanceof RegExp).map(e=>new RegExp(e.source,e.flags.replace(/[gy]/g,""))),d=e=>b.has(e.toLowerCase())||k.some(f=>f.test(e)),t=i===!1?void 0:i===!0?{}:i,n=new Set,s=(e,f)=>{if(typeof e=="string")return t?_(e,t):e;if(typeof e!="object"||e===null||!(Array.isArray(e)||C(e)||e instanceof Map))return e;if(n.has(e))return"[Circular]";if(f>0&&!o)return e;if(f>=l)return"[Truncated]";n.add(e);try{if(Array.isArray(e))return e.map(p=>s(p,f+1));if(e instanceof Map){const p=new Map;for(const[A,w]of e)p.set(A,typeof A=="string"&&d(A)?a:s(w,f+1));return p}const m=e,g={};for(const p of Object.keys(m))x(p)||(g[p]=d(p)?a:s(m[p],f+1));return g}finally{n.delete(e)}};return s(c,0)}export{L as DEFAULT_REDACT_KEYS,_ as maskPii,I as redact};
|