@ohos-ports/stdlib-object 0.0.0-stage → 0.4.1-beta.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.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +262 -2
- package/SECURITY.md +5 -0
- package/any-in-by/README.md +217 -0
- package/any-in-by/docs/repl.txt +41 -0
- package/any-in-by/docs/types/index.d.ts +102 -0
- package/any-in-by/docs/types/test.ts +53 -0
- package/any-in-by/lib/index.js +50 -0
- package/any-in-by/lib/main.js +75 -0
- package/any-in-by/package.json +66 -0
- package/any-own-by/README.md +221 -0
- package/any-own-by/docs/repl.txt +43 -0
- package/any-own-by/docs/types/index.d.ts +101 -0
- package/any-own-by/docs/types/test.ts +63 -0
- package/any-own-by/lib/index.js +46 -0
- package/any-own-by/lib/main.js +77 -0
- package/any-own-by/package.json +70 -0
- package/assign/README.md +139 -0
- package/assign/docs/repl.txt +34 -0
- package/assign/docs/types/index.d.ts +113 -0
- package/assign/docs/types/test.ts +47 -0
- package/assign/lib/builtin.js +55 -0
- package/assign/lib/has_object_assign.js +33 -0
- package/assign/lib/index.js +52 -0
- package/assign/lib/polyfill.js +86 -0
- package/assign/package.json +64 -0
- package/assign-in/README.md +145 -0
- package/assign-in/docs/repl.txt +34 -0
- package/assign-in/docs/types/index.d.ts +175 -0
- package/assign-in/docs/types/test.ts +44 -0
- package/assign-in/lib/index.js +54 -0
- package/assign-in/lib/main.js +92 -0
- package/assign-in/package.json +60 -0
- package/bifurcate-in/README.md +298 -0
- package/bifurcate-in/docs/repl.txt +68 -0
- package/bifurcate-in/docs/types/index.d.ts +189 -0
- package/bifurcate-in/docs/types/test.ts +97 -0
- package/bifurcate-in/lib/index.js +106 -0
- package/bifurcate-in/lib/main.js +148 -0
- package/bifurcate-in/lib/return_keys.js +81 -0
- package/bifurcate-in/lib/return_pairs.js +87 -0
- package/bifurcate-in/lib/return_values.js +87 -0
- package/bifurcate-in/lib/validate.js +76 -0
- package/bifurcate-in/package.json +72 -0
- package/bifurcate-own/README.md +255 -0
- package/bifurcate-own/docs/repl.txt +63 -0
- package/bifurcate-own/docs/types/index.d.ts +183 -0
- package/bifurcate-own/docs/types/test.ts +97 -0
- package/bifurcate-own/lib/index.js +87 -0
- package/bifurcate-own/lib/main.js +127 -0
- package/bifurcate-own/lib/return_keys.js +81 -0
- package/bifurcate-own/lib/return_pairs.js +87 -0
- package/bifurcate-own/lib/return_values.js +87 -0
- package/bifurcate-own/lib/validate.js +76 -0
- package/bifurcate-own/package.json +71 -0
- package/capitalize-keys/README.md +139 -0
- package/capitalize-keys/docs/repl.txt +28 -0
- package/capitalize-keys/docs/types/index.d.ts +46 -0
- package/capitalize-keys/docs/types/test.ts +33 -0
- package/capitalize-keys/lib/index.js +45 -0
- package/capitalize-keys/lib/main.js +69 -0
- package/capitalize-keys/package.json +76 -0
- package/common-keys/README.md +125 -0
- package/common-keys/docs/repl.txt +29 -0
- package/common-keys/docs/types/index.d.ts +70 -0
- package/common-keys/docs/types/test.ts +33 -0
- package/common-keys/lib/index.js +51 -0
- package/common-keys/lib/main.js +106 -0
- package/common-keys/package.json +70 -0
- package/common-keys-in/README.md +125 -0
- package/common-keys-in/docs/repl.txt +29 -0
- package/common-keys-in/docs/types/index.d.ts +70 -0
- package/common-keys-in/docs/types/test.ts +33 -0
- package/common-keys-in/lib/index.js +51 -0
- package/common-keys-in/lib/main.js +106 -0
- package/common-keys-in/package.json +72 -0
- package/ctor/README.md +536 -0
- package/ctor/docs/repl.txt +592 -0
- package/ctor/docs/types/index.d.ts +56 -0
- package/ctor/docs/types/test.ts +33 -0
- package/ctor/lib/index.js +54 -0
- package/ctor/lib/main.js +58 -0
- package/ctor/package.json +58 -0
- package/deep-get/README.md +181 -0
- package/deep-get/docs/repl.txt +63 -0
- package/deep-get/docs/types/index.d.ts +125 -0
- package/deep-get/docs/types/test.ts +109 -0
- package/deep-get/lib/defaults.js +38 -0
- package/deep-get/lib/dget.js +57 -0
- package/deep-get/lib/factory.js +94 -0
- package/deep-get/lib/index.js +58 -0
- package/deep-get/lib/main.js +101 -0
- package/deep-get/lib/validate.js +66 -0
- package/deep-get/package.json +68 -0
- package/deep-set/README.md +273 -0
- package/deep-set/docs/repl.txt +87 -0
- package/deep-set/docs/types/index.d.ts +180 -0
- package/deep-set/docs/types/test.ts +134 -0
- package/deep-set/lib/defaults.js +39 -0
- package/deep-set/lib/dset.js +80 -0
- package/deep-set/lib/factory.js +99 -0
- package/deep-set/lib/index.js +58 -0
- package/deep-set/lib/main.js +120 -0
- package/deep-set/lib/validate.js +74 -0
- package/deep-set/package.json +69 -0
- package/docs/types/index.d.ts +964 -0
- package/every-in-by/README.md +156 -0
- package/every-in-by/docs/repl.txt +43 -0
- package/every-in-by/docs/types/index.d.ts +83 -0
- package/every-in-by/docs/types/test.ts +60 -0
- package/every-in-by/lib/index.js +51 -0
- package/every-in-by/lib/main.js +70 -0
- package/every-in-by/package.json +67 -0
- package/every-own-by/README.md +223 -0
- package/every-own-by/docs/repl.txt +43 -0
- package/every-own-by/docs/types/index.d.ts +102 -0
- package/every-own-by/docs/types/test.ts +62 -0
- package/every-own-by/lib/index.js +46 -0
- package/every-own-by/lib/main.js +77 -0
- package/every-own-by/package.json +68 -0
- package/for-in/README.md +218 -0
- package/for-in/docs/repl.txt +44 -0
- package/for-in/docs/types/index.d.ts +65 -0
- package/for-in/docs/types/test.ts +50 -0
- package/for-in/lib/index.js +54 -0
- package/for-in/lib/main.js +82 -0
- package/for-in/package.json +74 -0
- package/for-own/README.md +209 -0
- package/for-own/docs/repl.txt +49 -0
- package/for-own/docs/types/index.d.ts +63 -0
- package/for-own/docs/types/test.ts +50 -0
- package/for-own/lib/index.js +50 -0
- package/for-own/lib/main.js +85 -0
- package/for-own/package.json +71 -0
- package/inverse/README.md +163 -0
- package/inverse/docs/repl.txt +53 -0
- package/inverse/docs/types/index.d.ts +66 -0
- package/inverse/docs/types/test.ts +60 -0
- package/inverse/lib/index.js +59 -0
- package/inverse/lib/main.js +123 -0
- package/inverse/package.json +69 -0
- package/inverse-by/README.md +205 -0
- package/inverse-by/docs/repl.txt +67 -0
- package/inverse-by/docs/types/index.d.ts +160 -0
- package/inverse-by/docs/types/test.ts +81 -0
- package/inverse-by/lib/index.js +78 -0
- package/inverse-by/lib/main.js +148 -0
- package/inverse-by/package.json +75 -0
- package/lib/index.js +276 -0
- package/lowercase-keys/README.md +139 -0
- package/lowercase-keys/docs/repl.txt +28 -0
- package/lowercase-keys/docs/types/index.d.ts +46 -0
- package/lowercase-keys/docs/types/test.ts +33 -0
- package/lowercase-keys/lib/index.js +45 -0
- package/lowercase-keys/lib/main.js +63 -0
- package/lowercase-keys/package.json +74 -0
- package/move-property/README.md +144 -0
- package/move-property/docs/repl.txt +38 -0
- package/move-property/docs/types/index.d.ts +53 -0
- package/move-property/docs/types/test.ts +46 -0
- package/move-property/lib/index.js +46 -0
- package/move-property/lib/main.js +74 -0
- package/move-property/package.json +69 -0
- package/none-in-by/README.md +241 -0
- package/none-in-by/docs/repl.txt +42 -0
- package/none-in-by/docs/types/index.d.ts +101 -0
- package/none-in-by/docs/types/test.ts +61 -0
- package/none-in-by/lib/index.js +46 -0
- package/none-in-by/lib/main.js +71 -0
- package/none-in-by/package.json +68 -0
- package/none-own-by/README.md +177 -0
- package/none-own-by/docs/repl.txt +42 -0
- package/none-own-by/docs/types/index.d.ts +102 -0
- package/none-own-by/docs/types/test.ts +61 -0
- package/none-own-by/lib/index.js +50 -0
- package/none-own-by/lib/main.js +75 -0
- package/none-own-by/package.json +68 -0
- package/package.json +66 -4
- package/some-in-by/README.md +232 -0
- package/some-in-by/docs/repl.txt +45 -0
- package/some-in-by/docs/types/index.d.ts +104 -0
- package/some-in-by/docs/types/test.ts +66 -0
- package/some-in-by/lib/index.js +46 -0
- package/some-in-by/lib/main.js +87 -0
- package/some-in-by/package.json +75 -0
- package/some-own-by/README.md +251 -0
- package/some-own-by/docs/repl.txt +45 -0
- package/some-own-by/docs/types/index.d.ts +103 -0
- package/some-own-by/docs/types/test.ts +66 -0
- package/some-own-by/lib/index.js +46 -0
- package/some-own-by/lib/main.js +85 -0
- package/some-own-by/package.json +72 -0
- package/uncapitalize-keys/README.md +139 -0
- package/uncapitalize-keys/docs/repl.txt +28 -0
- package/uncapitalize-keys/docs/types/index.d.ts +46 -0
- package/uncapitalize-keys/docs/types/test.ts +33 -0
- package/uncapitalize-keys/lib/index.js +45 -0
- package/uncapitalize-keys/lib/main.js +69 -0
- package/uncapitalize-keys/package.json +76 -0
- package/uppercase-keys/README.md +139 -0
- package/uppercase-keys/docs/repl.txt +28 -0
- package/uppercase-keys/docs/types/index.d.ts +46 -0
- package/uppercase-keys/docs/types/test.ts +33 -0
- package/uppercase-keys/lib/index.js +45 -0
- package/uppercase-keys/lib/main.js +63 -0
- package/uppercase-keys/package.json +74 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MAIN //
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Copies own enumerable properties from source objects to a target object.
|
|
25
|
+
*
|
|
26
|
+
* ## Notes
|
|
27
|
+
*
|
|
28
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
29
|
+
* - The target object is mutated.
|
|
30
|
+
* - Both string and symbol properties are copied.
|
|
31
|
+
*
|
|
32
|
+
* @name assign
|
|
33
|
+
* @type {Function}
|
|
34
|
+
* @param {Object} target - target object
|
|
35
|
+
* @param {...Object} source - source object(s)
|
|
36
|
+
* @throws {TypeError} first argument must not be null or undefined
|
|
37
|
+
* @returns {Object} target object
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var obj1 = {
|
|
41
|
+
* 'a': 'beep'
|
|
42
|
+
* };
|
|
43
|
+
* var obj2 = {
|
|
44
|
+
* 'b': 'boop'
|
|
45
|
+
* };
|
|
46
|
+
*
|
|
47
|
+
* var out = assign( obj1, obj2 );
|
|
48
|
+
* // returns { 'a': 'beep', 'b': 'boop' }
|
|
49
|
+
*/
|
|
50
|
+
var assign = Object.assign; // eslint-disable-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// EXPORTS //
|
|
54
|
+
|
|
55
|
+
module.exports = assign;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isFunction = require( '@ohos-ports/stdlib-assert/is-function' );
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// MAIN //
|
|
27
|
+
|
|
28
|
+
var bool = isFunction( Object.assign ); // eslint-disable-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// EXPORTS //
|
|
32
|
+
|
|
33
|
+
module.exports = bool;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Copy enumerable own properties from one or more source objects to a target object.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/object/assign
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var assign = require( '@ohos-ports/stdlib-object/assign' );
|
|
28
|
+
*
|
|
29
|
+
* var out = assign( {}, { 'foo': 'bar' }, { 'baz': 'beep' } );
|
|
30
|
+
* // returns { 'foo': 'bar', 'baz': 'beep' }
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
// MODULES //
|
|
34
|
+
|
|
35
|
+
var hasObjectAssign = require( './has_object_assign.js' );
|
|
36
|
+
var main = require( './builtin.js' );
|
|
37
|
+
var polyfill = require( './polyfill.js' );
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
// MAIN //
|
|
41
|
+
|
|
42
|
+
var assign;
|
|
43
|
+
if ( hasObjectAssign ) {
|
|
44
|
+
assign = main;
|
|
45
|
+
} else {
|
|
46
|
+
assign = polyfill;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
// EXPORTS //
|
|
51
|
+
|
|
52
|
+
module.exports = assign;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2023 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var enumerableProperties = require( '@ohos-ports/stdlib-utils/enumerable-properties' );
|
|
24
|
+
var Object = require( './../../ctor' );
|
|
25
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// MAIN //
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Copies own enumerable properties from source objects to a target object.
|
|
32
|
+
*
|
|
33
|
+
* ## Notes
|
|
34
|
+
*
|
|
35
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
36
|
+
* - The target object is mutated.
|
|
37
|
+
* - Both string and symbol properties are copied.
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} target - target object
|
|
40
|
+
* @param {...Object} source - source object(s)
|
|
41
|
+
* @throws {TypeError} first argument must not be null or undefined
|
|
42
|
+
* @returns {Object} target object
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var obj1 = {
|
|
46
|
+
* 'a': 'beep'
|
|
47
|
+
* };
|
|
48
|
+
* var obj2 = {
|
|
49
|
+
* 'b': 'boop'
|
|
50
|
+
* };
|
|
51
|
+
*
|
|
52
|
+
* var out = assign( obj1, obj2 );
|
|
53
|
+
* // returns { 'a': 'beep', 'b': 'boop' }
|
|
54
|
+
*/
|
|
55
|
+
function assign( target ) {
|
|
56
|
+
var source;
|
|
57
|
+
var keys;
|
|
58
|
+
var key;
|
|
59
|
+
var len;
|
|
60
|
+
var to;
|
|
61
|
+
var i;
|
|
62
|
+
var j;
|
|
63
|
+
if ( target === void 0 || target === null ) {
|
|
64
|
+
throw new TypeError( format( 'invalid argument. First argument must be a non-null object. Value: `%s`.', target ) );
|
|
65
|
+
}
|
|
66
|
+
to = Object( target );
|
|
67
|
+
for ( i = 1; i < arguments.length; i++ ) {
|
|
68
|
+
source = arguments[ i ];
|
|
69
|
+
if ( source === void 0 || source === null ) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
keys = enumerableProperties( Object( source ) );
|
|
74
|
+
len = keys.length;
|
|
75
|
+
for ( j = 0; j < len; j++ ) {
|
|
76
|
+
key = keys[ j ];
|
|
77
|
+
to[ key ] = source[ key ];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return to;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
// EXPORTS //
|
|
85
|
+
|
|
86
|
+
module.exports = assign;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/object/assign",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Copy enumerable own properties from one or more source objects to a target object.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"benchmark": "./benchmark",
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"example": "./examples",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"test": "./test"
|
|
23
|
+
},
|
|
24
|
+
"types": "./docs/types",
|
|
25
|
+
"scripts": {},
|
|
26
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"devDependencies": {},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=0.10.0",
|
|
38
|
+
"npm": ">2.7.0"
|
|
39
|
+
},
|
|
40
|
+
"os": [
|
|
41
|
+
"aix",
|
|
42
|
+
"darwin",
|
|
43
|
+
"freebsd",
|
|
44
|
+
"linux",
|
|
45
|
+
"macos",
|
|
46
|
+
"openbsd",
|
|
47
|
+
"sunos",
|
|
48
|
+
"win32",
|
|
49
|
+
"windows"
|
|
50
|
+
],
|
|
51
|
+
"keywords": [
|
|
52
|
+
"stdlib",
|
|
53
|
+
"stdtypes",
|
|
54
|
+
"types",
|
|
55
|
+
"data",
|
|
56
|
+
"structure",
|
|
57
|
+
"object",
|
|
58
|
+
"assign",
|
|
59
|
+
"merge",
|
|
60
|
+
"copy",
|
|
61
|
+
"clone",
|
|
62
|
+
"extend"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 The Stdlib Authors.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
|
18
|
+
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
# assignIn
|
|
22
|
+
|
|
23
|
+
> Copy enumerable own and inherited properties from one or more source objects to a target object.
|
|
24
|
+
|
|
25
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
26
|
+
|
|
27
|
+
<section class="intro">
|
|
28
|
+
|
|
29
|
+
</section>
|
|
30
|
+
|
|
31
|
+
<!-- /.intro -->
|
|
32
|
+
|
|
33
|
+
<!-- Package usage documentation. -->
|
|
34
|
+
|
|
35
|
+
<section class="usage">
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
var assignIn = require( '@stdlib/object/assign-in' );
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### assignIn( target, source1\[, source2\[,...,sourceN]] )
|
|
44
|
+
|
|
45
|
+
Copies enumerable own and inherited properties from one or more source objects to a target object.
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
function Foo() {
|
|
49
|
+
this.a = 'beep';
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Foo.prototype.b = 'boop';
|
|
54
|
+
|
|
55
|
+
var x = {};
|
|
56
|
+
var y = new Foo();
|
|
57
|
+
|
|
58
|
+
var z = assignIn( x, y );
|
|
59
|
+
// returns { 'a': 'beep', 'b': 'boop' }
|
|
60
|
+
|
|
61
|
+
var bool = ( z === x );
|
|
62
|
+
// returns true
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
</section>
|
|
66
|
+
|
|
67
|
+
<!-- /.usage -->
|
|
68
|
+
|
|
69
|
+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
70
|
+
|
|
71
|
+
<section class="notes">
|
|
72
|
+
|
|
73
|
+
## Notes
|
|
74
|
+
|
|
75
|
+
- If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
76
|
+
- The target object is mutated.
|
|
77
|
+
- Both string and symbol properties are copied.
|
|
78
|
+
|
|
79
|
+
</section>
|
|
80
|
+
|
|
81
|
+
<!-- /.notes -->
|
|
82
|
+
|
|
83
|
+
<!-- Package usage examples. -->
|
|
84
|
+
|
|
85
|
+
<section class="examples">
|
|
86
|
+
|
|
87
|
+
## Examples
|
|
88
|
+
|
|
89
|
+
<!-- eslint no-undef: "error" -->
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
var assignIn = require( '@stdlib/object/assign-in' );
|
|
93
|
+
|
|
94
|
+
function Foo() {
|
|
95
|
+
this.a = 1;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
Foo.prototype.b = 2;
|
|
100
|
+
|
|
101
|
+
function Bar() {
|
|
102
|
+
this.c = 3;
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
Bar.prototype.d = 4;
|
|
107
|
+
|
|
108
|
+
var obj1 = new Foo();
|
|
109
|
+
var obj2 = new Bar();
|
|
110
|
+
|
|
111
|
+
var result = assignIn( {}, obj1, obj2 );
|
|
112
|
+
// returns { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
</section>
|
|
116
|
+
|
|
117
|
+
<!-- /.examples -->
|
|
118
|
+
|
|
119
|
+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
120
|
+
|
|
121
|
+
<section class="references">
|
|
122
|
+
|
|
123
|
+
</section>
|
|
124
|
+
|
|
125
|
+
<!-- /.references -->
|
|
126
|
+
|
|
127
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
128
|
+
|
|
129
|
+
<section class="related">
|
|
130
|
+
|
|
131
|
+
</section>
|
|
132
|
+
|
|
133
|
+
<!-- /.related -->
|
|
134
|
+
|
|
135
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
136
|
+
|
|
137
|
+
<section class="links">
|
|
138
|
+
|
|
139
|
+
<!-- <related-links> -->
|
|
140
|
+
|
|
141
|
+
<!-- </related-links> -->
|
|
142
|
+
|
|
143
|
+
</section>
|
|
144
|
+
|
|
145
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( target, ...source )
|
|
3
|
+
Copies own and inherited enumerable properties from one or more source
|
|
4
|
+
objects to a target object.
|
|
5
|
+
|
|
6
|
+
If a property key is present in multiple sources, the property from the last
|
|
7
|
+
source that defines the key prevails.
|
|
8
|
+
|
|
9
|
+
Both string and symbol properties are copied.
|
|
10
|
+
|
|
11
|
+
The target object is mutated.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
target: Object
|
|
16
|
+
Target object.
|
|
17
|
+
|
|
18
|
+
source: ...Object
|
|
19
|
+
Source object(s).
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
out: Object
|
|
24
|
+
Target object.
|
|
25
|
+
|
|
26
|
+
Examples
|
|
27
|
+
--------
|
|
28
|
+
> var obj1 = { 'name': 'John', 'age': 30 };
|
|
29
|
+
> var obj2 = { 'country': 'US', 'city': 'San Francisco' };
|
|
30
|
+
> var result = {{alias}}( obj1, obj2 )
|
|
31
|
+
{ 'name': 'John', 'age': 30, 'country': 'US', 'city': 'San Francisco' }
|
|
32
|
+
|
|
33
|
+
See Also
|
|
34
|
+
--------
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Copies own enumerable and inherited properties from one or more source objects to a target object.
|
|
23
|
+
*
|
|
24
|
+
* ## Notes
|
|
25
|
+
*
|
|
26
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
27
|
+
* - The target object is mutated.
|
|
28
|
+
* - Both string and symbol properties are copied.
|
|
29
|
+
*
|
|
30
|
+
* @param target - target object
|
|
31
|
+
* @param source - source object
|
|
32
|
+
* @throws first argument must not be null or undefined
|
|
33
|
+
* @returns target object
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* function Foo() {
|
|
37
|
+
* this.a = 1;
|
|
38
|
+
* return this;
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* Foo.prototype.b = 2;
|
|
42
|
+
*
|
|
43
|
+
* function Bar() {
|
|
44
|
+
* this.c = 3;
|
|
45
|
+
* return this;
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* Bar.prototype.d = 4;
|
|
49
|
+
*
|
|
50
|
+
* var out = assignIn( {}, new Foo(), new Bar() );
|
|
51
|
+
* // returns { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
|
|
52
|
+
*/
|
|
53
|
+
declare function assignIn<T extends object, U>( target: T, source: U ): T & U;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Copies own and inherited enumerable properties from one or more source objects to a target object.
|
|
57
|
+
*
|
|
58
|
+
* ## Notes
|
|
59
|
+
*
|
|
60
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
61
|
+
* - The target object is mutated.
|
|
62
|
+
* - Both string and symbol properties are copied.
|
|
63
|
+
*
|
|
64
|
+
* @param target - target object
|
|
65
|
+
* @param source1 - first source object
|
|
66
|
+
* @param source2 - second source object
|
|
67
|
+
* @throws first argument must not be null or undefined
|
|
68
|
+
* @returns target object
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* function Foo() {
|
|
72
|
+
* this.a = 1;
|
|
73
|
+
* return this;
|
|
74
|
+
* }
|
|
75
|
+
*
|
|
76
|
+
* Foo.prototype.b = 2;
|
|
77
|
+
*
|
|
78
|
+
* function Bar() {
|
|
79
|
+
* this.c = 3;
|
|
80
|
+
* return this;
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* Bar.prototype.d = 4;
|
|
84
|
+
*
|
|
85
|
+
* var beep = {
|
|
86
|
+
* 'e': 5
|
|
87
|
+
* };
|
|
88
|
+
*
|
|
89
|
+
* var out = assignIn( {}, new Foo(), new Bar(), beep );
|
|
90
|
+
* // returns { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 }
|
|
91
|
+
*/
|
|
92
|
+
declare function assignIn<T extends object, U, V>( target: T, source1: U, source2: V ): T & U & V;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Copies own and inherited enumerable properties from one or more source objects to a target object.
|
|
96
|
+
*
|
|
97
|
+
* ## Notes
|
|
98
|
+
*
|
|
99
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
100
|
+
* - The target object is mutated.
|
|
101
|
+
* - Both string and symbol properties are copied.
|
|
102
|
+
*
|
|
103
|
+
* @param target - target object
|
|
104
|
+
* @param source1 - first source object
|
|
105
|
+
* @param source2 - second source object
|
|
106
|
+
* @param source3 - third source object
|
|
107
|
+
* @throws first argument must not be null or undefined
|
|
108
|
+
* @returns target object
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* function Foo() {
|
|
112
|
+
* this.a = 1;
|
|
113
|
+
* return this;
|
|
114
|
+
* }
|
|
115
|
+
*
|
|
116
|
+
* Foo.prototype.b = 2;
|
|
117
|
+
*
|
|
118
|
+
* function Bar() {
|
|
119
|
+
* this.c = 3;
|
|
120
|
+
* return this;
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* Bar.prototype.d = 4;
|
|
124
|
+
*
|
|
125
|
+
* var beep = {
|
|
126
|
+
* 'e': 5
|
|
127
|
+
* };
|
|
128
|
+
*
|
|
129
|
+
* var boop = {
|
|
130
|
+
* 'f': 6
|
|
131
|
+
* };
|
|
132
|
+
*
|
|
133
|
+
* var out = assignIn( {}, new Foo(), new Bar(), beep, boop );
|
|
134
|
+
* // returns { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6 }
|
|
135
|
+
*/
|
|
136
|
+
declare function assignIn<T extends object, U, V, W>( target: T, source1: U, source2: V, source3: W ): T & U & V & W;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Copies own and inherited enumerable properties from one or more source objects to a target object.
|
|
140
|
+
*
|
|
141
|
+
* ## Notes
|
|
142
|
+
*
|
|
143
|
+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
|
|
144
|
+
* - The target object is mutated.
|
|
145
|
+
* - Both string and symbol properties are copied.
|
|
146
|
+
*
|
|
147
|
+
* @param target - target object
|
|
148
|
+
* @param source - source object(s)
|
|
149
|
+
* @throws first argument must not be null or undefined
|
|
150
|
+
* @returns target object
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* function Foo() {
|
|
154
|
+
* this.a = 1;
|
|
155
|
+
* return this;
|
|
156
|
+
* }
|
|
157
|
+
*
|
|
158
|
+
* Foo.prototype.b = 2;
|
|
159
|
+
*
|
|
160
|
+
* function Bar() {
|
|
161
|
+
* this.c = 3;
|
|
162
|
+
* return this;
|
|
163
|
+
* }
|
|
164
|
+
*
|
|
165
|
+
* Bar.prototype.d = 4;
|
|
166
|
+
*
|
|
167
|
+
* var out = assignIn( {}, new Foo(), new Bar() );
|
|
168
|
+
* // returns { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
|
|
169
|
+
*/
|
|
170
|
+
declare function assignIn( target: object, ...source: Array<any> ): object;
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
// EXPORTS //
|
|
174
|
+
|
|
175
|
+
export = assignIn;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import assignIn = require( './index' );
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// TESTS //
|
|
23
|
+
|
|
24
|
+
// The function returns an object...
|
|
25
|
+
{
|
|
26
|
+
const obj1 = { 'name': 'John' };
|
|
27
|
+
const obj2 = { 'country': 'US' };
|
|
28
|
+
|
|
29
|
+
assignIn( obj1 ); // $ExpectType object
|
|
30
|
+
assignIn( obj1, obj2 ); // $ExpectType { name: string; } & { country: string; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// The compiler throws an error if the function is provided a first argument which is not an object...
|
|
34
|
+
{
|
|
35
|
+
assignIn( 'abc' ); // $ExpectError
|
|
36
|
+
assignIn( false ); // $ExpectError
|
|
37
|
+
assignIn( true ); // $ExpectError
|
|
38
|
+
assignIn( null ); // $ExpectError
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The compiler throws an error if the function is provided an insufficient number of arguments...
|
|
42
|
+
{
|
|
43
|
+
assignIn(); // $ExpectError
|
|
44
|
+
}
|