@webdeveric/utils 0.44.0 → 0.45.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,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOwnPaths = void 0;
4
+ const getOwnPaths = (input) => {
5
+ return Object.entries(input).reduce((paths, [key, value]) => {
6
+ paths.push(key);
7
+ if (value && typeof value === 'object') {
8
+ paths.push(...(0, exports.getOwnPaths)(value).map((childKey) => `${key}.${childKey}`));
9
+ }
10
+ return paths;
11
+ }, []);
12
+ };
13
+ exports.getOwnPaths = getOwnPaths;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPaths = void 0;
4
+ const getPaths = (input) => {
5
+ const paths = [];
6
+ for (const key in input) {
7
+ paths.push(key);
8
+ const value = input[key];
9
+ if (value && typeof value === 'object') {
10
+ paths.push(...(0, exports.getPaths)(value).map((childKey) => `${key}.${childKey}`));
11
+ }
12
+ }
13
+ return paths;
14
+ };
15
+ exports.getPaths = getPaths;
package/dist/cjs/index.js CHANGED
@@ -41,7 +41,9 @@ __exportStar(require("./getMaxValue.js"), exports);
41
41
  __exportStar(require("./getMilliseconds.js"), exports);
42
42
  __exportStar(require("./getMinValue.js"), exports);
43
43
  __exportStar(require("./getOwnKeys.js"), exports);
44
+ __exportStar(require("./getOwnPaths.js"), exports);
44
45
  __exportStar(require("./getOwnProperties.js"), exports);
46
+ __exportStar(require("./getPaths.js"), exports);
45
47
  __exportStar(require("./getType.js"), exports);
46
48
  __exportStar(require("./inRange.js"), exports);
47
49
  __exportStar(require("./isEmpty.js"), exports);
@@ -5,13 +5,6 @@ const allOf = (...predicates) => {
5
5
  if (!predicates.length) {
6
6
  throw new Error('Predicate functions not provided');
7
7
  }
8
- return (input) => {
9
- for (const predicate of predicates) {
10
- if (!predicate(input)) {
11
- return false;
12
- }
13
- }
14
- return true;
15
- };
8
+ return (input) => predicates.every((predicate) => predicate(input));
16
9
  };
17
10
  exports.allOf = allOf;
@@ -5,13 +5,6 @@ const anyOf = (...predicates) => {
5
5
  if (!predicates.length) {
6
6
  throw new Error('Predicate functions not provided');
7
7
  }
8
- return (input) => {
9
- for (const predicate of predicates) {
10
- if (predicate(input)) {
11
- return true;
12
- }
13
- }
14
- return false;
15
- };
8
+ return (input) => predicates.some((predicate) => predicate(input));
16
9
  };
17
10
  exports.anyOf = anyOf;
@@ -0,0 +1,9 @@
1
+ export const getOwnPaths = (input) => {
2
+ return Object.entries(input).reduce((paths, [key, value]) => {
3
+ paths.push(key);
4
+ if (value && typeof value === 'object') {
5
+ paths.push(...getOwnPaths(value).map((childKey) => `${key}.${childKey}`));
6
+ }
7
+ return paths;
8
+ }, []);
9
+ };
@@ -0,0 +1,11 @@
1
+ export const getPaths = (input) => {
2
+ const paths = [];
3
+ for (const key in input) {
4
+ paths.push(key);
5
+ const value = input[key];
6
+ if (value && typeof value === 'object') {
7
+ paths.push(...getPaths(value).map((childKey) => `${key}.${childKey}`));
8
+ }
9
+ }
10
+ return paths;
11
+ };
package/dist/mjs/index.js CHANGED
@@ -25,7 +25,9 @@ export * from './getMaxValue.js';
25
25
  export * from './getMilliseconds.js';
26
26
  export * from './getMinValue.js';
27
27
  export * from './getOwnKeys.js';
28
+ export * from './getOwnPaths.js';
28
29
  export * from './getOwnProperties.js';
30
+ export * from './getPaths.js';
29
31
  export * from './getType.js';
30
32
  export * from './inRange.js';
31
33
  export * from './isEmpty.js';
@@ -2,12 +2,5 @@ export const allOf = (...predicates) => {
2
2
  if (!predicates.length) {
3
3
  throw new Error('Predicate functions not provided');
4
4
  }
5
- return (input) => {
6
- for (const predicate of predicates) {
7
- if (!predicate(input)) {
8
- return false;
9
- }
10
- }
11
- return true;
12
- };
5
+ return (input) => predicates.every((predicate) => predicate(input));
13
6
  };
@@ -2,12 +2,5 @@ export const anyOf = (...predicates) => {
2
2
  if (!predicates.length) {
3
3
  throw new Error('Predicate functions not provided');
4
4
  }
5
- return (input) => {
6
- for (const predicate of predicates) {
7
- if (predicate(input)) {
8
- return true;
9
- }
10
- }
11
- return false;
12
- };
5
+ return (input) => predicates.some((predicate) => predicate(input));
13
6
  };
@@ -0,0 +1,3 @@
1
+ import type { Path } from './types/objects.js';
2
+ import type { AnyRecord } from './types/records.js';
3
+ export declare const getOwnPaths: <Type extends AnyRecord>(input: Type) => Path<Type>[];
@@ -0,0 +1,3 @@
1
+ import type { Path } from './types/objects.js';
2
+ import type { AnyRecord } from './types/records.js';
3
+ export declare const getPaths: <Type extends AnyRecord>(input: Type) => Path<Type>[];
@@ -25,7 +25,9 @@ export * from './getMaxValue.js';
25
25
  export * from './getMilliseconds.js';
26
26
  export * from './getMinValue.js';
27
27
  export * from './getOwnKeys.js';
28
+ export * from './getOwnPaths.js';
28
29
  export * from './getOwnProperties.js';
30
+ export * from './getPaths.js';
29
31
  export * from './getType.js';
30
32
  export * from './inRange.js';
31
33
  export * from './isEmpty.js';
@@ -1,7 +1,12 @@
1
- export type Predicate<A, T extends A = A> = ((value: T, index: number, array: readonly A[]) => value is T) | ((value: T, index: number, array: readonly A[]) => unknown);
2
- export type TypePredicateFn<T> = (input: unknown) => input is T;
3
- export type TypeAssertionFn<T> = (input: unknown) => asserts input is T;
1
+ export type ArrayPredicateFn<A, T extends A = A> = ((value: T, index: number, array: readonly A[]) => value is T) | ((value: T, index: number, array: readonly A[]) => unknown);
4
2
  export type CompareFn<T> = (a: T, b: T) => number;
3
+ export type TypePredicateFn<T> = (input: unknown, ...args: any[]) => input is T;
4
+ export type InferPredicateReturnType<Fn extends TypePredicateFn<unknown>> = Fn extends TypePredicateFn<infer T> ? T : never;
5
5
  export type InferPredicatesReturnType<Predicates extends TypePredicateFn<unknown>[]> = {
6
- [K in keyof Predicates]: Predicates[K] extends TypePredicateFn<infer T> ? T : never;
6
+ [K in keyof Predicates]: InferPredicateReturnType<Predicates[K]>;
7
+ }[number];
8
+ export type TypeAssertionFn<T> = (input: unknown, ...args: any[]) => asserts input is T;
9
+ export type InferAssertionReturnType<Fn extends TypeAssertionFn<unknown>> = Fn extends TypeAssertionFn<infer T> ? T : never;
10
+ export type InferAssertionsReturnType<Fns extends TypeAssertionFn<unknown>[]> = {
11
+ [K in keyof Fns]: InferAssertionReturnType<Fns[K]>;
7
12
  }[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.44.0",
4
+ "version": "0.45.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -88,7 +88,7 @@
88
88
  "@commitlint/config-conventional": "^19.6.0",
89
89
  "@commitlint/types": "^19.5.0",
90
90
  "@types/node": "^22.10.7",
91
- "@vitest/coverage-v8": "^3.0.2",
91
+ "@vitest/coverage-v8": "^3.0.3",
92
92
  "@webdeveric/eslint-config-ts": "^0.11.0",
93
93
  "@webdeveric/prettier-config": "^0.3.0",
94
94
  "commitlint": "^19.6.1",
@@ -96,7 +96,7 @@
96
96
  "conventional-changelog-conventionalcommits": "^8.0.0",
97
97
  "cspell": "^8.17.2",
98
98
  "eslint": "^8.57.1",
99
- "eslint-config-prettier": "^9.1.0",
99
+ "eslint-config-prettier": "^10.0.1",
100
100
  "eslint-import-resolver-typescript": "^3.7.0",
101
101
  "eslint-plugin-import": "^2.31.0",
102
102
  "husky": "^9.1.7",
@@ -107,6 +107,6 @@
107
107
  "semantic-release": "^24.2.1",
108
108
  "typescript": "^5.7.3",
109
109
  "validate-package-exports": "^0.8.0",
110
- "vitest": "^3.0.2"
110
+ "vitest": "^3.0.3"
111
111
  }
112
112
  }