@webdeveric/utils 0.47.0 → 0.49.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.
@@ -0,0 +1,19 @@
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;
@@ -0,0 +1,15 @@
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,5 +1,4 @@
1
1
  import type { TypeAssertionFn } from './types/functions.js';
2
2
  export type JsonReviver = Parameters<JSON['parse']>[1];
3
- export declare function jsonParse(input: string): unknown;
4
3
  export declare function jsonParse(input: string, reviver?: JsonReviver): unknown;
5
4
  export declare function jsonParse<T>(input: string, reviver: JsonReviver | undefined, assertionFn: TypeAssertionFn<T>): T;
@@ -0,0 +1,13 @@
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
+ export type WithRegExp<Type> = Type extends string ? Type | RegExp : Type;
5
+ export type ObjectShapeValue<Type> = Type extends object ? ObjectShapeRecord<Type> : WithRegExp<Extract<Type, Primitive>>;
6
+ export type ObjectShapeRecord<Type extends object = object> = {
7
+ [Property in keyof Type]: ObjectShapeValue<Type[Property]> | TypePredicateFn<Type[Property]>;
8
+ };
9
+ export type InferTypeFromShapeValue<Type> = Type extends RegExp ? string : Type extends Primitive ? Type : Type extends TypePredicateFn<unknown> ? InferPredicateReturnType<Type> : Type extends ObjectShapeRecord<object> ? InferTypeFromShape<Type> : never;
10
+ export type InferTypeFromShape<Shape extends ObjectShapeRecord<object>> = Pretty<{
11
+ -readonly [Property in keyof Shape]: InferTypeFromShapeValue<Shape[Property]>;
12
+ }>;
13
+ export declare const createObjectShapePredicate: <Type extends object, const Shape extends ObjectShapeRecord<Type> = ObjectShapeRecord<Type>>(shape: Shape) => TypePredicateFn<InferTypeFromShape<Shape>>;
@@ -1,2 +1,2 @@
1
1
  import type { TypePredicateFn } from '../types/functions.js';
2
- export declare const createStringLengthRangePredicate: (min: number, max?: number) => TypePredicateFn<string>;
2
+ export declare const createStringLengthRangePredicate: <Type extends string = string>(min: number, max?: number) => TypePredicateFn<Type>;
@@ -12,3 +12,4 @@ export type FirstChar<Type extends string> = Type extends `${infer First}${infer
12
12
  export type AddSpaceAroundNumbers<Type extends string> = Type extends `${infer First}${infer Rest}` ? Rest extends EmptyString ? First : First extends AlphaCharacter | Capitalize<AlphaCharacter> ? FirstChar<Rest> extends NumericCharacter ? `${First}${Space}${AddSpaceAroundNumbers<Rest>}` : `${First}${AddSpaceAroundNumbers<Rest>}` : First extends NumericCharacter ? FirstChar<Rest> extends AlphaCharacter | Capitalize<AlphaCharacter> ? `${First}${Space}${AddSpaceAroundNumbers<Rest>}` : `${First}${AddSpaceAroundNumbers<Rest>}` : `${First}${AddSpaceAroundNumbers<Rest>}` : never;
13
13
  export type CamelCase<Type extends string, Delimiter extends string = Space> = Type extends `${infer Left}${Delimiter}${infer Right}` ? `${Left}${CamelCase<Capitalize<Right>, Delimiter>}` : Type;
14
14
  export type PascalCase<Type extends string, Delimiter extends string = Space> = Capitalize<CamelCase<AlphanumericOnly<AddSpaceAroundNumbers<Strip<Type, "'">>>, Delimiter>>;
15
+ export type StringLength<Type extends string, Accumulator extends never[] = []> = string extends Type ? never : Type extends `${infer _}${infer Rest}` ? StringLength<Rest, [never, ...Accumulator]> : Accumulator['length'];
@@ -39,3 +39,6 @@ export type DeepPartial<Type> = Type extends object ? {
39
39
  [Property in keyof Type]?: DeepPartial<Type[Property]>;
40
40
  } : Type;
41
41
  export type UnionToIntersection<Union> = (Union extends any ? (union: Union) => void : never) extends (union: infer Type extends Union) => void ? Type : never;
42
+ export type Pretty<Type> = {
43
+ [Property in keyof Type]: Type[Property];
44
+ } & unknown;
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.47.0",
4
+ "version": "0.49.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -66,7 +66,7 @@
66
66
  "url": "https://github.com/webdeveric/utils/issues"
67
67
  },
68
68
  "homepage": "https://github.com/webdeveric/utils/#readme",
69
- "packageManager": "pnpm@10.2.0+sha512.0d27364e0139c6aadeed65ada153135e0ca96c8da42123bd50047f961339dc7a758fc2e944b428f52be570d1bd3372455c1c65fa2e7aa0bfbf931190f9552001",
69
+ "packageManager": "pnpm@10.4.1+sha512.c753b6c3ad7afa13af388fa6d808035a008e30ea9993f58c6663e2bc5ff21679aa834db094987129aa4d488b86df57f7b634981b2f827cdcacc698cc0cfb88af",
70
70
  "scripts": {
71
71
  "clean": "rimraf ./dist/",
72
72
  "prebuild": "pnpm clean",
@@ -87,26 +87,31 @@
87
87
  "devDependencies": {
88
88
  "@commitlint/config-conventional": "^19.7.1",
89
89
  "@commitlint/types": "^19.5.0",
90
- "@types/node": "^22.13.1",
91
- "@vitest/coverage-v8": "^3.0.5",
90
+ "@types/node": "^22.13.5",
91
+ "@vitest/coverage-v8": "^3.0.6",
92
92
  "@webdeveric/eslint-config-ts": "^0.11.0",
93
93
  "@webdeveric/prettier-config": "^0.3.0",
94
94
  "commitlint": "^19.7.1",
95
95
  "commitlint-plugin-cspell": "^0.1.1",
96
96
  "conventional-changelog-conventionalcommits": "^8.0.0",
97
- "cspell": "^8.17.3",
97
+ "cspell": "^8.17.5",
98
98
  "eslint": "^8.57.1",
99
99
  "eslint-config-prettier": "^10.0.1",
100
- "eslint-import-resolver-typescript": "^3.7.0",
100
+ "eslint-import-resolver-typescript": "^3.8.3",
101
101
  "eslint-plugin-import": "^2.31.0",
102
102
  "husky": "^9.1.7",
103
103
  "jsdom": "^26.0.0",
104
104
  "lint-staged": "^15.4.3",
105
- "prettier": "^3.4.2",
105
+ "prettier": "^3.5.2",
106
106
  "rimraf": "^6.0.1",
107
- "semantic-release": "^24.2.1",
107
+ "semantic-release": "^24.2.3",
108
108
  "typescript": "^5.7.3",
109
109
  "validate-package-exports": "^0.8.0",
110
- "vitest": "^3.0.5"
110
+ "vitest": "^3.0.6"
111
+ },
112
+ "pnpm": {
113
+ "overrides": {
114
+ "esbuild@<=0.24.2": ">=0.25.0"
115
+ }
111
116
  }
112
117
  }