@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,54 @@
|
|
|
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
|
+
'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-in
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var assignIn = require( '@ohos-ports/stdlib-object/assign-in' );
|
|
28
|
+
*
|
|
29
|
+
* function Foo() {
|
|
30
|
+
* this.a = 1;
|
|
31
|
+
* return this;
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* Foo.prototype.b = 2;
|
|
35
|
+
*
|
|
36
|
+
* function Bar() {
|
|
37
|
+
* this.c = 3;
|
|
38
|
+
* return this;
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* Bar.prototype.d = 4;
|
|
42
|
+
*
|
|
43
|
+
* var out = assignIn( {}, new Foo(), new Bar() );
|
|
44
|
+
* // returns { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
// MODULES //
|
|
48
|
+
|
|
49
|
+
var main = require( './main.js' );
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// EXPORTS //
|
|
53
|
+
|
|
54
|
+
module.exports = main;
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var enumerablePropertiesIn = require( '@ohos-ports/stdlib-utils/enumerable-properties-in' );
|
|
24
|
+
var Object = require( './../../ctor' );
|
|
25
|
+
var format = require( '@ohos-ports/stdlib-string/format' );
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// MAIN //
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Copies own and inherited 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
|
+
* function Foo() {
|
|
46
|
+
* this.a = 1;
|
|
47
|
+
* return this;
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* Foo.prototype.b = 2;
|
|
51
|
+
*
|
|
52
|
+
* function Bar() {
|
|
53
|
+
* this.c = 3;
|
|
54
|
+
* return this;
|
|
55
|
+
* }
|
|
56
|
+
*
|
|
57
|
+
* Bar.prototype.d = 4;
|
|
58
|
+
*
|
|
59
|
+
* var out = assignIn( {}, new Foo(), new Bar() );
|
|
60
|
+
* // returns { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
|
|
61
|
+
*/
|
|
62
|
+
function assignIn( target ) {
|
|
63
|
+
var source;
|
|
64
|
+
var keys;
|
|
65
|
+
var key;
|
|
66
|
+
var len;
|
|
67
|
+
var to;
|
|
68
|
+
var i;
|
|
69
|
+
var j;
|
|
70
|
+
if ( target === void 0 || target === null ) {
|
|
71
|
+
throw new TypeError( format( 'invalid argument. First argument must be a non-null object. Value: `%s`.', target ) );
|
|
72
|
+
}
|
|
73
|
+
to = Object( target );
|
|
74
|
+
for ( i = 1; i < arguments.length; i++ ) {
|
|
75
|
+
source = arguments[ i ];
|
|
76
|
+
if ( source === void 0 || source === null ) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
keys = enumerablePropertiesIn( Object( source ) );
|
|
80
|
+
len = keys.length;
|
|
81
|
+
for ( j = 0; j < len; j++ ) {
|
|
82
|
+
key = keys[ j ];
|
|
83
|
+
to[ key ] = source[ key ];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return to;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
// EXPORTS //
|
|
91
|
+
|
|
92
|
+
module.exports = assignIn;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/object/assign-in",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Copy enumerable own and inherited 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
|
+
"object",
|
|
54
|
+
"assign",
|
|
55
|
+
"merge",
|
|
56
|
+
"copy",
|
|
57
|
+
"clone",
|
|
58
|
+
"extend"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
@@ -0,0 +1,298 @@
|
|
|
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
|
+
# bifurcateIn
|
|
22
|
+
|
|
23
|
+
> Split an object's **own** and **inherited** property values into two groups according to a predicate function.
|
|
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 bifurcateIn = require( '@stdlib/object/bifurcate-in' );
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### bifurcateIn( obj, \[options,] predicate )
|
|
44
|
+
|
|
45
|
+
Splits an object's **own** and **inherited** property values into two groups according to a `predicate` function, which specifies which group a value in the input `object` belongs to. If a `predicate` function returns a truthy value, a value belongs to the first group; otherwise, a value belongs to the second group.
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
function predicate( v ) {
|
|
49
|
+
return v[ 0 ] === 'b';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function Foo() {
|
|
53
|
+
this.a = 'beep';
|
|
54
|
+
this.b = 'boop';
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Foo.prototype = Object.create( null );
|
|
59
|
+
Foo.prototype.c = 'foo';
|
|
60
|
+
Foo.prototype.d = 'bar';
|
|
61
|
+
|
|
62
|
+
var obj = new Foo();
|
|
63
|
+
|
|
64
|
+
var out = bifurcateIn( obj, predicate );
|
|
65
|
+
// e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A `predicate` function is provided two arguments:
|
|
69
|
+
|
|
70
|
+
- **value**: object value.
|
|
71
|
+
- **key**: object index.
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
function predicate( v, k ) {
|
|
75
|
+
console.log( '%s: %s', k, v );
|
|
76
|
+
return v[ 0 ] === 'b';
|
|
77
|
+
}
|
|
78
|
+
function Foo() {
|
|
79
|
+
this.a = 'beep';
|
|
80
|
+
this.b = 'boop';
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Foo.prototype = Object.create( null );
|
|
85
|
+
Foo.prototype.c = 'foo';
|
|
86
|
+
Foo.prototype.d = 'bar';
|
|
87
|
+
|
|
88
|
+
var obj = new Foo();
|
|
89
|
+
|
|
90
|
+
var out = bifurcateIn( obj, predicate );
|
|
91
|
+
// e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The function accepts the following `options`:
|
|
95
|
+
|
|
96
|
+
- **returns**: specifies the output format. If the option equals `'values'`, the function outputs values. If the option equals `'keys'`, the function outputs keys. If the option equals `'*'`, the function outputs both keys and values. Default: `'values'`.
|
|
97
|
+
- **thisArg**: execution context.
|
|
98
|
+
|
|
99
|
+
By default, the function returns object values. To return object keys, set the `returns` option to `'keys'`.
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
function predicate( v ) {
|
|
103
|
+
return v[ 0 ] === 'b';
|
|
104
|
+
}
|
|
105
|
+
function Foo() {
|
|
106
|
+
this.a = 'beep';
|
|
107
|
+
this.b = 'boop';
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
Foo.prototype = Object.create( null );
|
|
112
|
+
Foo.prototype.c = 'foo';
|
|
113
|
+
Foo.prototype.d = 'bar';
|
|
114
|
+
|
|
115
|
+
var obj = new Foo();
|
|
116
|
+
|
|
117
|
+
var opts = {
|
|
118
|
+
'returns': 'keys'
|
|
119
|
+
};
|
|
120
|
+
var out = bifurcateIn( obj, opts, predicate );
|
|
121
|
+
// e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
To return key-value pairs, set the `returns` option to `'*'`.
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
function predicate( v ) {
|
|
128
|
+
return v[ 0 ] === 'b';
|
|
129
|
+
}
|
|
130
|
+
function Foo() {
|
|
131
|
+
this.a = 'beep';
|
|
132
|
+
this.b = 'boop';
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
Foo.prototype = Object.create( null );
|
|
137
|
+
Foo.prototype.c = 'foo';
|
|
138
|
+
Foo.prototype.d = 'bar';
|
|
139
|
+
|
|
140
|
+
var obj = new Foo();
|
|
141
|
+
|
|
142
|
+
var opts = {
|
|
143
|
+
'returns': '*'
|
|
144
|
+
};
|
|
145
|
+
var out = bifurcateIn( obj, opts, predicate );
|
|
146
|
+
// e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ]
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
To set the `predicate` execution context, provide a `thisArg`.
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
function predicate( v ) {
|
|
153
|
+
this.count += 1;
|
|
154
|
+
return v[ 0 ] === 'b';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function Foo() {
|
|
158
|
+
this.a = 'beep';
|
|
159
|
+
this.b = 'boop';
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
Foo.prototype = Object.create( null );
|
|
164
|
+
Foo.prototype.c = 'foo';
|
|
165
|
+
Foo.prototype.d = 'bar';
|
|
166
|
+
|
|
167
|
+
var obj = new Foo();
|
|
168
|
+
|
|
169
|
+
var context = {
|
|
170
|
+
'count': 0
|
|
171
|
+
};
|
|
172
|
+
var opts = {
|
|
173
|
+
'thisArg': context
|
|
174
|
+
};
|
|
175
|
+
var out = bifurcateIn( obj, opts, predicate );
|
|
176
|
+
// e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
|
|
177
|
+
|
|
178
|
+
console.log( context.count );
|
|
179
|
+
// => 4
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
</section>
|
|
183
|
+
|
|
184
|
+
<!-- /.usage -->
|
|
185
|
+
|
|
186
|
+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
187
|
+
|
|
188
|
+
<section class="notes">
|
|
189
|
+
|
|
190
|
+
## Notes
|
|
191
|
+
|
|
192
|
+
- Iteration order is **not** guaranteed, as `object` key enumeration is not specified according to the [ECMAScript specification][ecma-262-for-in]. In practice, however, most engines use insertion order to sort an `object`'s keys, thus allowing for deterministic iteration.
|
|
193
|
+
- Because iteration order is **not** guaranteed, result order is **not** guaranteed.
|
|
194
|
+
- The function determines the list of own **and** inherited enumerable properties **before** invoking the provided function. Hence, any modifications made to the input `object` **after** calling this function (such as adding and removing properties) will **not** affect the list of visited properties.
|
|
195
|
+
|
|
196
|
+
</section>
|
|
197
|
+
|
|
198
|
+
<!-- /.notes -->
|
|
199
|
+
|
|
200
|
+
<!-- Package usage examples. -->
|
|
201
|
+
|
|
202
|
+
<section class="examples">
|
|
203
|
+
|
|
204
|
+
## Examples
|
|
205
|
+
|
|
206
|
+
<!-- eslint no-undef: "error" -->
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
var randu = require( '@stdlib/random/base/randu' );
|
|
210
|
+
var fromCodePoint = require( '@stdlib/string/from-code-point' );
|
|
211
|
+
var bifurcateIn = require( '@stdlib/object/bifurcate-in' );
|
|
212
|
+
|
|
213
|
+
var opts;
|
|
214
|
+
var key;
|
|
215
|
+
var obj;
|
|
216
|
+
var out;
|
|
217
|
+
var i;
|
|
218
|
+
|
|
219
|
+
function Foo() {
|
|
220
|
+
var key;
|
|
221
|
+
var i;
|
|
222
|
+
for ( i = 0; i < 50; i++ ) {
|
|
223
|
+
key = fromCodePoint( 147+i );
|
|
224
|
+
this[ key ] = randu();
|
|
225
|
+
}
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
Foo.prototype = Object.create( null );
|
|
230
|
+
for ( i = 0; i < 50; i++ ) {
|
|
231
|
+
key = fromCodePoint( 97+i );
|
|
232
|
+
Foo.prototype[ key ] = randu();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Generate a random object:
|
|
236
|
+
obj = new Foo();
|
|
237
|
+
|
|
238
|
+
// Compute the groups...
|
|
239
|
+
function predicate( v ) {
|
|
240
|
+
return ( v < 0.5 );
|
|
241
|
+
}
|
|
242
|
+
opts = {
|
|
243
|
+
'returns': '*'
|
|
244
|
+
};
|
|
245
|
+
out = bifurcateIn( obj, opts, predicate );
|
|
246
|
+
console.log( out );
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
</section>
|
|
250
|
+
|
|
251
|
+
<!-- /.examples -->
|
|
252
|
+
|
|
253
|
+
<!-- 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. -->
|
|
254
|
+
|
|
255
|
+
<section class="references">
|
|
256
|
+
|
|
257
|
+
</section>
|
|
258
|
+
|
|
259
|
+
<!-- /.references -->
|
|
260
|
+
|
|
261
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
262
|
+
|
|
263
|
+
<section class="related">
|
|
264
|
+
|
|
265
|
+
* * *
|
|
266
|
+
|
|
267
|
+
## See Also
|
|
268
|
+
|
|
269
|
+
- <span class="package-name">[`@stdlib/utils/bifurcate`][@stdlib/utils/bifurcate]</span><span class="delimiter">: </span><span class="description">split values into two groups.</span>
|
|
270
|
+
- <span class="package-name">[`@stdlib/utils/bifurcate-by`][@stdlib/utils/bifurcate-by]</span><span class="delimiter">: </span><span class="description">split values into two groups according to a predicate function.</span>
|
|
271
|
+
- <span class="package-name">[`@stdlib/object/bifurcate-own`][@stdlib/object/bifurcate-own]</span><span class="delimiter">: </span><span class="description">split an object's own property values into two groups according to a predicate function.</span>
|
|
272
|
+
- <span class="package-name">[`@stdlib/utils/group-in`][@stdlib/utils/group-in]</span><span class="delimiter">: </span><span class="description">group an object's own and inherited property values according to an indicator function.</span>
|
|
273
|
+
|
|
274
|
+
</section>
|
|
275
|
+
|
|
276
|
+
<!-- /.related -->
|
|
277
|
+
|
|
278
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
279
|
+
|
|
280
|
+
<section class="links">
|
|
281
|
+
|
|
282
|
+
[ecma-262-for-in]: https://262.ecma-international.org/5.1/#sec-12.6.4
|
|
283
|
+
|
|
284
|
+
<!-- <related-links> -->
|
|
285
|
+
|
|
286
|
+
[@stdlib/utils/bifurcate]: https://www.npmjs.com/package/@stdlib/utils-bifurcate
|
|
287
|
+
|
|
288
|
+
[@stdlib/utils/bifurcate-by]: https://www.npmjs.com/package/@stdlib/utils-bifurcate-by
|
|
289
|
+
|
|
290
|
+
[@stdlib/object/bifurcate-own]: https://github.com/stdlib-js/object/tree/main/bifurcate-own
|
|
291
|
+
|
|
292
|
+
[@stdlib/utils/group-in]: https://www.npmjs.com/package/@stdlib/utils-group-in
|
|
293
|
+
|
|
294
|
+
<!-- </related-links> -->
|
|
295
|
+
|
|
296
|
+
</section>
|
|
297
|
+
|
|
298
|
+
<!-- /.links -->
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( obj, [options,] predicate )
|
|
3
|
+
Splits values into two groups according to a predicate function.
|
|
4
|
+
|
|
5
|
+
When invoked, the predicate function is provided two arguments:
|
|
6
|
+
|
|
7
|
+
- value: object value.
|
|
8
|
+
- key: object key.
|
|
9
|
+
|
|
10
|
+
If a predicate function returns a truthy value, a value is placed in the
|
|
11
|
+
first group; otherwise, a value is placed in the second group.
|
|
12
|
+
|
|
13
|
+
If provided an empty object with no prototype, the function returns an empty
|
|
14
|
+
array.
|
|
15
|
+
|
|
16
|
+
The function iterates over an object's own and inherited properties.
|
|
17
|
+
|
|
18
|
+
Key iteration order is *not* guaranteed, and, thus, result order is *not*
|
|
19
|
+
guaranteed.
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
obj: Object|Array|TypedArray
|
|
24
|
+
Input object to group.
|
|
25
|
+
|
|
26
|
+
options: Object (optional)
|
|
27
|
+
Options.
|
|
28
|
+
|
|
29
|
+
options.thisArg: any (optional)
|
|
30
|
+
Execution context.
|
|
31
|
+
|
|
32
|
+
options.returns: string (optional)
|
|
33
|
+
If `values`, values are returned; if `keys`, keys are returned; if `*`,
|
|
34
|
+
both keys and values are returned. Default: 'values'.
|
|
35
|
+
|
|
36
|
+
predicate: Function
|
|
37
|
+
Predicate function indicating which group a value in the input object
|
|
38
|
+
belongs to.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
out: Array<Array>|Array
|
|
43
|
+
Group results.
|
|
44
|
+
|
|
45
|
+
Examples
|
|
46
|
+
--------
|
|
47
|
+
> function Foo() { this.a = 'beep'; this.b = 'boop'; return this; };
|
|
48
|
+
> Foo.prototype = Object.create( null );
|
|
49
|
+
> Foo.prototype.c = 'foo';
|
|
50
|
+
> Foo.prototype.d = 'bar';
|
|
51
|
+
> var obj = new Foo();
|
|
52
|
+
> function predicate( v ) { return v[ 0 ] === 'b'; };
|
|
53
|
+
> var out = {{alias}}( obj, predicate )
|
|
54
|
+
[ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
|
|
55
|
+
|
|
56
|
+
// Output group results as keys:
|
|
57
|
+
> var opts = { 'returns': 'keys' };
|
|
58
|
+
> out = {{alias}}( obj, opts, predicate )
|
|
59
|
+
[ [ 'a', 'b', 'd' ], [ 'c' ] ]
|
|
60
|
+
|
|
61
|
+
// Output group results as key-value pairs:
|
|
62
|
+
> opts = { 'returns': '*' };
|
|
63
|
+
> out = {{alias}}( obj, opts, predicate )
|
|
64
|
+
[ [ ['a', 'beep'], ['b', 'boop'], ['d', 'bar'] ], [ ['c', 'foo' ] ] ]
|
|
65
|
+
|
|
66
|
+
See Also
|
|
67
|
+
--------
|
|
68
|
+
|