@bbn/bbn 1.0.224 → 1.0.226
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.
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the value of the given field (property) from the first object matching the given filter in an array of objects.
|
|
3
|
+
*
|
|
4
|
+
* The filtering arguments follow the same scheme as bbn.fn.search.
|
|
5
|
+
*
|
|
6
|
+
* @method isWritable
|
|
7
|
+
* @global
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* class Foo {
|
|
11
|
+
* readonly a = 1
|
|
12
|
+
* b = 2
|
|
13
|
+
* }
|
|
14
|
+
* const foo = new Foo();
|
|
15
|
+
* bbn.fn.isWritable(foo, 'a');
|
|
16
|
+
* // false
|
|
17
|
+
* bbn.fn.isWritable(foo, 'b');
|
|
18
|
+
* // true
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```javascript
|
|
23
|
+
* class Zoo {
|
|
24
|
+
* get a () { return 1; }
|
|
25
|
+
* b = 2
|
|
26
|
+
* }
|
|
27
|
+
* const zoo = new Zoo();
|
|
28
|
+
* bbn.fn.isWritable(zoo, 'a');
|
|
29
|
+
* // false
|
|
30
|
+
* bbn.fn.isWritable(zoo, 'b');
|
|
31
|
+
* // true
|
|
32
|
+
* ```
|
|
33
|
+
* @memberof bbn.fn
|
|
34
|
+
* @param {Object} obj The subject object
|
|
35
|
+
* @param {keyof Object} key The property from which the value is returned
|
|
36
|
+
* @returns {Boolean}
|
|
37
|
+
*/
|
|
38
|
+
export default function isWritable(obj: Object, key: keyof Object): boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the value of the given field (property) from the first object matching the given filter in an array of objects.
|
|
3
|
+
*
|
|
4
|
+
* The filtering arguments follow the same scheme as bbn.fn.search.
|
|
5
|
+
*
|
|
6
|
+
* @method isWritable
|
|
7
|
+
* @global
|
|
8
|
+
* @example
|
|
9
|
+
* ```javascript
|
|
10
|
+
* class Foo {
|
|
11
|
+
* readonly a = 1
|
|
12
|
+
* b = 2
|
|
13
|
+
* }
|
|
14
|
+
* const foo = new Foo();
|
|
15
|
+
* bbn.fn.isWritable(foo, 'a');
|
|
16
|
+
* // false
|
|
17
|
+
* bbn.fn.isWritable(foo, 'b');
|
|
18
|
+
* // true
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```javascript
|
|
23
|
+
* class Zoo {
|
|
24
|
+
* get a () { return 1; }
|
|
25
|
+
* b = 2
|
|
26
|
+
* }
|
|
27
|
+
* const zoo = new Zoo();
|
|
28
|
+
* bbn.fn.isWritable(zoo, 'a');
|
|
29
|
+
* // false
|
|
30
|
+
* bbn.fn.isWritable(zoo, 'b');
|
|
31
|
+
* // true
|
|
32
|
+
* ```
|
|
33
|
+
* @memberof bbn.fn
|
|
34
|
+
* @param {Object} obj The subject object
|
|
35
|
+
* @param {keyof Object} key The property from which the value is returned
|
|
36
|
+
* @returns {Boolean}
|
|
37
|
+
*/
|
|
38
|
+
export default function isWritable(obj, key) {
|
|
39
|
+
var desc = Object.getOwnPropertyDescriptor(obj, key)
|
|
40
|
+
|| Object.getOwnPropertyDescriptor(Object.getPrototypeOf(obj), key)
|
|
41
|
+
|| {};
|
|
42
|
+
return Boolean(desc.writable);
|
|
43
|
+
}
|
|
44
|
+
;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function mutateObject(a1: any, a2: any, hashFn: any): any;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import isObject from '../type/isObject.js';
|
|
2
|
+
import hash from '../string/hash.js';
|
|
3
|
+
import isSame from '../type/isSame.js';
|
|
4
|
+
import checkType from '../type/checkType.js';
|
|
5
|
+
export default function mutateObject(a1, a2, hashFn) {
|
|
6
|
+
if (!isObject(a1, a2)) {
|
|
7
|
+
throw new TypeError('mutateObject can only be called with arrays');
|
|
8
|
+
}
|
|
9
|
+
if (hashFn) {
|
|
10
|
+
checkType(hashFn, 'function', 'The hash function must be a function');
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
hashFn = hash;
|
|
14
|
+
}
|
|
15
|
+
var mapA2 = Object.keys(a2);
|
|
16
|
+
// Remove items from a1 that are not in a2
|
|
17
|
+
for (var n in a1) {
|
|
18
|
+
if (!mapA2.includes(n)) {
|
|
19
|
+
delete a1[n];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
mapA2.forEach(function (n) {
|
|
23
|
+
if (!isSame(a1[n], a2[n])) {
|
|
24
|
+
a1[n] = a2[n];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return a1;
|
|
28
|
+
}
|
package/dist/fn.d.ts
CHANGED
|
@@ -159,6 +159,7 @@ import isValidDimension from './fn/type/isValidDimension.js';
|
|
|
159
159
|
import isValidName from './fn/type/isValidName.js';
|
|
160
160
|
import isValue from './fn/type/isValue.js';
|
|
161
161
|
import isVue from './fn/type/isVue.js';
|
|
162
|
+
import isWritable from './fn/object/isWritable.js';
|
|
162
163
|
import iterate from './fn/loop/iterate.js';
|
|
163
164
|
import lightenDarkenHex from './fn/style/lightenDarkenHex.js';
|
|
164
165
|
import link from './fn/ajax/link.js';
|
|
@@ -170,6 +171,7 @@ import money from './fn/misc/money.js';
|
|
|
170
171
|
import move from './fn/object/move.js';
|
|
171
172
|
import multiorder from './fn/object/multiorder.js';
|
|
172
173
|
import mutateArray from './fn/object/mutateArray.js';
|
|
174
|
+
import mutateObject from './fn/object/mutateObject.js';
|
|
173
175
|
import nl2br from './fn/string/nl2br.js';
|
|
174
176
|
import numProperties from './fn/object/numProperties.js';
|
|
175
177
|
import objectToFormData from './fn/form/objectToFormData.js';
|
|
@@ -390,6 +392,7 @@ declare const _default: {
|
|
|
390
392
|
isValidName: typeof isValidName;
|
|
391
393
|
isValue: typeof isValue;
|
|
392
394
|
isVue: typeof isVue;
|
|
395
|
+
isWritable: typeof isWritable;
|
|
393
396
|
iterate: typeof iterate;
|
|
394
397
|
lightenDarkenHex: typeof lightenDarkenHex;
|
|
395
398
|
link: typeof link;
|
|
@@ -401,6 +404,7 @@ declare const _default: {
|
|
|
401
404
|
move: typeof move;
|
|
402
405
|
multiorder: typeof multiorder;
|
|
403
406
|
mutateArray: typeof mutateArray;
|
|
407
|
+
mutateObject: typeof mutateObject;
|
|
404
408
|
nl2br: typeof nl2br;
|
|
405
409
|
numProperties: typeof numProperties;
|
|
406
410
|
objectToFormData: typeof objectToFormData;
|
package/dist/fn.js
CHANGED
|
@@ -159,6 +159,7 @@ import isValidDimension from './fn/type/isValidDimension.js';
|
|
|
159
159
|
import isValidName from './fn/type/isValidName.js';
|
|
160
160
|
import isValue from './fn/type/isValue.js';
|
|
161
161
|
import isVue from './fn/type/isVue.js';
|
|
162
|
+
import isWritable from './fn/object/isWritable.js';
|
|
162
163
|
import iterate from './fn/loop/iterate.js';
|
|
163
164
|
import lightenDarkenHex from './fn/style/lightenDarkenHex.js';
|
|
164
165
|
import link from './fn/ajax/link.js';
|
|
@@ -170,6 +171,7 @@ import money from './fn/misc/money.js';
|
|
|
170
171
|
import move from './fn/object/move.js';
|
|
171
172
|
import multiorder from './fn/object/multiorder.js';
|
|
172
173
|
import mutateArray from './fn/object/mutateArray.js';
|
|
174
|
+
import mutateObject from './fn/object/mutateObject.js';
|
|
173
175
|
import nl2br from './fn/string/nl2br.js';
|
|
174
176
|
import numProperties from './fn/object/numProperties.js';
|
|
175
177
|
import objectToFormData from './fn/form/objectToFormData.js';
|
|
@@ -390,6 +392,7 @@ export default {
|
|
|
390
392
|
isValidName: isValidName,
|
|
391
393
|
isValue: isValue,
|
|
392
394
|
isVue: isVue,
|
|
395
|
+
isWritable: isWritable,
|
|
393
396
|
iterate: iterate,
|
|
394
397
|
lightenDarkenHex: lightenDarkenHex,
|
|
395
398
|
link: link,
|
|
@@ -401,6 +404,7 @@ export default {
|
|
|
401
404
|
move: move,
|
|
402
405
|
multiorder: multiorder,
|
|
403
406
|
mutateArray: mutateArray,
|
|
407
|
+
mutateObject: mutateObject,
|
|
404
408
|
nl2br: nl2br,
|
|
405
409
|
numProperties: numProperties,
|
|
406
410
|
objectToFormData: objectToFormData,
|