@webdeveric/utils 0.48.0 → 0.49.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.
@@ -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
+ };
@@ -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>>;
@@ -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.48.0",
4
+ "version": "0.49.1",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -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.4",
90
+ "@types/node": "^22.13.5",
91
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.4",
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.8.2",
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.5.1",
105
+ "prettier": "^3.5.2",
106
106
  "rimraf": "^6.0.1",
107
107
  "semantic-release": "^24.2.3",
108
108
  "typescript": "^5.7.3",
109
109
  "validate-package-exports": "^0.8.0",
110
110
  "vitest": "^3.0.6"
111
+ },
112
+ "pnpm": {
113
+ "overrides": {
114
+ "esbuild@<=0.24.2": ">=0.25.0"
115
+ }
111
116
  }
112
117
  }
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @webdeveric/utils
2
2
 
3
- [![NodeJS](https://github.com/webdeveric/utils/actions/workflows/node.js.yml/badge.svg)](https://github.com/webdeveric/utils/actions/workflows/node.js.yml) [![CodeQL](https://github.com/webdeveric/utils/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/webdeveric/utils/actions/workflows/codeql-analysis.yml)
3
+ [![NodeJS](https://github.com/webdeveric/utils/actions/workflows/node.js.yml/badge.svg)](https://github.com/webdeveric/utils/actions/workflows/node.js.yml) [![CodeQL Advanced](https://github.com/webdeveric/utils/actions/workflows/codeql.yml/badge.svg)](https://github.com/webdeveric/utils/actions/workflows/codeql.yml)
4
4
 
5
5
  ## Install
6
6