@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,120 @@
|
|
|
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 isString = require( '@ohos-ports/stdlib-assert/is-string' ).isPrimitive;
|
|
25
|
+
var isArray = require( '@ohos-ports/stdlib-assert/is-array' );
|
|
26
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
27
|
+
var validate = require( './validate.js' );
|
|
28
|
+
var defaults = require( './defaults.js' );
|
|
29
|
+
var dset = require( './dset.js' );
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// MAIN //
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Sets a nested property value.
|
|
36
|
+
*
|
|
37
|
+
* @param {ObjectLike} obj - input object
|
|
38
|
+
* @param {(string|Array)} path - key path
|
|
39
|
+
* @param {*} value - value to set
|
|
40
|
+
* @param {Options} [options] - function options
|
|
41
|
+
* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist
|
|
42
|
+
* @param {string} [options.sep='.'] - key path separator
|
|
43
|
+
* @throws {TypeError} second argument must be a string or key array
|
|
44
|
+
* @throws {TypeError} options argument must be an object
|
|
45
|
+
* @throws {TypeError} must provide valid options
|
|
46
|
+
* @returns {boolean} boolean indicating if the property was successfully set
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
50
|
+
* var bool = deepSet( obj, 'a.b.c', 'woot' );
|
|
51
|
+
* // returns true
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
55
|
+
* var bool = deepSet( obj, 'a.beep.c', 'boop' );
|
|
56
|
+
* // returns false
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
60
|
+
* var bool = deepSet( null, 'a.beep.c', 'boop' );
|
|
61
|
+
* // returns false
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
65
|
+
* bool = deepSet( 'bap', 'a.beep.c', 'boop' );
|
|
66
|
+
* // returns false
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* var arr = [
|
|
70
|
+
* { 'a': [ {'x': 5} ] },
|
|
71
|
+
* { 'a': [ {'x': 10} ] }
|
|
72
|
+
* ];
|
|
73
|
+
* var bool = deepSet( arr, '1.a.0.x', 25 );
|
|
74
|
+
* // returns true
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
78
|
+
* var bool = deepSet( obj, 'a/b/c', 'beep', {
|
|
79
|
+
* 'sep': '/'
|
|
80
|
+
* });
|
|
81
|
+
* // returns true
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* var obj = { 'a': { 'b': { 'c': 'd' } } };
|
|
85
|
+
* var bool = deepSet( obj, 'a.e.c', 'boop', {
|
|
86
|
+
* 'create': true
|
|
87
|
+
* });
|
|
88
|
+
* // returns true
|
|
89
|
+
*/
|
|
90
|
+
function deepSet( obj, path, value, options ) {
|
|
91
|
+
var isStr;
|
|
92
|
+
var props;
|
|
93
|
+
var opts;
|
|
94
|
+
var err;
|
|
95
|
+
if ( !isObjectLike( obj ) ) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
isStr = isString( path );
|
|
99
|
+
if ( !isStr && !isArray( path ) ) {
|
|
100
|
+
throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) );
|
|
101
|
+
}
|
|
102
|
+
opts = defaults();
|
|
103
|
+
if ( arguments.length > 3 ) {
|
|
104
|
+
err = validate( opts, options );
|
|
105
|
+
if ( err ) {
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if ( isStr ) {
|
|
110
|
+
props = path.split( opts.sep );
|
|
111
|
+
} else {
|
|
112
|
+
props = path;
|
|
113
|
+
}
|
|
114
|
+
return dset( obj, props, opts.create, value );
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
// EXPORTS //
|
|
119
|
+
|
|
120
|
+
module.exports = deepSet;
|
|
@@ -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 isBoolean = require( '@ohos-ports/stdlib-assert/is-boolean' ).isPrimitive;
|
|
24
|
+
var isString = require( '@ohos-ports/stdlib-assert/is-string' ).isPrimitive;
|
|
25
|
+
var isObject = require( '@ohos-ports/stdlib-assert/is-plain-object' );
|
|
26
|
+
var hasOwnProp = require( '@ohos-ports/stdlib-assert/has-own-property' );
|
|
27
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// MAIN //
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Validates function options.
|
|
34
|
+
*
|
|
35
|
+
* @private
|
|
36
|
+
* @param {Object} opts - destination for function options
|
|
37
|
+
* @param {Options} options - function options
|
|
38
|
+
* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist
|
|
39
|
+
* @param {string} [options.sep] - key path separator
|
|
40
|
+
* @returns {(Error|null)} error or null
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* var opts = {};
|
|
44
|
+
* var options = {
|
|
45
|
+
* 'sep': '/'
|
|
46
|
+
* };
|
|
47
|
+
* var err = validate( opts, options );
|
|
48
|
+
* if ( err ) {
|
|
49
|
+
* throw err;
|
|
50
|
+
* }
|
|
51
|
+
*/
|
|
52
|
+
function validate( opts, options ) {
|
|
53
|
+
if ( !isObject( options ) ) {
|
|
54
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
55
|
+
}
|
|
56
|
+
if ( hasOwnProp( options, 'create' ) ) {
|
|
57
|
+
opts.create = options.create;
|
|
58
|
+
if ( !isBoolean( opts.create ) ) {
|
|
59
|
+
return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) );
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if ( hasOwnProp( options, 'sep' ) ) {
|
|
63
|
+
opts.sep = options.sep;
|
|
64
|
+
if ( !isString( opts.sep ) ) {
|
|
65
|
+
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) );
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// EXPORTS //
|
|
73
|
+
|
|
74
|
+
module.exports = validate;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/object/deep-set",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Set a nested property value.",
|
|
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
|
+
"deep",
|
|
60
|
+
"set",
|
|
61
|
+
"assign",
|
|
62
|
+
"object",
|
|
63
|
+
"obj",
|
|
64
|
+
"array",
|
|
65
|
+
"nested",
|
|
66
|
+
"property",
|
|
67
|
+
"prop"
|
|
68
|
+
]
|
|
69
|
+
}
|