@webdeveric/utils 0.53.0 → 0.54.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/assertion/assertIsStringMatching.js +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/{predicate-factory/createIsEnumPredicate.js → predicate/factory/fromEnum.js} +3 -3
- package/dist/cjs/{predicate-factory → predicate/factory}/index.js +11 -7
- package/dist/cjs/predicate/factory/instanceOf.js +5 -0
- package/dist/cjs/predicate/factory/literal.js +5 -0
- package/dist/cjs/predicate/factory/matching.js +5 -0
- package/dist/cjs/predicate/factory/range.js +16 -0
- package/dist/cjs/predicate/factory/shape.js +20 -0
- package/dist/cjs/predicate/factory/simple.js +5 -0
- package/dist/cjs/predicate/factory/stringLength.js +13 -0
- package/dist/cjs/{predicate-factory/createIsTuplePredicate.js → predicate/factory/tuple.js} +3 -3
- package/dist/cjs/predicate/factory/typeOf.js +5 -0
- package/dist/cjs/predicate/factory/withLength.js +13 -0
- package/dist/cjs/predicate/factory/withSize.js +13 -0
- package/dist/cjs/predicate/isAsyncIterable.js +4 -2
- package/dist/cjs/predicate/isBigIntArray.js +1 -1
- package/dist/cjs/predicate/isBooleanArray.js +1 -1
- package/dist/cjs/predicate/isDigitsString.js +2 -2
- package/dist/cjs/predicate/isISODateString.js +2 -2
- package/dist/cjs/predicate/isIntString.js +2 -2
- package/dist/cjs/predicate/isIterable.js +4 -2
- package/dist/cjs/predicate/isNullArray.js +1 -1
- package/dist/cjs/predicate/isNumberArray.js +1 -1
- package/dist/cjs/predicate/isNumericString.js +2 -2
- package/dist/cjs/predicate/isNumericValueArray.js +1 -1
- package/dist/cjs/predicate/isOptionalBigInt.js +1 -1
- package/dist/cjs/predicate/isOptionalBoolean.js +1 -1
- package/dist/cjs/predicate/isOptionalISODateString.js +1 -1
- package/dist/cjs/predicate/isOptionalNull.js +1 -1
- package/dist/cjs/predicate/isOptionalNumber.js +1 -1
- package/dist/cjs/predicate/isOptionalString.js +1 -1
- package/dist/cjs/predicate/isOptionalSymbol.js +1 -1
- package/dist/cjs/predicate/isPromiseLike.js +6 -5
- package/dist/cjs/predicate/isStringArray.js +1 -1
- package/dist/cjs/predicate/isSymbolArray.js +1 -1
- package/dist/cjs/predicate/isUndefinedArray.js +1 -1
- package/dist/mjs/assertion/assertIsStringMatching.js +2 -2
- package/dist/mjs/index.js +1 -1
- package/dist/mjs/{predicate-factory/createIsEnumPredicate.js → predicate/factory/fromEnum.js} +1 -1
- package/dist/mjs/predicate/factory/index.js +18 -0
- package/dist/mjs/predicate/factory/instanceOf.js +1 -0
- package/dist/mjs/predicate/factory/literal.js +1 -0
- package/dist/mjs/predicate/factory/matching.js +1 -0
- package/dist/mjs/predicate/factory/range.js +12 -0
- package/dist/mjs/predicate/factory/shape.js +16 -0
- package/dist/mjs/predicate/factory/simple.js +1 -0
- package/dist/mjs/predicate/factory/stringLength.js +9 -0
- package/dist/mjs/{predicate-factory/createIsTuplePredicate.js → predicate/factory/tuple.js} +1 -1
- package/dist/mjs/predicate/factory/typeOf.js +1 -0
- package/dist/mjs/predicate/factory/withLength.js +10 -0
- package/dist/mjs/predicate/factory/withSize.js +10 -0
- package/dist/mjs/predicate/isAsyncIterable.js +4 -2
- package/dist/mjs/predicate/isBigIntArray.js +1 -1
- package/dist/mjs/predicate/isBooleanArray.js +1 -1
- package/dist/mjs/predicate/isDigitsString.js +2 -2
- package/dist/mjs/predicate/isISODateString.js +2 -2
- package/dist/mjs/predicate/isIntString.js +2 -2
- package/dist/mjs/predicate/isIterable.js +4 -2
- package/dist/mjs/predicate/isNullArray.js +1 -1
- package/dist/mjs/predicate/isNumberArray.js +1 -1
- package/dist/mjs/predicate/isNumericString.js +2 -2
- package/dist/mjs/predicate/isNumericValueArray.js +1 -1
- package/dist/mjs/predicate/isOptionalBigInt.js +1 -1
- package/dist/mjs/predicate/isOptionalBoolean.js +1 -1
- package/dist/mjs/predicate/isOptionalISODateString.js +1 -1
- package/dist/mjs/predicate/isOptionalNull.js +1 -1
- package/dist/mjs/predicate/isOptionalNumber.js +1 -1
- package/dist/mjs/predicate/isOptionalString.js +1 -1
- package/dist/mjs/predicate/isOptionalSymbol.js +1 -1
- package/dist/mjs/predicate/isPromiseLike.js +5 -4
- package/dist/mjs/predicate/isStringArray.js +1 -1
- package/dist/mjs/predicate/isSymbolArray.js +1 -1
- package/dist/mjs/predicate/isUndefinedArray.js +1 -1
- package/dist/types/assertion/assertIsAsyncIterable.d.ts +1 -1
- package/dist/types/assertion/assertIsFunction.d.ts +1 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/{predicate-factory → predicate/factory}/allOf.d.ts +2 -2
- package/dist/types/{predicate-factory → predicate/factory}/anyOf.d.ts +2 -2
- package/dist/types/predicate/factory/everyItem.d.ts +2 -0
- package/dist/types/predicate/factory/fromEnum.d.ts +3 -0
- package/dist/types/predicate/factory/index.d.ts +18 -0
- package/dist/types/predicate/factory/instanceOf.d.ts +3 -0
- package/dist/types/predicate/factory/is.d.ts +3 -0
- package/dist/types/predicate/factory/literal.d.ts +2 -0
- package/dist/types/predicate/factory/matching.d.ts +2 -0
- package/dist/types/{predicate-factory → predicate/factory}/maybeArray.d.ts +1 -1
- package/dist/types/{predicate-factory → predicate/factory}/maybeNull.d.ts +1 -1
- package/dist/types/{predicate-factory → predicate/factory}/maybeUndefined.d.ts +1 -1
- package/dist/types/predicate/factory/range.d.ts +2 -0
- package/dist/types/{predicate-factory/createObjectShapePredicate.d.ts → predicate/factory/shape.d.ts} +5 -5
- package/dist/types/predicate/factory/simple.d.ts +3 -0
- package/dist/types/predicate/factory/stringLength.d.ts +2 -0
- package/dist/types/predicate/factory/tuple.d.ts +7 -0
- package/dist/types/predicate/factory/typeOf.d.ts +2 -0
- package/dist/types/predicate/factory/withLength.d.ts +17 -0
- package/dist/types/predicate/factory/withSize.d.ts +17 -0
- package/dist/types/predicate/isFunction.d.ts +1 -2
- package/dist/types/predicate/isPromiseLike.d.ts +3 -1
- package/dist/types/types/common.d.ts +10 -0
- package/dist/types/types/numbers.d.ts +1 -0
- package/package.json +14 -9
- package/dist/cjs/predicate-factory/createIsInstanceOfPredicate.js +0 -5
- package/dist/cjs/predicate-factory/createNumberRangePredicate.js +0 -20
- package/dist/cjs/predicate-factory/createObjectShapePredicate.js +0 -19
- package/dist/cjs/predicate-factory/createStringLengthRangePredicate.js +0 -10
- package/dist/cjs/predicate-factory/createStringMatchingPredicate.js +0 -5
- package/dist/mjs/predicate-factory/createIsInstanceOfPredicate.js +0 -1
- package/dist/mjs/predicate-factory/createNumberRangePredicate.js +0 -16
- package/dist/mjs/predicate-factory/createObjectShapePredicate.js +0 -15
- package/dist/mjs/predicate-factory/createStringLengthRangePredicate.js +0 -6
- package/dist/mjs/predicate-factory/createStringMatchingPredicate.js +0 -1
- package/dist/mjs/predicate-factory/index.js +0 -14
- package/dist/types/predicate-factory/createIsEnumPredicate.d.ts +0 -3
- package/dist/types/predicate-factory/createIsInstanceOfPredicate.d.ts +0 -3
- package/dist/types/predicate-factory/createIsTuplePredicate.d.ts +0 -7
- package/dist/types/predicate-factory/createNumberRangePredicate.d.ts +0 -2
- package/dist/types/predicate-factory/createStringLengthRangePredicate.d.ts +0 -2
- package/dist/types/predicate-factory/createStringMatchingPredicate.d.ts +0 -2
- package/dist/types/predicate-factory/everyItem.d.ts +0 -2
- package/dist/types/predicate-factory/index.d.ts +0 -14
- package/dist/types/predicate-factory/is.d.ts +0 -3
- /package/dist/cjs/{predicate-factory → predicate/factory}/allOf.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/anyOf.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/everyItem.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/is.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/maybeArray.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/maybeNull.js +0 -0
- /package/dist/cjs/{predicate-factory → predicate/factory}/maybeUndefined.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/allOf.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/anyOf.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/everyItem.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/is.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/maybeArray.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/maybeNull.js +0 -0
- /package/dist/mjs/{predicate-factory → predicate/factory}/maybeUndefined.js +0 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { isObject } from './isObject.js';
|
|
2
1
|
export const isIterable = (input) => {
|
|
3
|
-
return
|
|
2
|
+
return (input !== null &&
|
|
3
|
+
typeof input === 'object' &&
|
|
4
|
+
Symbol.iterator in input &&
|
|
5
|
+
typeof input[Symbol.iterator] === 'function');
|
|
4
6
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const isNumericString =
|
|
1
|
+
import { matching } from './factory/matching.js';
|
|
2
|
+
export const isNumericString = matching(/^[-+]?\d+(\.\d+)?$/);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { shape } from './factory/shape.js';
|
|
2
|
+
import { withLength } from './factory/withLength.js';
|
|
1
3
|
import { isFunction } from './isFunction.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
4
|
+
export const isPromiseLike = shape({
|
|
5
|
+
then: withLength(isFunction, 2),
|
|
6
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function assertIsAsyncIterable
|
|
1
|
+
export declare function assertIsAsyncIterable(input: unknown, error?: string | Error): asserts input is AsyncIterable<unknown>;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function assertIsFunction<Func extends AnyFunction = AnyFunction>(input: unknown, error?: string | Error): asserts input is Func;
|
|
1
|
+
export declare function assertIsFunction(input: unknown, error?: string | Error): asserts input is Function;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { InferPredicatesReturnType, TypePredicateFn } from '
|
|
2
|
-
import type { IntersectionOf } from '
|
|
1
|
+
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
2
|
+
import type { IntersectionOf } from '../../types/utils.js';
|
|
3
3
|
export declare const allOf: <Predicates extends TypePredicateFn<unknown>[]>(...predicates: Predicates) => TypePredicateFn<IntersectionOf<InferPredicatesReturnType<Predicates>>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { InferPredicatesReturnType, TypePredicateFn } from '
|
|
2
|
-
import type { UnionOf } from '
|
|
1
|
+
import type { InferPredicatesReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
2
|
+
import type { UnionOf } from '../../types/utils.js';
|
|
3
3
|
export declare const anyOf: <Predicates extends TypePredicateFn<unknown>[]>(...predicates: Predicates) => TypePredicateFn<UnionOf<InferPredicatesReturnType<Predicates>>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './allOf.js';
|
|
2
|
+
export * from './anyOf.js';
|
|
3
|
+
export * from './everyItem.js';
|
|
4
|
+
export * from './fromEnum.js';
|
|
5
|
+
export * from './instanceOf.js';
|
|
6
|
+
export * from './is.js';
|
|
7
|
+
export * from './literal.js';
|
|
8
|
+
export * from './matching.js';
|
|
9
|
+
export * from './maybeArray.js';
|
|
10
|
+
export * from './maybeNull.js';
|
|
11
|
+
export * from './maybeUndefined.js';
|
|
12
|
+
export * from './range.js';
|
|
13
|
+
export * from './shape.js';
|
|
14
|
+
export * from './stringLength.js';
|
|
15
|
+
export * from './tuple.js';
|
|
16
|
+
export * from './typeOf.js';
|
|
17
|
+
export * from './withLength.js';
|
|
18
|
+
export * from './withSize.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { TypePredicateFn } from '
|
|
1
|
+
import type { TypePredicateFn } from '../../types/functions.js';
|
|
2
2
|
export declare const maybeArray: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | T[]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { TypePredicateFn } from '
|
|
1
|
+
import type { TypePredicateFn } from '../../types/functions.js';
|
|
2
2
|
export declare const maybeNull: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | null>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { TypePredicateFn } from '
|
|
1
|
+
import type { TypePredicateFn } from '../../types/functions.js';
|
|
2
2
|
export declare const maybeUndefined: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | undefined>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Primitive } from '
|
|
2
|
-
import type { InferPredicateReturnType, TypePredicateFn } from '
|
|
3
|
-
import type { Pretty } from '
|
|
1
|
+
import type { Primitive } from '../../types/common.js';
|
|
2
|
+
import type { InferPredicateReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
3
|
+
import type { Pretty } from '../../types/utils.js';
|
|
4
4
|
export type WithRegExp<Type> = Type extends string ? Type | RegExp : Type;
|
|
5
|
-
export type ObjectShapeValue<Type> = Type extends object ? ObjectShapeRecord<Type> : WithRegExp<Extract<Type, Primitive>>;
|
|
5
|
+
export type ObjectShapeValue<Type> = Type extends object ? Type extends Function ? TypePredicateFn<Function> : ObjectShapeRecord<Type> : WithRegExp<Extract<Type, Primitive>>;
|
|
6
6
|
export type ObjectShapeRecord<Type extends object = object> = {
|
|
7
7
|
[Property in keyof Type]: ObjectShapeValue<Type[Property]> | TypePredicateFn<Type[Property]>;
|
|
8
8
|
};
|
|
@@ -10,4 +10,4 @@ export type InferTypeFromShapeValue<Type> = Type extends RegExp ? string : Type
|
|
|
10
10
|
export type InferTypeFromShape<Shape extends ObjectShapeRecord<object>> = Pretty<{
|
|
11
11
|
-readonly [Property in keyof Shape]: InferTypeFromShapeValue<Shape[Property]>;
|
|
12
12
|
}>;
|
|
13
|
-
export declare const
|
|
13
|
+
export declare const shape: <Type extends object, const Shape extends ObjectShapeRecord<Type> = ObjectShapeRecord<Type>>(objectShape: Shape) => TypePredicateFn<InferTypeFromShape<Shape>>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { InferPredicateReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
2
|
+
export type Simple<Type> = Type extends string ? string : Type extends number ? number : Type extends boolean ? boolean : Type extends bigint ? bigint : Type extends symbol ? symbol : Type extends undefined ? undefined : Type extends null ? null : Type extends Function ? Function : Type extends unknown[] ? unknown[] : Type extends object ? object : never;
|
|
3
|
+
export declare const simple: <Fn extends TypePredicateFn<unknown>>(fn: Fn) => TypePredicateFn<Simple<InferPredicateReturnType<Fn>>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Primitive } from '../../types/common.js';
|
|
2
|
+
import type { TypePredicateFn } from '../../types/functions.js';
|
|
3
|
+
export type TuplePredicateInput = (Primitive | TypePredicateFn<unknown>)[];
|
|
4
|
+
export type GetTupleFromInput<Type extends TuplePredicateInput> = {
|
|
5
|
+
[Property in keyof Type]: Type[Property] extends TypePredicateFn<infer T> ? T : Type[Property];
|
|
6
|
+
};
|
|
7
|
+
export declare const tuple: <const Input extends TuplePredicateInput>(tupleShape: Input) => TypePredicateFn<GetTupleFromInput<Input>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { InferPredicateReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
2
|
+
import type { NumberRange } from '../../types/numbers.js';
|
|
3
|
+
export declare function withLength<Fn extends TypePredicateFn<{
|
|
4
|
+
length: number;
|
|
5
|
+
}>, Length extends number>(fn: Fn, length: Length): TypePredicateFn<InferPredicateReturnType<Fn> & {
|
|
6
|
+
length: Length;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function withLength<Fn extends TypePredicateFn<{
|
|
9
|
+
length: number;
|
|
10
|
+
}>, const Length extends [number]>(fn: Fn, length: Length): TypePredicateFn<InferPredicateReturnType<Fn> & {
|
|
11
|
+
length: Length[0];
|
|
12
|
+
}>;
|
|
13
|
+
export declare function withLength<Fn extends TypePredicateFn<{
|
|
14
|
+
length: number;
|
|
15
|
+
}>, Range extends NumberRange>(fn: Fn, range: Range): TypePredicateFn<InferPredicateReturnType<Fn> & {
|
|
16
|
+
length: number;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { InferPredicateReturnType, TypePredicateFn } from '../../types/functions.js';
|
|
2
|
+
import type { NumberRange } from '../../types/numbers.js';
|
|
3
|
+
export declare function withSize<Fn extends TypePredicateFn<{
|
|
4
|
+
size: number;
|
|
5
|
+
}>, Size extends number>(fn: Fn, size: Size): TypePredicateFn<InferPredicateReturnType<Fn> & {
|
|
6
|
+
size: Size;
|
|
7
|
+
}>;
|
|
8
|
+
export declare function withSize<Fn extends TypePredicateFn<{
|
|
9
|
+
size: number;
|
|
10
|
+
}>, const Size extends [number]>(fn: Fn, size: Size): TypePredicateFn<InferPredicateReturnType<Fn> & {
|
|
11
|
+
size: Size[0];
|
|
12
|
+
}>;
|
|
13
|
+
export declare function withSize<Fn extends TypePredicateFn<{
|
|
14
|
+
size: number;
|
|
15
|
+
}>, Range extends NumberRange>(fn: Fn, range: Range): TypePredicateFn<InferPredicateReturnType<Fn> & {
|
|
16
|
+
size: number;
|
|
17
|
+
}>;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const isFunction: <Func extends AnyFunction = AnyFunction>(input: unknown) => input is Func;
|
|
1
|
+
export declare const isFunction: (input: unknown) => input is Function;
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export declare
|
|
1
|
+
export declare const isPromiseLike: import("../index.js").TypePredicateFn<{
|
|
2
|
+
then: Function | (<TResult1 = unknown, TResult2 = never>(onfulfilled?: ((value: unknown) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => PromiseLike<TResult1 | TResult2>);
|
|
3
|
+
}>;
|
|
@@ -8,6 +8,16 @@ export type JsonObject = {
|
|
|
8
8
|
export type JsonArray = JsonValue[];
|
|
9
9
|
export type JsonValue = string | number | boolean | null | object | JsonObject | JsonArray;
|
|
10
10
|
export type TypeOf = 'undefined' | 'object' | 'boolean' | 'number' | 'bigint' | 'string' | 'symbol' | 'function';
|
|
11
|
+
export type TypeOfMapping = {
|
|
12
|
+
undefined: undefined;
|
|
13
|
+
object: object;
|
|
14
|
+
boolean: boolean;
|
|
15
|
+
number: number;
|
|
16
|
+
bigint: bigint;
|
|
17
|
+
string: string;
|
|
18
|
+
symbol: symbol;
|
|
19
|
+
function: Function;
|
|
20
|
+
};
|
|
11
21
|
export type Builtin = Date | Error | Function | Primitive | RegExp;
|
|
12
22
|
export type AnyFunction = (...args: any[]) => any;
|
|
13
23
|
export type AnySyncFunction = (...args: any[]) => NotPromise<any>;
|
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.54.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"require": "./dist/cjs/index.js",
|
|
29
29
|
"import": "./dist/mjs/index.js"
|
|
30
30
|
},
|
|
31
|
-
"./predicate
|
|
32
|
-
"types": "./dist/types/predicate
|
|
33
|
-
"require": "./dist/cjs/predicate
|
|
34
|
-
"import": "./dist/mjs/predicate
|
|
31
|
+
"./predicate/factory": {
|
|
32
|
+
"types": "./dist/types/predicate/factory/index.d.ts",
|
|
33
|
+
"require": "./dist/cjs/predicate/factory/index.js",
|
|
34
|
+
"import": "./dist/mjs/predicate/factory/index.js"
|
|
35
35
|
},
|
|
36
36
|
"./predicate": {
|
|
37
37
|
"types": "./dist/types/predicate/index.d.ts",
|
|
@@ -66,13 +66,13 @@
|
|
|
66
66
|
"url": "https://github.com/webdeveric/utils/issues"
|
|
67
67
|
},
|
|
68
68
|
"homepage": "https://github.com/webdeveric/utils/#readme",
|
|
69
|
-
"packageManager": "pnpm@10.6.
|
|
69
|
+
"packageManager": "pnpm@10.6.3+sha512.bb45e34d50a9a76e858a95837301bfb6bd6d35aea2c5d52094fa497a467c43f5c440103ce2511e9e0a2f89c3d6071baac3358fc68ac6fb75e2ceb3d2736065e6",
|
|
70
70
|
"scripts": {
|
|
71
71
|
"clean": "rimraf ./dist/",
|
|
72
72
|
"prebuild": "pnpm clean",
|
|
73
73
|
"build": "tsc --build tsconfig.cjs.json tsconfig.mjs.json --force",
|
|
74
74
|
"postbuild": "echo '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json && echo '{\"type\":\"module\"}' > ./dist/mjs/package.json && pnpm validate",
|
|
75
|
-
"typecheck": "tsc --build --verbose --noEmit",
|
|
75
|
+
"typecheck": "tsc --build tsconfig.mjs.json tsconfig.test.json --verbose --noEmit",
|
|
76
76
|
"lint": "eslint ./*.{js,cjs,mjs,ts,cts,mts} ./src/ ./bench/ ./test/ --ext .ts,.mjs,.cjs",
|
|
77
77
|
"bench": "vitest bench",
|
|
78
78
|
"test": "vitest --typecheck",
|
|
@@ -97,16 +97,21 @@
|
|
|
97
97
|
"cspell": "^8.17.5",
|
|
98
98
|
"eslint": "^8.57.1",
|
|
99
99
|
"eslint-config-prettier": "^10.1.1",
|
|
100
|
-
"eslint-import-resolver-typescript": "^3.
|
|
100
|
+
"eslint-import-resolver-typescript": "^3.9.1",
|
|
101
101
|
"eslint-plugin-import": "^2.31.0",
|
|
102
102
|
"husky": "^9.1.7",
|
|
103
103
|
"jsdom": "^26.0.0",
|
|
104
|
-
"lint-staged": "^15.
|
|
104
|
+
"lint-staged": "^15.5.0",
|
|
105
105
|
"prettier": "^3.5.3",
|
|
106
106
|
"rimraf": "^6.0.1",
|
|
107
107
|
"semantic-release": "^24.2.3",
|
|
108
108
|
"typescript": "^5.8.2",
|
|
109
109
|
"validate-package-exports": "^0.8.0",
|
|
110
110
|
"vitest": "^3.0.8"
|
|
111
|
+
},
|
|
112
|
+
"pnpm": {
|
|
113
|
+
"onlyBuiltDependencies": [
|
|
114
|
+
"esbuild"
|
|
115
|
+
]
|
|
111
116
|
}
|
|
112
117
|
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createIsInstanceOfPredicate = void 0;
|
|
4
|
-
const createIsInstanceOfPredicate = (constructor) => (input) => input instanceof constructor;
|
|
5
|
-
exports.createIsInstanceOfPredicate = createIsInstanceOfPredicate;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNumberRangePredicate = void 0;
|
|
4
|
-
const assertIsNumber_js_1 = require("../assertion/assertIsNumber.js");
|
|
5
|
-
const isNumber_js_1 = require("../predicate/isNumber.js");
|
|
6
|
-
const createNumberRangePredicate = (min, max = Number.POSITIVE_INFINITY) => {
|
|
7
|
-
(0, assertIsNumber_js_1.assertIsNumber)(min, 'min is not a number');
|
|
8
|
-
(0, assertIsNumber_js_1.assertIsNumber)(max, 'max is not a number');
|
|
9
|
-
if (min === Number.NEGATIVE_INFINITY && max === Number.POSITIVE_INFINITY) {
|
|
10
|
-
throw new RangeError('min and max cannot be -Infinity and Infinity');
|
|
11
|
-
}
|
|
12
|
-
if (min > max) {
|
|
13
|
-
throw new RangeError('min cannot be greater than max');
|
|
14
|
-
}
|
|
15
|
-
if (min === max) {
|
|
16
|
-
throw new RangeError('min and max cannot be the same');
|
|
17
|
-
}
|
|
18
|
-
return (input) => (0, isNumber_js_1.isNumber)(input) && input >= min && input <= max;
|
|
19
|
-
};
|
|
20
|
-
exports.createNumberRangePredicate = createNumberRangePredicate;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createObjectShapePredicate = void 0;
|
|
4
|
-
const isAnyObject_js_1 = require("../predicate/isAnyObject.js");
|
|
5
|
-
const createStringMatchingPredicate_js_1 = require("./createStringMatchingPredicate.js");
|
|
6
|
-
const createObjectShapePredicate = (shape) => {
|
|
7
|
-
const entries = Object.entries(shape).map(([key, value]) => {
|
|
8
|
-
const predicate = typeof value === 'function'
|
|
9
|
-
? value
|
|
10
|
-
: value instanceof RegExp
|
|
11
|
-
? (0, createStringMatchingPredicate_js_1.createStringMatchingPredicate)(value)
|
|
12
|
-
: (0, isAnyObject_js_1.isAnyObject)(value)
|
|
13
|
-
? (0, exports.createObjectShapePredicate)(value)
|
|
14
|
-
: (input) => input === value;
|
|
15
|
-
return [key, predicate];
|
|
16
|
-
});
|
|
17
|
-
return (input) => (0, isAnyObject_js_1.isAnyObject)(input) && entries.every(([key, predicate]) => predicate(input[key]));
|
|
18
|
-
};
|
|
19
|
-
exports.createObjectShapePredicate = createObjectShapePredicate;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createStringLengthRangePredicate = void 0;
|
|
4
|
-
const createStringLengthRangePredicate = (min, max = Number.POSITIVE_INFINITY) => {
|
|
5
|
-
if (min < 0) {
|
|
6
|
-
throw new RangeError('min must be >= 0');
|
|
7
|
-
}
|
|
8
|
-
return (input) => typeof input === 'string' && input.length >= min && input.length <= max;
|
|
9
|
-
};
|
|
10
|
-
exports.createStringLengthRangePredicate = createStringLengthRangePredicate;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createStringMatchingPredicate = void 0;
|
|
4
|
-
const createStringMatchingPredicate = (pattern) => (input) => typeof input === 'string' && pattern.test(input);
|
|
5
|
-
exports.createStringMatchingPredicate = createStringMatchingPredicate;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const createIsInstanceOfPredicate = (constructor) => (input) => input instanceof constructor;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { assertIsNumber } from '../assertion/assertIsNumber.js';
|
|
2
|
-
import { isNumber } from '../predicate/isNumber.js';
|
|
3
|
-
export const createNumberRangePredicate = (min, max = Number.POSITIVE_INFINITY) => {
|
|
4
|
-
assertIsNumber(min, 'min is not a number');
|
|
5
|
-
assertIsNumber(max, 'max is not a number');
|
|
6
|
-
if (min === Number.NEGATIVE_INFINITY && max === Number.POSITIVE_INFINITY) {
|
|
7
|
-
throw new RangeError('min and max cannot be -Infinity and Infinity');
|
|
8
|
-
}
|
|
9
|
-
if (min > max) {
|
|
10
|
-
throw new RangeError('min cannot be greater than max');
|
|
11
|
-
}
|
|
12
|
-
if (min === max) {
|
|
13
|
-
throw new RangeError('min and max cannot be the same');
|
|
14
|
-
}
|
|
15
|
-
return (input) => isNumber(input) && input >= min && input <= max;
|
|
16
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { isAnyObject } from '../predicate/isAnyObject.js';
|
|
2
|
-
import { createStringMatchingPredicate } from './createStringMatchingPredicate.js';
|
|
3
|
-
export const createObjectShapePredicate = (shape) => {
|
|
4
|
-
const entries = Object.entries(shape).map(([key, value]) => {
|
|
5
|
-
const predicate = typeof value === 'function'
|
|
6
|
-
? value
|
|
7
|
-
: value instanceof RegExp
|
|
8
|
-
? createStringMatchingPredicate(value)
|
|
9
|
-
: isAnyObject(value)
|
|
10
|
-
? createObjectShapePredicate(value)
|
|
11
|
-
: (input) => input === value;
|
|
12
|
-
return [key, predicate];
|
|
13
|
-
});
|
|
14
|
-
return (input) => isAnyObject(input) && entries.every(([key, predicate]) => predicate(input[key]));
|
|
15
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const createStringMatchingPredicate = (pattern) => (input) => typeof input === 'string' && pattern.test(input);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export * from './allOf.js';
|
|
2
|
-
export * from './anyOf.js';
|
|
3
|
-
export * from './createIsEnumPredicate.js';
|
|
4
|
-
export * from './createIsInstanceOfPredicate.js';
|
|
5
|
-
export * from './createIsTuplePredicate.js';
|
|
6
|
-
export * from './createNumberRangePredicate.js';
|
|
7
|
-
export * from './createObjectShapePredicate.js';
|
|
8
|
-
export * from './createStringLengthRangePredicate.js';
|
|
9
|
-
export * from './createStringMatchingPredicate.js';
|
|
10
|
-
export * from './everyItem.js';
|
|
11
|
-
export * from './is.js';
|
|
12
|
-
export * from './maybeArray.js';
|
|
13
|
-
export * from './maybeNull.js';
|
|
14
|
-
export * from './maybeUndefined.js';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Primitive } from '../types/common.js';
|
|
2
|
-
import type { TypePredicateFn } from '../types/functions.js';
|
|
3
|
-
export type TuplePredicateInput = (Primitive | TypePredicateFn<unknown>)[];
|
|
4
|
-
export type GetTupleFromInput<Type extends TuplePredicateInput> = {
|
|
5
|
-
[Property in keyof Type]: Type[Property] extends TypePredicateFn<infer T> ? T : Type[Property];
|
|
6
|
-
};
|
|
7
|
-
export declare const createIsTuplePredicate: <const Input extends TuplePredicateInput>(tupleShape: Input) => TypePredicateFn<GetTupleFromInput<Input>>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export * from './allOf.js';
|
|
2
|
-
export * from './anyOf.js';
|
|
3
|
-
export * from './createIsEnumPredicate.js';
|
|
4
|
-
export * from './createIsInstanceOfPredicate.js';
|
|
5
|
-
export * from './createIsTuplePredicate.js';
|
|
6
|
-
export * from './createNumberRangePredicate.js';
|
|
7
|
-
export * from './createObjectShapePredicate.js';
|
|
8
|
-
export * from './createStringLengthRangePredicate.js';
|
|
9
|
-
export * from './createStringMatchingPredicate.js';
|
|
10
|
-
export * from './everyItem.js';
|
|
11
|
-
export * from './is.js';
|
|
12
|
-
export * from './maybeArray.js';
|
|
13
|
-
export * from './maybeNull.js';
|
|
14
|
-
export * from './maybeUndefined.js';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|