@naturalcycles/js-lib 15.55.1 → 15.57.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyObject, KeyValueTuple, MutateOptions, ObjectMapper, ObjectPredicate, Reviver, StringMap, ValueOf } from '../types.js';
|
|
1
|
+
import type { AnyObject, KeyValueTuple, MutateOptions, ObjectMapper, ObjectPredicate, RequiredProp, Reviver, StringMap, ValueOf } from '../types.js';
|
|
2
2
|
import { SKIP } from '../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Returns clone of `obj` with only `props` preserved.
|
|
@@ -228,4 +228,13 @@ export declare function _deepFreeze(o: any): void;
|
|
|
228
228
|
* To make mutation extra clear - function returns void (unlike Object.assign).
|
|
229
229
|
*/
|
|
230
230
|
export declare function _objectAssignExact<T extends AnyObject>(target: T, source: T): void;
|
|
231
|
+
/**
|
|
232
|
+
* type MyObj = { a?: string, b?: string }
|
|
233
|
+
*
|
|
234
|
+
* const collection: MyObj[] = [...]
|
|
235
|
+
*
|
|
236
|
+
* const collectionA = collection.filter(_hasProp('a'))
|
|
237
|
+
* --> collectionA is now RequiredProp<MyObj, 'a'>[], i.e. { a: string, b?: string }[]
|
|
238
|
+
*/
|
|
239
|
+
export declare function _hasProp<T, Prop extends keyof T>(prop: Prop): (object: T) => object is RequiredProp<T, Prop>;
|
|
231
240
|
export {};
|
|
@@ -370,7 +370,7 @@ export function _set(obj, path, value) {
|
|
|
370
370
|
a[c]
|
|
371
371
|
: // No: create the key. Is the next key a potential array-index?
|
|
372
372
|
(a[c] =
|
|
373
|
-
//
|
|
373
|
+
// oxlint-disable-next-line no-bitwise no-implicit-coercion unicorn/prefer-math-trunc
|
|
374
374
|
Math.abs(path[i + 1]) >> 0 === +path[i + 1]
|
|
375
375
|
? [] // Yes: assign a new array object
|
|
376
376
|
: {}), // No: assign a new plain object
|
|
@@ -446,3 +446,16 @@ export function _objectAssignExact(target, source) {
|
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* type MyObj = { a?: string, b?: string }
|
|
451
|
+
*
|
|
452
|
+
* const collection: MyObj[] = [...]
|
|
453
|
+
*
|
|
454
|
+
* const collectionA = collection.filter(_hasProp('a'))
|
|
455
|
+
* --> collectionA is now RequiredProp<MyObj, 'a'>[], i.e. { a: string, b?: string }[]
|
|
456
|
+
*/
|
|
457
|
+
export function _hasProp(prop) {
|
|
458
|
+
return function (object) {
|
|
459
|
+
return typeof object[prop] !== 'undefined';
|
|
460
|
+
};
|
|
461
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.57.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"tslib": "^2",
|
|
7
7
|
"undici": "^7",
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@types/crypto-js": "^4",
|
|
12
|
-
"@types/node": "^
|
|
12
|
+
"@types/node": "^25",
|
|
13
13
|
"@types/semver": "^7",
|
|
14
14
|
"crypto-js": "^4",
|
|
15
15
|
"dayjs": "^1",
|
|
16
|
-
"@naturalcycles/dev-lib": "
|
|
16
|
+
"@naturalcycles/dev-lib": "20.15.0"
|
|
17
17
|
},
|
|
18
18
|
"exports": {
|
|
19
19
|
".": "./dist/index.js",
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
MutateOptions,
|
|
6
6
|
ObjectMapper,
|
|
7
7
|
ObjectPredicate,
|
|
8
|
+
RequiredProp,
|
|
8
9
|
Reviver,
|
|
9
10
|
StringMap,
|
|
10
11
|
ValueOf,
|
|
@@ -442,7 +443,7 @@ export function _set<T extends AnyObject>(obj: T, path: PropertyPath, value: any
|
|
|
442
443
|
a[c]
|
|
443
444
|
: // No: create the key. Is the next key a potential array-index?
|
|
444
445
|
(a[c] =
|
|
445
|
-
//
|
|
446
|
+
// oxlint-disable-next-line no-bitwise no-implicit-coercion unicorn/prefer-math-trunc
|
|
446
447
|
Math.abs(path[i + 1]) >> 0 === +path[i + 1]
|
|
447
448
|
? [] // Yes: assign a new array object
|
|
448
449
|
: {}), // No: assign a new plain object
|
|
@@ -527,3 +528,17 @@ export function _objectAssignExact<T extends AnyObject>(target: T, source: T): v
|
|
|
527
528
|
}
|
|
528
529
|
}
|
|
529
530
|
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* type MyObj = { a?: string, b?: string }
|
|
534
|
+
*
|
|
535
|
+
* const collection: MyObj[] = [...]
|
|
536
|
+
*
|
|
537
|
+
* const collectionA = collection.filter(_hasProp('a'))
|
|
538
|
+
* --> collectionA is now RequiredProp<MyObj, 'a'>[], i.e. { a: string, b?: string }[]
|
|
539
|
+
*/
|
|
540
|
+
export function _hasProp<T, Prop extends keyof T>(prop: Prop) {
|
|
541
|
+
return function (object: T): object is RequiredProp<T, Prop> {
|
|
542
|
+
return typeof object[prop] !== 'undefined'
|
|
543
|
+
}
|
|
544
|
+
}
|