@simplysm/core-common 13.0.42 → 13.0.44
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 +5 -1
- package/docs/types.md +13 -3
- package/docs/utils.md +45 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,10 @@ To use extension methods (`getOrCreate()`, `toggle()`, etc.), you must import th
|
|
|
58
58
|
- [`objGetChainValueByDepth`](docs/utils.md#objgetchainvaluebydepth) - Query value by descending the same key repeatedly
|
|
59
59
|
- [`objSetChainValue`](docs/utils.md#objsetchainvalue) - Set value by chain path
|
|
60
60
|
- [`objDeleteChainValue`](docs/utils.md#objdeletechainvalue) - Delete value by chain path
|
|
61
|
+
- [`objClearUndefined`](docs/utils.md#objclearundefined) - Delete keys with `undefined` values (mutates original)
|
|
62
|
+
- [`objClear`](docs/utils.md#objclear) - Delete all keys from an object (mutates original)
|
|
63
|
+
- [`objNullToUndefined`](docs/utils.md#objnulltoundefined) - Recursively convert null to undefined (mutates original)
|
|
64
|
+
- [`objUnflatten`](docs/utils.md#objunflatten) - Convert dot-notation flat object to nested object
|
|
61
65
|
- [`objKeys`](docs/utils.md#objkeys) - Type-safe `Object.keys`
|
|
62
66
|
- [`objEntries`](docs/utils.md#objentries) - Type-safe `Object.entries`
|
|
63
67
|
- [`objFromEntries`](docs/utils.md#objfromentries) - Type-safe `Object.fromEntries`
|
|
@@ -206,7 +210,7 @@ To use extension methods (`getOrCreate()`, `toggle()`, etc.), you must import th
|
|
|
206
210
|
- [`Bytes`](docs/types.md#bytes) - Alias for `Uint8Array`
|
|
207
211
|
- [`PrimitiveTypeStr`](docs/types.md#primitivetypestr) - Primitive type string keys
|
|
208
212
|
- [`PrimitiveTypeMap`](docs/types.md#primitivetypemap) - Mapping from type string to type
|
|
209
|
-
- [`PrimitiveType`](docs/types.md#primitivetype) - Union of all primitive types
|
|
213
|
+
- [`PrimitiveType`](docs/types.md#primitivetype) - Union of all primitive types (includes `undefined`)
|
|
210
214
|
- [`DeepPartial`](docs/types.md#deeppartial) - Recursively convert properties to optional
|
|
211
215
|
- [`Type`](docs/types.md#type) - Constructor type
|
|
212
216
|
- [`ObjUndefToOptional`](docs/types.md#objundeftooptional) - Convert `undefined` properties to optional
|
package/docs/types.md
CHANGED
|
@@ -51,8 +51,18 @@ Timeout error. Thrown automatically by `waitUntil` when max attempts are exceede
|
|
|
51
51
|
```typescript
|
|
52
52
|
import { TimeoutError } from "@simplysm/core-common";
|
|
53
53
|
|
|
54
|
+
// Thrown automatically by waitUntil on timeout
|
|
55
|
+
try {
|
|
56
|
+
await waitUntil(() => isReady, 100, 50);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
if (err instanceof TimeoutError) {
|
|
59
|
+
console.log("Timed out");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Throw manually
|
|
54
64
|
throw new TimeoutError(5, "API response wait exceeded");
|
|
55
|
-
//
|
|
65
|
+
// count: number of attempts, message: additional description (both optional)
|
|
56
66
|
```
|
|
57
67
|
|
|
58
68
|
---
|
|
@@ -301,10 +311,10 @@ type PrimitiveTypeMap = {
|
|
|
301
311
|
|
|
302
312
|
### PrimitiveType
|
|
303
313
|
|
|
304
|
-
Union of all Primitive types.
|
|
314
|
+
Union of all Primitive types (includes `undefined`).
|
|
305
315
|
|
|
306
316
|
```typescript
|
|
307
|
-
type PrimitiveType = string | number | boolean | DateTime | DateOnly | Time | Uuid | Bytes;
|
|
317
|
+
type PrimitiveType = string | number | boolean | DateTime | DateOnly | Time | Uuid | Bytes | undefined;
|
|
308
318
|
```
|
|
309
319
|
|
|
310
320
|
### DeepPartial
|
package/docs/utils.md
CHANGED
|
@@ -139,6 +139,51 @@ import { objDeleteChainValue } from "@simplysm/core-common";
|
|
|
139
139
|
objDeleteChainValue(obj, "a.b[0].c");
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
+
### objClearUndefined
|
|
143
|
+
|
|
144
|
+
Delete keys with `undefined` values from an object (mutates the original).
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { objClearUndefined } from "@simplysm/core-common";
|
|
148
|
+
|
|
149
|
+
const obj = { a: 1, b: undefined, c: "hello" };
|
|
150
|
+
objClearUndefined(obj); // { a: 1, c: "hello" }
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### objClear
|
|
154
|
+
|
|
155
|
+
Delete all keys from an object (mutates the original).
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { objClear } from "@simplysm/core-common";
|
|
159
|
+
|
|
160
|
+
const obj = { a: 1, b: 2 };
|
|
161
|
+
objClear(obj); // {}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### objNullToUndefined
|
|
165
|
+
|
|
166
|
+
Recursively convert `null` values to `undefined` (mutates the original object/array).
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { objNullToUndefined } from "@simplysm/core-common";
|
|
170
|
+
|
|
171
|
+
const data = { a: null, b: { c: null }, d: [null, 1] };
|
|
172
|
+
objNullToUndefined(data);
|
|
173
|
+
// { a: undefined, b: { c: undefined }, d: [undefined, 1] }
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### objUnflatten
|
|
177
|
+
|
|
178
|
+
Convert a flat object with dot-notation keys into a nested object.
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import { objUnflatten } from "@simplysm/core-common";
|
|
182
|
+
|
|
183
|
+
objUnflatten({ "a.b.c": 1, "a.b.d": 2, "e": 3 });
|
|
184
|
+
// { a: { b: { c: 1, d: 2 } }, e: 3 }
|
|
185
|
+
```
|
|
186
|
+
|
|
142
187
|
### objKeys
|
|
143
188
|
|
|
144
189
|
Type-safe `Object.keys`.
|