@simplysm/core-common 14.0.4 → 14.0.5
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 +123 -59
- package/docs/array-extensions.md +171 -164
- package/docs/env.md +8 -27
- package/docs/errors.md +15 -51
- package/docs/features.md +52 -68
- package/docs/map-extensions.md +41 -0
- package/docs/set-extensions.md +38 -0
- package/docs/template-strings-and-zip.md +87 -0
- package/docs/type-utilities.md +19 -35
- package/docs/types.md +111 -111
- package/docs/utilities.md +723 -0
- package/package.json +1 -1
- package/docs/utils.md +0 -641
package/README.md
CHANGED
|
@@ -14,35 +14,19 @@ npm install @simplysm/core-common
|
|
|
14
14
|
|
|
15
15
|
| API | Type | Description |
|
|
16
16
|
|-----|------|-------------|
|
|
17
|
-
| `env` | `
|
|
18
|
-
| `parseBoolEnv` | `function` | Parse a value to boolean (`"true"`, `"1"`, `"yes"`, `"on"` -> `true`) |
|
|
17
|
+
| `env` | `const` | Unified environment variables from `import.meta.env` and `process.env`. `DEV` is parsed as boolean, `VER` as optional string. |
|
|
18
|
+
| `parseBoolEnv(value)` | `function` | Parse a value to boolean (`"true"`, `"1"`, `"yes"`, `"on"` case-insensitive -> `true`, otherwise `false`) |
|
|
19
19
|
|
|
20
20
|
-> See [docs/env.md](./docs/env.md) for details.
|
|
21
21
|
|
|
22
|
-
### Array / Set / Map Extensions
|
|
23
|
-
|
|
24
|
-
| API | Type | Description |
|
|
25
|
-
|-----|------|-------------|
|
|
26
|
-
| `Array.prototype.*` | extension | 30+ methods: `single`, `first`, `last`, `groupBy`, `toMap`, `distinct`, `orderBy`, `diffs`, `sum`, `min`, `max`, etc. |
|
|
27
|
-
| `Set.prototype.adds` | extension | Add multiple values at once |
|
|
28
|
-
| `Set.prototype.toggle` | extension | Toggle a value (add if absent, remove if present) |
|
|
29
|
-
| `Map.prototype.getOrCreate` | extension | Get value or create with default/factory |
|
|
30
|
-
| `Map.prototype.update` | extension | Update a value using a function |
|
|
31
|
-
| `ArrayDiffsResult` | type | Result type for `diffs()` |
|
|
32
|
-
| `ArrayOneWayDiffResult` | type | Result type for `oneWayDiffs()` |
|
|
33
|
-
| `TreeArray` | type | Tree node type for `toTree()` |
|
|
34
|
-
| `ComparableType` | type | Union of types usable in ordering |
|
|
35
|
-
|
|
36
|
-
-> See [docs/array-extensions.md](./docs/array-extensions.md) for details.
|
|
37
|
-
|
|
38
22
|
### Errors
|
|
39
23
|
|
|
40
24
|
| API | Type | Description |
|
|
41
25
|
|-----|------|-------------|
|
|
42
|
-
| `SdError` | class | Tree-structured error with cause
|
|
43
|
-
| `ArgumentError` | class | Invalid argument error with YAML-formatted
|
|
44
|
-
| `NotImplementedError` | class | Unimplemented feature error |
|
|
45
|
-
| `TimeoutError` | class | Timeout exceeded error |
|
|
26
|
+
| `SdError` | `class` | Tree-structured error with chained messages via ES2024 `cause` |
|
|
27
|
+
| `ArgumentError` | `class` | Invalid argument error with YAML-formatted argument dump |
|
|
28
|
+
| `NotImplementedError` | `class` | Unimplemented feature error |
|
|
29
|
+
| `TimeoutError` | `class` | Timeout exceeded error with retry count |
|
|
46
30
|
|
|
47
31
|
-> See [docs/errors.md](./docs/errors.md) for details.
|
|
48
32
|
|
|
@@ -50,11 +34,11 @@ npm install @simplysm/core-common
|
|
|
50
34
|
|
|
51
35
|
| API | Type | Description |
|
|
52
36
|
|-----|------|-------------|
|
|
53
|
-
| `Uuid` | class | UUID v4 generation and parsing |
|
|
54
|
-
| `LazyGcMap
|
|
55
|
-
| `DateTime` | class | Immutable date-time wrapper with millisecond precision |
|
|
56
|
-
| `DateOnly` | class | Immutable date-only
|
|
57
|
-
| `Time` | class | Immutable time-only
|
|
37
|
+
| `Uuid` | `class` | UUID v4 generation and parsing using `crypto.getRandomValues` |
|
|
38
|
+
| `LazyGcMap<K,V>` | `class` | Auto-expiring Map with LRU access tracking and GC timer |
|
|
39
|
+
| `DateTime` | `class` | Immutable date-time wrapper around `Date` with millisecond precision |
|
|
40
|
+
| `DateOnly` | `class` | Immutable date-only class (no time component) with week-sequence support |
|
|
41
|
+
| `Time` | `class` | Immutable time-only class with 24-hour wrapping |
|
|
58
42
|
|
|
59
43
|
-> See [docs/types.md](./docs/types.md) for details.
|
|
60
44
|
|
|
@@ -62,49 +46,128 @@ npm install @simplysm/core-common
|
|
|
62
46
|
|
|
63
47
|
| API | Type | Description |
|
|
64
48
|
|-----|------|-------------|
|
|
65
|
-
| `DebounceQueue` | class | Async debounce queue -- only
|
|
66
|
-
| `SerialQueue` | class | Async serial queue --
|
|
67
|
-
| `EventEmitter
|
|
49
|
+
| `DebounceQueue` | `class` | Async debounce queue -- only the last enqueued function runs after delay |
|
|
50
|
+
| `SerialQueue` | `class` | Async serial queue -- functions execute one at a time in order |
|
|
51
|
+
| `EventEmitter<TEvents>` | `class` | Type-safe event emitter built on `EventTarget` |
|
|
68
52
|
|
|
69
53
|
-> See [docs/features.md](./docs/features.md) for details.
|
|
70
54
|
|
|
71
|
-
###
|
|
55
|
+
### Array Extensions
|
|
72
56
|
|
|
73
57
|
| API | Type | Description |
|
|
74
58
|
|-----|------|-------------|
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
|
|
90
|
-
|
|
59
|
+
| `Array.prototype.single` | extension | Return single matching element or throw if multiple |
|
|
60
|
+
| `Array.prototype.first` | extension | Return first element or first matching |
|
|
61
|
+
| `Array.prototype.last` | extension | Return last element or last matching |
|
|
62
|
+
| `Array.prototype.filterExists` | extension | Remove null/undefined elements |
|
|
63
|
+
| `Array.prototype.ofType` | extension | Filter by primitive type string or constructor |
|
|
64
|
+
| `Array.prototype.filterAsync` | extension | Async sequential filter |
|
|
65
|
+
| `Array.prototype.mapAsync` | extension | Async sequential map |
|
|
66
|
+
| `Array.prototype.mapMany` | extension | Flatten or map-then-flatten |
|
|
67
|
+
| `Array.prototype.mapManyAsync` | extension | Async map then flatten |
|
|
68
|
+
| `Array.prototype.parallelAsync` | extension | Parallel async map via `Promise.all` |
|
|
69
|
+
| `Array.prototype.groupBy` | extension | Group by key selector |
|
|
70
|
+
| `Array.prototype.toMap` | extension | Convert to `Map` with key/value selectors |
|
|
71
|
+
| `Array.prototype.toMapAsync` | extension | Async version of `toMap` |
|
|
72
|
+
| `Array.prototype.toArrayMap` | extension | Convert to `Map<K, V[]>` |
|
|
73
|
+
| `Array.prototype.toSetMap` | extension | Convert to `Map<K, Set<V>>` |
|
|
74
|
+
| `Array.prototype.toMapValues` | extension | Group then aggregate values |
|
|
75
|
+
| `Array.prototype.toObject` | extension | Convert to `Record<string, V>` |
|
|
76
|
+
| `Array.prototype.toTree` | extension | Convert flat array to tree structure |
|
|
77
|
+
| `Array.prototype.distinct` | extension | Remove duplicates (new array) |
|
|
78
|
+
| `Array.prototype.orderBy` | extension | Sort ascending (new array) |
|
|
79
|
+
| `Array.prototype.orderByDesc` | extension | Sort descending (new array) |
|
|
80
|
+
| `Array.prototype.diffs` | extension | Compare two arrays (insert/delete/update) |
|
|
81
|
+
| `Array.prototype.oneWayDiffs` | extension | One-way diff (create/update/same) |
|
|
82
|
+
| `Array.prototype.merge` | extension | Merge two arrays by key |
|
|
83
|
+
| `Array.prototype.sum` | extension | Sum of elements |
|
|
84
|
+
| `Array.prototype.min` | extension | Minimum element |
|
|
85
|
+
| `Array.prototype.max` | extension | Maximum element |
|
|
86
|
+
| `Array.prototype.shuffle` | extension | Random shuffle (new array) |
|
|
87
|
+
| `Array.prototype.distinctThis` | extension | Remove duplicates in-place |
|
|
88
|
+
| `Array.prototype.orderByThis` | extension | Sort ascending in-place |
|
|
89
|
+
| `Array.prototype.orderByDescThis` | extension | Sort descending in-place |
|
|
90
|
+
| `Array.prototype.insert` | extension | Insert items at index in-place |
|
|
91
|
+
| `Array.prototype.remove` | extension | Remove items in-place |
|
|
92
|
+
| `Array.prototype.toggle` | extension | Toggle item in-place |
|
|
93
|
+
| `Array.prototype.clear` | extension | Remove all items in-place |
|
|
94
|
+
| `ArrayDiffsResult<T,P>` | `type` | Diff result: insert / delete / update |
|
|
95
|
+
| `ArrayOneWayDiffResult<T>` | `type` | One-way diff result: create / update / same |
|
|
96
|
+
| `TreeArray<T>` | `type` | Tree node type with `children` array |
|
|
97
|
+
| `ComparableType` | `type` | Union of sortable types |
|
|
98
|
+
|
|
99
|
+
-> See [docs/array-extensions.md](./docs/array-extensions.md) for details.
|
|
100
|
+
|
|
101
|
+
### Map Extensions
|
|
102
|
+
|
|
103
|
+
| API | Type | Description |
|
|
104
|
+
|-----|------|-------------|
|
|
105
|
+
| `Map.prototype.getOrCreate` | extension | Get value or create with default/factory |
|
|
106
|
+
| `Map.prototype.update` | extension | Update a value using a transform function |
|
|
107
|
+
|
|
108
|
+
-> See [docs/map-extensions.md](./docs/map-extensions.md) for details.
|
|
109
|
+
|
|
110
|
+
### Set Extensions
|
|
111
|
+
|
|
112
|
+
| API | Type | Description |
|
|
113
|
+
|-----|------|-------------|
|
|
114
|
+
| `Set.prototype.adds` | extension | Add multiple values at once |
|
|
115
|
+
| `Set.prototype.toggle` | extension | Toggle a value with optional force add/delete |
|
|
116
|
+
|
|
117
|
+
-> See [docs/set-extensions.md](./docs/set-extensions.md) for details.
|
|
118
|
+
|
|
119
|
+
### Utility Namespaces
|
|
120
|
+
|
|
121
|
+
All utility namespaces are exported as `export * as name` and accessed as `obj.clone(...)`, `str.toPascalCase(...)`, etc.
|
|
122
|
+
|
|
123
|
+
| Namespace | Description |
|
|
124
|
+
|-----------|-------------|
|
|
125
|
+
| `obj` | Deep clone, deep equal, deep merge, 3-way merge, omit, pick, chain value access, type-safe keys/entries/fromEntries/map |
|
|
126
|
+
| `str` | Korean suffix, full-width conversion, case conversion (pascal/camel/kebab/snake), isNullOrEmpty, insert |
|
|
127
|
+
| `num` | parseInt, parseFloat, parseRoundedInt, isNullOrEmpty, format with thousand separators |
|
|
128
|
+
| `bytes` | Uint8Array concat, hex, base64 conversion |
|
|
129
|
+
| `path` | POSIX path join, basename, extname (browser-compatible, no backslash support) |
|
|
130
|
+
| `json` | Custom JSON stringify/parse with DateTime, Uuid, Set, Map, Error, Uint8Array support |
|
|
131
|
+
| `xml` | XML parse/stringify via fast-xml-parser |
|
|
132
|
+
| `wait` | Async `until` (poll condition) and `time` (delay) |
|
|
133
|
+
| `transfer` | Worker-safe encode/decode for custom types with transferable list extraction |
|
|
134
|
+
| `err` | Extract error message from unknown catch value |
|
|
135
|
+
| `dt` | Date/time formatting with C#-style format strings, normalizeMonth, convert12To24 |
|
|
136
|
+
| `primitive` | Get PrimitiveTypeStr from runtime value |
|
|
137
|
+
|
|
138
|
+
-> See [docs/utilities.md](./docs/utilities.md) for details.
|
|
139
|
+
|
|
140
|
+
### Template Strings and Zip
|
|
141
|
+
|
|
142
|
+
| API | Type | Description |
|
|
143
|
+
|-----|------|-------------|
|
|
144
|
+
| `js` | tag function | JavaScript template tag with indent normalization |
|
|
145
|
+
| `ts` | tag function | TypeScript template tag with indent normalization |
|
|
146
|
+
| `html` | tag function | HTML template tag with indent normalization |
|
|
147
|
+
| `tsql` | tag function | MSSQL T-SQL template tag with indent normalization |
|
|
148
|
+
| `mysql` | tag function | MySQL template tag with indent normalization |
|
|
149
|
+
| `pgsql` | tag function | PostgreSQL template tag with indent normalization |
|
|
150
|
+
| `ZipArchive` | `class` | ZIP read/write/compress/extract with caching |
|
|
151
|
+
| `ZipArchiveProgress` | `interface` | Progress callback data for extraction |
|
|
152
|
+
|
|
153
|
+
-> See [docs/template-strings-and-zip.md](./docs/template-strings-and-zip.md) for details.
|
|
91
154
|
|
|
92
155
|
### Type Utilities
|
|
93
156
|
|
|
94
157
|
| API | Type | Description |
|
|
95
158
|
|-----|------|-------------|
|
|
96
|
-
| `Bytes` | type
|
|
97
|
-
| `PrimitiveTypeMap` | type | Maps type-string keys to their TypeScript types |
|
|
98
|
-
| `PrimitiveTypeStr` | type | `
|
|
99
|
-
| `PrimitiveType` | type | Union of all primitive type values |
|
|
100
|
-
| `DeepPartial<T>` | type | Recursively makes all properties optional |
|
|
101
|
-
| `Type<T>` | interface | Constructor type (`new (...args) => T`) |
|
|
159
|
+
| `Bytes` | `type` | Alias for `Uint8Array` (replaces `Buffer`) |
|
|
160
|
+
| `PrimitiveTypeMap` | `type` | Maps type-string keys to their TypeScript types |
|
|
161
|
+
| `PrimitiveTypeStr` | `type` | `keyof PrimitiveTypeMap` |
|
|
162
|
+
| `PrimitiveType` | `type` | Union of all primitive type values plus `undefined` |
|
|
163
|
+
| `DeepPartial<T>` | `type` | Recursively makes all properties optional |
|
|
164
|
+
| `Type<T>` | `interface` | Constructor type (`new (...args: unknown[]) => T`) |
|
|
102
165
|
|
|
103
166
|
-> See [docs/type-utilities.md](./docs/type-utilities.md) for details.
|
|
104
167
|
|
|
105
168
|
## Usage Examples
|
|
106
169
|
|
|
107
|
-
### Deep
|
|
170
|
+
### Deep Cloning and Comparing
|
|
108
171
|
|
|
109
172
|
```typescript
|
|
110
173
|
import { obj } from "@simplysm/core-common";
|
|
@@ -117,7 +180,7 @@ const merged = obj.merge(original, { b: { d: 4 } });
|
|
|
117
180
|
// { a: 1, b: { c: [2, 3], d: 4 } }
|
|
118
181
|
```
|
|
119
182
|
|
|
120
|
-
###
|
|
183
|
+
### Array Extensions
|
|
121
184
|
|
|
122
185
|
```typescript
|
|
123
186
|
import "@simplysm/core-common";
|
|
@@ -128,16 +191,17 @@ const users = [
|
|
|
128
191
|
{ id: 3, role: "user", name: "Carol" },
|
|
129
192
|
];
|
|
130
193
|
|
|
131
|
-
|
|
194
|
+
users.groupBy((u) => u.role);
|
|
132
195
|
// [{ key: "admin", values: [Alice] }, { key: "user", values: [Bob, Carol] }]
|
|
133
196
|
|
|
134
|
-
|
|
197
|
+
users.toMap((u) => u.id);
|
|
135
198
|
// Map { 1 => Alice, 2 => Bob, 3 => Carol }
|
|
136
199
|
|
|
137
|
-
|
|
200
|
+
[3, 1, 2].orderBy(); // [1, 2, 3]
|
|
201
|
+
[1, 2, 2, 3].distinct(); // [1, 2, 3]
|
|
138
202
|
```
|
|
139
203
|
|
|
140
|
-
### JSON
|
|
204
|
+
### JSON Serialization with Custom Types
|
|
141
205
|
|
|
142
206
|
```typescript
|
|
143
207
|
import { json, DateTime, Uuid } from "@simplysm/core-common";
|