@webdeveric/utils 0.13.0 → 0.15.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/asArray.js.map +1 -1
- package/dist/cjs/convert.js.map +1 -1
- package/dist/cjs/delay.js.map +1 -1
- package/dist/cjs/delayAnimationFrame.js.map +1 -1
- package/dist/cjs/getMaxValue.js.map +1 -1
- package/dist/cjs/getMinValue.js.map +1 -1
- package/dist/cjs/getOwnProperties.js +1 -4
- package/dist/cjs/getOwnProperties.js.map +1 -1
- package/dist/cjs/isEmpty.js +5 -1
- package/dist/cjs/isEmpty.js.map +1 -1
- package/dist/cjs/node/fcrdns.js.map +1 -1
- package/dist/cjs/normalize.js +0 -15
- package/dist/cjs/normalize.js.map +1 -1
- package/dist/cjs/secToString.js.map +1 -1
- package/dist/cjs/toPascalCase.js +1 -4
- package/dist/cjs/toPascalCase.js.map +1 -1
- package/dist/cjs/type-assertion.js.map +1 -1
- package/dist/cjs/type-predicate.js +5 -1
- package/dist/cjs/type-predicate.js.map +1 -1
- package/dist/cjs/uniqueItems.js.map +1 -1
- package/dist/cjs/until.js +9 -8
- package/dist/cjs/until.js.map +1 -1
- package/dist/mjs/asArray.js.map +1 -1
- package/dist/mjs/convert.js.map +1 -1
- package/dist/mjs/delay.js.map +1 -1
- package/dist/mjs/delayAnimationFrame.js.map +1 -1
- package/dist/mjs/getMaxValue.js.map +1 -1
- package/dist/mjs/getMinValue.js.map +1 -1
- package/dist/mjs/getOwnProperties.js +1 -4
- package/dist/mjs/getOwnProperties.js.map +1 -1
- package/dist/mjs/isEmpty.js +5 -1
- package/dist/mjs/isEmpty.js.map +1 -1
- package/dist/mjs/node/fcrdns.js.map +1 -1
- package/dist/mjs/normalize.js +0 -15
- package/dist/mjs/normalize.js.map +1 -1
- package/dist/mjs/secToString.js.map +1 -1
- package/dist/mjs/toPascalCase.js +1 -4
- package/dist/mjs/toPascalCase.js.map +1 -1
- package/dist/mjs/type-assertion.js.map +1 -1
- package/dist/mjs/type-predicate.js +3 -0
- package/dist/mjs/type-predicate.js.map +1 -1
- package/dist/mjs/uniqueItems.js.map +1 -1
- package/dist/mjs/until.js +5 -5
- package/dist/mjs/until.js.map +1 -1
- package/dist/types/asArray.d.ts.map +1 -1
- package/dist/types/delay.d.ts.map +1 -1
- package/dist/types/delayAnimationFrame.d.ts.map +1 -1
- package/dist/types/getMaxValue.d.ts.map +1 -1
- package/dist/types/getMinValue.d.ts.map +1 -1
- package/dist/types/getOwnProperties.d.ts.map +1 -1
- package/dist/types/isEmpty.d.ts.map +1 -1
- package/dist/types/node/fcrdns.d.ts.map +1 -1
- package/dist/types/normalize.d.ts +4 -2
- package/dist/types/normalize.d.ts.map +1 -1
- package/dist/types/secToString.d.ts.map +1 -1
- package/dist/types/toPascalCase.d.ts.map +1 -1
- package/dist/types/type-predicate.d.ts +3 -0
- package/dist/types/type-predicate.d.ts.map +1 -1
- package/dist/types/types.d.ts +3 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/uniqueItems.d.ts.map +1 -1
- package/dist/types/until.d.ts +2 -1
- package/dist/types/until.d.ts.map +1 -1
- package/package.json +32 -13
- package/readme.md +1 -1
- package/src/asArray.ts +2 -3
- package/src/convert.ts +1 -1
- package/src/delay.ts +6 -7
- package/src/delayAnimationFrame.ts +6 -8
- package/src/getMaxValue.ts +4 -6
- package/src/getMinValue.ts +4 -6
- package/src/getOwnProperties.ts +1 -4
- package/src/isEmpty.ts +8 -2
- package/src/node/fcrdns.ts +10 -16
- package/src/normalize.ts +26 -9
- package/src/secToString.ts +19 -22
- package/src/toPascalCase.ts +9 -13
- package/src/type-assertion.ts +3 -3
- package/src/type-predicate.ts +5 -1
- package/src/types.ts +7 -0
- package/src/uniqueItems.ts +2 -3
- package/src/until.ts +35 -38
|
@@ -5,11 +5,12 @@ export declare type NormalizeContext<OwnerRecordType, ContextData extends AnyRec
|
|
|
5
5
|
current: OwnerRecordType;
|
|
6
6
|
data: ContextData;
|
|
7
7
|
};
|
|
8
|
-
export declare type NormalizerFn<PropertyType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = (input: PropertyType, context: NormalizeContext<OwnerRecordType, ContextData>) => PropertyType;
|
|
8
|
+
export declare type NormalizerFn<PropertyType, OwnerRecordType = unknown, ContextData extends AnyRecord = AnyRecord> = (input: PropertyType, context: NormalizeContext<OwnerRecordType, ContextData>) => PropertyType;
|
|
9
9
|
export declare type NormalizersRecord<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = {
|
|
10
10
|
readonly [Property in keyof RecordType]?: RecordType[Property] extends Builtin ? NormalizerFn<RecordType[Property], OwnerRecordType, ContextData> : AnyNormalizer<RecordType[Property], OwnerRecordType, ContextData>;
|
|
11
11
|
};
|
|
12
12
|
export declare type AnyNormalizer<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = NormalizerFn<RecordType, OwnerRecordType, ContextData> | NormalizersRecord<RecordType, OwnerRecordType, ContextData>;
|
|
13
|
+
export declare type ContextInitializer<OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = (data: OwnerRecordType, normalizers: AnyNormalizer<OwnerRecordType, OwnerRecordType, ContextData>) => ContextData;
|
|
13
14
|
/**
|
|
14
15
|
* @example
|
|
15
16
|
*
|
|
@@ -25,5 +26,6 @@ export declare type AnyNormalizer<RecordType, OwnerRecordType, ContextData exten
|
|
|
25
26
|
* normalize(true, () => false );
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
|
-
export declare function normalize<Data, ContextData extends AnyRecord = AnyRecord>(input: Readonly<Data>, normalizers
|
|
29
|
+
export declare function normalize<Data, ContextData extends AnyRecord = AnyRecord>(input: Readonly<Data>, normalizers: AnyNormalizer<Data, Data, Partial<ContextData>>): Data;
|
|
30
|
+
export declare function normalize<Data, ContextData extends AnyRecord = AnyRecord>(input: Readonly<Data>, normalizers: AnyNormalizer<Data, Data, ContextData>, initContextData: ContextInitializer<Data, ContextData>): Data;
|
|
29
31
|
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAK7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,oBAAY,gBAAgB,CAAC,eAAe,EAAE,WAAW,SAAS,SAAS,IAAI;IAC7E,QAAQ,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACpC,OAAO,EAAE,eAAe,CAAC;IACzB,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF,oBAAY,YAAY,CAAC,YAAY,EAAE,eAAe,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,IAAI,
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/normalize.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAK7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,oBAAY,gBAAgB,CAAC,eAAe,EAAE,WAAW,SAAS,SAAS,IAAI;IAC7E,QAAQ,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;IACpC,OAAO,EAAE,eAAe,CAAC;IACzB,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAEF,oBAAY,YAAY,CAAC,YAAY,EAAE,eAAe,GAAG,OAAO,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,IAAI,CAC7G,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,gBAAgB,CAAC,eAAe,EAAE,WAAW,CAAC,KACpD,YAAY,CAAC;AAElB,oBAAY,iBAAiB,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,IAAI;IACtG,QAAQ,EAAE,QAAQ,IAAI,MAAM,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,SAAS,OAAO,GAC1E,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,WAAW,CAAC,GAChE,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,WAAW,CAAC;CACtE,CAAC;AAEF,oBAAY,aAAa,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,IAC5F,YAAY,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,CAAC,GACtD,iBAAiB,CAAC,UAAU,EAAE,eAAe,EAAE,WAAW,CAAC,CAAC;AAEhE,oBAAY,kBAAkB,CAAC,eAAe,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,IAAI,CAC3F,IAAI,EAAE,eAAe,EACrB,WAAW,EAAE,aAAa,CAAC,eAAe,EAAE,eAAe,EAAE,WAAW,CAAC,KACtE,WAAW,CAAC;AAEjB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,EACvE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EACrB,WAAW,EAAE,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,GAC3D,IAAI,CAAC;AAER,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW,SAAS,SAAS,GAAG,SAAS,EACvE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EACrB,WAAW,EAAE,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,EACnD,eAAe,EAAE,kBAAkB,CAAC,IAAI,EAAE,WAAW,CAAC,GACrD,IAAI,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secToString.d.ts","sourceRoot":"","sources":["../../src/secToString.ts"],"names":[],"mappings":"AAAA,oBAAY,OAAO;IACjB,MAAM,IAAI;IACV,MAAM,KAAc;IACpB,IAAI,OAAc;IAClB,GAAG,QAAY;IACf,IAAI,SAAU;IACd,KAAK,UAAsB;IAC3B,IAAI,WAAa;IACjB,MAAM,YAAY;IAClB,OAAO,aAAc;IACrB,UAAU,cAAe;CAC1B;AAID,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,SAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"secToString.d.ts","sourceRoot":"","sources":["../../src/secToString.ts"],"names":[],"mappings":"AAAA,oBAAY,OAAO;IACjB,MAAM,IAAI;IACV,MAAM,KAAc;IACpB,IAAI,OAAc;IAClB,GAAG,QAAY;IACf,IAAI,SAAU;IACd,KAAK,UAAsB;IAC3B,IAAI,WAAa;IACjB,MAAM,YAAY;IAClB,OAAO,aAAc;IACrB,UAAU,cAAe;CAC1B;AAID,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,SAAM,GAAG,MAAM,CA6BlE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toPascalCase.d.ts","sourceRoot":"","sources":["../../src/toPascalCase.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"toPascalCase.d.ts","sourceRoot":"","sources":["../../src/toPascalCase.ts"],"names":[],"mappings":"AAEA,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAoCvF"}
|
|
@@ -11,4 +11,7 @@ export declare const isFiniteNumber: (input: unknown) => input is number;
|
|
|
11
11
|
export declare const isInteger: (input: unknown) => input is number;
|
|
12
12
|
export declare const isPositiveInteger: (input: unknown) => input is number;
|
|
13
13
|
export declare const isPositiveFiniteNumber: (input: unknown) => input is number;
|
|
14
|
+
export declare const isLengthAware: (input: unknown) => input is {
|
|
15
|
+
length: number;
|
|
16
|
+
};
|
|
14
17
|
//# sourceMappingURL=type-predicate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-predicate.d.ts","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3D,eAAO,MAAM,gBAAgB,UAAW,OAAO,gCACY,CAAC;AAE5D,eAAO,MAAM,gBAAgB,UAAW,OAAO,
|
|
1
|
+
{"version":3,"file":"type-predicate.d.ts","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3D,eAAO,MAAM,gBAAgB,UAAW,OAAO,gCACY,CAAC;AAE5D,eAAO,MAAM,gBAAgB,UAAW,OAAO,gCACsC,CAAC;AAEtF,eAAO,MAAM,gBAAgB,UAAW,OAAO,WAAW,MAAM,oBACd,CAAC;AAEnD,eAAO,MAAM,aAAa,UAAW,OAAO,yBACyC,CAAC;AAEtF,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,oBAAyE,CAAC;AAEvH,eAAO,MAAM,SAAS,UAAW,OAAO,oBAA6C,CAAC;AAEtF,eAAO,MAAM,iBAAiB,UAAW,OAAO,oBAAoD,CAAC;AAErG,eAAO,MAAM,sBAAsB,UAAW,OAAO,oBAAyD,CAAC;AAE/G,eAAO,MAAM,aAAa,UAAW,OAAO;YAAsB,MAAM;CAEuC,CAAC"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -4,4 +4,7 @@ export declare type NumericString<T extends string | number = number> = `${T}` e
|
|
|
4
4
|
export declare type NumericValue = number | bigint | NumericString;
|
|
5
5
|
export declare type MaybePlural<T extends string> = T | `${T}s`;
|
|
6
6
|
export declare type StringKeys<T> = keyof T & string;
|
|
7
|
+
export declare type IfDefined<T, D, U> = undefined extends T ? U : D;
|
|
8
|
+
export declare type IfNever<T, N, O> = [T] extends [never] ? N : O;
|
|
9
|
+
export declare type ReturnTypeDefault<F, D = undefined> = F extends (...args: any) => infer R ? R : D;
|
|
7
10
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AACA,oBAAY,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AAEjD,oBAAY,aAAa,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAEzD,oBAAY,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,GAAG,CAAC,EAAE,SAAS,GAAG,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC;AAE5G,oBAAY,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,CAAC;AAE3D,oBAAY,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC;AAExD,oBAAY,UAAU,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AACA,oBAAY,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AAEjD,oBAAY,aAAa,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAEzD,oBAAY,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,IAAI,GAAG,CAAC,EAAE,SAAS,GAAG,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC;AAE5G,oBAAY,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,CAAC;AAE3D,oBAAY,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC;AAExD,oBAAY,UAAU,CAAC,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC;AAE7C,oBAAY,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,SAAS,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE7D,oBAAY,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAG3D,oBAAY,iBAAiB,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniqueItems.d.ts","sourceRoot":"","sources":["../../src/uniqueItems.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"uniqueItems.d.ts","sourceRoot":"","sources":["../../src/uniqueItems.ts"],"names":[],"mappings":"AAAA,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAE7C"}
|
package/dist/types/until.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AnyRecord } from './types';
|
|
2
2
|
export interface UntilContext {
|
|
3
3
|
callCount: number;
|
|
4
|
-
lastCall
|
|
4
|
+
lastCall: number | undefined;
|
|
5
5
|
data: AnyRecord;
|
|
6
6
|
options: UntilOptions;
|
|
7
7
|
}
|
|
@@ -16,6 +16,7 @@ export declare type ResolverValue<T> = T | PromiseLike<T>;
|
|
|
16
16
|
export declare type ResolveFn<T> = (value: ResolverValue<T>) => void;
|
|
17
17
|
export declare type RejectFn = (error?: Error) => void;
|
|
18
18
|
export declare type UntilCallback<T> = (resolve: ResolveFn<T>, reject: RejectFn, context: Readonly<UntilContext>) => void;
|
|
19
|
+
export declare const isDelay: (input: unknown) => input is Delay;
|
|
19
20
|
/**
|
|
20
21
|
* Return a Promise that delegates resolving/rejecting to the passed in function.
|
|
21
22
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,
|
|
1
|
+
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../src/until.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,oBAAY,OAAO,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,KAAK,MAAM,CAAC;AAElE,oBAAY,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAErC,oBAAY,YAAY,GAAG;IACzB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,oBAAY,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAElD,oBAAY,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAE7D,oBAAY,QAAQ,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;AAE/C,oBAAY,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;AAMlH,eAAO,MAAM,OAAO,UAAW,OAAO,mBAA2E,CAAC;AAElH;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,YAA6B,GAAG,OAAO,CAAC,CAAC,CAAC,CA4FjG"}
|
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.15.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"trimEnd",
|
|
30
30
|
"trimStart",
|
|
31
31
|
"type-assertion",
|
|
32
|
-
"
|
|
32
|
+
"type-predicate",
|
|
33
33
|
"uniqueItems",
|
|
34
34
|
"until"
|
|
35
35
|
],
|
|
@@ -46,12 +46,14 @@
|
|
|
46
46
|
},
|
|
47
47
|
"exports": {
|
|
48
48
|
".": {
|
|
49
|
+
"types": "./dist/types/index.d.ts",
|
|
49
50
|
"require": "./dist/cjs/index.js",
|
|
50
51
|
"import": "./dist/mjs/index.js"
|
|
51
52
|
},
|
|
52
53
|
"./*": {
|
|
53
|
-
"
|
|
54
|
-
"
|
|
54
|
+
"types": "./dist/types/*.d.ts",
|
|
55
|
+
"require": "./dist/cjs/*.js",
|
|
56
|
+
"import": "./dist/mjs/*.js"
|
|
55
57
|
},
|
|
56
58
|
"./package.json": "./package.json"
|
|
57
59
|
},
|
|
@@ -77,12 +79,22 @@
|
|
|
77
79
|
"build": "npm run build:cjs && npm run build:mjs",
|
|
78
80
|
"postbuild": "npm run validate",
|
|
79
81
|
"typecheck": "tsc --noEmit",
|
|
80
|
-
"lint": "eslint ./*.js ./src/ ./test/ --ext .ts
|
|
82
|
+
"lint": "eslint ./*.js ./bin/ ./src/ ./test/ --ext .ts,.mjs,.cjs",
|
|
81
83
|
"test": "NODE_ENV=test jest",
|
|
82
84
|
"validate": "./bin/validate.cjs",
|
|
83
85
|
"update-keywords": "./bin/update-keywords.mjs",
|
|
84
86
|
"spellcheck": "cspell './{.github,src,test}/**/*.{ts,json}' './*.{md,js}' './package.json' --no-progress",
|
|
85
|
-
"prepublishOnly": "npm run typecheck && npm run spellcheck && npm run lint && npm test && npm run build"
|
|
87
|
+
"prepublishOnly": "npm run typecheck && npm run spellcheck && npm run lint && npm test && npm run build",
|
|
88
|
+
"format": "prettier --write ./*.{js,json,md} ./bin/ ./src/ ./test/",
|
|
89
|
+
"prepare": "husky install"
|
|
90
|
+
},
|
|
91
|
+
"prettier": "@webdeveric/prettier-config",
|
|
92
|
+
"lint-staged": {
|
|
93
|
+
"*.{js,ts}": "eslint --fix",
|
|
94
|
+
"*.{ts,js,json,md}": [
|
|
95
|
+
"cspell lint --no-progress --no-summary --no-must-find-files",
|
|
96
|
+
"prettier --write"
|
|
97
|
+
]
|
|
86
98
|
},
|
|
87
99
|
"dependencies": {
|
|
88
100
|
"lodash.clonedeep": "^4.5.0",
|
|
@@ -90,22 +102,29 @@
|
|
|
90
102
|
"ts-essentials": "^9.0.0"
|
|
91
103
|
},
|
|
92
104
|
"devDependencies": {
|
|
93
|
-
"@types/jest": "^
|
|
105
|
+
"@types/jest": "^28.1.1",
|
|
94
106
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
95
107
|
"@types/lodash.escaperegexp": "^4.1.6",
|
|
96
|
-
"@types/node": "^
|
|
97
|
-
"@webdeveric/eslint-config-ts": "^0.
|
|
108
|
+
"@types/node": "^18.0.0",
|
|
109
|
+
"@webdeveric/eslint-config-ts": "^0.5.2",
|
|
110
|
+
"@webdeveric/prettier-config": "^0.2.0",
|
|
98
111
|
"core-js": "^3.11.1",
|
|
99
|
-
"cspell": "^
|
|
112
|
+
"cspell": "^6.1.0",
|
|
100
113
|
"eslint": "^8.10.0",
|
|
114
|
+
"eslint-config-prettier": "^8.5.0",
|
|
101
115
|
"eslint-import-resolver-typescript": "^2.5.0",
|
|
102
116
|
"eslint-plugin-import": "^2.25.4",
|
|
103
117
|
"eslint-plugin-jest": "^26.0.0",
|
|
104
|
-
"
|
|
118
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
119
|
+
"husky": "^8.0.1",
|
|
120
|
+
"jest": "^28.1.0",
|
|
121
|
+
"jest-environment-jsdom": "^28.1.0",
|
|
105
122
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
|
123
|
+
"lint-staged": "^13.0.0",
|
|
124
|
+
"prettier": "^2.6.2",
|
|
106
125
|
"rimraf": "^3.0.2",
|
|
107
|
-
"ts-jest": "^
|
|
126
|
+
"ts-jest": "^28.0.3",
|
|
108
127
|
"ts-node": "^10.6.0",
|
|
109
|
-
"typescript": "^4.
|
|
128
|
+
"typescript": "^4.7.3"
|
|
110
129
|
}
|
|
111
130
|
}
|
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @webdeveric/utils
|
|
2
2
|
|
|
3
|
-
[](https://github.com/webdeveric/utils/actions/workflows/node.js.yml) [](https://github.com/webdeveric/utils/actions/workflows/codeql-analysis.yml)
|
|
4
4
|
|
|
5
5
|
```shell
|
|
6
6
|
npm i @webdeveric/utils --save
|
package/src/asArray.ts
CHANGED
package/src/convert.ts
CHANGED
|
@@ -20,7 +20,7 @@ export const convert = <Input, Output>(input: Readonly<Input>, converter: AnyCon
|
|
|
20
20
|
|
|
21
21
|
if (typeof converter === 'object' && converter !== null) {
|
|
22
22
|
return getOwnProperties(converter).reduce<Partial<Output>>((data, key) => {
|
|
23
|
-
data[
|
|
23
|
+
data[key] = convert(input, converter[key]);
|
|
24
24
|
|
|
25
25
|
return data;
|
|
26
26
|
}, {}) as Output;
|
package/src/delay.ts
CHANGED
|
@@ -6,15 +6,14 @@ import { getType } from './getType.js';
|
|
|
6
6
|
*
|
|
7
7
|
* {@link https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value}
|
|
8
8
|
*/
|
|
9
|
-
export function delay<T>(milliseconds: number, value?: T)
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
reject( new TypeError(`milliseconds must be a number. ${getType(milliseconds)} was provided.`) );
|
|
9
|
+
export function delay<T>(milliseconds: number, value?: T): Promise<T> {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
if (typeof milliseconds !== 'number') {
|
|
12
|
+
reject(new TypeError(`milliseconds must be a number. ${getType(milliseconds)} was provided.`));
|
|
14
13
|
|
|
15
14
|
return;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
setTimeout(
|
|
19
|
-
}
|
|
17
|
+
setTimeout(resolve, Math.max(0, Math.min(milliseconds, 2_147_483_647)), value);
|
|
18
|
+
});
|
|
20
19
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
export function delayAnimationFrame<T>(value?: T)
|
|
2
|
-
{
|
|
1
|
+
export function delayAnimationFrame<T>(value?: T): Promise<typeof value> {
|
|
3
2
|
return new Promise(resolve => {
|
|
4
|
-
window.requestAnimationFrame(
|
|
3
|
+
window.requestAnimationFrame(() => resolve(value));
|
|
5
4
|
});
|
|
6
5
|
}
|
|
7
6
|
|
|
8
|
-
export function delayAnimationFrames<T>(frames: number, value?: T): Promise<typeof value>
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
reject( new TypeError('frames must be a positive integer') );
|
|
7
|
+
export function delayAnimationFrames<T>(frames: number, value?: T): Promise<typeof value> {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
if (!Number.isInteger(frames) || frames < 1) {
|
|
10
|
+
reject(new TypeError('frames must be a positive integer'));
|
|
13
11
|
|
|
14
12
|
return;
|
|
15
13
|
}
|
package/src/getMaxValue.ts
CHANGED
|
@@ -8,11 +8,9 @@ export function getMaxValue(...values: [NumericValue, ...NumericValue[]]): Numer
|
|
|
8
8
|
|
|
9
9
|
assertIsNumericValueArray(values);
|
|
10
10
|
|
|
11
|
-
return values.reduce(
|
|
12
|
-
|
|
13
|
-
const value = typeof current === 'string' ? Number(current) : current;
|
|
11
|
+
return values.reduce((high, current) => {
|
|
12
|
+
const value = typeof current === 'string' ? Number(current) : current;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
return value > high ? current : high;
|
|
15
|
+
});
|
|
18
16
|
}
|
package/src/getMinValue.ts
CHANGED
|
@@ -8,11 +8,9 @@ export function getMinValue(...values: [NumericValue, ...NumericValue[]]): Numer
|
|
|
8
8
|
|
|
9
9
|
assertIsNumericValueArray(values);
|
|
10
10
|
|
|
11
|
-
return values.reduce(
|
|
12
|
-
|
|
13
|
-
const value = typeof current === 'string' ? Number(current) : current;
|
|
11
|
+
return values.reduce((low, current) => {
|
|
12
|
+
const value = typeof current === 'string' ? Number(current) : current;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
);
|
|
14
|
+
return value < low ? current : low;
|
|
15
|
+
});
|
|
18
16
|
}
|
package/src/getOwnProperties.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export function getOwnProperties<T, K extends keyof T>(data: T): K[] {
|
|
2
|
-
return [
|
|
3
|
-
...Object.getOwnPropertyNames(data),
|
|
4
|
-
...Object.getOwnPropertySymbols(data),
|
|
5
|
-
] as K[];
|
|
2
|
+
return [...Object.getOwnPropertyNames(data), ...Object.getOwnPropertySymbols(data)] as K[];
|
|
6
3
|
}
|
package/src/isEmpty.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { isLengthAware } from './type-predicate.js';
|
|
2
|
+
|
|
1
3
|
export function isEmpty(input: unknown): boolean {
|
|
2
|
-
if (typeof input === 'undefined' || input === null || (typeof input === 'string' && !
|
|
4
|
+
if (typeof input === 'undefined' || input === null || (typeof input === 'string' && !input.length)) {
|
|
3
5
|
return true;
|
|
4
6
|
}
|
|
5
7
|
|
|
@@ -7,8 +9,12 @@ export function isEmpty(input: unknown): boolean {
|
|
|
7
9
|
return input.length === 0;
|
|
8
10
|
}
|
|
9
11
|
|
|
12
|
+
if (input instanceof Set || input instanceof Map) {
|
|
13
|
+
return input.size === 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
if (typeof input === 'object') {
|
|
11
|
-
return Object.keys(input).length === 0;
|
|
17
|
+
return isLengthAware(input) ? input.length === 0 : Object.keys(input).length === 0;
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
return false;
|
package/src/node/fcrdns.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { promises as dns } from 'node:dns';
|
|
2
2
|
import { isIP } from 'node:net';
|
|
3
3
|
|
|
4
|
-
export async function hostnameResolvesToIp(
|
|
5
|
-
|
|
6
|
-
const ipVersion = isIP( ip );
|
|
4
|
+
export async function hostnameResolvesToIp(hostname: string, ip: string): Promise<boolean> {
|
|
5
|
+
const ipVersion = isIP(ip);
|
|
7
6
|
|
|
8
|
-
if (
|
|
7
|
+
if (!ipVersion) {
|
|
9
8
|
throw new Error(`Invalid IP: ${ip}`);
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
const resolve = ipVersion === 4 ? dns.resolve4 : dns.resolve6;
|
|
13
12
|
|
|
14
|
-
const resolved = await resolve(
|
|
13
|
+
const resolved = await resolve(hostname);
|
|
15
14
|
|
|
16
|
-
return resolved.some(
|
|
15
|
+
return resolved.some(addr => addr === ip);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
/**
|
|
@@ -21,23 +20,18 @@ export async function hostnameResolvesToIp( hostname: string, ip: string ) : Pro
|
|
|
21
20
|
*
|
|
22
21
|
* @see https://en.wikipedia.org/wiki/Forward-confirmed_reverse_DNS
|
|
23
22
|
*/
|
|
24
|
-
export async function fcrdns(
|
|
25
|
-
{
|
|
23
|
+
export async function fcrdns(hostname: string, ip: string): Promise<boolean> {
|
|
26
24
|
const hostnames = await dns.reverse(ip);
|
|
27
25
|
|
|
28
|
-
if (
|
|
26
|
+
if (!hostnames.length) {
|
|
29
27
|
throw new Error(`Unable to get hostnames for ${ip}`);
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
if (
|
|
30
|
+
if (!hostnames.every(name => name.endsWith(hostname))) {
|
|
33
31
|
throw new Error(`${ip} does not belong to ${hostname}`);
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
const results = await Promise.all(
|
|
37
|
-
hostnames.map(
|
|
38
|
-
name => hostnameResolvesToIp( name, ip ),
|
|
39
|
-
),
|
|
40
|
-
);
|
|
34
|
+
const results = await Promise.all(hostnames.map(name => hostnameResolvesToIp(name, ip)));
|
|
41
35
|
|
|
42
|
-
return results.some(
|
|
36
|
+
return results.some(val => val);
|
|
43
37
|
}
|
package/src/normalize.ts
CHANGED
|
@@ -13,7 +13,7 @@ export type NormalizeContext<OwnerRecordType, ContextData extends AnyRecord> = {
|
|
|
13
13
|
data: ContextData;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export type NormalizerFn<PropertyType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = (
|
|
16
|
+
export type NormalizerFn<PropertyType, OwnerRecordType = unknown, ContextData extends AnyRecord = AnyRecord> = (
|
|
17
17
|
input: PropertyType,
|
|
18
18
|
context: NormalizeContext<OwnerRecordType, ContextData>,
|
|
19
19
|
) => PropertyType;
|
|
@@ -21,13 +21,18 @@ export type NormalizerFn<PropertyType, OwnerRecordType, ContextData extends AnyR
|
|
|
21
21
|
export type NormalizersRecord<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = {
|
|
22
22
|
readonly [Property in keyof RecordType]?: RecordType[Property] extends Builtin
|
|
23
23
|
? NormalizerFn<RecordType[Property], OwnerRecordType, ContextData>
|
|
24
|
-
: AnyNormalizer<RecordType[Property], OwnerRecordType, ContextData
|
|
24
|
+
: AnyNormalizer<RecordType[Property], OwnerRecordType, ContextData>;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export type AnyNormalizer<RecordType, OwnerRecordType, ContextData extends AnyRecord = AnyRecord> =
|
|
28
28
|
| NormalizerFn<RecordType, OwnerRecordType, ContextData>
|
|
29
29
|
| NormalizersRecord<RecordType, OwnerRecordType, ContextData>;
|
|
30
30
|
|
|
31
|
+
export type ContextInitializer<OwnerRecordType, ContextData extends AnyRecord = AnyRecord> = (
|
|
32
|
+
data: OwnerRecordType,
|
|
33
|
+
normalizers: AnyNormalizer<OwnerRecordType, OwnerRecordType, ContextData>,
|
|
34
|
+
) => ContextData;
|
|
35
|
+
|
|
31
36
|
/**
|
|
32
37
|
* @example
|
|
33
38
|
*
|
|
@@ -45,8 +50,19 @@ export type AnyNormalizer<RecordType, OwnerRecordType, ContextData extends AnyRe
|
|
|
45
50
|
*/
|
|
46
51
|
export function normalize<Data, ContextData extends AnyRecord = AnyRecord>(
|
|
47
52
|
input: Readonly<Data>,
|
|
48
|
-
normalizers
|
|
49
|
-
|
|
53
|
+
normalizers: AnyNormalizer<Data, Data, Partial<ContextData>>, // No initializer so data must be partial
|
|
54
|
+
): Data;
|
|
55
|
+
|
|
56
|
+
export function normalize<Data, ContextData extends AnyRecord = AnyRecord>(
|
|
57
|
+
input: Readonly<Data>,
|
|
58
|
+
normalizers: AnyNormalizer<Data, Data, ContextData>,
|
|
59
|
+
initContextData: ContextInitializer<Data, ContextData>,
|
|
60
|
+
): Data;
|
|
61
|
+
|
|
62
|
+
export function normalize<Data, ContextData extends AnyRecord = AnyRecord>(
|
|
63
|
+
input: Readonly<Data>,
|
|
64
|
+
normalizers: AnyNormalizer<Data, Data, ContextData>,
|
|
65
|
+
initContextData: ContextInitializer<Data, ContextData> = (): AnyRecord => ({}),
|
|
50
66
|
): Data {
|
|
51
67
|
const current = cloneDeep(input);
|
|
52
68
|
|
|
@@ -67,13 +83,14 @@ export function normalize<Data, ContextData extends AnyRecord = AnyRecord>(
|
|
|
67
83
|
if (typeof currentNormalizers === 'object' && currentNormalizers !== null) {
|
|
68
84
|
if (typeof currentRecord === 'object' && currentRecord !== null) {
|
|
69
85
|
return getOwnProperties(currentNormalizers).reduce((data, key) => {
|
|
70
|
-
const normalizers = currentNormalizers[
|
|
86
|
+
const normalizers = currentNormalizers[key];
|
|
71
87
|
// If the value is undefined but there is a normalizer record, set value to empty object.
|
|
72
|
-
const value =
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
const value =
|
|
89
|
+
typeof data[key] === 'undefined' && isObject(normalizers)
|
|
90
|
+
? ({} as unknown as CurrentRecord[keyof CurrentRecord])
|
|
91
|
+
: data[key];
|
|
75
92
|
|
|
76
|
-
data[
|
|
93
|
+
data[key] = walk(value, normalizers);
|
|
77
94
|
|
|
78
95
|
return data;
|
|
79
96
|
}, currentRecord);
|
package/src/secToString.ts
CHANGED
|
@@ -15,33 +15,30 @@ type SecondsTuple = [key: Lowercase<keyof typeof Seconds>, seconds: Seconds];
|
|
|
15
15
|
|
|
16
16
|
export function secToString(time: number, joinString = ' '): string {
|
|
17
17
|
const secTime: SecondsTuple[] = [
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
26
|
-
[
|
|
27
|
-
[
|
|
18
|
+
['millennium', Seconds.Millennium],
|
|
19
|
+
['century', Seconds.Century],
|
|
20
|
+
['decade', Seconds.Decade],
|
|
21
|
+
['year', Seconds.Year],
|
|
22
|
+
['month', Seconds.Month],
|
|
23
|
+
['week', Seconds.Week],
|
|
24
|
+
['day', Seconds.Day],
|
|
25
|
+
['hour', Seconds.Hour],
|
|
26
|
+
['minute', Seconds.Minute],
|
|
27
|
+
['second', Seconds.Second],
|
|
28
28
|
];
|
|
29
29
|
|
|
30
|
-
const parts = secTime.reduce<string[]>(
|
|
31
|
-
(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const suffix = currentValue === 1 ? units : `${units}s`;
|
|
30
|
+
const parts = secTime.reduce<string[]>((output, [units, seconds]) => {
|
|
31
|
+
if (seconds <= time) {
|
|
32
|
+
const currentValue = Math.floor(time / seconds);
|
|
33
|
+
const suffix = currentValue === 1 ? units : `${units}s`;
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
time %= seconds;
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
output.push(`${currentValue} ${suffix}`);
|
|
38
|
+
}
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
[],
|
|
44
|
-
);
|
|
40
|
+
return output;
|
|
41
|
+
}, []);
|
|
45
42
|
|
|
46
43
|
// cSpell:ignore centurys
|
|
47
44
|
return parts.join(joinString).replace('centurys', 'centuries');
|
package/src/toPascalCase.ts
CHANGED
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
import { getType } from './getType.js';
|
|
2
2
|
|
|
3
|
-
export function toPascalCase(text: string, customWords?: Record<string, string>)
|
|
4
|
-
|
|
5
|
-
let words = String(text).match( /[A-Z][a-z']+|\d+|[a-z']+/g );
|
|
3
|
+
export function toPascalCase(text: string, customWords?: Record<string, string>): string {
|
|
4
|
+
let words = String(text).match(/[A-Z][a-z']+|\d+|[a-z']+/g);
|
|
6
5
|
|
|
7
|
-
if (
|
|
6
|
+
if (!words) {
|
|
8
7
|
return '';
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
// Remove apostrophes then uppercase the first letter of each word.
|
|
12
|
-
words = words.map(
|
|
11
|
+
words = words.map(word => {
|
|
13
12
|
const fixedWord = word.replace(/'/g, '');
|
|
14
13
|
|
|
15
14
|
return fixedWord.substring(0, 1).toUpperCase() + fixedWord.substring(1);
|
|
16
15
|
});
|
|
17
16
|
|
|
18
|
-
if (
|
|
19
|
-
const replacements = Object.entries(
|
|
20
|
-
key.toLowerCase(),
|
|
21
|
-
value,
|
|
22
|
-
]);
|
|
17
|
+
if (customWords && getType(customWords) === 'Object') {
|
|
18
|
+
const replacements = Object.entries(customWords).map(([key, value]) => [key.toLowerCase(), value]);
|
|
23
19
|
|
|
24
|
-
if (
|
|
20
|
+
if (replacements.length) {
|
|
25
21
|
// This takes a single word and returns the first matching replacement, if any.
|
|
26
|
-
const replaceCustomWords = (word: string)
|
|
22
|
+
const replaceCustomWords = (word: string): string => {
|
|
27
23
|
const lowerWord = word.toLowerCase();
|
|
28
24
|
|
|
29
|
-
for (const [
|
|
25
|
+
for (const [key, value] of replacements) {
|
|
30
26
|
if (key === lowerWord && typeof value === 'string') {
|
|
31
27
|
return value;
|
|
32
28
|
}
|
package/src/type-assertion.ts
CHANGED
|
@@ -2,19 +2,19 @@ import { isNumericValueArray } from './type-predicate.js';
|
|
|
2
2
|
import type { NumericValue } from './types';
|
|
3
3
|
|
|
4
4
|
export function assertIsInteger(input: unknown): asserts input is number {
|
|
5
|
-
if (!
|
|
5
|
+
if (!Number.isInteger(input)) {
|
|
6
6
|
throw new TypeError('input is not an integer');
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function assertIsFiniteNumber(input: unknown): asserts input is number {
|
|
11
|
-
if (!
|
|
11
|
+
if (!Number.isFinite(input)) {
|
|
12
12
|
throw new TypeError('input is not a finite number');
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function assertIsNumericValueArray(input: unknown): asserts input is NumericValue[] {
|
|
17
|
-
if (!
|
|
17
|
+
if (!isNumericValueArray(input)) {
|
|
18
18
|
throw new TypeError('all items must be a NumericValue');
|
|
19
19
|
}
|
|
20
20
|
}
|
package/src/type-predicate.ts
CHANGED
|
@@ -4,7 +4,7 @@ export const isOptionalString = (input: unknown): input is string | undefined =>
|
|
|
4
4
|
typeof input === 'string' || typeof input === 'undefined';
|
|
5
5
|
|
|
6
6
|
export const isOptionalNumber = (input: unknown): input is number | undefined =>
|
|
7
|
-
(typeof input === 'number' && !
|
|
7
|
+
(typeof input === 'number' && !Number.isNaN(input)) || typeof input === 'undefined';
|
|
8
8
|
|
|
9
9
|
export const isStringMatching = (input: unknown, pattern: RegExp): input is string =>
|
|
10
10
|
typeof input === 'string' && pattern.test(input);
|
|
@@ -30,3 +30,7 @@ export const isInteger = (input: unknown): input is number => Number.isInteger(i
|
|
|
30
30
|
export const isPositiveInteger = (input: unknown): input is number => isInteger(input) && input >= 0;
|
|
31
31
|
|
|
32
32
|
export const isPositiveFiniteNumber = (input: unknown): input is number => isFiniteNumber(input) && input >= 0;
|
|
33
|
+
|
|
34
|
+
export const isLengthAware = (input: unknown): input is { length: number } =>
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
typeof input === 'object' && input !== null && 'length' in input && typeof (input as any).length === 'number';
|
package/src/types.ts
CHANGED
|
@@ -10,3 +10,10 @@ export type NumericValue = number | bigint | NumericString;
|
|
|
10
10
|
export type MaybePlural<T extends string> = T | `${T}s`;
|
|
11
11
|
|
|
12
12
|
export type StringKeys<T> = keyof T & string;
|
|
13
|
+
|
|
14
|
+
export type IfDefined<T, D, U> = undefined extends T ? U : D;
|
|
15
|
+
|
|
16
|
+
export type IfNever<T, N, O> = [T] extends [never] ? N : O;
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
export type ReturnTypeDefault<F, D = undefined> = F extends (...args: any) => infer R ? R : D;
|
package/src/uniqueItems.ts
CHANGED