@pivanov/utils 0.0.3 → 1.0.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.
- package/README.md +125 -335
- package/dist/cjs/assertion/index.js +7 -0
- package/dist/cjs/cache/index.js +7 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/object/index.js +7 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/promise/index.js +7 -0
- package/dist/cjs/string/index.js +7 -0
- package/dist/cjs/tools/index.js +7 -0
- package/dist/cjs/types/index.js +7 -0
- package/dist/esm/assertion/index.js +7 -0
- package/dist/esm/cache/index.js +7 -0
- package/dist/esm/chunk-3ymwkv74.js +8 -0
- package/dist/esm/chunk-jtvcg9xg.js +6 -0
- package/dist/esm/chunk-m1ymbxy0.js +8 -0
- package/dist/esm/chunk-m7vtwv05.js +8 -0
- package/dist/esm/chunk-vtcj34cd.js +8 -0
- package/dist/esm/chunk-y84wjyfx.js +7 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/object/index.js +7 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/promise/index.js +7 -0
- package/dist/esm/string/index.js +7 -0
- package/dist/esm/tools/index.js +7 -0
- package/dist/esm/types/index.js +7 -0
- package/dist/types/assertion/index.d.ts +145 -0
- package/dist/types/cache/index.d.ts +16 -0
- package/dist/types/cache/internal.d.ts +12 -0
- package/dist/types/cache/response.d.ts +91 -0
- package/dist/types/cache/storage.d.ts +75 -0
- package/dist/types/cache/support.d.ts +14 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/object/index.d.ts +118 -0
- package/dist/types/promise/index.d.ts +81 -0
- package/dist/types/string/index.d.ts +127 -0
- package/dist/types/tools/deepClone.d.ts +2 -0
- package/dist/types/tools/dom.d.ts +82 -0
- package/dist/types/tools/eventBus/eventBus.d.ts +37 -0
- package/dist/types/tools/eventBus/index.d.ts +3 -0
- package/dist/types/tools/eventBus/types.d.ts +47 -0
- package/dist/types/tools/eventBus/useEventBus.d.ts +3 -0
- package/dist/types/tools/index.d.ts +5 -0
- package/dist/types/tools/isEqual.d.ts +21 -0
- package/dist/types/types/index.d.ts +61 -0
- package/package.json +74 -35
- package/dist/index.d.ts +0 -691
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A dictionary with string keys and values of type T.
|
|
3
|
+
*/
|
|
4
|
+
export type TDict<T = unknown> = Record<string, T>;
|
|
5
|
+
/**
|
|
6
|
+
* Object with string or number keys and values of type T.
|
|
7
|
+
*/
|
|
8
|
+
export type TObjType<T = unknown> = {
|
|
9
|
+
[key: string | number]: T;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Recursively applies `Partial` to every nested object property. Primitives
|
|
13
|
+
* and arrays pass through unchanged.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* type A = DeepPartial<{ a: { b: { c: number } } }>;
|
|
18
|
+
* // { a?: { b?: { c?: number } } }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type DeepPartial<T> = T extends object ? {
|
|
22
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
23
|
+
} : T;
|
|
24
|
+
/**
|
|
25
|
+
* Recursively applies `Readonly` to every nested object property.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* type Config = DeepReadonly<{ flags: { debug: boolean } }>;
|
|
30
|
+
* // { readonly flags: { readonly debug: boolean } }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type DeepReadonly<T> = T extends object ? {
|
|
34
|
+
readonly [K in keyof T]: DeepReadonly<T[K]>;
|
|
35
|
+
} : T;
|
|
36
|
+
/**
|
|
37
|
+
* Removes `readonly` modifiers from every property (top level only).
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const tuple = [1, 2, 3] as const;
|
|
42
|
+
* type T = Mutable<typeof tuple>; // number[]
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export type Mutable<T> = {
|
|
46
|
+
-readonly [K in keyof T]: T[K];
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Flattens an intersection or mapped type into a single object literal so it
|
|
50
|
+
* shows up clean in IDE tooltips. Pure type-level; no runtime impact.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* type A = { a: number };
|
|
55
|
+
* type B = { b: string };
|
|
56
|
+
* type C = Prettify<A & B>; // { a: number; b: string }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export type Prettify<T> = {
|
|
60
|
+
[K in keyof T]: T[K];
|
|
61
|
+
} & {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pivanov/utils",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A collection of
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A focused collection of TypeScript utilities for modern web development",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -11,6 +11,23 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/pivanov/pivanov-utils/issues"
|
|
13
13
|
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "rm -rf dist && bun run scripts/build.ts && bun x tsc --emitDeclarationOnly",
|
|
16
|
+
"test": "bun test",
|
|
17
|
+
"test:coverage": "bun test --coverage",
|
|
18
|
+
"lint": "biome lint .",
|
|
19
|
+
"format": "biome format . --write",
|
|
20
|
+
"check": "biome check . --write",
|
|
21
|
+
"typecheck": "bun x tsc --noEmit",
|
|
22
|
+
"docs:dev": "bun x vitepress dev docs",
|
|
23
|
+
"docs:build": "bun x vitepress build docs",
|
|
24
|
+
"docs:preview": "bun x vitepress preview docs",
|
|
25
|
+
"bench": "bun run bench/index.ts",
|
|
26
|
+
"prepublishOnly": "bun run build && bun run verify:dist",
|
|
27
|
+
"publish": "npm publish --access public",
|
|
28
|
+
"verify:dist": "bun run scripts/verify-dist.ts",
|
|
29
|
+
"verify": "bun run lint && bun run typecheck && bun test && bun run build && bun run verify:dist"
|
|
30
|
+
},
|
|
14
31
|
"author": {
|
|
15
32
|
"name": "Pavel Ivanov",
|
|
16
33
|
"email": "iweb.ivanov@gmail.com",
|
|
@@ -29,14 +46,50 @@
|
|
|
29
46
|
"promise"
|
|
30
47
|
],
|
|
31
48
|
"license": "MIT",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
49
|
+
"sideEffects": false,
|
|
50
|
+
"main": "./dist/cjs/index.js",
|
|
51
|
+
"module": "./dist/esm/index.js",
|
|
52
|
+
"types": "./dist/types/index.d.ts",
|
|
35
53
|
"exports": {
|
|
36
54
|
".": {
|
|
37
|
-
"types": "./dist/index.d.ts",
|
|
55
|
+
"types": "./dist/types/index.d.ts",
|
|
38
56
|
"import": "./dist/esm/index.js",
|
|
39
57
|
"require": "./dist/cjs/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./assertion": {
|
|
60
|
+
"types": "./dist/types/assertion/index.d.ts",
|
|
61
|
+
"import": "./dist/esm/assertion/index.js",
|
|
62
|
+
"require": "./dist/cjs/assertion/index.js"
|
|
63
|
+
},
|
|
64
|
+
"./cache": {
|
|
65
|
+
"types": "./dist/types/cache/index.d.ts",
|
|
66
|
+
"import": "./dist/esm/cache/index.js",
|
|
67
|
+
"require": "./dist/cjs/cache/index.js"
|
|
68
|
+
},
|
|
69
|
+
"./object": {
|
|
70
|
+
"types": "./dist/types/object/index.d.ts",
|
|
71
|
+
"import": "./dist/esm/object/index.js",
|
|
72
|
+
"require": "./dist/cjs/object/index.js"
|
|
73
|
+
},
|
|
74
|
+
"./promise": {
|
|
75
|
+
"types": "./dist/types/promise/index.d.ts",
|
|
76
|
+
"import": "./dist/esm/promise/index.js",
|
|
77
|
+
"require": "./dist/cjs/promise/index.js"
|
|
78
|
+
},
|
|
79
|
+
"./string": {
|
|
80
|
+
"types": "./dist/types/string/index.d.ts",
|
|
81
|
+
"import": "./dist/esm/string/index.js",
|
|
82
|
+
"require": "./dist/cjs/string/index.js"
|
|
83
|
+
},
|
|
84
|
+
"./tools": {
|
|
85
|
+
"types": "./dist/types/tools/index.d.ts",
|
|
86
|
+
"import": "./dist/esm/tools/index.js",
|
|
87
|
+
"require": "./dist/cjs/tools/index.js"
|
|
88
|
+
},
|
|
89
|
+
"./types": {
|
|
90
|
+
"types": "./dist/types/types/index.d.ts",
|
|
91
|
+
"import": "./dist/esm/types/index.js",
|
|
92
|
+
"require": "./dist/cjs/types/index.js"
|
|
40
93
|
}
|
|
41
94
|
},
|
|
42
95
|
"files": [
|
|
@@ -46,42 +99,28 @@
|
|
|
46
99
|
"react": ">=18",
|
|
47
100
|
"react-dom": ">=18"
|
|
48
101
|
},
|
|
102
|
+
"peerDependenciesMeta": {
|
|
103
|
+
"react": {
|
|
104
|
+
"optional": true
|
|
105
|
+
},
|
|
106
|
+
"react-dom": {
|
|
107
|
+
"optional": true
|
|
108
|
+
}
|
|
109
|
+
},
|
|
49
110
|
"devDependencies": {
|
|
50
|
-
"@biomejs/biome": "^
|
|
51
|
-
"@
|
|
52
|
-
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
53
|
-
"@rollup/plugin-typescript": "^12.1.1",
|
|
54
|
-
"@testing-library/dom": "^10.4.0",
|
|
111
|
+
"@biomejs/biome": "^2.4.11",
|
|
112
|
+
"@happy-dom/global-registrator": "^15.11.7",
|
|
55
113
|
"@testing-library/react": "^16.0.1",
|
|
56
|
-
"@
|
|
57
|
-
"@types/node": "^22.9.0",
|
|
114
|
+
"@types/bun": "^1.1.14",
|
|
58
115
|
"@types/react": "^18.3.12",
|
|
59
116
|
"@types/react-dom": "^18.3.1",
|
|
60
|
-
"
|
|
61
|
-
"@vitest/coverage-v8": "^2.1.4",
|
|
62
|
-
"evt": "^2.4.18",
|
|
63
|
-
"glob": "^11.0.0",
|
|
64
|
-
"husky": "^4.3.0",
|
|
65
|
-
"jsdom": "^25.0.1",
|
|
117
|
+
"mitata": "^1.0.34",
|
|
66
118
|
"react": "^18.3.1",
|
|
67
119
|
"react-dom": "^18.3.1",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
71
|
-
"tslib": "^2.7.0",
|
|
72
|
-
"typescript": "5.7.2",
|
|
73
|
-
"vitest": "^2.1.4"
|
|
120
|
+
"typescript": "^5.7.2",
|
|
121
|
+
"vitepress": "~1.5.0"
|
|
74
122
|
},
|
|
75
123
|
"publishConfig": {
|
|
76
124
|
"access": "public"
|
|
77
|
-
},
|
|
78
|
-
"scripts": {
|
|
79
|
-
"build": "rm -rf dist && pnpm rollup -c",
|
|
80
|
-
"test": "pnpm vitest",
|
|
81
|
-
"test:coverage": "pnpm vitest --coverage",
|
|
82
|
-
"test:ui": "pnpm vitest --ui",
|
|
83
|
-
"lint": "biome lint .",
|
|
84
|
-
"format": "biome format . --write",
|
|
85
|
-
"check": "biome check . --write"
|
|
86
125
|
}
|
|
87
|
-
}
|
|
126
|
+
}
|