@webdeveric/utils 0.43.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.
- package/dist/cjs/getOwnPaths.js +13 -0
- package/dist/cjs/getPaths.js +15 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/isEmpty.js +2 -2
- package/dist/cjs/predicate-factory/allOf.js +1 -8
- package/dist/cjs/predicate-factory/anyOf.js +1 -8
- package/dist/cjs/predicate-factory/createIsInstanceOfPredicate.js +5 -0
- package/dist/cjs/predicate-factory/index.js +1 -0
- package/dist/cjs/stripWhitespace.js +5 -0
- package/dist/cjs/until.js +2 -1
- package/dist/mjs/getOwnPaths.js +9 -0
- package/dist/mjs/getPaths.js +11 -0
- package/dist/mjs/index.js +3 -0
- package/dist/mjs/isEmpty.js +2 -2
- package/dist/mjs/predicate-factory/allOf.js +1 -8
- package/dist/mjs/predicate-factory/anyOf.js +1 -8
- package/dist/mjs/predicate-factory/createIsInstanceOfPredicate.js +1 -0
- package/dist/mjs/predicate-factory/index.js +1 -0
- package/dist/mjs/stripWhitespace.js +1 -0
- package/dist/mjs/until.js +2 -1
- package/dist/types/getOwnPaths.d.ts +3 -0
- package/dist/types/getPaths.d.ts +3 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/predicate-factory/createIsInstanceOfPredicate.d.ts +3 -0
- package/dist/types/predicate-factory/index.d.ts +1 -0
- package/dist/types/stripWhitespace.d.ts +2 -0
- package/dist/types/types/functions.d.ts +9 -4
- package/dist/types/types/strings.d.ts +1 -1
- package/package.json +8 -8
|
@@ -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);
|
|
@@ -56,6 +58,7 @@ __exportStar(require("./resultify.js"), exports);
|
|
|
56
58
|
__exportStar(require("./secToString.js"), exports);
|
|
57
59
|
__exportStar(require("./sort-factory.js"), exports);
|
|
58
60
|
__exportStar(require("./sort.js"), exports);
|
|
61
|
+
__exportStar(require("./stripWhitespace.js"), exports);
|
|
59
62
|
__exportStar(require("./suffix.js"), exports);
|
|
60
63
|
__exportStar(require("./toPascalCase.js"), exports);
|
|
61
64
|
__exportStar(require("./trimEnd.js"), exports);
|
package/dist/cjs/isEmpty.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isEmpty = isEmpty;
|
|
4
4
|
const isLengthAware_js_1 = require("./predicate/isLengthAware.js");
|
|
5
5
|
function isEmpty(input) {
|
|
6
|
-
if (
|
|
6
|
+
if (input == null || (typeof input === 'string' && !input.length)) {
|
|
7
7
|
return true;
|
|
8
8
|
}
|
|
9
9
|
if (input instanceof Set || input instanceof Map) {
|
|
@@ -13,7 +13,7 @@ function isEmpty(input) {
|
|
|
13
13
|
return input.length === 0;
|
|
14
14
|
}
|
|
15
15
|
if (typeof input === 'object') {
|
|
16
|
-
return
|
|
16
|
+
return Reflect.ownKeys(input).length === 0;
|
|
17
17
|
}
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
@@ -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,5 @@
|
|
|
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;
|
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./allOf.js"), exports);
|
|
18
18
|
__exportStar(require("./anyOf.js"), exports);
|
|
19
19
|
__exportStar(require("./createIsEnumPredicate.js"), exports);
|
|
20
|
+
__exportStar(require("./createIsInstanceOfPredicate.js"), exports);
|
|
20
21
|
__exportStar(require("./createIsTuplePredicate.js"), exports);
|
|
21
22
|
__exportStar(require("./createStringMatchingPredicate.js"), exports);
|
|
22
23
|
__exportStar(require("./everyItem.js"), exports);
|
package/dist/cjs/until.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDelay = exports.isDelay = void 0;
|
|
4
4
|
exports.until = until;
|
|
5
|
+
const asError_js_1 = require("./asError.js");
|
|
5
6
|
const getType_js_1 = require("./getType.js");
|
|
6
7
|
const defaultOptions = {
|
|
7
8
|
delay: 10,
|
|
@@ -71,7 +72,7 @@ function until(fn, options = defaultOptions) {
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
catch (error) {
|
|
74
|
-
rejectFn(
|
|
75
|
+
rejectFn((0, asError_js_1.asError)(error));
|
|
75
76
|
}
|
|
76
77
|
};
|
|
77
78
|
callUntilDone(fn, delay, resolve, reject);
|
|
@@ -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';
|
|
@@ -40,6 +42,7 @@ export * from './resultify.js';
|
|
|
40
42
|
export * from './secToString.js';
|
|
41
43
|
export * from './sort-factory.js';
|
|
42
44
|
export * from './sort.js';
|
|
45
|
+
export * from './stripWhitespace.js';
|
|
43
46
|
export * from './suffix.js';
|
|
44
47
|
export * from './toPascalCase.js';
|
|
45
48
|
export * from './trimEnd.js';
|
package/dist/mjs/isEmpty.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isLengthAware } from './predicate/isLengthAware.js';
|
|
2
2
|
export function isEmpty(input) {
|
|
3
|
-
if (
|
|
3
|
+
if (input == null || (typeof input === 'string' && !input.length)) {
|
|
4
4
|
return true;
|
|
5
5
|
}
|
|
6
6
|
if (input instanceof Set || input instanceof Map) {
|
|
@@ -10,7 +10,7 @@ export function isEmpty(input) {
|
|
|
10
10
|
return input.length === 0;
|
|
11
11
|
}
|
|
12
12
|
if (typeof input === 'object') {
|
|
13
|
-
return
|
|
13
|
+
return Reflect.ownKeys(input).length === 0;
|
|
14
14
|
}
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
@@ -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 @@
|
|
|
1
|
+
export const createIsInstanceOfPredicate = (constructor) => (input) => input instanceof constructor;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './allOf.js';
|
|
2
2
|
export * from './anyOf.js';
|
|
3
3
|
export * from './createIsEnumPredicate.js';
|
|
4
|
+
export * from './createIsInstanceOfPredicate.js';
|
|
4
5
|
export * from './createIsTuplePredicate.js';
|
|
5
6
|
export * from './createStringMatchingPredicate.js';
|
|
6
7
|
export * from './everyItem.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const stripWhitespace = (input) => input.replace(/\s+/g, '');
|
package/dist/mjs/until.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { asError } from './asError.js';
|
|
1
2
|
import { getType } from './getType.js';
|
|
2
3
|
const defaultOptions = {
|
|
3
4
|
delay: 10,
|
|
@@ -65,7 +66,7 @@ export function until(fn, options = defaultOptions) {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
catch (error) {
|
|
68
|
-
rejectFn(
|
|
69
|
+
rejectFn(asError(error));
|
|
69
70
|
}
|
|
70
71
|
};
|
|
71
72
|
callUntilDone(fn, delay, resolve, reject);
|
package/dist/types/index.d.ts
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';
|
|
@@ -40,6 +42,7 @@ export * from './resultify.js';
|
|
|
40
42
|
export * from './secToString.js';
|
|
41
43
|
export * from './sort-factory.js';
|
|
42
44
|
export * from './sort.js';
|
|
45
|
+
export * from './stripWhitespace.js';
|
|
43
46
|
export * from './suffix.js';
|
|
44
47
|
export * from './toPascalCase.js';
|
|
45
48
|
export * from './trimEnd.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './allOf.js';
|
|
2
2
|
export * from './anyOf.js';
|
|
3
3
|
export * from './createIsEnumPredicate.js';
|
|
4
|
+
export * from './createIsInstanceOfPredicate.js';
|
|
4
5
|
export * from './createIsTuplePredicate.js';
|
|
5
6
|
export * from './createStringMatchingPredicate.js';
|
|
6
7
|
export * from './everyItem.js';
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
export type
|
|
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]
|
|
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];
|
|
@@ -4,7 +4,7 @@ export type AlphaCharacter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i'
|
|
|
4
4
|
export type NumericCharacter = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
5
5
|
export type AlphanumericCharacter = AlphaCharacter | Capitalize<AlphaCharacter> | NumericCharacter;
|
|
6
6
|
export type MaybePlural<T extends string> = T | `${T}s`;
|
|
7
|
-
export type StripWhitespace<Type extends string> = Type extends `${infer First}${infer Rest}` ? First extends Space ? StripWhitespace<Rest> : `${First}${StripWhitespace<Rest>}` : EmptyString;
|
|
7
|
+
export type StripWhitespace<Type extends string> = string extends Type ? Type : Type extends `${infer First}${infer Rest}` ? First extends Space ? StripWhitespace<Rest> : `${First}${StripWhitespace<Rest>}` : EmptyString;
|
|
8
8
|
export type AlphanumericOnly<Type extends string> = Type extends EmptyString ? EmptyString : Type extends `${infer First}${infer Rest}` ? First extends AlphanumericCharacter | Space ? `${First}${AlphanumericOnly<Rest>}` : Rest extends EmptyString ? Rest : `${Space}${AlphanumericOnly<Rest>}` : never;
|
|
9
9
|
export type Replace<Type extends string, Remove extends string, Replacement extends string> = Type extends `${infer First}${infer Rest}` ? First extends Remove ? `${Replacement}${Replace<Rest, Remove, Replacement>}` : `${First}${Replace<Rest, Remove, Replacement>}` : EmptyString;
|
|
10
10
|
export type Strip<Type extends string, Remove extends string> = Replace<Type, Remove, EmptyString>;
|
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.45.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@9.15.
|
|
69
|
+
"packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0",
|
|
70
70
|
"scripts": {
|
|
71
71
|
"clean": "rimraf ./dist/",
|
|
72
72
|
"prebuild": "pnpm clean",
|
|
@@ -87,26 +87,26 @@
|
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@commitlint/config-conventional": "^19.6.0",
|
|
89
89
|
"@commitlint/types": "^19.5.0",
|
|
90
|
-
"@types/node": "^22.10.
|
|
91
|
-
"@vitest/coverage-v8": "^
|
|
90
|
+
"@types/node": "^22.10.7",
|
|
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",
|
|
95
95
|
"commitlint-plugin-cspell": "^0.1.1",
|
|
96
96
|
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
97
|
-
"cspell": "^8.17.
|
|
97
|
+
"cspell": "^8.17.2",
|
|
98
98
|
"eslint": "^8.57.1",
|
|
99
|
-
"eslint-config-prettier": "^
|
|
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",
|
|
103
103
|
"jsdom": "^26.0.0",
|
|
104
|
-
"lint-staged": "^15.
|
|
104
|
+
"lint-staged": "^15.4.1",
|
|
105
105
|
"prettier": "^3.4.2",
|
|
106
106
|
"rimraf": "^6.0.1",
|
|
107
107
|
"semantic-release": "^24.2.1",
|
|
108
108
|
"typescript": "^5.7.3",
|
|
109
109
|
"validate-package-exports": "^0.8.0",
|
|
110
|
-
"vitest": "^
|
|
110
|
+
"vitest": "^3.0.3"
|
|
111
111
|
}
|
|
112
112
|
}
|