@web-ts-toolkit/utils 0.3.0 → 0.5.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/README.md +49 -0
- package/index.d.mts +3 -1
- package/index.d.ts +3 -1
- package/index.js +7 -0
- package/index.mjs +6 -0
- package/package.json +14 -5
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# `@web-ts-toolkit/utils`
|
|
2
|
+
|
|
3
|
+
Shared collection, object, async, and URL helpers used across the workspace.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @web-ts-toolkit/utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Highlights
|
|
12
|
+
|
|
13
|
+
- object-path helpers such as `get(...)` and `set(...)`
|
|
14
|
+
- collection helpers such as `map(...)`, `filter(...)`, `uniq(...)`, and `orderBy(...)`
|
|
15
|
+
- small type guards
|
|
16
|
+
- URL helpers such as `normalizeUrlPath(...)`
|
|
17
|
+
- async helpers such as `mapValuesAsync(...)`
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { get, set, normalizeUrlPath, parseBooleanString } from '@web-ts-toolkit/utils';
|
|
23
|
+
|
|
24
|
+
const payload = {
|
|
25
|
+
user: {
|
|
26
|
+
profile: {
|
|
27
|
+
name: 'Ada',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
get(payload, 'user.profile.name');
|
|
33
|
+
set(payload, 'user.profile.role', 'admin');
|
|
34
|
+
normalizeUrlPath('api//users');
|
|
35
|
+
parseBooleanString('true', false);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Main Exports
|
|
39
|
+
|
|
40
|
+
- object helpers: `get`, `set`, `pick`, `omit`, `assign`, `cloneDeep`
|
|
41
|
+
- collection helpers: `map`, `filter`, `reduce`, `find`, `flatten`, `uniq`, `orderBy`
|
|
42
|
+
- guards: `isArray`, `isPlainObject`, `isString`, `isPromise`
|
|
43
|
+
- URL helpers: `addLeadingSlash`, `removeConsecutiveSlashesFromUrl`, `normalizeUrlPath`
|
|
44
|
+
|
|
45
|
+
## Documentation
|
|
46
|
+
|
|
47
|
+
Full package documentation lives in `website/docs/packages/utils.md`.
|
|
48
|
+
|
|
49
|
+
- live docs: https://web-ts-toolkit.pages.dev/docs/packages/utils
|
package/index.d.mts
CHANGED
|
@@ -71,6 +71,8 @@ declare function noop(): void;
|
|
|
71
71
|
|
|
72
72
|
declare function omit<T extends object>(object: T, paths: PropertyPath | PropertyPath[]): Partial<T>;
|
|
73
73
|
|
|
74
|
+
declare function parseBooleanString(str: string | undefined, defaultValue?: boolean): boolean | undefined;
|
|
75
|
+
|
|
74
76
|
declare function orderBy<T>(collection: T[] | null | undefined, iteratees?: Array<string | number | ((value: T) => unknown)>, orders?: string[]): T[];
|
|
75
77
|
|
|
76
78
|
declare function padEnd(value: unknown, length?: number, chars?: string): string;
|
|
@@ -92,4 +94,4 @@ declare function toStringRecord(value: unknown): Record<string, string> | undefi
|
|
|
92
94
|
|
|
93
95
|
declare function uniq<T>(array: T[] | null | undefined): T[];
|
|
94
96
|
|
|
95
|
-
export { addLeadingSlash, arrayToRecord, assign, castArray, cloneDeep, compact, difference, filter, find, flatten, flattenDeep, forEach, get, intersection, intersectionBy, isArray, isBoolean, isEmpty, isEqual, isFunction, isMatch, isNaNValue as isNaN, isNil, isNumber, isObject, isPlainObject, isPromise, isString, isUndefined, keys, map, mapValues, mapValuesAsync, noop, normalizeUrlPath, omit, orderBy, padEnd, pick, reduce, removeConsecutiveSlashesFromUrl, set, toAsyncFn, toStringRecord, uniq };
|
|
97
|
+
export { addLeadingSlash, arrayToRecord, assign, castArray, cloneDeep, compact, difference, filter, find, flatten, flattenDeep, forEach, get, intersection, intersectionBy, isArray, isBoolean, isEmpty, isEqual, isFunction, isMatch, isNaNValue as isNaN, isNil, isNumber, isObject, isPlainObject, isPromise, isString, isUndefined, keys, map, mapValues, mapValuesAsync, noop, normalizeUrlPath, omit, orderBy, padEnd, parseBooleanString, pick, reduce, removeConsecutiveSlashesFromUrl, set, toAsyncFn, toStringRecord, uniq };
|
package/index.d.ts
CHANGED
|
@@ -71,6 +71,8 @@ declare function noop(): void;
|
|
|
71
71
|
|
|
72
72
|
declare function omit<T extends object>(object: T, paths: PropertyPath | PropertyPath[]): Partial<T>;
|
|
73
73
|
|
|
74
|
+
declare function parseBooleanString(str: string | undefined, defaultValue?: boolean): boolean | undefined;
|
|
75
|
+
|
|
74
76
|
declare function orderBy<T>(collection: T[] | null | undefined, iteratees?: Array<string | number | ((value: T) => unknown)>, orders?: string[]): T[];
|
|
75
77
|
|
|
76
78
|
declare function padEnd(value: unknown, length?: number, chars?: string): string;
|
|
@@ -92,4 +94,4 @@ declare function toStringRecord(value: unknown): Record<string, string> | undefi
|
|
|
92
94
|
|
|
93
95
|
declare function uniq<T>(array: T[] | null | undefined): T[];
|
|
94
96
|
|
|
95
|
-
export { addLeadingSlash, arrayToRecord, assign, castArray, cloneDeep, compact, difference, filter, find, flatten, flattenDeep, forEach, get, intersection, intersectionBy, isArray, isBoolean, isEmpty, isEqual, isFunction, isMatch, isNaNValue as isNaN, isNil, isNumber, isObject, isPlainObject, isPromise, isString, isUndefined, keys, map, mapValues, mapValuesAsync, noop, normalizeUrlPath, omit, orderBy, padEnd, pick, reduce, removeConsecutiveSlashesFromUrl, set, toAsyncFn, toStringRecord, uniq };
|
|
97
|
+
export { addLeadingSlash, arrayToRecord, assign, castArray, cloneDeep, compact, difference, filter, find, flatten, flattenDeep, forEach, get, intersection, intersectionBy, isArray, isBoolean, isEmpty, isEqual, isFunction, isMatch, isNaNValue as isNaN, isNil, isNumber, isObject, isPlainObject, isPromise, isString, isUndefined, keys, map, mapValues, mapValuesAsync, noop, normalizeUrlPath, omit, orderBy, padEnd, parseBooleanString, pick, reduce, removeConsecutiveSlashesFromUrl, set, toAsyncFn, toStringRecord, uniq };
|
package/index.js
CHANGED
|
@@ -57,6 +57,7 @@ __export(index_exports, {
|
|
|
57
57
|
omit: () => omit,
|
|
58
58
|
orderBy: () => orderBy,
|
|
59
59
|
padEnd: () => padEnd,
|
|
60
|
+
parseBooleanString: () => parseBooleanString,
|
|
60
61
|
pick: () => pick,
|
|
61
62
|
reduce: () => reduce,
|
|
62
63
|
removeConsecutiveSlashesFromUrl: () => removeConsecutiveSlashesFromUrl,
|
|
@@ -679,6 +680,11 @@ function omit(object, paths) {
|
|
|
679
680
|
return result;
|
|
680
681
|
}
|
|
681
682
|
|
|
683
|
+
// src/parseBooleanString.ts
|
|
684
|
+
function parseBooleanString(str, defaultValue) {
|
|
685
|
+
return str ? str === "true" : defaultValue;
|
|
686
|
+
}
|
|
687
|
+
|
|
682
688
|
// src/orderBy.ts
|
|
683
689
|
function orderBy(collection, iteratees = [], orders = []) {
|
|
684
690
|
if (!Array.isArray(collection)) {
|
|
@@ -835,6 +841,7 @@ function uniq(array) {
|
|
|
835
841
|
omit,
|
|
836
842
|
orderBy,
|
|
837
843
|
padEnd,
|
|
844
|
+
parseBooleanString,
|
|
838
845
|
pick,
|
|
839
846
|
reduce,
|
|
840
847
|
removeConsecutiveSlashesFromUrl,
|
package/index.mjs
CHANGED
|
@@ -610,6 +610,11 @@ function omit(object, paths) {
|
|
|
610
610
|
return result;
|
|
611
611
|
}
|
|
612
612
|
|
|
613
|
+
// src/parseBooleanString.ts
|
|
614
|
+
function parseBooleanString(str, defaultValue) {
|
|
615
|
+
return str ? str === "true" : defaultValue;
|
|
616
|
+
}
|
|
617
|
+
|
|
613
618
|
// src/orderBy.ts
|
|
614
619
|
function orderBy(collection, iteratees = [], orders = []) {
|
|
615
620
|
if (!Array.isArray(collection)) {
|
|
@@ -765,6 +770,7 @@ export {
|
|
|
765
770
|
omit,
|
|
766
771
|
orderBy,
|
|
767
772
|
padEnd,
|
|
773
|
+
parseBooleanString,
|
|
768
774
|
pick,
|
|
769
775
|
reduce,
|
|
770
776
|
removeConsecutiveSlashesFromUrl,
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web-ts-toolkit/utils",
|
|
3
|
-
"description": "Shared
|
|
4
|
-
"
|
|
3
|
+
"description": "Shared collection, object, async, and URL helpers used across workspace packages",
|
|
4
|
+
"homepage": "https://web-ts-toolkit.pages.dev/docs/packages/utils",
|
|
5
|
+
"version": "0.5.0",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"keywords": [
|
|
8
|
+
"utilities",
|
|
9
|
+
"collections",
|
|
10
|
+
"objects",
|
|
11
|
+
"url",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
5
14
|
"main": "./index.js",
|
|
6
15
|
"module": "./index.mjs",
|
|
7
16
|
"types": "./index.d.ts",
|
|
@@ -13,13 +22,13 @@
|
|
|
13
22
|
"default": "./index.js"
|
|
14
23
|
}
|
|
15
24
|
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=20"
|
|
27
|
+
},
|
|
16
28
|
"author": "Junmin Ahn",
|
|
17
29
|
"bugs": {
|
|
18
30
|
"url": "https://github.com/egose/web-ts-toolkit/issues"
|
|
19
31
|
},
|
|
20
|
-
"engines": {
|
|
21
|
-
"node": ">=20"
|
|
22
|
-
},
|
|
23
32
|
"license": "Apache-2.0",
|
|
24
33
|
"repository": {
|
|
25
34
|
"type": "git",
|