@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,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 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 lowercaseKeys = require( './index' );
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// TESTS //
|
|
23
|
+
|
|
24
|
+
// The function returns an object...
|
|
25
|
+
{
|
|
26
|
+
lowercaseKeys( { 'beep': 1, 'boop': 2 } ); // $ExpectType Object
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The compiler throws an error if the function is provided an incorrect number of arguments...
|
|
30
|
+
{
|
|
31
|
+
lowercaseKeys(); // $ExpectError
|
|
32
|
+
lowercaseKeys( [], 2 ); // $ExpectError
|
|
33
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
* Convert each object key to lowercase.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/object/lowercase-keys
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var lowercaseKeys = require( '@ohos-ports/stdlib-object/lowercase-keys' );
|
|
28
|
+
*
|
|
29
|
+
* var obj1 = {
|
|
30
|
+
* 'A': 1,
|
|
31
|
+
* 'B': 2
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* var obj2 = lowercaseKeys( obj1 );
|
|
35
|
+
* // returns { 'a': 1, 'b': 2 }
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
// MODULES //
|
|
39
|
+
|
|
40
|
+
var main = require( './main.js' );
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// EXPORTS //
|
|
44
|
+
|
|
45
|
+
module.exports = main;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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 hasOwnProp = require( '@ohos-ports/stdlib-assert/has-own-property' );
|
|
24
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Converts each object key to lowercase.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} obj - source object
|
|
33
|
+
* @throws {TypeError} must provide an object
|
|
34
|
+
* @returns {Object} new object
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var obj1 = {
|
|
38
|
+
* 'A': 1,
|
|
39
|
+
* 'B': 2
|
|
40
|
+
* };
|
|
41
|
+
*
|
|
42
|
+
* var obj2 = lowercaseKeys( obj1 );
|
|
43
|
+
* // returns { 'a': 1, 'b': 2 }
|
|
44
|
+
*/
|
|
45
|
+
function lowercaseKeys( obj ) {
|
|
46
|
+
var out;
|
|
47
|
+
var key;
|
|
48
|
+
if ( typeof obj !== 'object' || obj === null ) {
|
|
49
|
+
throw new TypeError( format( 'invalid argument. Must provide an object. Value: `%s`.', obj ) );
|
|
50
|
+
}
|
|
51
|
+
out = {};
|
|
52
|
+
for ( key in obj ) {
|
|
53
|
+
if ( hasOwnProp( obj, key ) ) {
|
|
54
|
+
out[ key.toLowerCase() ] = obj[ key ];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// EXPORTS //
|
|
62
|
+
|
|
63
|
+
module.exports = lowercaseKeys;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/object/lowercase-keys",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Convert each object key to lowercase.",
|
|
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
|
+
"stdutils",
|
|
54
|
+
"stdutil",
|
|
55
|
+
"utilities",
|
|
56
|
+
"utility",
|
|
57
|
+
"utils",
|
|
58
|
+
"util",
|
|
59
|
+
"map",
|
|
60
|
+
"transform",
|
|
61
|
+
"lowercase",
|
|
62
|
+
"copy",
|
|
63
|
+
"cp",
|
|
64
|
+
"clone",
|
|
65
|
+
"extract",
|
|
66
|
+
"property",
|
|
67
|
+
"props",
|
|
68
|
+
"properties",
|
|
69
|
+
"keys",
|
|
70
|
+
"object",
|
|
71
|
+
"array",
|
|
72
|
+
"obj"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2018 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
|
+
# Move Property
|
|
22
|
+
|
|
23
|
+
> Move a property from one object to another object.
|
|
24
|
+
|
|
25
|
+
<section class="usage">
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
var moveProperty = require( '@stdlib/object/move-property' );
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### moveProperty( source, prop, target )
|
|
34
|
+
|
|
35
|
+
Moves a property from one `object` to another `object`.
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
var obj1 = {
|
|
39
|
+
'a': 'b'
|
|
40
|
+
};
|
|
41
|
+
var obj2 = {};
|
|
42
|
+
|
|
43
|
+
var bool = moveProperty( obj1, 'a', obj2 );
|
|
44
|
+
// returns true
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
If the operation is successful, the function returns `true`; otherwise, `false`.
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
var obj1 = {
|
|
51
|
+
'a': 'b'
|
|
52
|
+
};
|
|
53
|
+
var obj2 = {};
|
|
54
|
+
|
|
55
|
+
var bool = moveProperty( obj1, 'c', obj2 );
|
|
56
|
+
// returns false
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
</section>
|
|
60
|
+
|
|
61
|
+
<!-- /.usage -->
|
|
62
|
+
|
|
63
|
+
<section class="notes">
|
|
64
|
+
|
|
65
|
+
## Notes
|
|
66
|
+
|
|
67
|
+
- A transfer is **shallow**.
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
var arr = [ 1, 2, 3 ];
|
|
71
|
+
|
|
72
|
+
var obj1 = {
|
|
73
|
+
'a': arr
|
|
74
|
+
};
|
|
75
|
+
var obj2 = {};
|
|
76
|
+
|
|
77
|
+
var bool = moveProperty( obj1, 'a', obj2 );
|
|
78
|
+
console.log( obj2.a === arr );
|
|
79
|
+
// => true
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- The property is **deleted** from the _source_ `object`.
|
|
83
|
+
|
|
84
|
+
- The property's descriptor **is** preserved during transfer.
|
|
85
|
+
|
|
86
|
+
- If a _source_ property is **not** `configurable`, the function throws an `Error`, as the property **cannot** be deleted from the _source_ `object`.
|
|
87
|
+
|
|
88
|
+
</section>
|
|
89
|
+
|
|
90
|
+
<!-- /.notes -->
|
|
91
|
+
|
|
92
|
+
<section class="examples">
|
|
93
|
+
|
|
94
|
+
## Examples
|
|
95
|
+
|
|
96
|
+
<!-- eslint no-undef: "error" -->
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
var moveProperty = require( '@stdlib/object/move-property' );
|
|
100
|
+
|
|
101
|
+
var obj1 = {
|
|
102
|
+
'beep': 'boop'
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
var obj2 = {
|
|
106
|
+
'foo': 'bar'
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
var bool = moveProperty( obj1, 'beep', obj2 );
|
|
110
|
+
if ( bool === false ) {
|
|
111
|
+
console.log( 'failed to move property' );
|
|
112
|
+
}
|
|
113
|
+
console.dir( obj1 );
|
|
114
|
+
/* =>
|
|
115
|
+
{}
|
|
116
|
+
*/
|
|
117
|
+
console.dir( obj2 );
|
|
118
|
+
/* =>
|
|
119
|
+
{
|
|
120
|
+
'foo': 'bar',
|
|
121
|
+
'beep': 'boop'
|
|
122
|
+
}
|
|
123
|
+
*/
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
</section>
|
|
127
|
+
|
|
128
|
+
<!-- /.examples -->
|
|
129
|
+
|
|
130
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
131
|
+
|
|
132
|
+
<section class="related">
|
|
133
|
+
|
|
134
|
+
</section>
|
|
135
|
+
|
|
136
|
+
<!-- /.related -->
|
|
137
|
+
|
|
138
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
139
|
+
|
|
140
|
+
<section class="links">
|
|
141
|
+
|
|
142
|
+
</section>
|
|
143
|
+
|
|
144
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( source, prop, target )
|
|
3
|
+
Moves a property from one object to another object.
|
|
4
|
+
|
|
5
|
+
The property is deleted from the source object and the property's descriptor
|
|
6
|
+
is preserved during transfer.
|
|
7
|
+
|
|
8
|
+
If a source property is not configurable, the function throws an error, as
|
|
9
|
+
the property cannot be deleted from the source object.
|
|
10
|
+
|
|
11
|
+
Parameters
|
|
12
|
+
----------
|
|
13
|
+
source: Object
|
|
14
|
+
Source object.
|
|
15
|
+
|
|
16
|
+
prop: string
|
|
17
|
+
Property to move.
|
|
18
|
+
|
|
19
|
+
target: Object
|
|
20
|
+
Target object.
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
bool: boolean
|
|
25
|
+
Boolean indicating whether operation was successful.
|
|
26
|
+
|
|
27
|
+
Examples
|
|
28
|
+
--------
|
|
29
|
+
> var obj1 = { 'a': 'b' };
|
|
30
|
+
> var obj2 = {};
|
|
31
|
+
> var bool = {{alias}}( obj1, 'a', obj2 )
|
|
32
|
+
true
|
|
33
|
+
> bool = {{alias}}( obj1, 'c', obj2 )
|
|
34
|
+
false
|
|
35
|
+
|
|
36
|
+
See Also
|
|
37
|
+
--------
|
|
38
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 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
|
+
* Moves a property from one object to another object.
|
|
23
|
+
*
|
|
24
|
+
* ## Notes
|
|
25
|
+
*
|
|
26
|
+
* - The property is deleted from the source object and the property's descriptor is preserved during transfer.
|
|
27
|
+
* - If a source property is not configurable, the function throws an error, as the property cannot be deleted from the source object.
|
|
28
|
+
*
|
|
29
|
+
* @param source - source object
|
|
30
|
+
* @param prop - property to move
|
|
31
|
+
* @param target - target object
|
|
32
|
+
* @returns boolean indicating whether operation was successful
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* var obj1 = { 'a': 'b' };
|
|
36
|
+
* var obj2 = {};
|
|
37
|
+
*
|
|
38
|
+
* var bool = moveProperty( obj1, 'a', obj2 );
|
|
39
|
+
* // returns true
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var obj1 = { 'a': 'b' };
|
|
43
|
+
* var obj2 = {};
|
|
44
|
+
*
|
|
45
|
+
* var bool = moveProperty( obj1, 'c', obj2 );
|
|
46
|
+
* // returns false
|
|
47
|
+
*/
|
|
48
|
+
declare function moveProperty( source: any, prop: string, target: any ): boolean;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
// EXPORTS //
|
|
52
|
+
|
|
53
|
+
export = moveProperty;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 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 moveProperty = require( './index' );
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// TESTS //
|
|
23
|
+
|
|
24
|
+
// The function returns a boolean...
|
|
25
|
+
{
|
|
26
|
+
moveProperty( { 'a': 'b' }, 'a', {} ); // $ExpectType boolean
|
|
27
|
+
moveProperty( { 'a': 'b' }, 'a', {} ); // $ExpectType boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// The compiler throws an error if the function is not provided a string as its second argument...
|
|
31
|
+
{
|
|
32
|
+
moveProperty( { 'a': 'b' }, true, {} ); // $ExpectError
|
|
33
|
+
moveProperty( { 'a': 'b' }, 3.12, {} ); // $ExpectError
|
|
34
|
+
moveProperty( { 'a': 'b' }, false, {} ); // $ExpectError
|
|
35
|
+
moveProperty( { 'a': 'b' }, ( x: number ): number => x, {} ); // $ExpectError
|
|
36
|
+
moveProperty( { 'a': 'b' }, [], {} ); // $ExpectError
|
|
37
|
+
moveProperty( { 'a': 'b' }, {}, {} ); // $ExpectError
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// The compiler throws an error if the function is provided an incorrect number of arguments...
|
|
41
|
+
{
|
|
42
|
+
moveProperty(); // $ExpectError
|
|
43
|
+
moveProperty( { 'a': 'b' } ); // $ExpectError
|
|
44
|
+
moveProperty( { 'a': 'b' }, 'a' ); // $ExpectError
|
|
45
|
+
moveProperty( { 'a': 'b' }, 'a', {}, 3.12 ); // $ExpectError
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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
|
+
* Move a property from one object to another object.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/object/move-property
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var moveProperty = require( '@ohos-ports/stdlib-object/move-property' );
|
|
28
|
+
*
|
|
29
|
+
* var obj1 = { 'a': 'b' };
|
|
30
|
+
* var obj2 = {};
|
|
31
|
+
*
|
|
32
|
+
* var bool = moveProperty( obj1, 'a', obj2 );
|
|
33
|
+
* // returns true
|
|
34
|
+
*
|
|
35
|
+
* bool = moveProperty( obj1, 'c', obj2 );
|
|
36
|
+
* // returns false
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// MODULES //
|
|
40
|
+
|
|
41
|
+
var moveProperty = require( './main.js' );
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// EXPORTS //
|
|
45
|
+
|
|
46
|
+
module.exports = moveProperty;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018 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 defineProperty = require( '@ohos-ports/stdlib-utils/define-property' );
|
|
24
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Moves a property from one object to another object.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} source - source object
|
|
33
|
+
* @param {string} prop - property to move
|
|
34
|
+
* @param {Object} target - target object
|
|
35
|
+
* @throws {TypeError} first argument must be an object
|
|
36
|
+
* @throws {TypeError} third argument must be an object
|
|
37
|
+
* @returns {boolean} boolean indicating whether operation was successful
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var obj1 = { 'a': 'b' };
|
|
41
|
+
* var obj2 = {};
|
|
42
|
+
*
|
|
43
|
+
* var bool = moveProperty( obj1, 'a', obj2 );
|
|
44
|
+
* // returns true
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* var obj1 = { 'a': 'b' };
|
|
48
|
+
* var obj2 = {};
|
|
49
|
+
*
|
|
50
|
+
* var bool = moveProperty( obj1, 'c', obj2 );
|
|
51
|
+
* // returns false
|
|
52
|
+
*/
|
|
53
|
+
function moveProperty( source, prop, target ) {
|
|
54
|
+
var desc;
|
|
55
|
+
if ( typeof source !== 'object' || source === null ) {
|
|
56
|
+
throw new TypeError( format( 'invalid argument. Source argument must be an object. Value: `%s`.', source ) );
|
|
57
|
+
}
|
|
58
|
+
if ( typeof target !== 'object' || target === null ) {
|
|
59
|
+
throw new TypeError( format( 'invalid argument. Target argument must be an object. Value: `%s`.', target ) );
|
|
60
|
+
}
|
|
61
|
+
// TODO: handle case where gOPD is not supported
|
|
62
|
+
desc = Object.getOwnPropertyDescriptor( source, prop );
|
|
63
|
+
if ( desc === void 0 ) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
delete source[ prop ];
|
|
67
|
+
defineProperty( target, prop, desc );
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// EXPORTS //
|
|
73
|
+
|
|
74
|
+
module.exports = moveProperty;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/object/move-property",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Move a property from one object to another 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
|
+
"stdutils",
|
|
54
|
+
"stdutil",
|
|
55
|
+
"util",
|
|
56
|
+
"utils",
|
|
57
|
+
"utility",
|
|
58
|
+
"utilities",
|
|
59
|
+
"move",
|
|
60
|
+
"copy",
|
|
61
|
+
"property",
|
|
62
|
+
"prop",
|
|
63
|
+
"object",
|
|
64
|
+
"transfer",
|
|
65
|
+
"cp",
|
|
66
|
+
"mv",
|
|
67
|
+
"obj"
|
|
68
|
+
]
|
|
69
|
+
}
|