@pawells/typescript-common 1.1.0 → 1.1.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/build/array/array-chunk.d.ts +10 -4
- package/build/array/array-chunk.d.ts.map +1 -1
- package/build/array/array-chunk.js +10 -4
- package/build/array/array-chunk.js.map +1 -1
- package/build/array/array-contains.d.ts +11 -3
- package/build/array/array-contains.d.ts.map +1 -1
- package/build/array/array-contains.js +11 -3
- package/build/array/array-contains.js.map +1 -1
- package/build/array/array-group-by.d.ts +14 -5
- package/build/array/array-group-by.d.ts.map +1 -1
- package/build/array/array-group-by.js +14 -5
- package/build/array/array-group-by.js.map +1 -1
- package/build/array/array-shuffle.d.ts +12 -3
- package/build/array/array-shuffle.d.ts.map +1 -1
- package/build/array/array-shuffle.js +12 -3
- package/build/array/array-shuffle.js.map +1 -1
- package/build/array/unique.d.ts +13 -3
- package/build/array/unique.d.ts.map +1 -1
- package/build/array/unique.js +13 -3
- package/build/array/unique.js.map +1 -1
- package/build/asserts/errors.d.ts +91 -7
- package/build/asserts/errors.d.ts.map +1 -1
- package/build/asserts/errors.js +91 -7
- package/build/asserts/errors.js.map +1 -1
- package/build/asserts/generic.d.ts +8 -4
- package/build/asserts/generic.d.ts.map +1 -1
- package/build/asserts/generic.js +8 -4
- package/build/asserts/generic.js.map +1 -1
- package/build/enum/enum-entries.d.ts +8 -3
- package/build/enum/enum-entries.d.ts.map +1 -1
- package/build/enum/enum-entries.js +8 -3
- package/build/enum/enum-entries.js.map +1 -1
- package/build/enum/enum-key-by-value.d.ts +10 -5
- package/build/enum/enum-key-by-value.d.ts.map +1 -1
- package/build/enum/enum-key-by-value.js +10 -5
- package/build/enum/enum-key-by-value.js.map +1 -1
- package/build/enum/enum-keys.d.ts +12 -3
- package/build/enum/enum-keys.d.ts.map +1 -1
- package/build/enum/enum-keys.js +12 -3
- package/build/enum/enum-keys.js.map +1 -1
- package/build/enum/enum-safe-value.d.ts +11 -6
- package/build/enum/enum-safe-value.d.ts.map +1 -1
- package/build/enum/enum-safe-value.js +11 -6
- package/build/enum/enum-safe-value.js.map +1 -1
- package/build/enum/validate-enum-value.d.ts +10 -5
- package/build/enum/validate-enum-value.d.ts.map +1 -1
- package/build/enum/validate-enum-value.js +10 -5
- package/build/enum/validate-enum-value.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/number/assert.d.ts +14 -14
- package/build/number/assert.d.ts.map +1 -1
- package/build/object/clone.d.ts +17 -6
- package/build/object/clone.d.ts.map +1 -1
- package/build/object/clone.js +17 -6
- package/build/object/clone.js.map +1 -1
- package/build/object/filter-cached.d.ts +15 -3
- package/build/object/filter-cached.d.ts.map +1 -1
- package/build/object/filter-cached.js +15 -3
- package/build/object/filter-cached.js.map +1 -1
- package/build/object/has-circular-reference.d.ts +12 -3
- package/build/object/has-circular-reference.d.ts.map +1 -1
- package/build/object/has-circular-reference.js +12 -3
- package/build/object/has-circular-reference.js.map +1 -1
- package/build/object/key-value-pairs.d.ts +11 -3
- package/build/object/key-value-pairs.d.ts.map +1 -1
- package/build/object/key-value-pairs.js +11 -3
- package/build/object/key-value-pairs.js.map +1 -1
- package/build/object/map-cached.d.ts +14 -3
- package/build/object/map-cached.d.ts.map +1 -1
- package/build/object/map-cached.js +14 -3
- package/build/object/map-cached.js.map +1 -1
- package/build/object/merge.d.ts +18 -7
- package/build/object/merge.d.ts.map +1 -1
- package/build/object/merge.js +18 -7
- package/build/object/merge.js.map +1 -1
- package/build/object/omit.d.ts +13 -4
- package/build/object/omit.d.ts.map +1 -1
- package/build/object/omit.js +13 -4
- package/build/object/omit.js.map +1 -1
- package/build/string/formatting.d.ts +10 -3
- package/build/string/formatting.d.ts.map +1 -1
- package/build/string/formatting.js +10 -3
- package/build/string/formatting.js.map +1 -1
- package/package.json +1 -1
- package/build/asserts/object.d.ts +0 -138
- package/build/asserts/object.d.ts.map +0 -1
- package/build/asserts/object.js +0 -204
- package/build/asserts/object.js.map +0 -1
- package/build/asserts/string.d.ts +0 -100
- package/build/asserts/string.d.ts.map +0 -1
- package/build/asserts/string.js +0 -185
- package/build/asserts/string.js.map +0 -1
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Checks whether an object contains circular references
|
|
2
|
+
* Checks whether an object (or any nested value) contains circular references.
|
|
3
3
|
*
|
|
4
|
-
* @param obj - The
|
|
5
|
-
* @returns
|
|
4
|
+
* @param obj - The value to inspect
|
|
5
|
+
* @returns `true` if a circular reference is detected, `false` otherwise
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* ObjectHasCircularReference({ a: 1, b: { c: 2 } }); // false
|
|
10
|
+
*
|
|
11
|
+
* const circular: any = { a: 1 };
|
|
12
|
+
* circular.self = circular;
|
|
13
|
+
* ObjectHasCircularReference(circular); // true
|
|
14
|
+
* ```
|
|
6
15
|
*/
|
|
7
16
|
export declare function ObjectHasCircularReference(obj: unknown): boolean;
|
|
8
17
|
//# sourceMappingURL=has-circular-reference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-circular-reference.d.ts","sourceRoot":"","sources":["../../src/object/has-circular-reference.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"has-circular-reference.d.ts","sourceRoot":"","sources":["../../src/object/has-circular-reference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAyChE"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Checks whether an object contains circular references
|
|
2
|
+
* Checks whether an object (or any nested value) contains circular references.
|
|
3
3
|
*
|
|
4
|
-
* @param obj - The
|
|
5
|
-
* @returns
|
|
4
|
+
* @param obj - The value to inspect
|
|
5
|
+
* @returns `true` if a circular reference is detected, `false` otherwise
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* ObjectHasCircularReference({ a: 1, b: { c: 2 } }); // false
|
|
10
|
+
*
|
|
11
|
+
* const circular: any = { a: 1 };
|
|
12
|
+
* circular.self = circular;
|
|
13
|
+
* ObjectHasCircularReference(circular); // true
|
|
14
|
+
* ```
|
|
6
15
|
*/
|
|
7
16
|
export function ObjectHasCircularReference(obj) {
|
|
8
17
|
const seen = new WeakSet();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-circular-reference.js","sourceRoot":"","sources":["../../src/object/has-circular-reference.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"has-circular-reference.js","sourceRoot":"","sources":["../../src/object/has-circular-reference.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAY;IACtD,MAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;IAE3B,MAAM,cAAc,GAAG,CAAC,KAAc,EAAW,EAAE;QAClD,yDAAyD;QACzD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACjD,OAAO,KAAK,CAAC;QACd,CAAC;QAED,8DAA8D;QAC9D,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACb,CAAC;QAED,2BAA2B;QAC3B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEhB,iCAAiC;QACjC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBAC1B,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC1B,OAAO,IAAI,CAAC;gBACb,CAAC;YACF,CAAC;YAED,OAAO,KAAK,CAAC;QACd,CAAC;QAED,kDAAkD;QAClD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAgC,CAAC,CAAC;QAE3D,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACxB,IAAI,cAAc,CAAE,KAAiC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC7D,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;QAED,OAAO,KAAK,CAAC;IACd,CAAC,CAAC;IAEF,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates an object from an array of key-value
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Creates an object from an array of key-value pair tuples.
|
|
3
|
+
* The inverse of {@link ObjectToKeyValuePairs}.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The value type
|
|
6
|
+
* @param entries - Array of `[key, value]` tuples
|
|
7
|
+
* @returns Object whose keys and values come from `entries`
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* ObjectFromKeyValuePairs([['a', 1], ['b', 2]]); // { a: 1, b: 2 }
|
|
12
|
+
* ```
|
|
5
13
|
*/
|
|
6
14
|
export declare function ObjectFromKeyValuePairs<T = unknown>(entries: [string, T][]): Record<string, T>;
|
|
7
15
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-value-pairs.d.ts","sourceRoot":"","sources":["../../src/object/key-value-pairs.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"key-value-pairs.d.ts","sourceRoot":"","sources":["../../src/object/key-value-pairs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAK9F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAExF"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates an object from an array of key-value
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Creates an object from an array of key-value pair tuples.
|
|
3
|
+
* The inverse of {@link ObjectToKeyValuePairs}.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The value type
|
|
6
|
+
* @param entries - Array of `[key, value]` tuples
|
|
7
|
+
* @returns Object whose keys and values come from `entries`
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* ObjectFromKeyValuePairs([['a', 1], ['b', 2]]); // { a: 1, b: 2 }
|
|
12
|
+
* ```
|
|
5
13
|
*/
|
|
6
14
|
export function ObjectFromKeyValuePairs(entries) {
|
|
7
15
|
return entries.reduce((obj, [key, value]) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-value-pairs.js","sourceRoot":"","sources":["../../src/object/key-value-pairs.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"key-value-pairs.js","sourceRoot":"","sources":["../../src/object/key-value-pairs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,uBAAuB,CAAc,OAAsB;IAC1E,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC3C,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACjB,OAAO,GAAG,CAAC;IACZ,CAAC,EAAE,EAAuB,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,qBAAqB,CAAc,GAAsB;IACxE,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAkB,CAAC;AAC7C,CAAC"}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import type { TPropertyMapper, ICachedObjectMapOptions } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Creates a cached version of MapObject for improved performance
|
|
3
|
+
* Creates a cached version of {@link MapObject} for improved performance
|
|
4
|
+
* when mapping the same objects repeatedly.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* Results are cached by hashing the object. Cache entries are evicted in
|
|
7
|
+
* approximately 20% batches when the limit is reached.
|
|
8
|
+
*
|
|
9
|
+
* @template T - The object type being mapped
|
|
10
|
+
* @param options - Configuration options for cache behaviour
|
|
11
|
+
* @returns A cached map function `(cursor, mapper, mapperKey?) => Promise<Record<keyof T, unknown>>`
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const cachedMap = MapObjectCached<User>();
|
|
16
|
+
* const display = await cachedMap(user, (key, value) => String(value));
|
|
17
|
+
* ```
|
|
7
18
|
*/
|
|
8
19
|
export declare function MapObjectCached<T extends object>(options?: ICachedObjectMapOptions): (cursor: T, mapper: TPropertyMapper<T>, mapperKey?: string) => Promise<Record<keyof T, unknown>>;
|
|
9
20
|
//# sourceMappingURL=map-cached.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-cached.d.ts","sourceRoot":"","sources":["../../src/object/map-cached.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAO3E
|
|
1
|
+
{"version":3,"file":"map-cached.d.ts","sourceRoot":"","sources":["../../src/object/map-cached.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAO3E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,GAAE,uBAA4B,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAkGzL"}
|
|
@@ -5,10 +5,21 @@ const DEFAULT_MAX_CACHE_SIZE = 1000;
|
|
|
5
5
|
const CACHE_EVICTION_PERCENTAGE = 0.2; // 20%
|
|
6
6
|
const INITIAL_CACHE_HASH_LENGTH = 16;
|
|
7
7
|
/**
|
|
8
|
-
* Creates a cached version of MapObject for improved performance
|
|
8
|
+
* Creates a cached version of {@link MapObject} for improved performance
|
|
9
|
+
* when mapping the same objects repeatedly.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
11
|
+
* Results are cached by hashing the object. Cache entries are evicted in
|
|
12
|
+
* approximately 20% batches when the limit is reached.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The object type being mapped
|
|
15
|
+
* @param options - Configuration options for cache behaviour
|
|
16
|
+
* @returns A cached map function `(cursor, mapper, mapperKey?) => Promise<Record<keyof T, unknown>>`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const cachedMap = MapObjectCached<User>();
|
|
21
|
+
* const display = await cachedMap(user, (key, value) => String(value));
|
|
22
|
+
* ```
|
|
12
23
|
*/
|
|
13
24
|
export function MapObjectCached(options = {}) {
|
|
14
25
|
const { maxCacheSize = DEFAULT_MAX_CACHE_SIZE } = options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-cached.js","sourceRoot":"","sources":["../../src/object/map-cached.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,gCAAgC;AAChC,MAAM,sBAAsB,GAAG,IA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QAAC,MAAM,CAAC;YACR,uEAAuE;YACvE,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;QACnD,CAAC;QAED,mCAAmC;QACnC,IAAI,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAChC,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAChD,OAAO,OAAO,CAAC,OAAO,CAAC,YAAY,IAAI,EAA8B,CAAC,CAAC;QACxE,CAAC;QAED,uBAAuB;QACvB,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEzC,mBAAmB;QACnB,WAAW,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACnC,kBAAkB,EAAE,CAAC;QAErB,kDAAkD;QAClD,IAAI,kBAAkB,GAAG,YAAY,EAAE,CAAC;YACvC,kBAAkB,EAAE,CAAC;QACtB,CAAC;QAED,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC,CAAC;AACH,CAAC"}
|
package/build/object/merge.d.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Merges two objects deeply with security protections
|
|
2
|
+
* Merges two objects deeply with security protections.
|
|
3
|
+
*
|
|
4
|
+
* **Merge behaviour:**
|
|
5
|
+
* - Primitive values from `source` overwrite those in `target`.
|
|
6
|
+
* - Arrays are concatenated (target array followed by source array).
|
|
7
|
+
* - Plain objects are recursively merged.
|
|
3
8
|
*
|
|
4
9
|
* **Security Features:**
|
|
5
|
-
* - Prevents prototype pollution by filtering dangerous keys
|
|
6
|
-
* - Safely handles nested object merging
|
|
7
|
-
*
|
|
10
|
+
* - Prevents prototype pollution by filtering dangerous keys (`__proto__`, `constructor`, `prototype`).
|
|
11
|
+
* - Safely handles nested object merging.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The type of the target object
|
|
14
|
+
* @param target - Target object (base values)
|
|
15
|
+
* @param source - Source object (values to merge in)
|
|
16
|
+
* @returns A new merged object (neither `target` nor `source` is mutated)
|
|
8
17
|
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* ObjectMerge({ a: 1, b: { x: 1 } }, { b: { y: 2 }, c: 3 });
|
|
21
|
+
* // { a: 1, b: { x: 1, y: 2 }, c: 3 }
|
|
22
|
+
* ```
|
|
12
23
|
*/
|
|
13
24
|
export declare function ObjectMerge<T extends object = object>(target: T, source: Partial<T>): T;
|
|
14
25
|
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/object/merge.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/object/merge.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CA6BvF"}
|
package/build/object/merge.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import { filterDangerousKeys } from './security-utils.js';
|
|
2
2
|
/**
|
|
3
|
-
* Merges two objects deeply with security protections
|
|
3
|
+
* Merges two objects deeply with security protections.
|
|
4
|
+
*
|
|
5
|
+
* **Merge behaviour:**
|
|
6
|
+
* - Primitive values from `source` overwrite those in `target`.
|
|
7
|
+
* - Arrays are concatenated (target array followed by source array).
|
|
8
|
+
* - Plain objects are recursively merged.
|
|
4
9
|
*
|
|
5
10
|
* **Security Features:**
|
|
6
|
-
* - Prevents prototype pollution by filtering dangerous keys
|
|
7
|
-
* - Safely handles nested object merging
|
|
8
|
-
*
|
|
11
|
+
* - Prevents prototype pollution by filtering dangerous keys (`__proto__`, `constructor`, `prototype`).
|
|
12
|
+
* - Safely handles nested object merging.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type of the target object
|
|
15
|
+
* @param target - Target object (base values)
|
|
16
|
+
* @param source - Source object (values to merge in)
|
|
17
|
+
* @returns A new merged object (neither `target` nor `source` is mutated)
|
|
9
18
|
*
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
12
|
-
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* ObjectMerge({ a: 1, b: { x: 1 } }, { b: { y: 2 }, c: 3 });
|
|
22
|
+
* // { a: 1, b: { x: 1, y: 2 }, c: 3 }
|
|
23
|
+
* ```
|
|
13
24
|
*/
|
|
14
25
|
export function ObjectMerge(target, source) {
|
|
15
26
|
if (!target || typeof target !== 'object')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/object/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/object/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,WAAW,CAA4B,MAAS,EAAE,MAAkB;IACnF,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAW,CAAC;IAC9D,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAEzD,yDAAyD;IACzD,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAA6B,CAAC,CAAC;IAEtE,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;IAC7B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACvC,wDAAwD;QACxD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE,CAAC;YAC5D,OAAO;QACR,CAAC;QAED,MAAM,WAAW,GAAI,MAA8B,CAAC,GAAG,CAAC,CAAC;QACzD,MAAM,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QAEpC,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7D,MAA8B,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,EAAE,GAAG,WAAW,CAAC,CAAC;QACzE,CAAC;aAAM,IACN,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAC/F,CAAC;YACD,MAA8B,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QAC9E,CAAC;aAAM,CAAC;YACN,MAA8B,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;QACpD,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,MAAW,CAAC;AACpB,CAAC"}
|
package/build/object/omit.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates a new object without the specified keys from the source object
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
2
|
+
* Creates a new object without the specified keys from the source object.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the source object
|
|
5
|
+
* @template K - The keys to omit (must be keys of `T`)
|
|
6
|
+
* @param obj - Source object
|
|
7
|
+
* @param keys - Array of keys to exclude from the result
|
|
8
|
+
* @returns A shallow copy of `obj` without the specified keys
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const user = { id: 1, name: 'John', password: 'secret' };
|
|
13
|
+
* ObjectOmit(user, ['password']); // { id: 1, name: 'John' }
|
|
14
|
+
* ```
|
|
6
15
|
*/
|
|
7
16
|
export declare function ObjectOmit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
8
17
|
//# sourceMappingURL=omit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit.d.ts","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"omit.d.ts","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAU7F"}
|
package/build/object/omit.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Creates a new object without the specified keys from the source object
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
2
|
+
* Creates a new object without the specified keys from the source object.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the source object
|
|
5
|
+
* @template K - The keys to omit (must be keys of `T`)
|
|
6
|
+
* @param obj - Source object
|
|
7
|
+
* @param keys - Array of keys to exclude from the result
|
|
8
|
+
* @returns A shallow copy of `obj` without the specified keys
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const user = { id: 1, name: 'John', password: 'secret' };
|
|
13
|
+
* ObjectOmit(user, ['password']); // { id: 1, name: 'John' }
|
|
14
|
+
* ```
|
|
6
15
|
*/
|
|
7
16
|
export function ObjectOmit(obj, keys) {
|
|
8
17
|
if (!obj) {
|
package/build/object/omit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"omit.js","sourceRoot":"","sources":["../../src/object/omit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,UAAU,CAAsC,GAAM,EAAE,IAAS;IAChF,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO,EAAgB,CAAC;IACzB,CAAC;IAED,MAAM,MAAM,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;IAC1B,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACpB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IACH,OAAO,MAAoB,CAAC;AAC7B,CAAC"}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import type { TFormatParams, TFormatArgs } from './types';
|
|
2
2
|
/**
|
|
3
|
-
* Escapes a string for safe use in HTML
|
|
3
|
+
* Escapes a string for safe use in HTML by replacing special characters with
|
|
4
|
+
* their HTML entity equivalents.
|
|
4
5
|
*
|
|
5
|
-
* @param str The input string
|
|
6
|
-
* @returns The HTML-escaped string
|
|
6
|
+
* @param str - The input string
|
|
7
|
+
* @returns The HTML-escaped string
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* EscapeHTML('<b>Hello & "World"</b>');
|
|
12
|
+
* // '<b>Hello & "World"</b>'
|
|
13
|
+
* ```
|
|
7
14
|
*/
|
|
8
15
|
export declare function EscapeHTML(str: string): string;
|
|
9
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/string/formatting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1D
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/string/formatting.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE1D;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAW9C;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,aAAa,GAAG,WAAW,GACjC,MAAM,CAoBR;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,SAAQ,GAAG,MAAM,CAUvF;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,SAAM,EAAE,MAAM,UAAO,GAAG,MAAM,CASxF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG7C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAG9E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG7C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CASpE"}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Escapes a string for safe use in HTML
|
|
2
|
+
* Escapes a string for safe use in HTML by replacing special characters with
|
|
3
|
+
* their HTML entity equivalents.
|
|
3
4
|
*
|
|
4
|
-
* @param str The input string
|
|
5
|
-
* @returns The HTML-escaped string
|
|
5
|
+
* @param str - The input string
|
|
6
|
+
* @returns The HTML-escaped string
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* EscapeHTML('<b>Hello & "World"</b>');
|
|
11
|
+
* // '<b>Hello & "World"</b>'
|
|
12
|
+
* ```
|
|
6
13
|
*/
|
|
7
14
|
export function EscapeHTML(str) {
|
|
8
15
|
if (str && typeof str === 'string') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src/string/formatting.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src/string/formatting.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACrC,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,GAAG;aACR,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC;aACvB,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;aACtB,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;aACtB,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC;aACxB,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,YAAY,CAC3B,QAAgB,EAChB,MAAmC;IAEnC,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC9C,IAAI,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,EAAE,CAAC;YACrE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAA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AC3D,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,CAAC;IAC9B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAChD,KAAK,EAAE,CAAC;QACR,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pawells/typescript-common",
|
|
3
3
|
"displayName": "TypeScript Common Utilities",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.1",
|
|
5
5
|
"description": "Shared TypeScript utility library — array, object, string, time, and enum helpers. ESM-only, no runtime dependencies.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./build/index.js",
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { IAssertException } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Error thrown when a value is not a valid object or fails an object assertion.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* throw new ObjectError('Value is not a valid object');
|
|
7
|
-
*/
|
|
8
|
-
export declare class ObjectError extends Error {
|
|
9
|
-
constructor(message?: string);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Error thrown when an object is missing a required property or a property fails an assertion.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* throw new PropertyError('Object is missing required property');
|
|
16
|
-
*/
|
|
17
|
-
export declare class ObjectPropertyError extends Error {
|
|
18
|
-
constructor(message?: string);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Asserts that a value is a plain object (not null, not an array, not a function).
|
|
22
|
-
*
|
|
23
|
-
* This method validates that the provided value is an object type, excluding null,
|
|
24
|
-
* arrays, and functions which are technically objects in JavaScript but not plain
|
|
25
|
-
* objects. After this assertion, the value is typed as Record<string, unknown>
|
|
26
|
-
* for safe property access.
|
|
27
|
-
*
|
|
28
|
-
* @template TError - Custom error type to throw on failure
|
|
29
|
-
* @param value - The value to validate as an object
|
|
30
|
-
* @param exception - Optional exception configuration for custom error handling
|
|
31
|
-
* @throws {ObjectError} When value is not a plain object
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* AssertObject({ name: "John" }); // ✓ Valid (plain object)
|
|
36
|
-
* AssertObject({}); // ✓ Valid (empty object)
|
|
37
|
-
* AssertObject(new Date()); // ✓ Valid (object instance)
|
|
38
|
-
* AssertObject([1, 2, 3]); // ✗ Throws ObjectError (array)
|
|
39
|
-
* AssertObject(null); // ✗ Throws ObjectError (null)
|
|
40
|
-
* AssertObject("string"); // ✗ Throws ObjectError (primitive)
|
|
41
|
-
* AssertObject(() => {}); // ✗ Throws ObjectError (function)
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function AssertObject(value: unknown, exception?: IAssertException): asserts value is Record<string, unknown>;
|
|
45
|
-
/**
|
|
46
|
-
* Asserts that an object has a specific property (inherited or own).
|
|
47
|
-
*
|
|
48
|
-
* This method validates that the specified property exists in the object,
|
|
49
|
-
* including properties from the prototype chain. Uses the 'in' operator
|
|
50
|
-
* for property detection. This is useful for checking if an object conforms
|
|
51
|
-
* to an expected interface or has required properties.
|
|
52
|
-
*
|
|
53
|
-
* @template T - The object type
|
|
54
|
-
* @template K - The property key type
|
|
55
|
-
* @template TError - Custom error type to throw on failure
|
|
56
|
-
* @param value - The object to check for the property
|
|
57
|
-
* @param property - The property key to check for
|
|
58
|
-
* @param exception - Optional exception configuration for custom error handling
|
|
59
|
-
* @throws {PropertyError} When object does not have the specified property
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* const obj = { name: "John", age: 30 };
|
|
64
|
-
* AssertHasProperty(obj, "name"); // ✓ Valid (own property)
|
|
65
|
-
* AssertHasProperty(obj, "toString"); // ✓ Valid (inherited property)
|
|
66
|
-
* AssertHasProperty(obj, "invalid"); // ✗ Throws PropertyError
|
|
67
|
-
*
|
|
68
|
-
* // Type narrowing with property presence
|
|
69
|
-
* function processUser(obj: unknown) {
|
|
70
|
-
* AssertObject(obj);
|
|
71
|
-
* AssertHasProperty(obj, "name");
|
|
72
|
-
* // obj["name"] is now accessible safely
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export declare function AssertObjectHasProperty<T extends object, K extends PropertyKey>(value: T, property: K, exception?: IAssertException): void;
|
|
77
|
-
/**
|
|
78
|
-
* Asserts that an object has a specific own property (not inherited).
|
|
79
|
-
*
|
|
80
|
-
* This method validates that the specified property exists as an own property
|
|
81
|
-
* of the object, excluding properties from the prototype chain. Uses
|
|
82
|
-
* Object.prototype.hasOwnProperty.call() for reliable detection. This is useful
|
|
83
|
-
* when you need to ensure a property is directly defined on the object.
|
|
84
|
-
*
|
|
85
|
-
* @template T - The object type
|
|
86
|
-
* @template K - The property key type
|
|
87
|
-
* @template TError - Custom error type to throw on failure
|
|
88
|
-
* @param value - The object to check for the own property
|
|
89
|
-
* @param property - The property key to check for
|
|
90
|
-
* @param exception - Optional exception configuration for custom error handling
|
|
91
|
-
* @throws {PropertyError} When object does not have the specified own property
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* const obj = { name: "John" };
|
|
96
|
-
* AssertHasOwnProperty(obj, "name"); // ✓ Valid (own property)
|
|
97
|
-
* AssertHasOwnProperty(obj, "toString"); // ✗ Throws (inherited property)
|
|
98
|
-
* AssertHasOwnProperty(obj, "invalid"); // ✗ Throws (doesn't exist)
|
|
99
|
-
*
|
|
100
|
-
* // Checking for data vs inherited methods
|
|
101
|
-
* function validateUserData(obj: object) {
|
|
102
|
-
* AssertHasOwnProperty(obj, "id"); // Must be own property
|
|
103
|
-
* AssertHasOwnProperty(obj, "name"); // Must be own property
|
|
104
|
-
* }
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
export declare function AssertObjectHasOwnProperty<T extends object, K extends PropertyKey>(value: T, property: K, exception?: IAssertException): void;
|
|
108
|
-
/**
|
|
109
|
-
* Asserts that a specific property of an object is not null or undefined.
|
|
110
|
-
*
|
|
111
|
-
* This method validates that the specified property exists and has a non-nullish value.
|
|
112
|
-
* It combines property existence checking with null/undefined validation. Useful for
|
|
113
|
-
* validating that required object properties have been properly initialized.
|
|
114
|
-
*
|
|
115
|
-
* @template T - The object type
|
|
116
|
-
* @template K - The property key type (must be a key of T)
|
|
117
|
-
* @template TError - Custom error type to throw on failure
|
|
118
|
-
* @param value - The object to check
|
|
119
|
-
* @param property - The property key to validate for non-null value
|
|
120
|
-
* @param exception - Optional exception configuration for custom error handling
|
|
121
|
-
* @throws {PropertyError} When property is null, undefined, or doesn't exist
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* const user = { id: 123, name: "John", email: null };
|
|
126
|
-
* AssertPropertyNotNull(user, "id"); // ✓ Valid (123 is not null/undefined)
|
|
127
|
-
* AssertPropertyNotNull(user, "name"); // ✓ Valid ("John" is not null/undefined)
|
|
128
|
-
* AssertPropertyNotNull(user, "email"); // ✗ Throws PropertyError (null)
|
|
129
|
-
*
|
|
130
|
-
* // Type narrowing for property values
|
|
131
|
-
* function processUser(user: { name?: string | null }) {
|
|
132
|
-
* AssertPropertyNotNull(user, "name");
|
|
133
|
-
* // user.name is now typed as string (null/undefined excluded)
|
|
134
|
-
* }
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
export declare function AssertObjectPropertyNotNull<T extends object, K extends keyof T>(value: T, property: K, exception?: IAssertException): void;
|
|
138
|
-
//# sourceMappingURL=object.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/asserts/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAM9C;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,KAAK;gBACzB,OAAO,CAAC,EAAE,MAAM;CAK5B;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBACjC,OAAO,CAAC,EAAE,MAAM;CAK5B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBvH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAU9I;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAUjJ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAW9I"}
|