@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
package/ctor/lib/main.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2022 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
|
+
* Returns an object.
|
|
25
|
+
*
|
|
26
|
+
* @name Object
|
|
27
|
+
* @constructor
|
|
28
|
+
* @type {Function}
|
|
29
|
+
* @param {*} value - input value
|
|
30
|
+
* @returns {Object} object
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* var o = new Object( null );
|
|
34
|
+
* // returns {}
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var o = new Object( 5.0 );
|
|
38
|
+
* // returns <Number>
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var o = new Object( 'beep' );
|
|
42
|
+
* // returns <String>
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var o1 = {};
|
|
46
|
+
*
|
|
47
|
+
* var o2 = new Object( o1 );
|
|
48
|
+
* // returns {}
|
|
49
|
+
*
|
|
50
|
+
* var bool = ( o1 === o2 );
|
|
51
|
+
* // returns true
|
|
52
|
+
*/
|
|
53
|
+
var Obj = Object; // eslint-disable-line stdlib/require-globals
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// EXPORTS //
|
|
57
|
+
|
|
58
|
+
module.exports = Obj;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/object/ctor",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Object constructor.",
|
|
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
|
+
"object",
|
|
54
|
+
"constructor",
|
|
55
|
+
"ctor"
|
|
56
|
+
],
|
|
57
|
+
"__stdlib__": {}
|
|
58
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
# Deep Get
|
|
22
|
+
|
|
23
|
+
> Get a nested property value.
|
|
24
|
+
|
|
25
|
+
<section class="usage">
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
var deepGet = require( '@stdlib/object/deep-get' );
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
#### deepGet( obj, path\[, options] )
|
|
34
|
+
|
|
35
|
+
Returns a nested property value.
|
|
36
|
+
|
|
37
|
+
<!-- eslint-disable object-curly-newline, object-curly-spacing -->
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
41
|
+
|
|
42
|
+
var val = deepGet( obj, 'a.b.c' );
|
|
43
|
+
// returns 'd'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
For `paths` including `arrays`, specify the numeric index.
|
|
47
|
+
|
|
48
|
+
<!-- eslint-disable object-curly-newline, object-curly-spacing -->
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
var arr = [
|
|
52
|
+
{ 'a': [ {'x': 5} ] },
|
|
53
|
+
{ 'a': [ {'x': 10} ] }
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
var val = deepGet( arr, '1.a.0.x' );
|
|
57
|
+
// returns 10
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The key `path` may be specified as either a delimited `string` or a key `array`.
|
|
61
|
+
|
|
62
|
+
<!-- eslint-disable object-curly-newline, object-curly-spacing -->
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
66
|
+
|
|
67
|
+
var val = deepGet( obj, [ 'a', 'b', 'c' ] );
|
|
68
|
+
// returns 'd'
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The function accepts the following `options`:
|
|
72
|
+
|
|
73
|
+
- **sep**: key path separator. Default: `'.'`.
|
|
74
|
+
|
|
75
|
+
By default, the function assumes `dot` separated key values. To specify an alternative separator, set the `sep` option.
|
|
76
|
+
|
|
77
|
+
<!-- eslint-disable object-curly-newline, object-curly-spacing -->
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
81
|
+
|
|
82
|
+
var val = deepGet( obj, 'a/b/c', {
|
|
83
|
+
'sep': '/'
|
|
84
|
+
});
|
|
85
|
+
// returns 'd'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### deepGet.factory( path\[, options] )
|
|
89
|
+
|
|
90
|
+
Creates a reusable deep get function. The factory method ensures a `deepGet` function is configured identically by using the same set of provided `options`.
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
var dget = deepGet.factory( 'a/b/c', {
|
|
94
|
+
'sep': '/'
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### dget( obj )
|
|
99
|
+
|
|
100
|
+
Returns a nested property value.
|
|
101
|
+
|
|
102
|
+
<!-- eslint-disable object-curly-newline, object-curly-spacing -->
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
var dget = deepGet.factory( 'a.b.c' );
|
|
106
|
+
|
|
107
|
+
var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
108
|
+
|
|
109
|
+
var val = dget( obj );
|
|
110
|
+
// returns 'd'
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
</section>
|
|
114
|
+
|
|
115
|
+
<!-- /.usage -->
|
|
116
|
+
|
|
117
|
+
<section class="examples">
|
|
118
|
+
|
|
119
|
+
## Examples
|
|
120
|
+
|
|
121
|
+
<!-- eslint no-undef: "error" -->
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
var randu = require( '@stdlib/random/base/randu' );
|
|
125
|
+
var deepGet = require( '@stdlib/object/deep-get' );
|
|
126
|
+
|
|
127
|
+
var data;
|
|
128
|
+
var keys;
|
|
129
|
+
var val;
|
|
130
|
+
var i;
|
|
131
|
+
|
|
132
|
+
data = new Array( 100 );
|
|
133
|
+
for ( i = 0; i < data.length; i++ ) {
|
|
134
|
+
data[ i ] = {
|
|
135
|
+
'x': Date.now(),
|
|
136
|
+
'y': [ randu(), randu(), i ]
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
keys = [ 0, 'y', 2 ];
|
|
141
|
+
for ( i = 0; i < data.length; i++ ) {
|
|
142
|
+
keys[ 0 ] = i;
|
|
143
|
+
val = deepGet( data, keys );
|
|
144
|
+
console.log( val );
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
</section>
|
|
149
|
+
|
|
150
|
+
<!-- /.examples -->
|
|
151
|
+
|
|
152
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
153
|
+
|
|
154
|
+
<section class="related">
|
|
155
|
+
|
|
156
|
+
* * *
|
|
157
|
+
|
|
158
|
+
## See Also
|
|
159
|
+
|
|
160
|
+
- <span class="package-name">[`@stdlib/utils/deep-pluck`][@stdlib/utils/deep-pluck]</span><span class="delimiter">: </span><span class="description">extract a nested property value from each element of an object array.</span>
|
|
161
|
+
- <span class="package-name">[`@stdlib/object/deep-set`][@stdlib/object/deep-set]</span><span class="delimiter">: </span><span class="description">set a nested property value.</span>
|
|
162
|
+
|
|
163
|
+
</section>
|
|
164
|
+
|
|
165
|
+
<!-- /.related -->
|
|
166
|
+
|
|
167
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
168
|
+
|
|
169
|
+
<section class="links">
|
|
170
|
+
|
|
171
|
+
<!-- <related-links> -->
|
|
172
|
+
|
|
173
|
+
[@stdlib/utils/deep-pluck]: https://www.npmjs.com/package/@stdlib/utils-deep-pluck
|
|
174
|
+
|
|
175
|
+
[@stdlib/object/deep-set]: https://github.com/stdlib-js/object/tree/main/deep-set
|
|
176
|
+
|
|
177
|
+
<!-- </related-links> -->
|
|
178
|
+
|
|
179
|
+
</section>
|
|
180
|
+
|
|
181
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( obj, path[, options] )
|
|
3
|
+
Returns a nested property value.
|
|
4
|
+
|
|
5
|
+
Parameters
|
|
6
|
+
----------
|
|
7
|
+
obj: ObjectLike
|
|
8
|
+
Input object.
|
|
9
|
+
|
|
10
|
+
path: string|Array
|
|
11
|
+
Key path.
|
|
12
|
+
|
|
13
|
+
options: Object (optional)
|
|
14
|
+
Options.
|
|
15
|
+
|
|
16
|
+
options.sep: string (optional)
|
|
17
|
+
Key path separator. Default: '.'.
|
|
18
|
+
|
|
19
|
+
Returns
|
|
20
|
+
-------
|
|
21
|
+
out: any
|
|
22
|
+
Nested property value.
|
|
23
|
+
|
|
24
|
+
Examples
|
|
25
|
+
--------
|
|
26
|
+
> var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
27
|
+
> var val = {{alias}}( obj, 'a.b.c' )
|
|
28
|
+
'd'
|
|
29
|
+
|
|
30
|
+
// Specify a custom separator via the `sep` option:
|
|
31
|
+
> var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
32
|
+
> var val = {{alias}}( obj, 'a/b/c', { 'sep': '/' } )
|
|
33
|
+
'd'
|
|
34
|
+
|
|
35
|
+
{{alias}}.factory( path[, options] )
|
|
36
|
+
Creates a reusable deep get function.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
path: string|Array
|
|
41
|
+
Key path.
|
|
42
|
+
|
|
43
|
+
options: Object (optional)
|
|
44
|
+
Options.
|
|
45
|
+
|
|
46
|
+
options.sep: string (optional)
|
|
47
|
+
Key path separator. Default: '.'.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
out: Function
|
|
52
|
+
Deep get factory.
|
|
53
|
+
|
|
54
|
+
Examples
|
|
55
|
+
--------
|
|
56
|
+
> var dget = {{alias}}.factory( 'a/b/c', { 'sep': '/' } );
|
|
57
|
+
> var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
58
|
+
> var val = dget( obj )
|
|
59
|
+
'd'
|
|
60
|
+
|
|
61
|
+
See Also
|
|
62
|
+
--------
|
|
63
|
+
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
* Interface defining function options.
|
|
23
|
+
*/
|
|
24
|
+
interface Options {
|
|
25
|
+
/**
|
|
26
|
+
* Key path separator.
|
|
27
|
+
*/
|
|
28
|
+
sep?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns a nested property value.
|
|
33
|
+
*
|
|
34
|
+
* @param obj - input object
|
|
35
|
+
* @returns nested property value
|
|
36
|
+
*/
|
|
37
|
+
type Unary = ( obj: any ) => any;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Interface for retrieving nested property values.
|
|
41
|
+
*/
|
|
42
|
+
interface DeepGet {
|
|
43
|
+
/**
|
|
44
|
+
* Returns a nested property value.
|
|
45
|
+
*
|
|
46
|
+
* @param obj - input object
|
|
47
|
+
* @param path - key path
|
|
48
|
+
* @param options - function options
|
|
49
|
+
* @param options.sep - key path separator (default: '.')
|
|
50
|
+
* @returns nested property value
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
54
|
+
* var val = deepGet( obj, 'a.b.c' );
|
|
55
|
+
* // returns 'd'
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* var arr = [
|
|
59
|
+
* { 'a': [ {'x': 5} ] },
|
|
60
|
+
* { 'a': [ {'x': 10} ] }
|
|
61
|
+
* ];
|
|
62
|
+
* var val = deepGet( arr, '1.a.0.x' );
|
|
63
|
+
* // returns 10
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
67
|
+
* var val = deepGet( obj, ['a','b','c'] );
|
|
68
|
+
* // returns 'd'
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
72
|
+
* var val = deepGet( obj, 'a/b/c', {
|
|
73
|
+
* 'sep': '/'
|
|
74
|
+
* });
|
|
75
|
+
* // returns 'd'
|
|
76
|
+
*/
|
|
77
|
+
( obj: any, path: string | Array<string>, options?: Options ): any;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns a function for retrieving a nested property value.
|
|
81
|
+
*
|
|
82
|
+
* @param path - key path
|
|
83
|
+
* @param options - function options
|
|
84
|
+
* @param options.sep - key path separator (default: '.')
|
|
85
|
+
* @returns deep get factory
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* var dget = deepGet.factory( 'a/b/c', {
|
|
89
|
+
* 'sep': '/'
|
|
90
|
+
* });
|
|
91
|
+
*/
|
|
92
|
+
factory( path: string | Array<string>, options?: Options ): Unary;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Returns a nested property value.
|
|
97
|
+
*
|
|
98
|
+
* @param obj - input object
|
|
99
|
+
* @param path - key path
|
|
100
|
+
* @param options - function options
|
|
101
|
+
* @param options.sep - key path separator (default: '.')
|
|
102
|
+
* @returns nested property value
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
106
|
+
*
|
|
107
|
+
* var val = deepGet( obj, 'a.b.c' );
|
|
108
|
+
* // returns 'd'
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* var dget = deepGet.factory( 'a/b/c', {
|
|
112
|
+
* 'sep': '/'
|
|
113
|
+
* });
|
|
114
|
+
*
|
|
115
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
116
|
+
*
|
|
117
|
+
* var val = dget( obj );
|
|
118
|
+
* // returns 'd'
|
|
119
|
+
*/
|
|
120
|
+
declare var deepGet: DeepGet;
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
// EXPORTS //
|
|
124
|
+
|
|
125
|
+
export = deepGet;
|
|
@@ -0,0 +1,109 @@
|
|
|
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 deepGet = require( './index' );
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// TESTS //
|
|
23
|
+
|
|
24
|
+
// The function returns an object...
|
|
25
|
+
{
|
|
26
|
+
const obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
27
|
+
deepGet( obj, 'a.b.c' ); // $ExpectType any
|
|
28
|
+
deepGet( obj, [ 'a', 'b', 'c' ] ); // $ExpectType any
|
|
29
|
+
deepGet( obj, 'a-b-c', { 'sep': '-' } ); // $ExpectType any
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The compiler throws an error if the function is provided a second argument which is not a string or array of strings...
|
|
33
|
+
{
|
|
34
|
+
const obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
35
|
+
deepGet( obj, true ); // $ExpectError
|
|
36
|
+
deepGet( obj, false ); // $ExpectError
|
|
37
|
+
deepGet( obj, 2.12 ); // $ExpectError
|
|
38
|
+
deepGet( obj, {} ); // $ExpectError
|
|
39
|
+
deepGet( obj, [ 1, 2, 3 ] ); // $ExpectError
|
|
40
|
+
deepGet( obj, ( x: number ): number => x ); // $ExpectError
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The compiler throws an error if the function is provided a third argument which is not an object...
|
|
44
|
+
{
|
|
45
|
+
const obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
46
|
+
deepGet( obj, 'a.b.c', null ); // $ExpectError
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// The compiler throws an error if the function is provided a `sep` option which is not a string...
|
|
50
|
+
{
|
|
51
|
+
const obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
52
|
+
deepGet( obj, 'a.b.c', { 'sep': true } ); // $ExpectError
|
|
53
|
+
deepGet( obj, 'a.b.c', { 'sep': false } ); // $ExpectError
|
|
54
|
+
deepGet( obj, 'a.b.c', { 'sep': 123 } ); // $ExpectError
|
|
55
|
+
deepGet( obj, 'a.b.c', { 'sep': null } ); // $ExpectError
|
|
56
|
+
deepGet( obj, 'a.b.c', { 'sep': [] } ); // $ExpectError
|
|
57
|
+
deepGet( obj, 'a.b.c', { 'sep': {} } ); // $ExpectError
|
|
58
|
+
deepGet( obj, 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The compiler throws an error if the function is provided no arguments...
|
|
62
|
+
{
|
|
63
|
+
deepGet(); // $ExpectError
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Attached to main export is a `factory` method which returns a function...
|
|
67
|
+
{
|
|
68
|
+
deepGet.factory( 'a.b.c' ); // $ExpectType Unary
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The compiler throws an error if the `factory` method is provided an unsupported number of arguments...
|
|
72
|
+
{
|
|
73
|
+
deepGet.factory(); // $ExpectError
|
|
74
|
+
deepGet.factory( 'a.b.c', {}, 21 ); // $ExpectError
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The `factory` method returns a function which returns an object...
|
|
78
|
+
{
|
|
79
|
+
const obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
80
|
+
let fcn = deepGet.factory( 'a.b.c' );
|
|
81
|
+
fcn( obj ); // $ExpectType any
|
|
82
|
+
|
|
83
|
+
fcn = deepGet.factory( 'a-b-c', { 'sep': '-' } );
|
|
84
|
+
fcn( obj ); // $ExpectType any
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// The compiler throws an error if the `factory` method is provided a second argument which is not an object...
|
|
88
|
+
{
|
|
89
|
+
deepGet.factory( 'a.b.c', null ); // $ExpectError
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string...
|
|
93
|
+
{
|
|
94
|
+
deepGet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError
|
|
95
|
+
deepGet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError
|
|
96
|
+
deepGet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError
|
|
97
|
+
deepGet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError
|
|
98
|
+
deepGet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError
|
|
99
|
+
deepGet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError
|
|
100
|
+
deepGet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments...
|
|
104
|
+
{
|
|
105
|
+
const obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
106
|
+
const fcn = deepGet.factory( 'a.b.c' );
|
|
107
|
+
fcn(); // $ExpectError
|
|
108
|
+
fcn( obj, 2 ); // $ExpectError
|
|
109
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
* Returns default options.
|
|
25
|
+
*
|
|
26
|
+
* @private
|
|
27
|
+
* @returns {Object} default options
|
|
28
|
+
*/
|
|
29
|
+
function defaults() {
|
|
30
|
+
return {
|
|
31
|
+
'sep': '.'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
// EXPORTS //
|
|
37
|
+
|
|
38
|
+
module.exports = defaults;
|
|
@@ -0,0 +1,57 @@
|
|
|
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 isObjectLike = require( '@ohos-ports/stdlib-assert/is-object-like' );
|
|
24
|
+
var hasOwnProp = require( '@ohos-ports/stdlib-assert/has-own-property' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// MAIN //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns a nested property value.
|
|
31
|
+
*
|
|
32
|
+
* @private
|
|
33
|
+
* @param {ObjectLike} obj - input object
|
|
34
|
+
* @param {Array} props - list of properties defining a key path
|
|
35
|
+
* @returns {*} nested property value
|
|
36
|
+
*/
|
|
37
|
+
function deepGet( obj, props ) {
|
|
38
|
+
var len = props.length;
|
|
39
|
+
var v = obj;
|
|
40
|
+
var i;
|
|
41
|
+
for ( i = 0; i < len; i++ ) {
|
|
42
|
+
if (
|
|
43
|
+
isObjectLike( v ) &&
|
|
44
|
+
hasOwnProp( v, props[ i ] )
|
|
45
|
+
) {
|
|
46
|
+
v = v[ props[ i ] ];
|
|
47
|
+
} else {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return v;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// EXPORTS //
|
|
56
|
+
|
|
57
|
+
module.exports = deepGet;
|