@webdeveric/utils 0.53.0 → 0.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/cjs/assertion/assertIsStringMatching.js +2 -2
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/{predicate-factory/createIsEnumPredicate.js → predicate/factory/fromEnum.js} +3 -3
  4. package/dist/cjs/{predicate-factory → predicate/factory}/index.js +11 -7
  5. package/dist/cjs/predicate/factory/instanceOf.js +5 -0
  6. package/dist/cjs/predicate/factory/literal.js +5 -0
  7. package/dist/cjs/predicate/factory/matching.js +5 -0
  8. package/dist/cjs/predicate/factory/range.js +15 -0
  9. package/dist/cjs/predicate/factory/shape.js +20 -0
  10. package/dist/cjs/predicate/factory/simple.js +5 -0
  11. package/dist/cjs/predicate/factory/stringLength.js +13 -0
  12. package/dist/cjs/{predicate-factory/createIsTuplePredicate.js → predicate/factory/tuple.js} +3 -3
  13. package/dist/cjs/predicate/factory/typeOf.js +5 -0
  14. package/dist/cjs/predicate/factory/withLength.js +13 -0
  15. package/dist/cjs/predicate/factory/withSize.js +13 -0
  16. package/dist/cjs/predicate/isAsyncIterable.js +4 -2
  17. package/dist/cjs/predicate/isBigIntArray.js +1 -1
  18. package/dist/cjs/predicate/isBooleanArray.js +1 -1
  19. package/dist/cjs/predicate/isDigitsString.js +2 -2
  20. package/dist/cjs/predicate/isISODateString.js +2 -2
  21. package/dist/cjs/predicate/isIntString.js +2 -2
  22. package/dist/cjs/predicate/isIterable.js +4 -2
  23. package/dist/cjs/predicate/isNullArray.js +1 -1
  24. package/dist/cjs/predicate/isNumberArray.js +1 -1
  25. package/dist/cjs/predicate/isNumericString.js +2 -2
  26. package/dist/cjs/predicate/isNumericValueArray.js +1 -1
  27. package/dist/cjs/predicate/isOptionalBigInt.js +1 -1
  28. package/dist/cjs/predicate/isOptionalBoolean.js +1 -1
  29. package/dist/cjs/predicate/isOptionalISODateString.js +1 -1
  30. package/dist/cjs/predicate/isOptionalNull.js +1 -1
  31. package/dist/cjs/predicate/isOptionalNumber.js +1 -1
  32. package/dist/cjs/predicate/isOptionalString.js +1 -1
  33. package/dist/cjs/predicate/isOptionalSymbol.js +1 -1
  34. package/dist/cjs/predicate/isPromiseLike.js +6 -5
  35. package/dist/cjs/predicate/isStringArray.js +1 -1
  36. package/dist/cjs/predicate/isSymbolArray.js +1 -1
  37. package/dist/cjs/predicate/isUndefinedArray.js +1 -1
  38. package/dist/mjs/assertion/assertIsStringMatching.js +2 -2
  39. package/dist/mjs/index.js +1 -1
  40. package/dist/mjs/{predicate-factory/createIsEnumPredicate.js → predicate/factory/fromEnum.js} +1 -1
  41. package/dist/mjs/predicate/factory/index.js +18 -0
  42. package/dist/mjs/predicate/factory/instanceOf.js +1 -0
  43. package/dist/mjs/predicate/factory/literal.js +1 -0
  44. package/dist/mjs/predicate/factory/matching.js +1 -0
  45. package/dist/mjs/predicate/factory/range.js +12 -0
  46. package/dist/mjs/predicate/factory/shape.js +16 -0
  47. package/dist/mjs/predicate/factory/simple.js +1 -0
  48. package/dist/mjs/predicate/factory/stringLength.js +9 -0
  49. package/dist/mjs/{predicate-factory/createIsTuplePredicate.js → predicate/factory/tuple.js} +1 -1
  50. package/dist/mjs/predicate/factory/typeOf.js +1 -0
  51. package/dist/mjs/predicate/factory/withLength.js +10 -0
  52. package/dist/mjs/predicate/factory/withSize.js +10 -0
  53. package/dist/mjs/predicate/isAsyncIterable.js +4 -2
  54. package/dist/mjs/predicate/isBigIntArray.js +1 -1
  55. package/dist/mjs/predicate/isBooleanArray.js +1 -1
  56. package/dist/mjs/predicate/isDigitsString.js +2 -2
  57. package/dist/mjs/predicate/isISODateString.js +2 -2
  58. package/dist/mjs/predicate/isIntString.js +2 -2
  59. package/dist/mjs/predicate/isIterable.js +4 -2
  60. package/dist/mjs/predicate/isNullArray.js +1 -1
  61. package/dist/mjs/predicate/isNumberArray.js +1 -1
  62. package/dist/mjs/predicate/isNumericString.js +2 -2
  63. package/dist/mjs/predicate/isNumericValueArray.js +1 -1
  64. package/dist/mjs/predicate/isOptionalBigInt.js +1 -1
  65. package/dist/mjs/predicate/isOptionalBoolean.js +1 -1
  66. package/dist/mjs/predicate/isOptionalISODateString.js +1 -1
  67. package/dist/mjs/predicate/isOptionalNull.js +1 -1
  68. package/dist/mjs/predicate/isOptionalNumber.js +1 -1
  69. package/dist/mjs/predicate/isOptionalString.js +1 -1
  70. package/dist/mjs/predicate/isOptionalSymbol.js +1 -1
  71. package/dist/mjs/predicate/isPromiseLike.js +5 -4
  72. package/dist/mjs/predicate/isStringArray.js +1 -1
  73. package/dist/mjs/predicate/isSymbolArray.js +1 -1
  74. package/dist/mjs/predicate/isUndefinedArray.js +1 -1
  75. package/dist/types/assertion/assertIsAsyncIterable.d.ts +1 -1
  76. package/dist/types/assertion/assertIsFunction.d.ts +1 -2
  77. package/dist/types/index.d.ts +1 -1
  78. package/dist/types/{predicate-factory → predicate/factory}/allOf.d.ts +2 -2
  79. package/dist/types/{predicate-factory → predicate/factory}/anyOf.d.ts +2 -2
  80. package/dist/types/predicate/factory/everyItem.d.ts +2 -0
  81. package/dist/types/predicate/factory/fromEnum.d.ts +3 -0
  82. package/dist/types/predicate/factory/index.d.ts +18 -0
  83. package/dist/types/predicate/factory/instanceOf.d.ts +3 -0
  84. package/dist/types/predicate/factory/is.d.ts +3 -0
  85. package/dist/types/predicate/factory/literal.d.ts +2 -0
  86. package/dist/types/predicate/factory/matching.d.ts +2 -0
  87. package/dist/types/{predicate-factory → predicate/factory}/maybeArray.d.ts +1 -1
  88. package/dist/types/{predicate-factory → predicate/factory}/maybeNull.d.ts +1 -1
  89. package/dist/types/{predicate-factory → predicate/factory}/maybeUndefined.d.ts +1 -1
  90. package/dist/types/predicate/factory/range.d.ts +3 -0
  91. package/dist/types/{predicate-factory/createObjectShapePredicate.d.ts → predicate/factory/shape.d.ts} +5 -5
  92. package/dist/types/predicate/factory/simple.d.ts +3 -0
  93. package/dist/types/predicate/factory/stringLength.d.ts +2 -0
  94. package/dist/types/predicate/factory/tuple.d.ts +7 -0
  95. package/dist/types/predicate/factory/typeOf.d.ts +2 -0
  96. package/dist/types/predicate/factory/withLength.d.ts +17 -0
  97. package/dist/types/predicate/factory/withSize.d.ts +17 -0
  98. package/dist/types/predicate/isFunction.d.ts +1 -2
  99. package/dist/types/predicate/isPromiseLike.d.ts +3 -1
  100. package/dist/types/types/common.d.ts +10 -0
  101. package/dist/types/types/numbers.d.ts +1 -0
  102. package/package.json +14 -9
  103. package/dist/cjs/predicate-factory/createIsInstanceOfPredicate.js +0 -5
  104. package/dist/cjs/predicate-factory/createNumberRangePredicate.js +0 -20
  105. package/dist/cjs/predicate-factory/createObjectShapePredicate.js +0 -19
  106. package/dist/cjs/predicate-factory/createStringLengthRangePredicate.js +0 -10
  107. package/dist/cjs/predicate-factory/createStringMatchingPredicate.js +0 -5
  108. package/dist/mjs/predicate-factory/createIsInstanceOfPredicate.js +0 -1
  109. package/dist/mjs/predicate-factory/createNumberRangePredicate.js +0 -16
  110. package/dist/mjs/predicate-factory/createObjectShapePredicate.js +0 -15
  111. package/dist/mjs/predicate-factory/createStringLengthRangePredicate.js +0 -6
  112. package/dist/mjs/predicate-factory/createStringMatchingPredicate.js +0 -1
  113. package/dist/mjs/predicate-factory/index.js +0 -14
  114. package/dist/types/predicate-factory/createIsEnumPredicate.d.ts +0 -3
  115. package/dist/types/predicate-factory/createIsInstanceOfPredicate.d.ts +0 -3
  116. package/dist/types/predicate-factory/createIsTuplePredicate.d.ts +0 -7
  117. package/dist/types/predicate-factory/createNumberRangePredicate.d.ts +0 -2
  118. package/dist/types/predicate-factory/createStringLengthRangePredicate.d.ts +0 -2
  119. package/dist/types/predicate-factory/createStringMatchingPredicate.d.ts +0 -2
  120. package/dist/types/predicate-factory/everyItem.d.ts +0 -2
  121. package/dist/types/predicate-factory/index.d.ts +0 -14
  122. package/dist/types/predicate-factory/is.d.ts +0 -3
  123. /package/dist/cjs/{predicate-factory → predicate/factory}/allOf.js +0 -0
  124. /package/dist/cjs/{predicate-factory → predicate/factory}/anyOf.js +0 -0
  125. /package/dist/cjs/{predicate-factory → predicate/factory}/everyItem.js +0 -0
  126. /package/dist/cjs/{predicate-factory → predicate/factory}/is.js +0 -0
  127. /package/dist/cjs/{predicate-factory → predicate/factory}/maybeArray.js +0 -0
  128. /package/dist/cjs/{predicate-factory → predicate/factory}/maybeNull.js +0 -0
  129. /package/dist/cjs/{predicate-factory → predicate/factory}/maybeUndefined.js +0 -0
  130. /package/dist/mjs/{predicate-factory → predicate/factory}/allOf.js +0 -0
  131. /package/dist/mjs/{predicate-factory → predicate/factory}/anyOf.js +0 -0
  132. /package/dist/mjs/{predicate-factory → predicate/factory}/everyItem.js +0 -0
  133. /package/dist/mjs/{predicate-factory → predicate/factory}/is.js +0 -0
  134. /package/dist/mjs/{predicate-factory → predicate/factory}/maybeArray.js +0 -0
  135. /package/dist/mjs/{predicate-factory → predicate/factory}/maybeNull.js +0 -0
  136. /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 isObject(input) && typeof input[Symbol.iterator] === 'function';
2
+ return (input !== null &&
3
+ typeof input === 'object' &&
4
+ Symbol.iterator in input &&
5
+ typeof input[Symbol.iterator] === 'function');
4
6
  };
@@ -1,3 +1,3 @@
1
- import { everyItem } from '../predicate-factory/everyItem.js';
1
+ import { everyItem } from './factory/everyItem.js';
2
2
  import { isNull } from './isNull.js';
3
3
  export const isNullArray = everyItem(isNull);
@@ -1,3 +1,3 @@
1
- import { everyItem } from '../predicate-factory/everyItem.js';
1
+ import { everyItem } from './factory/everyItem.js';
2
2
  import { isNumber } from './isNumber.js';
3
3
  export const isNumberArray = everyItem(isNumber);
@@ -1,2 +1,2 @@
1
- import { createStringMatchingPredicate } from '../predicate-factory/createStringMatchingPredicate.js';
2
- export const isNumericString = createStringMatchingPredicate(/^[-+]?\d+(\.\d+)?$/);
1
+ import { matching } from './factory/matching.js';
2
+ export const isNumericString = matching(/^[-+]?\d+(\.\d+)?$/);
@@ -1,3 +1,3 @@
1
- import { everyItem } from '../predicate-factory/everyItem.js';
1
+ import { everyItem } from './factory/everyItem.js';
2
2
  import { isNumericValue } from './isNumericValue.js';
3
3
  export const isNumericValueArray = everyItem(isNumericValue);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from '../predicate-factory/maybeUndefined.js';
1
+ import { maybeUndefined } from './factory/maybeUndefined.js';
2
2
  import { isBigInt } from './isBigInt.js';
3
3
  export const isOptionalBigInt = maybeUndefined(isBigInt);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from '../predicate-factory/maybeUndefined.js';
1
+ import { maybeUndefined } from './factory/maybeUndefined.js';
2
2
  import { isBoolean } from './isBoolean.js';
3
3
  export const isOptionalBoolean = maybeUndefined(isBoolean);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from '../predicate-factory/maybeUndefined.js';
1
+ import { maybeUndefined } from './factory/maybeUndefined.js';
2
2
  import { isISODateString } from './isISODateString.js';
3
3
  export const isOptionalISODateString = maybeUndefined(isISODateString);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from '../predicate-factory/maybeUndefined.js';
1
+ import { maybeUndefined } from './factory/maybeUndefined.js';
2
2
  import { isNull } from './isNull.js';
3
3
  export const isOptionalNull = maybeUndefined(isNull);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from '../predicate-factory/maybeUndefined.js';
1
+ import { maybeUndefined } from './factory/maybeUndefined.js';
2
2
  import { isNumber } from './isNumber.js';
3
3
  export const isOptionalNumber = maybeUndefined(isNumber);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from '../predicate-factory/maybeUndefined.js';
1
+ import { maybeUndefined } from './factory/maybeUndefined.js';
2
2
  import { isString } from './isString.js';
3
3
  export const isOptionalString = maybeUndefined(isString);
@@ -1,3 +1,3 @@
1
- import { maybeUndefined } from '../predicate-factory/maybeUndefined.js';
1
+ import { maybeUndefined } from './factory/maybeUndefined.js';
2
2
  import { isSymbol } from './isSymbol.js';
3
3
  export const isOptionalSymbol = maybeUndefined(isSymbol);
@@ -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
- import { isObjectWith } from './isObjectWith.js';
3
- export function isPromiseLike(input) {
4
- return isObjectWith(input, 'then') && isFunction(input.then) && input.then.length === 2;
5
- }
4
+ export const isPromiseLike = shape({
5
+ then: withLength(isFunction, 2),
6
+ });
@@ -1,3 +1,3 @@
1
- import { everyItem } from '../predicate-factory/everyItem.js';
1
+ import { everyItem } from './factory/everyItem.js';
2
2
  import { isString } from './isString.js';
3
3
  export const isStringArray = everyItem(isString);
@@ -1,3 +1,3 @@
1
- import { everyItem } from '../predicate-factory/everyItem.js';
1
+ import { everyItem } from './factory/everyItem.js';
2
2
  import { isSymbol } from './isSymbol.js';
3
3
  export const isSymbolArray = everyItem(isSymbol);
@@ -1,3 +1,3 @@
1
- import { everyItem } from '../predicate-factory/everyItem.js';
1
+ import { everyItem } from './factory/everyItem.js';
2
2
  import { isUndefined } from './isUndefined.js';
3
3
  export const isUndefinedArray = everyItem(isUndefined);
@@ -1 +1 @@
1
- export declare function assertIsAsyncIterable<Type>(input: unknown, error?: string | Error): asserts input is AsyncIterable<Type>;
1
+ export declare function assertIsAsyncIterable(input: unknown, error?: string | Error): asserts input is AsyncIterable<unknown>;
@@ -1,2 +1 @@
1
- import type { AnyFunction } from '../types/common.js';
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;
@@ -1,5 +1,5 @@
1
1
  export * from './assertion/index.js';
2
- export * from './predicate-factory/index.js';
2
+ export * from './predicate/factory/index.js';
3
3
  export * from './predicate/index.js';
4
4
  export * from './types/index.js';
5
5
  export * from './asArray.js';
@@ -1,3 +1,3 @@
1
- import type { InferPredicatesReturnType, TypePredicateFn } from '../types/functions.js';
2
- import type { IntersectionOf } from '../types/utils.js';
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 '../types/functions.js';
2
- import type { UnionOf } from '../types/utils.js';
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,2 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ export declare const everyItem: <Type>(predicate: TypePredicateFn<Type>) => TypePredicateFn<Type[]>;
@@ -0,0 +1,3 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ import type { UnknownRecord } from '../../types/records.js';
3
+ export declare const fromEnum: <T extends UnknownRecord>(enumObject: T) => TypePredicateFn<T[keyof T]>;
@@ -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';
@@ -0,0 +1,3 @@
1
+ import type { AnyNewable } from '../../types/common.js';
2
+ import type { TypePredicateFn } from '../../types/functions.js';
3
+ export declare const instanceOf: <T extends AnyNewable>(constructor: T) => TypePredicateFn<InstanceType<T>>;
@@ -0,0 +1,3 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ import type { Pretty, Writable } from '../../types/utils.js';
3
+ export declare const is: <const T extends unknown[]>(...options: T) => TypePredicateFn<Pretty<Writable<T[number]>>>;
@@ -0,0 +1,2 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ export declare const literal: <const Type>(value: Type) => TypePredicateFn<Type>;
@@ -0,0 +1,2 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ export declare const matching: <T extends string>(pattern: RegExp) => TypePredicateFn<T>;
@@ -1,2 +1,2 @@
1
- import type { TypePredicateFn } from '../types/functions.js';
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 '../types/functions.js';
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 '../types/functions.js';
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
2
  export declare const maybeUndefined: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T | undefined>;
@@ -0,0 +1,3 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ export declare function range(min: number, max: number): TypePredicateFn<number>;
3
+ export declare function range(min: bigint, max: bigint): TypePredicateFn<bigint>;
@@ -1,8 +1,8 @@
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';
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 createObjectShapePredicate: <Type extends object, const Shape extends ObjectShapeRecord<Type> = ObjectShapeRecord<Type>>(shape: Shape) => TypePredicateFn<InferTypeFromShape<Shape>>;
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,2 @@
1
+ import type { TypePredicateFn } from '../../types/functions.js';
2
+ export declare const stringLength: <Type extends string = string>(min: number, max?: number) => TypePredicateFn<Type>;
@@ -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,2 @@
1
+ import type { TypeOf, TypeOfMapping } from '../../types/common.js';
2
+ export declare const typeOf: <T extends TypeOf>(...types: T[]) => <Input>(input: Input) => input is Input & TypeOfMapping[T];
@@ -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
- import type { AnyFunction } from '../types/common.js';
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 function isPromiseLike<T>(input: unknown): input is PromiseLike<T>;
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>;
@@ -1,2 +1,3 @@
1
1
  import type { Branded } from './branded.js';
2
2
  export type Int32 = Branded<number, 'Int32'>;
3
+ export type NumberRange = [min: number] | [min: number, max: undefined] | [min: number, max: number] | [min: undefined, max: number];
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.53.0",
4
+ "version": "0.54.1",
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-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"
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.1+sha512.40ee09af407fa9fbb5fbfb8e1cb40fbb74c0af0c3e10e9224d7b53c7658528615b2c92450e74cfad91e3a2dcafe3ce4050d80bda71d757756d2ce2b66213e9a3",
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.8.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.4.3",
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,6 +0,0 @@
1
- export const createStringLengthRangePredicate = (min, max = Number.POSITIVE_INFINITY) => {
2
- if (min < 0) {
3
- throw new RangeError('min must be >= 0');
4
- }
5
- return (input) => typeof input === 'string' && input.length >= min && input.length <= max;
6
- };
@@ -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,3 +0,0 @@
1
- import type { TypePredicateFn } from '../types/functions.js';
2
- import type { UnknownRecord } from '../types/records.js';
3
- export declare const createIsEnumPredicate: <T extends UnknownRecord>(enumObject: T) => TypePredicateFn<T[keyof T]>;
@@ -1,3 +0,0 @@
1
- import type { AnyNewable } from '../types/common.js';
2
- import type { TypePredicateFn } from '../types/functions.js';
3
- export declare const createIsInstanceOfPredicate: <T extends AnyNewable>(constructor: T) => TypePredicateFn<InstanceType<T>>;
@@ -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,2 +0,0 @@
1
- import type { TypePredicateFn } from '../types/functions.js';
2
- export declare const createNumberRangePredicate: <Type extends number = number>(min: number, max?: number) => TypePredicateFn<Type>;
@@ -1,2 +0,0 @@
1
- import type { TypePredicateFn } from '../types/functions.js';
2
- export declare const createStringLengthRangePredicate: <Type extends string = string>(min: number, max?: number) => TypePredicateFn<Type>;
@@ -1,2 +0,0 @@
1
- import type { TypePredicateFn } from '../types/functions.js';
2
- export declare const createStringMatchingPredicate: <T extends string>(pattern: RegExp) => TypePredicateFn<T>;
@@ -1,2 +0,0 @@
1
- import type { TypePredicateFn } from '../types/functions.js';
2
- export declare const everyItem: <T>(predicate: TypePredicateFn<T>) => TypePredicateFn<T[]>;
@@ -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,3 +0,0 @@
1
- import type { TypePredicateFn } from '../types/functions.js';
2
- import type { Pretty, Writable } from '../types/utils.js';
3
- export declare const is: <const T extends unknown[]>(...options: T) => TypePredicateFn<Pretty<Writable<T[number]>>>;