@webdeveric/utils 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/type-assertion.js +185 -10
- package/dist/cjs/type-assertion.js.map +1 -1
- package/dist/cjs/type-predicate-factory.js +19 -0
- package/dist/cjs/type-predicate-factory.js.map +1 -0
- package/dist/cjs/type-predicate.js +53 -20
- package/dist/cjs/type-predicate.js.map +1 -1
- package/dist/mjs/type-assertion.js +155 -9
- package/dist/mjs/type-assertion.js.map +1 -1
- package/dist/mjs/type-predicate-factory.js +11 -0
- package/dist/mjs/type-predicate-factory.js.map +1 -0
- package/dist/mjs/type-predicate.js +38 -14
- package/dist/mjs/type-predicate.js.map +1 -1
- package/dist/types/type-assertion.d.ts +35 -4
- package/dist/types/type-assertion.d.ts.map +1 -1
- package/dist/types/type-predicate-factory.d.ts +7 -0
- package/dist/types/type-predicate-factory.d.ts.map +1 -0
- package/dist/types/type-predicate.d.ts +21 -6
- package/dist/types/type-predicate.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +23 -22
- package/src/asArray.ts +0 -3
- package/src/capitalize.ts +0 -1
- package/src/clamp.ts +0 -7
- package/src/compose.ts +0 -13
- package/src/convert.ts +0 -30
- package/src/delay.ts +0 -23
- package/src/delayAnimationFrame.ts +0 -35
- package/src/getMaxValue.ts +0 -16
- package/src/getMinValue.ts +0 -16
- package/src/getOwnKeys.ts +0 -3
- package/src/getOwnProperties.ts +0 -3
- package/src/getType.ts +0 -3
- package/src/index.ts +0 -24
- package/src/isEmpty.ts +0 -21
- package/src/isObject.ts +0 -3
- package/src/joinStrings.ts +0 -6
- package/src/node/fcrdns.ts +0 -37
- package/src/node/index.ts +0 -1
- package/src/normalize.ts +0 -102
- package/src/secToString.ts +0 -45
- package/src/toPascalCase.ts +0 -29
- package/src/trimEnd.ts +0 -5
- package/src/trimIndentation.ts +0 -18
- package/src/trimStart.ts +0 -5
- package/src/type-assertion.ts +0 -20
- package/src/type-predicate.ts +0 -48
- package/src/types.ts +0 -42
- package/src/uniqueItems.ts +0 -3
- package/src/until.ts +0 -130
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAI7D,aAAa;AAEb,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEvF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAE/G,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEvF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAoB,EAAE,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC;AAE1F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAsB,EAAE,CAAC,OAAO,KAAK,KAAK,WAAW,CAAC;AAEhG,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEvF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC;AAExE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAsB,EAAE,CAChE,QAAQ,CAAC,KAAK,CAAC;IACf,QAAQ,CAAC,KAAK,CAA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AEvG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAyB,EAAE;IACtE,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;AACxF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAI,KAAc,EAAsC,EAAE;IAChG,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAc,EAAkC,EAAE;IACxF,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC7E,CAAC,CAAC"}
|
|
@@ -1,5 +1,36 @@
|
|
|
1
|
-
import type { NumericValue } from './types.js';
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
1
|
+
import type { NumericString, NumericValue, Primitive, StringRecord, UnknownRecord } from './types.js';
|
|
2
|
+
export declare function assertIsBigInt(input: unknown, error?: string | Error): asserts input is bigint;
|
|
3
|
+
export declare function assertIsBoolean(input: unknown, error?: string | Error): asserts input is boolean;
|
|
4
|
+
export declare function assertIsFiniteNumber(input: unknown, error?: string | Error): asserts input is number;
|
|
5
|
+
export declare function assertIsInteger(input: unknown, error?: string | Error): asserts input is number;
|
|
6
|
+
export declare function assertIsIntString(input: unknown, error?: string | Error): asserts input is NumericString;
|
|
7
|
+
export declare function assertIsLengthAware(input: unknown, error?: string | Error): asserts input is {
|
|
8
|
+
length: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function assertIsNull(input: unknown, error?: string | Error): asserts input is null;
|
|
11
|
+
export declare function assertIsNumber(input: unknown, error?: string | Error): asserts input is number;
|
|
12
|
+
export declare function assertIsNumericString(input: unknown, error?: string | Error): asserts input is NumericString;
|
|
13
|
+
export declare function assertIsNumericValue(input: unknown, error?: string | Error): asserts input is NumericValue;
|
|
14
|
+
export declare function assertIsNumericValueArray(input: unknown, error?: string | Error): asserts input is NumericValue[];
|
|
15
|
+
export declare function assertIsObject<T extends UnknownRecord = UnknownRecord>(input: unknown, error?: string | Error): asserts input is T;
|
|
16
|
+
export declare function assertIsOptionalBigInt(input: unknown, error?: string | Error): asserts input is bigint | undefined;
|
|
17
|
+
export declare function assertIsOptionalBoolean(input: unknown, error?: string | Error): asserts input is boolean | undefined;
|
|
18
|
+
export declare function assertIsOptionalNull(input: unknown, error?: string | Error): asserts input is null | undefined;
|
|
19
|
+
export declare function assertIsOptionalNumber(input: unknown, error?: string | Error): asserts input is number | undefined;
|
|
20
|
+
export declare function assertIsOptionalString(input: unknown, error?: string | Error): asserts input is string | undefined;
|
|
21
|
+
export declare function assertIsOptionalSymbol(input: unknown, error?: string | Error): asserts input is symbol | undefined;
|
|
22
|
+
export declare function assertIsPositiveFiniteNumber(input: unknown, error?: string | Error): asserts input is number;
|
|
23
|
+
export declare function assertIsNumberGTEOne(input: unknown, error?: string | Error): asserts input is number;
|
|
24
|
+
export declare function assertIsPositiveInteger(input: unknown, error?: string | Error): asserts input is number;
|
|
25
|
+
export declare function assertIsPrimitive(input: unknown, error?: string | Error): asserts input is Primitive;
|
|
26
|
+
export declare function assertIsPromiseFulfilledResult<T>(input: unknown, error?: string | Error): asserts input is PromiseFulfilledResult<T>;
|
|
27
|
+
export declare function assertIsPromiseRejectedResult(input: unknown, error?: string | Error): asserts input is PromiseRejectedResult;
|
|
28
|
+
export declare function assertIsPropertyKey(input: unknown, error?: string | Error): asserts input is PropertyKey;
|
|
29
|
+
export declare function assertIsString(input: unknown, error?: string | Error): asserts input is string;
|
|
30
|
+
export declare function assertIsStringMatching(input: unknown, pattern: RegExp, error?: string | Error): asserts input is string;
|
|
31
|
+
export declare function assertIsStringRecord(input: unknown, error?: string | Error): asserts input is StringRecord;
|
|
32
|
+
export declare function assertIsStringWithLength(input: unknown, error?: string | Error): asserts input is string;
|
|
33
|
+
export declare function assertIsSymbol(input: unknown, error?: string | Error): asserts input is symbol;
|
|
34
|
+
export declare function assertIsUndefined(input: unknown, error?: string | Error): asserts input is undefined;
|
|
35
|
+
export declare function assertExhaustive(_: never, error?: string | Error): never;
|
|
5
36
|
//# sourceMappingURL=type-assertion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-assertion.d.ts","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-assertion.d.ts","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMtG,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAA+B,GAC9C,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAAgC,GAC/C,OAAO,CAAC,KAAK,IAAI,OAAO,CAI1B;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAAsC,GACrD,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAAiC,GAChD,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAAwC,GACvD,OAAO,CAAC,KAAK,IAAI,aAAa,CAIhC;AAED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AAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAAgD,GAC/D,OAAO,CAAC,KAAK,IAAI,qBAAqB,CAIxC;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAAqC,GACpD,OAAO,CAAC,KAAK,IAAI,WAAW,CAI9B;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAA+B,GAC9C,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,KAAK,GAAE,MAAM,GAAG,KAAwD,GACvE,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAAsC,GACrD,OAAO,CAAC,KAAK,IAAI,YAAY,CAI/B;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAA2C,GAC1D,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAA+B,GAC9C,OAAO,CAAC,KAAK,IAAI,MAAM,CAIzB;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,MAAM,GAAG,KAAgC,GAC/C,OAAO,CAAC,KAAK,IAAI,SAAS,CAI5B;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,GAAE,MAAM,GAAG,KAAiC,GAAG,KAAK,CAEnG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TypePredicateFn, UnknownRecord } from './types.js';
|
|
2
|
+
export declare const createIsEnumPredicate: <T extends UnknownRecord>(enumObject: T) => TypePredicateFn<T[keyof T]>;
|
|
3
|
+
export declare const everyItem: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T[]>;
|
|
4
|
+
export declare const maybeArray: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | T[]>;
|
|
5
|
+
export declare const maybeNull: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | null>;
|
|
6
|
+
export declare const maybeUndefined: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | undefined>;
|
|
7
|
+
//# sourceMappingURL=type-predicate-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-predicate-factory.d.ts","sourceRoot":"","sources":["../../src/type-predicate-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEjE,eAAO,MAAM,qBAAqB,yEAMjC,CAAC;AAEF,eAAO,MAAM,SAAS,4DAG4B,CAAC;AAEnD,eAAO,MAAM,UAAU,gEAG6C,CAAC;AAErE,eAAO,MAAM,SAAS,iEAGgB,CAAC;AAEvC,eAAO,MAAM,cAAc,sEAGyB,CAAC"}
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import type { NumericValue, Primitive, UnknownRecord } from './types.js';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
1
|
+
import type { NumericValue, Primitive, StringRecord, UnknownRecord } from './types.js';
|
|
2
|
+
export declare const isString: (input: unknown) => input is string;
|
|
3
|
+
export declare const isNumber: (input: unknown) => input is number;
|
|
4
|
+
export declare const isBigInt: (input: unknown) => input is bigint;
|
|
5
|
+
export declare const isBoolean: (input: unknown) => input is boolean;
|
|
6
|
+
export declare const isUndefined: (input: unknown) => input is undefined;
|
|
7
|
+
export declare const isSymbol: (input: unknown) => input is symbol;
|
|
8
|
+
export declare const isNull: (input: unknown) => input is null;
|
|
9
|
+
export declare const isPrimitive: (input: unknown) => input is Primitive;
|
|
10
|
+
export declare const isOptionalString: import("./types.js").TypePredicateFn<string | undefined>;
|
|
11
|
+
export declare const isOptionalNumber: import("./types.js").TypePredicateFn<number | undefined>;
|
|
12
|
+
export declare const isOptionalBigInt: import("./types.js").TypePredicateFn<bigint | undefined>;
|
|
13
|
+
export declare const isOptionalBoolean: import("./types.js").TypePredicateFn<boolean | undefined>;
|
|
14
|
+
export declare const isOptionalSymbol: import("./types.js").TypePredicateFn<symbol | undefined>;
|
|
15
|
+
export declare const isOptionalNull: import("./types.js").TypePredicateFn<null | undefined>;
|
|
16
|
+
export declare const isStringWithLength: (input: unknown) => input is string;
|
|
4
17
|
export declare const isStringMatching: (input: unknown, pattern: RegExp) => input is string;
|
|
5
|
-
export declare const isPropertyKey: (input: unknown) => input is PropertyKey;
|
|
6
18
|
export declare const isNumericString: (input: unknown) => input is `${number}`;
|
|
7
19
|
export declare const isNumericValue: (input: unknown) => input is NumericValue;
|
|
8
20
|
export declare const isNumericValueArray: (input: unknown) => input is NumericValue[];
|
|
@@ -11,9 +23,12 @@ export declare const isFiniteNumber: (input: unknown) => input is number;
|
|
|
11
23
|
export declare const isInteger: (input: unknown) => input is number;
|
|
12
24
|
export declare const isPositiveInteger: (input: unknown) => input is number;
|
|
13
25
|
export declare const isPositiveFiniteNumber: (input: unknown) => input is number;
|
|
26
|
+
export declare const isPropertyKey: (input: unknown) => input is PropertyKey;
|
|
27
|
+
export declare const isObject: <T extends UnknownRecord = UnknownRecord>(input: unknown) => input is T;
|
|
14
28
|
export declare const isLengthAware: (input: unknown) => input is {
|
|
15
29
|
length: number;
|
|
16
30
|
};
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
31
|
+
export declare const isStringRecord: (input: unknown) => input is StringRecord;
|
|
32
|
+
export declare const isPromiseFulfilledResult: <T>(input: unknown) => input is PromiseFulfilledResult<T>;
|
|
33
|
+
export declare const isPromiseRejectedResult: (input: unknown) => input is PromiseRejectedResult;
|
|
19
34
|
//# sourceMappingURL=type-predicate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-predicate.d.ts","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type-predicate.d.ts","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAItG,eAAO,MAAM,QAAQ,UAAW,OAAO,oBAA+C,CAAC;AAEvF,eAAO,MAAM,QAAQ,UAAW,OAAO,oBAAuE,CAAC;AAE/G,eAAO,MAAM,QAAQ,UAAW,OAAO,oBAA+C,CAAC;AAEvF,eAAO,MAAM,SAAS,UAAW,OAAO,qBAAiD,CAAC;AAE1F,eAAO,MAAM,WAAW,UAAW,OAAO,uBAAqD,CAAC;AAEhG,eAAO,MAAM,QAAQ,UAAW,OAAO,oBAA+C,CAAC;AAEvF,eAAO,MAAM,MAAM,UAAW,OAAO,kBAAkC,CAAC;AAExE,eAAO,MAAM,WAAW,UAAW,OAAO,uBAO3B,CAAC;AAIhB,eAAO,MAAM,gBAAgB,0DAA2B,CAAC;AAEzD,eAAO,MAAM,gBAAgB,0DAA2B,CAAC;AAEzD,eAAO,MAAM,gBAAgB,0DAA2B,CAAC;AAEzD,eAAO,MAAM,iBAAiB,2DAA4B,CAAC;AAE3D,eAAO,MAAM,gBAAgB,0DAA2B,CAAC;AAEzD,eAAO,MAAM,cAAc,wDAAyB,CAAC;AAIrD,eAAO,MAAM,kBAAkB,UAAW,OAAO,oBAAmE,CAAC;AAErH,eAAO,MAAM,gBAAgB,UAAW,OAAO,WAAW,MAAM,oBACd,CAAC;AAEnD,eAAO,MAAM,eAAe,UAAW,OAAO,yBACC,CAAC;AAEhD,eAAO,MAAM,cAAc,UAAW,OAAO,0BACqC,CAAC;AAEnF,eAAO,MAAM,mBAAmB,UAAW,OAAO,4BACG,CAAC;AAEtD,eAAO,MAAM,WAAW,UAAW,OAAO,yBAAkE,CAAC;AAE7G,eAAO,MAAM,cAAc,UAAW,OAAO,oBAA4C,CAAC;AAE1F,eAAO,MAAM,SAAS,UAAW,OAAO,oBAA6C,CAAC;AAEtF,eAAO,MAAM,iBAAiB,UAAW,OAAO,oBAAoD,CAAC;AAErG,eAAO,MAAM,sBAAsB,UAAW,OAAO,oBAAyD,CAAC;AAI/G,eAAO,MAAM,aAAa,UAAW,OAAO,yBACyC,CAAC;AAEtF,eAAO,MAAM,QAAQ,mDAAoD,OAAO,eACV,CAAC;AAEvE,eAAO,MAAM,aAAa,UAAW,OAAO;YAAsB,MAAM;CAC8B,CAAC;AAEvG,eAAO,MAAM,cAAc,UAAW,OAAO,0BAE5C,CAAC;AAEF,eAAO,MAAM,wBAAwB,aAAc,OAAO,uCAEzD,CAAC;AAEF,eAAO,MAAM,uBAAuB,UAAW,OAAO,mCAErD,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -18,4 +18,6 @@ export type RangeTuple<T> = [min: T, max: T];
|
|
|
18
18
|
export type RangeTupleDistributive<T> = T extends any ? [min: T, max: T] : never;
|
|
19
19
|
export type NumberRangeTuple = RangeTuple<number>;
|
|
20
20
|
export type KeyValueTuple<K extends PropertyKey = PropertyKey, V = unknown> = [key: K, value: V];
|
|
21
|
+
export type Predicate<A, T extends A = A> = ((value: T, index: number, array: readonly A[]) => value is T) | ((value: T, index: number, array: readonly A[]) => unknown);
|
|
22
|
+
export type TypePredicateFn<T> = (input: unknown) => input is T;
|
|
21
23
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAGvF,MAAM,MAAM,OAAO,GAAG,IAAI,GAAG,KAAK,GAA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,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAEjG,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,IACpC,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,GAC9D,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC;AAEhE,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdeveric/utils",
|
|
3
3
|
"description": "Just another collection of utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.20.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"keywords": [
|
|
10
10
|
"utilities",
|
|
11
11
|
"asArray",
|
|
12
|
+
"capitalize",
|
|
12
13
|
"clamp",
|
|
13
14
|
"compose",
|
|
14
15
|
"convert",
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
"secToString",
|
|
28
29
|
"toPascalCase",
|
|
29
30
|
"trimEnd",
|
|
31
|
+
"trimIndentation",
|
|
30
32
|
"trimStart",
|
|
31
33
|
"type-assertion",
|
|
32
34
|
"type-predicate",
|
|
@@ -58,8 +60,7 @@
|
|
|
58
60
|
"./package.json": "./package.json"
|
|
59
61
|
},
|
|
60
62
|
"files": [
|
|
61
|
-
"dist"
|
|
62
|
-
"src"
|
|
63
|
+
"dist"
|
|
63
64
|
],
|
|
64
65
|
"repository": {
|
|
65
66
|
"type": "git",
|
|
@@ -101,29 +102,29 @@
|
|
|
101
102
|
"lodash.escaperegexp": "^4.1.2"
|
|
102
103
|
},
|
|
103
104
|
"devDependencies": {
|
|
104
|
-
"@swc/core": "^1.
|
|
105
|
-
"@swc/jest": "^0.2.
|
|
106
|
-
"@types/jest": "^29.
|
|
107
|
-
"@types/lodash.clonedeep": "^4.5.
|
|
108
|
-
"@types/lodash.escaperegexp": "^4.1.
|
|
109
|
-
"@types/node": "^18.
|
|
105
|
+
"@swc/core": "^1.3.22",
|
|
106
|
+
"@swc/jest": "^0.2.23",
|
|
107
|
+
"@types/jest": "^29.2.4",
|
|
108
|
+
"@types/lodash.clonedeep": "^4.5.7",
|
|
109
|
+
"@types/lodash.escaperegexp": "^4.1.7",
|
|
110
|
+
"@types/node": "^18.11.12",
|
|
110
111
|
"@webdeveric/eslint-config-ts": "^0.5.2",
|
|
111
112
|
"@webdeveric/prettier-config": "^0.2.0",
|
|
112
|
-
"core-js": "^3.
|
|
113
|
-
"cspell": "^6.
|
|
114
|
-
"eslint": "^8.
|
|
113
|
+
"core-js": "^3.26.1",
|
|
114
|
+
"cspell": "^6.17.0",
|
|
115
|
+
"eslint": "^8.29.0",
|
|
115
116
|
"eslint-config-prettier": "^8.5.0",
|
|
116
|
-
"eslint-import-resolver-typescript": "^3.
|
|
117
|
-
"eslint-plugin-import": "^2.
|
|
118
|
-
"eslint-plugin-jest": "^27.
|
|
119
|
-
"eslint-plugin-prettier": "^4.
|
|
120
|
-
"husky": "^8.0.
|
|
121
|
-
"jest": "^29.
|
|
122
|
-
"jest-environment-jsdom": "^29.
|
|
117
|
+
"eslint-import-resolver-typescript": "^3.5.2",
|
|
118
|
+
"eslint-plugin-import": "^2.26.0",
|
|
119
|
+
"eslint-plugin-jest": "^27.1.6",
|
|
120
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
121
|
+
"husky": "^8.0.2",
|
|
122
|
+
"jest": "^29.3.1",
|
|
123
|
+
"jest-environment-jsdom": "^29.3.1",
|
|
123
124
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
124
|
-
"lint-staged": "^13.
|
|
125
|
-
"prettier": "^2.
|
|
125
|
+
"lint-staged": "^13.1.0",
|
|
126
|
+
"prettier": "^2.8.1",
|
|
126
127
|
"rimraf": "^3.0.2",
|
|
127
|
-
"typescript": "^4.9.
|
|
128
|
+
"typescript": "^4.9.4"
|
|
128
129
|
}
|
|
129
130
|
}
|
package/src/asArray.ts
DELETED
package/src/capitalize.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const capitalize = (word: string): string => word.substring(0, 1).toUpperCase() + word.substring(1);
|
package/src/clamp.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { getMaxValue } from './getMaxValue.js';
|
|
2
|
-
import { getMinValue } from './getMinValue.js';
|
|
3
|
-
import type { NumericValue } from './types.js';
|
|
4
|
-
|
|
5
|
-
export function clamp(min: NumericValue, value: NumericValue, max: NumericValue): NumericValue {
|
|
6
|
-
return getMaxValue(min, getMinValue(value, max));
|
|
7
|
-
}
|
package/src/compose.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type ComposeFn<T, A extends unknown[], R = T> = ((data: T) => R) | ((data: T, ...args: A) => R);
|
|
2
|
-
|
|
3
|
-
export function compose<T, A extends unknown[]>(...functions: ComposeFn<T, A, T | void>[]): ComposeFn<T, A> {
|
|
4
|
-
return functions.reduce<ComposeFn<T, A>>(
|
|
5
|
-
(prev, next) =>
|
|
6
|
-
(data: T, ...args: A): T => {
|
|
7
|
-
const updatedData = prev(data, ...args);
|
|
8
|
-
|
|
9
|
-
return (next(updatedData, ...args) ?? updatedData) as T;
|
|
10
|
-
},
|
|
11
|
-
(data: T) => data,
|
|
12
|
-
);
|
|
13
|
-
}
|
package/src/convert.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { getOwnProperties } from './getOwnProperties.js';
|
|
2
|
-
import { getType } from './getType.js';
|
|
3
|
-
|
|
4
|
-
import type { Builtin } from './types.js';
|
|
5
|
-
|
|
6
|
-
export type ConvertFn<SourceType, ReturnType> = (source: Readonly<SourceType>) => ReturnType;
|
|
7
|
-
|
|
8
|
-
export type ConvertRecord<Input, Output> = {
|
|
9
|
-
[Property in keyof Output]: Output[Property] extends Builtin
|
|
10
|
-
? ConvertFn<Input, Output[Property]>
|
|
11
|
-
: AnyConverter<Input, Output[Property]>;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type AnyConverter<Input, Output> = ConvertRecord<Input, Output> | ConvertFn<Input, Output>;
|
|
15
|
-
|
|
16
|
-
export const convert = <Input, Output>(input: Readonly<Input>, converter: AnyConverter<Input, Output>): Output => {
|
|
17
|
-
if (typeof converter === 'function') {
|
|
18
|
-
return converter(input);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (typeof converter === 'object' && converter !== null) {
|
|
22
|
-
return getOwnProperties(converter).reduce<Partial<Output>>((data, key) => {
|
|
23
|
-
data[key] = convert(input, converter[key]);
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}, {}) as Output;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
throw new TypeError(`${getType(converter)} is not a valid converter`);
|
|
30
|
-
};
|
package/src/delay.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getType } from './getType.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Delay a specified number of milliseconds before resolving.
|
|
5
|
-
* The `ms` value can be between zero and the max delay value for `setTimeout`.
|
|
6
|
-
*
|
|
7
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value}
|
|
8
|
-
*/
|
|
9
|
-
export function delay(milliseconds: number): Promise<undefined>;
|
|
10
|
-
|
|
11
|
-
export function delay<T>(milliseconds: number, value: T): Promise<T>;
|
|
12
|
-
|
|
13
|
-
export function delay<T>(milliseconds: number, value?: T): Promise<typeof value> {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
if (typeof milliseconds !== 'number') {
|
|
16
|
-
reject(new TypeError(`milliseconds must be a number. ${getType(milliseconds)} was provided.`));
|
|
17
|
-
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
setTimeout(resolve, Math.max(0, Math.min(milliseconds, 2_147_483_647)), value);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export function delayAnimationFrame(): Promise<undefined>;
|
|
2
|
-
|
|
3
|
-
export function delayAnimationFrame<T>(value: T): Promise<T>;
|
|
4
|
-
|
|
5
|
-
export function delayAnimationFrame<T>(value?: T): Promise<typeof value> {
|
|
6
|
-
return new Promise(resolve => {
|
|
7
|
-
window.requestAnimationFrame(() => resolve(value));
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function delayAnimationFrames(frames: number): Promise<undefined>;
|
|
12
|
-
|
|
13
|
-
export function delayAnimationFrames<T>(frames: number, value: T): Promise<T>;
|
|
14
|
-
|
|
15
|
-
export function delayAnimationFrames<T>(frames: number, value?: T): Promise<typeof value> {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
if (!Number.isInteger(frames) || frames < 1) {
|
|
18
|
-
reject(new TypeError('frames must be a positive integer'));
|
|
19
|
-
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const loop = (frame: number): void => {
|
|
24
|
-
if (frame === 0) {
|
|
25
|
-
resolve(value);
|
|
26
|
-
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
window.requestAnimationFrame(() => loop(frame - 1));
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
loop(frames);
|
|
34
|
-
});
|
|
35
|
-
}
|
package/src/getMaxValue.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { assertIsNumericValueArray } from './type-assertion.js';
|
|
2
|
-
import type { NumericValue } from './types.js';
|
|
3
|
-
|
|
4
|
-
export function getMaxValue(...values: [NumericValue, ...NumericValue[]]): NumericValue {
|
|
5
|
-
if (values.length === 0) {
|
|
6
|
-
throw new Error('Expected at least one numeric value');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
assertIsNumericValueArray(values);
|
|
10
|
-
|
|
11
|
-
return values.reduce((high, current) => {
|
|
12
|
-
const value = typeof current === 'string' ? Number(current) : current;
|
|
13
|
-
|
|
14
|
-
return value > high ? current : high;
|
|
15
|
-
});
|
|
16
|
-
}
|
package/src/getMinValue.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { assertIsNumericValueArray } from './type-assertion.js';
|
|
2
|
-
import type { NumericValue } from './types.js';
|
|
3
|
-
|
|
4
|
-
export function getMinValue(...values: [NumericValue, ...NumericValue[]]): NumericValue {
|
|
5
|
-
if (values.length === 0) {
|
|
6
|
-
throw new Error('Expected at least one numeric value');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
assertIsNumericValueArray(values);
|
|
10
|
-
|
|
11
|
-
return values.reduce((low, current) => {
|
|
12
|
-
const value = typeof current === 'string' ? Number(current) : current;
|
|
13
|
-
|
|
14
|
-
return value < low ? current : low;
|
|
15
|
-
});
|
|
16
|
-
}
|
package/src/getOwnKeys.ts
DELETED
package/src/getOwnProperties.ts
DELETED
package/src/getType.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export * from './asArray.js';
|
|
2
|
-
export * from './capitalize.js';
|
|
3
|
-
export * from './clamp.js';
|
|
4
|
-
export * from './compose.js';
|
|
5
|
-
export * from './convert.js';
|
|
6
|
-
export * from './delay.js';
|
|
7
|
-
export * from './delayAnimationFrame.js';
|
|
8
|
-
export * from './getMaxValue.js';
|
|
9
|
-
export * from './getMinValue.js';
|
|
10
|
-
export * from './getOwnKeys.js';
|
|
11
|
-
export * from './getOwnProperties.js';
|
|
12
|
-
export * from './getType.js';
|
|
13
|
-
export * from './isEmpty.js';
|
|
14
|
-
export * from './isObject.js';
|
|
15
|
-
export * from './joinStrings.js';
|
|
16
|
-
export * from './normalize.js';
|
|
17
|
-
export * from './secToString.js';
|
|
18
|
-
export * from './toPascalCase.js';
|
|
19
|
-
export * from './trimEnd.js';
|
|
20
|
-
export * from './trimIndentation.js';
|
|
21
|
-
export * from './trimStart.js';
|
|
22
|
-
export * from './types.js';
|
|
23
|
-
export * from './uniqueItems.js';
|
|
24
|
-
export * from './until.js';
|
package/src/isEmpty.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { isLengthAware } from './type-predicate.js';
|
|
2
|
-
|
|
3
|
-
export function isEmpty(input: unknown): boolean {
|
|
4
|
-
if (typeof input === 'undefined' || input === null || (typeof input === 'string' && !input.length)) {
|
|
5
|
-
return true;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (Array.isArray(input)) {
|
|
9
|
-
return input.length === 0;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (input instanceof Set || input instanceof Map) {
|
|
13
|
-
return input.size === 0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (typeof input === 'object') {
|
|
17
|
-
return isLengthAware(input) ? input.length === 0 : Object.keys(input).length === 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return false;
|
|
21
|
-
}
|
package/src/isObject.ts
DELETED
package/src/joinStrings.ts
DELETED
package/src/node/fcrdns.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { promises as dns } from 'node:dns';
|
|
2
|
-
import { isIP } from 'node:net';
|
|
3
|
-
|
|
4
|
-
export async function hostnameResolvesToIp(hostname: string, ip: string): Promise<boolean> {
|
|
5
|
-
const ipVersion = isIP(ip);
|
|
6
|
-
|
|
7
|
-
if (!ipVersion) {
|
|
8
|
-
throw new Error(`Invalid IP: ${ip}`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const resolve = ipVersion === 4 ? dns.resolve4 : dns.resolve6;
|
|
12
|
-
|
|
13
|
-
const resolved = await resolve(hostname);
|
|
14
|
-
|
|
15
|
-
return resolved.some(addr => addr === ip);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Forward-confirmed reverse DNS
|
|
20
|
-
*
|
|
21
|
-
* @see https://en.wikipedia.org/wiki/Forward-confirmed_reverse_DNS
|
|
22
|
-
*/
|
|
23
|
-
export async function fcrdns(hostname: string, ip: string): Promise<boolean> {
|
|
24
|
-
const hostnames = await dns.reverse(ip);
|
|
25
|
-
|
|
26
|
-
if (!hostnames.length) {
|
|
27
|
-
throw new Error(`Unable to get hostnames for ${ip}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!hostnames.every(name => name.endsWith(hostname))) {
|
|
31
|
-
throw new Error(`${ip} does not belong to ${hostname}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const results = await Promise.all(hostnames.map(name => hostnameResolvesToIp(name, ip)));
|
|
35
|
-
|
|
36
|
-
return results.some(val => val);
|
|
37
|
-
}
|
package/src/node/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './fcrdns.js';
|
package/src/normalize.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import cloneDeep from 'lodash.clonedeep';
|
|
2
|
-
|
|
3
|
-
import { getOwnProperties } from './getOwnProperties.js';
|
|
4
|
-
import { isObject } from './isObject.js';
|
|
5
|
-
|
|
6
|
-
import type { AnyRecord, Builtin } from './types.js';
|
|
7
|
-
|
|
8
|
-
export type NormalizeContext<OwnerRecordType, ContextData extends AnyRecord> = {
|
|
9
|
-
original: Readonly<OwnerRecordType>;
|
|
10
|
-
current: OwnerRecordType;
|
|
11
|
-
data: ContextData;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type NormalizerFn<PropertyType, OwnerRecordType = unknown, ContextData extends AnyRecord = AnyRecord> = (
|
|
15
|
-
input: PropertyType,
|
|
16
|
-
context: NormalizeContext<OwnerRecordType, ContextData>,
|
|
17
|
-
) => PropertyType;
|
|
18
|
-
|
|
19
|
-
export type NormalizersRecord<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = {
|
|
20
|
-
readonly [Property in keyof RecordType]?: RecordType[Property] extends Builtin
|
|
21
|
-
? NormalizerFn<RecordType[Property], OwnerRecordType, ContextData>
|
|
22
|
-
: AnyNormalizer<RecordType[Property], OwnerRecordType, ContextData>;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type AnyNormalizer<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> =
|
|
26
|
-
| NormalizerFn<RecordType, OwnerRecordType, ContextData>
|
|
27
|
-
| NormalizersRecord<RecordType, OwnerRecordType, ContextData>;
|
|
28
|
-
|
|
29
|
-
export type ContextInitializer<OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = (
|
|
30
|
-
data: OwnerRecordType,
|
|
31
|
-
normalizers: AnyNormalizer<OwnerRecordType, OwnerRecordType, ContextData>,
|
|
32
|
-
) => ContextData;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @example
|
|
36
|
-
*
|
|
37
|
-
* ```ts
|
|
38
|
-
* normalize({ demo: true }, { demo: () => false });
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* ```ts
|
|
42
|
-
* normalize({ demo: true }, () => ({ demo: false }) });
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* ```ts
|
|
46
|
-
* normalize(true, () => false );
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export function normalize<Data extends object, ContextData extends AnyRecord = AnyRecord>(
|
|
50
|
-
input: Readonly<Data>,
|
|
51
|
-
normalizers: AnyNormalizer<Data, Data, Partial<ContextData>>, // No initializer so data must be partial
|
|
52
|
-
): Data;
|
|
53
|
-
|
|
54
|
-
export function normalize<Data extends object, ContextData extends AnyRecord = AnyRecord>(
|
|
55
|
-
input: Readonly<Data>,
|
|
56
|
-
normalizers: AnyNormalizer<Data, Data, ContextData>,
|
|
57
|
-
initContextData: ContextInitializer<Data, ContextData>,
|
|
58
|
-
): Data;
|
|
59
|
-
|
|
60
|
-
export function normalize<Data extends object, ContextData extends AnyRecord = AnyRecord>(
|
|
61
|
-
input: Readonly<Data>,
|
|
62
|
-
normalizers: AnyNormalizer<Data, Data, ContextData>,
|
|
63
|
-
initContextData: ContextInitializer<Data, ContextData> = (): AnyRecord => ({}),
|
|
64
|
-
): Data {
|
|
65
|
-
const current = cloneDeep(input);
|
|
66
|
-
|
|
67
|
-
const context: NormalizeContext<Data, ContextData> = Object.seal({
|
|
68
|
-
original: input,
|
|
69
|
-
current,
|
|
70
|
-
data: initContextData(input, normalizers),
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const walk = <CurrentRecord extends AnyRecord>(
|
|
74
|
-
currentRecord: CurrentRecord,
|
|
75
|
-
currentNormalizers?: AnyNormalizer<CurrentRecord, Data, ContextData>,
|
|
76
|
-
): CurrentRecord => {
|
|
77
|
-
if (typeof currentNormalizers === 'function') {
|
|
78
|
-
return currentNormalizers(currentRecord, context);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
|
|
82
|
-
if (typeof currentRecord === 'object' && currentRecord !== null) {
|
|
83
|
-
return getOwnProperties(currentNormalizers).reduce((data, key) => {
|
|
84
|
-
const normalizers = currentNormalizers[key];
|
|
85
|
-
// If the value is undefined but there is a normalizer record, set value to empty object.
|
|
86
|
-
const value =
|
|
87
|
-
typeof data[key] === 'undefined' && isObject(normalizers)
|
|
88
|
-
? ({} as unknown as CurrentRecord[keyof CurrentRecord])
|
|
89
|
-
: data[key];
|
|
90
|
-
|
|
91
|
-
data[key] = walk(value, normalizers);
|
|
92
|
-
|
|
93
|
-
return data;
|
|
94
|
-
}, currentRecord);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return currentRecord;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
return walk(current, normalizers);
|
|
102
|
-
}
|