@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.
Files changed (207) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +1 -0
  3. package/README.md +262 -2
  4. package/SECURITY.md +5 -0
  5. package/any-in-by/README.md +217 -0
  6. package/any-in-by/docs/repl.txt +41 -0
  7. package/any-in-by/docs/types/index.d.ts +102 -0
  8. package/any-in-by/docs/types/test.ts +53 -0
  9. package/any-in-by/lib/index.js +50 -0
  10. package/any-in-by/lib/main.js +75 -0
  11. package/any-in-by/package.json +66 -0
  12. package/any-own-by/README.md +221 -0
  13. package/any-own-by/docs/repl.txt +43 -0
  14. package/any-own-by/docs/types/index.d.ts +101 -0
  15. package/any-own-by/docs/types/test.ts +63 -0
  16. package/any-own-by/lib/index.js +46 -0
  17. package/any-own-by/lib/main.js +77 -0
  18. package/any-own-by/package.json +70 -0
  19. package/assign/README.md +139 -0
  20. package/assign/docs/repl.txt +34 -0
  21. package/assign/docs/types/index.d.ts +113 -0
  22. package/assign/docs/types/test.ts +47 -0
  23. package/assign/lib/builtin.js +55 -0
  24. package/assign/lib/has_object_assign.js +33 -0
  25. package/assign/lib/index.js +52 -0
  26. package/assign/lib/polyfill.js +86 -0
  27. package/assign/package.json +64 -0
  28. package/assign-in/README.md +145 -0
  29. package/assign-in/docs/repl.txt +34 -0
  30. package/assign-in/docs/types/index.d.ts +175 -0
  31. package/assign-in/docs/types/test.ts +44 -0
  32. package/assign-in/lib/index.js +54 -0
  33. package/assign-in/lib/main.js +92 -0
  34. package/assign-in/package.json +60 -0
  35. package/bifurcate-in/README.md +298 -0
  36. package/bifurcate-in/docs/repl.txt +68 -0
  37. package/bifurcate-in/docs/types/index.d.ts +189 -0
  38. package/bifurcate-in/docs/types/test.ts +97 -0
  39. package/bifurcate-in/lib/index.js +106 -0
  40. package/bifurcate-in/lib/main.js +148 -0
  41. package/bifurcate-in/lib/return_keys.js +81 -0
  42. package/bifurcate-in/lib/return_pairs.js +87 -0
  43. package/bifurcate-in/lib/return_values.js +87 -0
  44. package/bifurcate-in/lib/validate.js +76 -0
  45. package/bifurcate-in/package.json +72 -0
  46. package/bifurcate-own/README.md +255 -0
  47. package/bifurcate-own/docs/repl.txt +63 -0
  48. package/bifurcate-own/docs/types/index.d.ts +183 -0
  49. package/bifurcate-own/docs/types/test.ts +97 -0
  50. package/bifurcate-own/lib/index.js +87 -0
  51. package/bifurcate-own/lib/main.js +127 -0
  52. package/bifurcate-own/lib/return_keys.js +81 -0
  53. package/bifurcate-own/lib/return_pairs.js +87 -0
  54. package/bifurcate-own/lib/return_values.js +87 -0
  55. package/bifurcate-own/lib/validate.js +76 -0
  56. package/bifurcate-own/package.json +71 -0
  57. package/capitalize-keys/README.md +139 -0
  58. package/capitalize-keys/docs/repl.txt +28 -0
  59. package/capitalize-keys/docs/types/index.d.ts +46 -0
  60. package/capitalize-keys/docs/types/test.ts +33 -0
  61. package/capitalize-keys/lib/index.js +45 -0
  62. package/capitalize-keys/lib/main.js +69 -0
  63. package/capitalize-keys/package.json +76 -0
  64. package/common-keys/README.md +125 -0
  65. package/common-keys/docs/repl.txt +29 -0
  66. package/common-keys/docs/types/index.d.ts +70 -0
  67. package/common-keys/docs/types/test.ts +33 -0
  68. package/common-keys/lib/index.js +51 -0
  69. package/common-keys/lib/main.js +106 -0
  70. package/common-keys/package.json +70 -0
  71. package/common-keys-in/README.md +125 -0
  72. package/common-keys-in/docs/repl.txt +29 -0
  73. package/common-keys-in/docs/types/index.d.ts +70 -0
  74. package/common-keys-in/docs/types/test.ts +33 -0
  75. package/common-keys-in/lib/index.js +51 -0
  76. package/common-keys-in/lib/main.js +106 -0
  77. package/common-keys-in/package.json +72 -0
  78. package/ctor/README.md +536 -0
  79. package/ctor/docs/repl.txt +592 -0
  80. package/ctor/docs/types/index.d.ts +56 -0
  81. package/ctor/docs/types/test.ts +33 -0
  82. package/ctor/lib/index.js +54 -0
  83. package/ctor/lib/main.js +58 -0
  84. package/ctor/package.json +58 -0
  85. package/deep-get/README.md +181 -0
  86. package/deep-get/docs/repl.txt +63 -0
  87. package/deep-get/docs/types/index.d.ts +125 -0
  88. package/deep-get/docs/types/test.ts +109 -0
  89. package/deep-get/lib/defaults.js +38 -0
  90. package/deep-get/lib/dget.js +57 -0
  91. package/deep-get/lib/factory.js +94 -0
  92. package/deep-get/lib/index.js +58 -0
  93. package/deep-get/lib/main.js +101 -0
  94. package/deep-get/lib/validate.js +66 -0
  95. package/deep-get/package.json +68 -0
  96. package/deep-set/README.md +273 -0
  97. package/deep-set/docs/repl.txt +87 -0
  98. package/deep-set/docs/types/index.d.ts +180 -0
  99. package/deep-set/docs/types/test.ts +134 -0
  100. package/deep-set/lib/defaults.js +39 -0
  101. package/deep-set/lib/dset.js +80 -0
  102. package/deep-set/lib/factory.js +99 -0
  103. package/deep-set/lib/index.js +58 -0
  104. package/deep-set/lib/main.js +120 -0
  105. package/deep-set/lib/validate.js +74 -0
  106. package/deep-set/package.json +69 -0
  107. package/docs/types/index.d.ts +964 -0
  108. package/every-in-by/README.md +156 -0
  109. package/every-in-by/docs/repl.txt +43 -0
  110. package/every-in-by/docs/types/index.d.ts +83 -0
  111. package/every-in-by/docs/types/test.ts +60 -0
  112. package/every-in-by/lib/index.js +51 -0
  113. package/every-in-by/lib/main.js +70 -0
  114. package/every-in-by/package.json +67 -0
  115. package/every-own-by/README.md +223 -0
  116. package/every-own-by/docs/repl.txt +43 -0
  117. package/every-own-by/docs/types/index.d.ts +102 -0
  118. package/every-own-by/docs/types/test.ts +62 -0
  119. package/every-own-by/lib/index.js +46 -0
  120. package/every-own-by/lib/main.js +77 -0
  121. package/every-own-by/package.json +68 -0
  122. package/for-in/README.md +218 -0
  123. package/for-in/docs/repl.txt +44 -0
  124. package/for-in/docs/types/index.d.ts +65 -0
  125. package/for-in/docs/types/test.ts +50 -0
  126. package/for-in/lib/index.js +54 -0
  127. package/for-in/lib/main.js +82 -0
  128. package/for-in/package.json +74 -0
  129. package/for-own/README.md +209 -0
  130. package/for-own/docs/repl.txt +49 -0
  131. package/for-own/docs/types/index.d.ts +63 -0
  132. package/for-own/docs/types/test.ts +50 -0
  133. package/for-own/lib/index.js +50 -0
  134. package/for-own/lib/main.js +85 -0
  135. package/for-own/package.json +71 -0
  136. package/inverse/README.md +163 -0
  137. package/inverse/docs/repl.txt +53 -0
  138. package/inverse/docs/types/index.d.ts +66 -0
  139. package/inverse/docs/types/test.ts +60 -0
  140. package/inverse/lib/index.js +59 -0
  141. package/inverse/lib/main.js +123 -0
  142. package/inverse/package.json +69 -0
  143. package/inverse-by/README.md +205 -0
  144. package/inverse-by/docs/repl.txt +67 -0
  145. package/inverse-by/docs/types/index.d.ts +160 -0
  146. package/inverse-by/docs/types/test.ts +81 -0
  147. package/inverse-by/lib/index.js +78 -0
  148. package/inverse-by/lib/main.js +148 -0
  149. package/inverse-by/package.json +75 -0
  150. package/lib/index.js +276 -0
  151. package/lowercase-keys/README.md +139 -0
  152. package/lowercase-keys/docs/repl.txt +28 -0
  153. package/lowercase-keys/docs/types/index.d.ts +46 -0
  154. package/lowercase-keys/docs/types/test.ts +33 -0
  155. package/lowercase-keys/lib/index.js +45 -0
  156. package/lowercase-keys/lib/main.js +63 -0
  157. package/lowercase-keys/package.json +74 -0
  158. package/move-property/README.md +144 -0
  159. package/move-property/docs/repl.txt +38 -0
  160. package/move-property/docs/types/index.d.ts +53 -0
  161. package/move-property/docs/types/test.ts +46 -0
  162. package/move-property/lib/index.js +46 -0
  163. package/move-property/lib/main.js +74 -0
  164. package/move-property/package.json +69 -0
  165. package/none-in-by/README.md +241 -0
  166. package/none-in-by/docs/repl.txt +42 -0
  167. package/none-in-by/docs/types/index.d.ts +101 -0
  168. package/none-in-by/docs/types/test.ts +61 -0
  169. package/none-in-by/lib/index.js +46 -0
  170. package/none-in-by/lib/main.js +71 -0
  171. package/none-in-by/package.json +68 -0
  172. package/none-own-by/README.md +177 -0
  173. package/none-own-by/docs/repl.txt +42 -0
  174. package/none-own-by/docs/types/index.d.ts +102 -0
  175. package/none-own-by/docs/types/test.ts +61 -0
  176. package/none-own-by/lib/index.js +50 -0
  177. package/none-own-by/lib/main.js +75 -0
  178. package/none-own-by/package.json +68 -0
  179. package/package.json +66 -4
  180. package/some-in-by/README.md +232 -0
  181. package/some-in-by/docs/repl.txt +45 -0
  182. package/some-in-by/docs/types/index.d.ts +104 -0
  183. package/some-in-by/docs/types/test.ts +66 -0
  184. package/some-in-by/lib/index.js +46 -0
  185. package/some-in-by/lib/main.js +87 -0
  186. package/some-in-by/package.json +75 -0
  187. package/some-own-by/README.md +251 -0
  188. package/some-own-by/docs/repl.txt +45 -0
  189. package/some-own-by/docs/types/index.d.ts +103 -0
  190. package/some-own-by/docs/types/test.ts +66 -0
  191. package/some-own-by/lib/index.js +46 -0
  192. package/some-own-by/lib/main.js +85 -0
  193. package/some-own-by/package.json +72 -0
  194. package/uncapitalize-keys/README.md +139 -0
  195. package/uncapitalize-keys/docs/repl.txt +28 -0
  196. package/uncapitalize-keys/docs/types/index.d.ts +46 -0
  197. package/uncapitalize-keys/docs/types/test.ts +33 -0
  198. package/uncapitalize-keys/lib/index.js +45 -0
  199. package/uncapitalize-keys/lib/main.js +69 -0
  200. package/uncapitalize-keys/package.json +76 -0
  201. package/uppercase-keys/README.md +139 -0
  202. package/uppercase-keys/docs/repl.txt +28 -0
  203. package/uppercase-keys/docs/types/index.d.ts +46 -0
  204. package/uppercase-keys/docs/types/test.ts +33 -0
  205. package/uppercase-keys/lib/index.js +45 -0
  206. package/uppercase-keys/lib/main.js +63 -0
  207. package/uppercase-keys/package.json +74 -0
@@ -0,0 +1,87 @@
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
+ // MAIN //
22
+
23
+ /**
24
+ * Splits values into two groups according to a predicate function and outputs results as object values.
25
+ *
26
+ * ## Notes
27
+ *
28
+ * - We need to cache the object value to prevent the edge case where, during the invocation of the predicate function, the value at key `k` is swapped for some other value. For some, that might be a feature; here, we take the stance that one should be less clever.
29
+ *
30
+ * @private
31
+ * @param {(Object|Array|TypedArray)} obj - input object
32
+ * @param {Options} opts - function options
33
+ * @param {*} [opts.thisArg] - execution context
34
+ * @param {Function} predicate - predicate function indicating which group an element in the input object belongs to
35
+ * @returns {(Array<Array>|Array)} results
36
+ *
37
+ * @example
38
+ * function predicate( v ) {
39
+ * return v[ 0 ] === 'b';
40
+ * }
41
+ *
42
+ * function Foo() {
43
+ * this.a = 'beep';
44
+ * this.b = 'boop';
45
+ * return this;
46
+ * }
47
+ *
48
+ * Foo.prototype = Object.create( null );
49
+ * Foo.prototype.c = 'foo';
50
+ * Foo.prototype.d = 'bar';
51
+ *
52
+ * var obj = new Foo();
53
+ *
54
+ * var out = bifurcateIn( obj, {}, predicate );
55
+ * // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
56
+ */
57
+ function bifurcateIn( obj, opts, predicate ) {
58
+ var thisArg;
59
+ var bool;
60
+ var out;
61
+ var key;
62
+ var flg;
63
+ var v;
64
+
65
+ thisArg = opts.thisArg;
66
+ out = [ [], [] ];
67
+ flg = true;
68
+ for ( key in obj ) { // eslint-disable-line guard-for-in
69
+ flg = false;
70
+ v = obj[ key ];
71
+ bool = predicate.call( thisArg, v, key );
72
+ if ( bool ) {
73
+ out[ 0 ].push( v );
74
+ } else {
75
+ out[ 1 ].push( v );
76
+ }
77
+ }
78
+ if ( flg ) {
79
+ out.length = 0;
80
+ }
81
+ return out;
82
+ }
83
+
84
+
85
+ // EXPORTS //
86
+
87
+ module.exports = bifurcateIn;
@@ -0,0 +1,76 @@
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 isObject = require( '@ohos-ports/stdlib-assert/is-plain-object' );
24
+ var hasOwnProp = require( '@ohos-ports/stdlib-assert/has-own-property' );
25
+ var indexOf = require( '@ohos-ports/stdlib-utils/index-of' );
26
+ var format = require( '@ohos-ports/stdlib-string/format' );
27
+
28
+
29
+ // VARIABLES //
30
+
31
+ var returns = [ 'values', 'keys', '*' ];
32
+
33
+
34
+ // MAIN //
35
+
36
+ /**
37
+ * Validates function options.
38
+ *
39
+ * @private
40
+ * @param {Object} opts - destination object
41
+ * @param {Options} options - function options
42
+ * @param {*} [options.thisArg] - execution context
43
+ * @param {string} [options.returns] - output format
44
+ * @returns {(Error|null)} null or an error object
45
+ *
46
+ * @example
47
+ * var opts = {};
48
+ * var options = {
49
+ * 'returns': '*',
50
+ * 'thisArg': {}
51
+ * };
52
+ * var err = validate( opts, options );
53
+ * if ( err ) {
54
+ * throw err;
55
+ * }
56
+ */
57
+ function validate( opts, options ) {
58
+ if ( !isObject( options ) ) {
59
+ return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
60
+ }
61
+ if ( hasOwnProp( options, 'thisArg' ) ) {
62
+ opts.thisArg = options.thisArg;
63
+ }
64
+ if ( hasOwnProp( options, 'returns' ) ) {
65
+ opts.returns = options.returns;
66
+ if ( indexOf( returns, opts.returns ) === -1 ) {
67
+ return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'returns', returns.join( '", "' ), opts.returns ) );
68
+ }
69
+ }
70
+ return null;
71
+ }
72
+
73
+
74
+ // EXPORTS //
75
+
76
+ module.exports = validate;
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@stdlib/object/bifurcate-in",
3
+ "version": "0.0.0",
4
+ "description": "Split an object's own and inherited property values into two groups according to a predicate function.",
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
+ "group",
60
+ "groupby",
61
+ "group-by",
62
+ "bifurcate",
63
+ "bifurcation",
64
+ "aggregate",
65
+ "partition",
66
+ "split",
67
+ "object",
68
+ "obj",
69
+ "for-in",
70
+ "in"
71
+ ]
72
+ }
@@ -0,0 +1,255 @@
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
+ # bifurcateOwn
22
+
23
+ > Split an object's **own** 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 bifurcateOwn = require( '@stdlib/object/bifurcate-own' );
41
+ ```
42
+
43
+ #### bifurcateOwn( obj, \[options,] predicate )
44
+
45
+ Splits an object's **own** 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
+ var obj = {
52
+ 'a': 'beep',
53
+ 'b': 'boop',
54
+ 'c': 'foo',
55
+ 'd': 'bar'
56
+ };
57
+
58
+ var out = bifurcateOwn( obj, predicate );
59
+ // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
60
+ ```
61
+
62
+ A `predicate` function is provided two arguments:
63
+
64
+ - **value**: object value.
65
+ - **key**: object index.
66
+
67
+ ```javascript
68
+ function predicate( v, k ) {
69
+ console.log( '%s: %s', k, v );
70
+ return v[ 0 ] === 'b';
71
+ }
72
+ var obj = {
73
+ 'a': 'beep',
74
+ 'b': 'boop',
75
+ 'c': 'foo',
76
+ 'd': 'bar'
77
+ };
78
+
79
+ var out = bifurcateOwn( obj, predicate );
80
+ // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
81
+ ```
82
+
83
+ The function accepts the following `options`:
84
+
85
+ - **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'`.
86
+ - **thisArg**: execution context.
87
+
88
+ By default, the function returns object values. To return object keys, set the `returns` option to `'keys'`.
89
+
90
+ ```javascript
91
+ function predicate( v ) {
92
+ return v[ 0 ] === 'b';
93
+ }
94
+ var obj = {
95
+ 'a': 'beep',
96
+ 'b': 'boop',
97
+ 'c': 'foo',
98
+ 'd': 'bar'
99
+ };
100
+
101
+ var opts = {
102
+ 'returns': 'keys'
103
+ };
104
+ var out = bifurcateOwn( obj, opts, predicate );
105
+ // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ]
106
+ ```
107
+
108
+ To return key-value pairs, set the `returns` option to `'*'`.
109
+
110
+ ```javascript
111
+ function predicate( v ) {
112
+ return v[ 0 ] === 'b';
113
+ }
114
+ var obj = {
115
+ 'a': 'beep',
116
+ 'b': 'boop',
117
+ 'c': 'foo',
118
+ 'd': 'bar'
119
+ };
120
+
121
+ var opts = {
122
+ 'returns': '*'
123
+ };
124
+ var out = bifurcateOwn( obj, opts, predicate );
125
+ // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ]
126
+ ```
127
+
128
+ To set the `predicate` execution context, provide a `thisArg`.
129
+
130
+ ```javascript
131
+ function predicate( v ) {
132
+ this.count += 1;
133
+ return v[ 0 ] === 'b';
134
+ }
135
+ var context = {
136
+ 'count': 0
137
+ };
138
+ var opts = {
139
+ 'thisArg': context
140
+ };
141
+ var obj = {
142
+ 'a': 'beep',
143
+ 'b': 'boop',
144
+ 'c': 'foo',
145
+ 'd': 'bar'
146
+ };
147
+ var out = bifurcateOwn( obj, opts, predicate );
148
+ // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
149
+
150
+ console.log( context.count );
151
+ // => 4
152
+ ```
153
+
154
+ </section>
155
+
156
+ <!-- /.usage -->
157
+
158
+ <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
159
+
160
+ <section class="notes">
161
+
162
+ ## Notes
163
+
164
+ - 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.
165
+ - Because iteration order is **not** guaranteed, result order is **not** guaranteed.
166
+ - The function determines the list of own 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.
167
+
168
+ </section>
169
+
170
+ <!-- /.notes -->
171
+
172
+ <!-- Package usage examples. -->
173
+
174
+ <section class="examples">
175
+
176
+ ## Examples
177
+
178
+ <!-- eslint no-undef: "error" -->
179
+
180
+ ```javascript
181
+ var randu = require( '@stdlib/random/base/randu' );
182
+ var fromCodePoint = require( '@stdlib/string/from-code-point' );
183
+ var bifurcateOwn = require( '@stdlib/object/bifurcate-own' );
184
+
185
+ var key;
186
+ var obj;
187
+ var out;
188
+ var i;
189
+
190
+ // Generate a random object...
191
+ obj = {};
192
+ for ( i = 0; i < 100; i++ ) {
193
+ key = fromCodePoint( 97+i );
194
+ obj[ key ] = randu();
195
+ }
196
+
197
+ function predicate( v ) {
198
+ return ( v < 0.5 );
199
+ }
200
+
201
+ // Compute the groups:
202
+ out = bifurcateOwn( obj, predicate );
203
+ console.log( out );
204
+ ```
205
+
206
+ </section>
207
+
208
+ <!-- /.examples -->
209
+
210
+ <!-- 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. -->
211
+
212
+ <section class="references">
213
+
214
+ </section>
215
+
216
+ <!-- /.references -->
217
+
218
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
219
+
220
+ <section class="related">
221
+
222
+ * * *
223
+
224
+ ## See Also
225
+
226
+ - <span class="package-name">[`@stdlib/utils/bifurcate`][@stdlib/utils/bifurcate]</span><span class="delimiter">: </span><span class="description">split values into two groups.</span>
227
+ - <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>
228
+ - <span class="package-name">[`@stdlib/object/bifurcate-in`][@stdlib/object/bifurcate-in]</span><span class="delimiter">: </span><span class="description">split an object's own and inherited property values into two groups according to a predicate function.</span>
229
+ - <span class="package-name">[`@stdlib/utils/group-own`][@stdlib/utils/group-own]</span><span class="delimiter">: </span><span class="description">group an object's own property values according to an indicator function.</span>
230
+
231
+ </section>
232
+
233
+ <!-- /.related -->
234
+
235
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
236
+
237
+ <section class="links">
238
+
239
+ [ecma-262-for-in]: https://262.ecma-international.org/5.1/#sec-12.6.4
240
+
241
+ <!-- <related-links> -->
242
+
243
+ [@stdlib/utils/bifurcate]: https://www.npmjs.com/package/@stdlib/utils-bifurcate
244
+
245
+ [@stdlib/utils/bifurcate-by]: https://www.npmjs.com/package/@stdlib/utils-bifurcate-by
246
+
247
+ [@stdlib/object/bifurcate-in]: https://github.com/stdlib-js/object/tree/main/bifurcate-in
248
+
249
+ [@stdlib/utils/group-own]: https://www.npmjs.com/package/@stdlib/utils-group-own
250
+
251
+ <!-- </related-links> -->
252
+
253
+ </section>
254
+
255
+ <!-- /.links -->
@@ -0,0 +1,63 @@
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, the function returns an empty array.
14
+
15
+ The function iterates over an object's own properties.
16
+
17
+ Key iteration order is *not* guaranteed, and, thus, result order is *not*
18
+ guaranteed.
19
+
20
+ Parameters
21
+ ----------
22
+ obj: Object|Array|TypedArray
23
+ Input object to group.
24
+
25
+ options: Object (optional)
26
+ Options.
27
+
28
+ options.thisArg: any (optional)
29
+ Execution context.
30
+
31
+ options.returns: string (optional)
32
+ If `values`, values are returned; if `keys`, keys are returned; if `*`,
33
+ both keys and values are returned. Default: 'values'.
34
+
35
+ predicate: Function
36
+ Predicate function indicating which group a value in the input object
37
+ belongs to.
38
+
39
+ Returns
40
+ -------
41
+ out: Array<Array>|Array
42
+ Group results.
43
+
44
+ Examples
45
+ --------
46
+ > function predicate( v ) { return v[ 0 ] === 'b'; };
47
+ > var obj = { 'a': 'beep', 'b': 'boop', 'c': 'foo', 'd': 'bar' };
48
+ > var out = {{alias}}( obj, predicate )
49
+ [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ]
50
+
51
+ // Output group results as keys:
52
+ > var opts = { 'returns': 'keys' };
53
+ > out = {{alias}}( obj, opts, predicate )
54
+ [ [ 'a', 'b', 'd' ], [ 'c' ] ]
55
+
56
+ // Output group results as key-value pairs:
57
+ > opts = { 'returns': '*' };
58
+ > out = {{alias}}( obj, opts, predicate )
59
+ [ [ ['a', 'beep'], ['b', 'boop'], ['d', 'bar'] ], [ ['c', 'foo' ] ] ]
60
+
61
+ See Also
62
+ --------
63
+