From 6489cd6c93b38a11a5800404555faa1cea2b5f2e Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 7 Jan 2026 10:15:55 +0530 Subject: [PATCH 1/4] feat: add `object/bifurcate-own` Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/object/bifurcate-own/README.md | 255 ++++++ .../bifurcate-own/benchmark/benchmark.js | 206 +++++ .../object/bifurcate-own/docs/repl.txt | 63 ++ .../bifurcate-own/docs/types/index.d.ts | 183 +++++ .../object/bifurcate-own/docs/types/test.ts | 97 +++ .../object/bifurcate-own/examples/index.js | 43 + .../@stdlib/object/bifurcate-own/lib/index.js | 87 +++ .../@stdlib/object/bifurcate-own/lib/main.js | 127 +++ .../object/bifurcate-own/lib/return_keys.js | 81 ++ .../object/bifurcate-own/lib/return_pairs.js | 87 +++ .../object/bifurcate-own/lib/return_values.js | 87 +++ .../object/bifurcate-own/lib/validate.js | 76 ++ .../@stdlib/object/bifurcate-own/package.json | 71 ++ .../@stdlib/object/bifurcate-own/test/test.js | 733 ++++++++++++++++++ .../bifurcate-own/test/test.validate.js | 163 ++++ 15 files changed, 2359 insertions(+) create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/README.md create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/examples/index.js create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/lib/index.js create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/lib/main.js create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/lib/return_keys.js create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/lib/return_pairs.js create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/lib/return_values.js create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/lib/validate.js create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/package.json create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/test/test.js create mode 100644 lib/node_modules/@stdlib/object/bifurcate-own/test/test.validate.js diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/README.md b/lib/node_modules/@stdlib/object/bifurcate-own/README.md new file mode 100644 index 000000000000..44941de3f0e3 --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/README.md @@ -0,0 +1,255 @@ + + +# bifurcateOwn + +> Split an object's **own** property values into two groups according to a predicate function. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var bifurcateOwn = require( '@stdlib/object/bifurcate-own' ); +``` + +#### bifurcateOwn( obj, \[options,] predicate ) + +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. + +```javascript +function predicate( v ) { + return v[ 0 ] === 'b'; +} +var obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar' +}; + +var out = bifurcateOwn( obj, predicate ); +// e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] +``` + +A `predicate` function is provided two arguments: + +- **value**: object value. +- **key**: object index. + +```javascript +function predicate( v, k ) { + console.log( '%s: %s', k, v ); + return v[ 0 ] === 'b'; +} +var obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar' +}; + +var out = bifurcateOwn( obj, predicate ); +// e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] +``` + +The function accepts the following `options`: + +- **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'`. +- **thisArg**: execution context. + +By default, the function returns object values. To return object keys, set the `returns` option to `'keys'`. + +```javascript +function predicate( v ) { + return v[ 0 ] === 'b'; +} +var obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar' +}; + +var opts = { + 'returns': 'keys' +}; +var out = bifurcateOwn( obj, opts, predicate ); +// e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] +``` + +To return key-value pairs, set the `returns` option to `'*'`. + +```javascript +function predicate( v ) { + return v[ 0 ] === 'b'; +} +var obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar' +}; + +var opts = { + 'returns': '*' +}; +var out = bifurcateOwn( obj, opts, predicate ); +// e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] +``` + +To set the `predicate` execution context, provide a `thisArg`. + +```javascript +function predicate( v ) { + this.count += 1; + return v[ 0 ] === 'b'; +} +var context = { + 'count': 0 +}; +var opts = { + 'thisArg': context +}; +var obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar' +}; +var out = bifurcateOwn( obj, opts, predicate ); +// e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] + +console.log( context.count ); +// => 4 +``` + +
+ + + + + +
+ +## Notes + +- 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. +- Because iteration order is **not** guaranteed, result order is **not** guaranteed. +- 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. + +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var fromCodePoint = require( '@stdlib/string/from-code-point' ); +var bifurcateOwn = require( '@stdlib/object/bifurcate-own' ); + +var key; +var obj; +var out; +var i; + +// Generate a random object... +obj = {}; +for ( i = 0; i < 100; i++ ) { + key = fromCodePoint( 97+i ); + obj[ key ] = randu(); +} + +function predicate( v ) { + return ( v < 0.5 ); +} + +// Compute the groups: +out = bifurcateOwn( obj, predicate ); +console.log( out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/benchmark/benchmark.js b/lib/node_modules/@stdlib/object/bifurcate-own/benchmark/benchmark.js new file mode 100644 index 000000000000..e598a156fadb --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/benchmark/benchmark.js @@ -0,0 +1,206 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var randu = require( '@stdlib/random/base/randu' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var bifurcateOwn = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var key; + var obj; + var o; + var i; + + function predicate( v ) { + return v < 0.5; + } + + key = ''; + obj = {}; + for ( i = 0; i < 100; i++ ) { + key += 'a'; + obj[ key ] = randu(); + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj.a = randu(); + o = bifurcateOwn( obj, predicate ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArray( o ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::values', function benchmark( b ) { + var opts; + var key; + var obj; + var o; + var i; + + function predicate( v ) { + return v < 0.5; + } + + opts = { + 'returns': 'values' + }; + key = ''; + obj = {}; + for ( i = 0; i < 100; i++ ) { + key += 'a'; + obj[ key ] = randu(); + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj.a = randu(); + o = bifurcateOwn( obj, opts, predicate ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArray( o ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::keys', function benchmark( b ) { + var opts; + var key; + var obj; + var o; + var i; + + function predicate( v ) { + return v < 0.5; + } + + opts = { + 'returns': 'keys' + }; + key = ''; + obj = {}; + for ( i = 0; i < 100; i++ ) { + key += 'a'; + obj[ key ] = randu(); + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj.a = randu(); + o = bifurcateOwn( obj, opts, predicate ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArray( o ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::pairs', function benchmark( b ) { + var opts; + var key; + var obj; + var o; + var i; + + function predicate( v ) { + return v < 0.5; + } + + opts = { + 'returns': '*' + }; + key = ''; + obj = {}; + for ( i = 0; i < 100; i++ ) { + key += 'a'; + obj[ key ] = randu(); + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj.a = randu(); + o = bifurcateOwn( obj, opts, predicate ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArray( o ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::this_context', function benchmark( b ) { + var opts; + var key; + var obj; + var o; + var i; + + function predicate( v ) { + return v < 0.5; + } + + opts = { + 'thisArg': {} + }; + key = ''; + obj = {}; + for ( i = 0; i < 100; i++ ) { + key += 'a'; + obj[ key ] = randu(); + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj.a = randu(); + o = bifurcateOwn( obj, opts, predicate ); + if ( typeof o !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isArray( o ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/docs/repl.txt b/lib/node_modules/@stdlib/object/bifurcate-own/docs/repl.txt new file mode 100644 index 000000000000..32e5021f2233 --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/docs/repl.txt @@ -0,0 +1,63 @@ + +{{alias}}( obj, [options,] predicate ) + Splits values into two groups according to a predicate function. + + When invoked, the predicate function is provided two arguments: + + - value: object value. + - key: object key. + + If a predicate function returns a truthy value, a value is placed in the + first group; otherwise, a value is placed in the second group. + + If provided an empty object, the function returns an empty array. + + The function iterates over an object's own properties. + + Key iteration order is *not* guaranteed, and, thus, result order is *not* + guaranteed. + + Parameters + ---------- + obj: Object|Array|TypedArray + Input object to group. + + options: Object (optional) + Options. + + options.thisArg: any (optional) + Execution context. + + options.returns: string (optional) + If `values`, values are returned; if `keys`, keys are returned; if `*`, + both keys and values are returned. Default: 'values'. + + predicate: Function + Predicate function indicating which group a value in the input object + belongs to. + + Returns + ------- + out: Array|Array + Group results. + + Examples + -------- + > function predicate( v ) { return v[ 0 ] === 'b'; }; + > var obj = { 'a': 'beep', 'b': 'boop', 'c': 'foo', 'd': 'bar' }; + > var out = {{alias}}( obj, predicate ) + [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] + + // Output group results as keys: + > var opts = { 'returns': 'keys' }; + > out = {{alias}}( obj, opts, predicate ) + [ [ 'a', 'b', 'd' ], [ 'c' ] ] + + // Output group results as key-value pairs: + > opts = { 'returns': '*' }; + > out = {{alias}}( obj, opts, predicate ) + [ [ ['a', 'beep'], ['b', 'boop'], ['d', 'bar'] ], [ ['c', 'foo' ] ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/docs/types/index.d.ts b/lib/node_modules/@stdlib/object/bifurcate-own/docs/types/index.d.ts new file mode 100644 index 000000000000..726ee7b79dfd --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/docs/types/index.d.ts @@ -0,0 +1,183 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Interface defining function options. +*/ +interface Options { + /** + * Execution context. + */ + thisArg?: any; + + /** + * If `'values'`, values are returned; if `'keys'`, keys are returned; if `'*'`, both keys and values are returned. + */ + returns?: 'values' | 'keys' | '*'; +} + +/** +* Returns a boolean indicating which group an object's own and inherited property values belongs to. +* +* @returns boolean indicating whether a property value should be placed in the first or second group +*/ +type Nullary = () => boolean; + +/** +* Returns a boolean indicating which group an object's own and inherited property values belongs to. +* +* @param value - object value +* @returns boolean indicating whether a property value should be placed in the first or second group +*/ +type Unary = ( value: any ) => boolean; + +/** +* Returns a boolean indicating which group an object's own and inherited property values belongs to. +* +* @param value - object value +* @param key - object key +* @returns boolean indicating whether a property value should be placed in the first or second group +*/ +type Binary = ( value: any, key: string | symbol ) => boolean; + +/** +* Returns a boolean indicating which group an object's own and inherited property values belongs to. +* +* @param value - object value +* @param key - object key +* @returns boolean indicating whether a property value should be placed in the first or second group +*/ +type Predicate = Nullary | Unary | Binary; + +/** +* Splits an object's own property values into two groups according to a predicate function. +* +* @param obj - input object +* @param predicate - predicate function indicating which group an element in the input object belongs to +* @returns group results +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var out = bifurcateOwn( obj, predicate ); +* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var opts = { +* 'returns': 'keys' +* }; +* var out = bifurcateOwn( obj, opts, predicate ); +* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var opts = { +* 'returns': '*' +* }; +* var out = bifurcateOwn( obj, opts, predicate ); +* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] +*/ +declare function bifurcateOwn( obj: any, predicate: Predicate ): Array>; + +/** +* Splits an object's own property values into two groups according to a predicate function. +* +* @param obj - input object +* @param options - function options +* @param options.thisArg - execution context +* @param options.returns - if `'values'`, values are returned; if `'keys'`, keys are returned; if `'*'`, both keys and values are returned +* @param predicate - predicate function indicating which group an element in the input object belongs to +* @returns group results +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var out = bifurcateOwn( obj, predicate ); +* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var opts = { +* 'returns': 'keys' +* }; +* var out = bifurcateOwn( obj, opts, predicate ); +* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var opts = { +* 'returns': '*' +* }; +* var out = bifurcateOwn( obj, opts, predicate ); +* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] +*/ +declare function bifurcateOwn( obj: any, options: Options, predicate: Predicate ): Array>; + + +// EXPORTS // + +export = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/docs/types/test.ts b/lib/node_modules/@stdlib/object/bifurcate-own/docs/types/test.ts new file mode 100644 index 000000000000..7217e1bec168 --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/docs/types/test.ts @@ -0,0 +1,97 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import bifurcateOwn = require( './index' ); + +const predicate = ( v: Array ): boolean => v[ 0 ] === 'b'; + +/** +* A class for instantiating objects with `a` and `b` dummy properties. +*/ +class Foo { + /** + * String property. + */ + a: string; + + /** + * String property. + */ + b: string; + + constructor() { + this.a = 'beep'; + this.b = 'boop'; + } +} + + +// TESTS // + +// The function return an array of arrays... +{ + const obj = new Foo(); + bifurcateOwn( obj, predicate ); // $ExpectType any[][] + bifurcateOwn( {}, predicate ); // $ExpectType any[][] + const opts = { + 'returns': 'keys' as 'keys' + }; + bifurcateOwn( obj, opts, predicate ); // $ExpectType any[][] +} + +// The compiler throws an error if the function is provided a last argument which is not a function... +{ + const obj = new Foo(); + bifurcateOwn( obj, false ); // $ExpectError + bifurcateOwn( obj, true ); // $ExpectError + bifurcateOwn( obj, 32 ); // $ExpectError + bifurcateOwn( obj, 'abc' ); // $ExpectError + bifurcateOwn( obj, [] ); // $ExpectError + bifurcateOwn( obj, {} ); // $ExpectError + + bifurcateOwn( obj, {}, false ); // $ExpectError + bifurcateOwn( obj, {}, true ); // $ExpectError + bifurcateOwn( obj, {}, 32 ); // $ExpectError + bifurcateOwn( obj, {}, 'abc' ); // $ExpectError + bifurcateOwn( obj, {}, [] ); // $ExpectError + bifurcateOwn( obj, {}, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const obj = new Foo(); + bifurcateOwn( obj, null, predicate ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `returns` option which is not one of 'keys', 'values', or '*'... +{ + const obj = new Foo(); + bifurcateOwn( obj, { 'returns': '5' }, predicate ); // $ExpectError + bifurcateOwn( obj, { 'returns': 123 }, predicate ); // $ExpectError + bifurcateOwn( obj, { 'returns': [] }, predicate ); // $ExpectError + bifurcateOwn( obj, { 'returns': {} }, predicate ); // $ExpectError + bifurcateOwn( obj, { 'returns': ( x: number ): number => x }, predicate ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + const obj = new Foo(); + bifurcateOwn(); // $ExpectError + bifurcateOwn( obj ); // $ExpectError + bifurcateOwn( obj, {}, predicate, 16 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/examples/index.js b/lib/node_modules/@stdlib/object/bifurcate-own/examples/index.js new file mode 100644 index 000000000000..e10f65a4d381 --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var fromCodePoint = require( '@stdlib/string/from-code-point' ); +var bifurcateOwn = require( './../lib' ); + +var key; +var obj; +var out; +var i; + +// Generate a random object... +obj = {}; +for ( i = 0; i < 100; i++ ) { + key = fromCodePoint( 97+i ); + obj[ key ] = randu(); +} + +function predicate( v ) { + return ( v < 0.5 ); +} + +// Compute the groups: +out = bifurcateOwn( obj, predicate ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/lib/index.js b/lib/node_modules/@stdlib/object/bifurcate-own/lib/index.js new file mode 100644 index 000000000000..c76916e9cf9b --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/lib/index.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Split an object's own property values into two groups according to a predicate function. +* +* @module @stdlib/object/bifurcate-own +* +* @example +* var bifurcateOwn = require( '@stdlib/object/bifurcate-own' ); +* +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* +* var out = bifurcateOwn( obj, predicate ); +* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] +* +* @example +* var bifurcateOwn = require( '@stdlib/object/bifurcate-own' ); +* +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* +* var opts = { +* 'returns': 'keys' +* }; +* var out = bifurcateOwn( obj, opts, predicate ); +* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] +* +* @example +* var bifurcateOwn = require( '@stdlib/object/bifurcate-own' ); +* +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var opts = { +* 'returns': '*' +* }; +* var out = bifurcateOwn( obj, opts, predicate ); +* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/lib/main.js b/lib/node_modules/@stdlib/object/bifurcate-own/lib/main.js new file mode 100644 index 000000000000..ced113ca2a7c --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/lib/main.js @@ -0,0 +1,127 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isObjectLike = require( '@stdlib/assert/is-object-like' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var format = require( '@stdlib/string/format' ); +var validate = require( './validate.js' ); +var returnValues = require( './return_values.js' ); +var returnKeys = require( './return_keys.js' ); +var returnPairs = require( './return_pairs.js' ); + + +// MAIN // + +/** +* Splits an object's own property values into two groups according to a predicate function. +* +* @param {(Object|Array|TypedArray)} obj - input object +* @param {Options} [options] - function options +* @param {*} [options.thisArg] - execution context +* @param {string} [options.returns="values"] - if `values`, values are returned; if `keys`, keys are returned; if `*`, both keys and values are returned +* @param {Function} predicate - predicate function indicating which group an element in the input object belongs to +* @throws {TypeError} first argument must be an object, array, or typed array +* @throws {TypeError} options argument must be an object +* @throws {TypeError} last argument must be a function +* @throws {TypeError} must provide valid options +* @returns {(Array|Array)} group results +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var out = bifurcateOwn( obj, predicate ); +* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var opts = { +* 'returns': 'keys' +* }; +* var out = bifurcateOwn( obj, opts, predicate ); +* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var opts = { +* 'returns': '*' +* }; +* var out = bifurcateOwn( obj, opts, predicate ); +* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] +*/ +function bifurcateOwn( obj, options, predicate ) { + var opts; + var err; + var cb; + if ( !isObjectLike( obj ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + } + opts = { + 'returns': 'values' + }; + if ( arguments.length === 2 ) { + cb = options; + } else { + err = validate( opts, options ); + if ( err ) { + throw err; + } + cb = predicate; + } + if ( !isFunction( cb ) ) { + throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', cb ) ); + } + if ( opts.returns === 'values' ) { + return returnValues( obj, opts, cb ); + } + if ( opts.returns === 'keys' ) { + return returnKeys( obj, opts, cb ); + } + return returnPairs( obj, opts, cb ); +} + + +// EXPORTS // + +module.exports = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/lib/return_keys.js b/lib/node_modules/@stdlib/object/bifurcate-own/lib/return_keys.js new file mode 100644 index 000000000000..9f1766dc362c --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/lib/return_keys.js @@ -0,0 +1,81 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); + + +// MAIN // + +/** +* Splits values into two groups according to a predicate function and outputs results as keys. +* +* @private +* @param {(Object|Array|TypedArray)} obj - input object +* @param {Options} opts - function options +* @param {*} [opts.thisArg] - execution context +* @param {Function} predicate - predicate function specifying which group an element in the input object belongs to +* @returns {(Array|Array)} results +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var out = bifurcateOwn( obj, {}, predicate ); +* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] +*/ +function bifurcateOwn( obj, opts, predicate ) { + var thisArg; + var bool; + var out; + var key; + var flg; + + thisArg = opts.thisArg; + out = [ [], [] ]; + flg = true; + for ( key in obj ) { + if ( hasOwnProp( obj, key ) ) { + flg = false; + bool = predicate.call( thisArg, obj[ key ], key ); + if ( bool ) { + out[ 0 ].push( key ); + } else { + out[ 1 ].push( key ); + } + } + } + if ( flg ) { + out.length = 0; + } + return out; +} + + +// EXPORTS // + +module.exports = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/lib/return_pairs.js b/lib/node_modules/@stdlib/object/bifurcate-own/lib/return_pairs.js new file mode 100644 index 000000000000..1e5d8614ffdc --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/lib/return_pairs.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); + + +// MAIN // + +/** +* Splits values into two groups according to a predicate function and outputs results as key-value values. +* +* ## Notes +* +* - 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. +* +* @private +* @param {(Object|Array|TypedArray)} obj - input object +* @param {Options} opts - function options +* @param {*} [opts.thisArg] - execution context +* @param {Function} predicate - predicate function indicating which group an element in the input object belongs to +* @returns {(Array|Array)} results +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var out = bifurcateOwn( obj, {}, predicate ); +* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] +*/ +function bifurcateOwn( obj, opts, predicate ) { + var thisArg; + var bool; + var out; + var key; + var flg; + var v; + + thisArg = opts.thisArg; + out = [ [], [] ]; + flg = true; + for ( key in obj ) { + if ( hasOwnProp( obj, key ) ) { + flg = false; + v = obj[ key ]; + bool = predicate.call( thisArg, v, key ); + if ( bool ) { + out[ 0 ].push( [ key, v ] ); + } else { + out[ 1 ].push( [ key, v ] ); + } + } + } + if ( flg ) { + out.length = 0; + } + return out; +} + + +// EXPORTS // + +module.exports = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/lib/return_values.js b/lib/node_modules/@stdlib/object/bifurcate-own/lib/return_values.js new file mode 100644 index 000000000000..f58cda18f453 --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/lib/return_values.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); + + +// MAIN // + +/** +* Splits values into two groups according to a predicate function and outputs results as object values. +* +* ## Notes +* +* - 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. +* +* @private +* @param {(Object|Array|TypedArray)} obj - input object +* @param {Options} opts - function options +* @param {*} [opts.thisArg] - execution context +* @param {Function} predicate - predicate function indicating which group an element in the input object belongs to +* @returns {(Array|Array)} results +* +* @example +* function predicate( v ) { +* return v[ 0 ] === 'b'; +* } +* var obj = { +* 'a': 'beep', +* 'b': 'boop', +* 'c': 'foo', +* 'd': 'bar' +* }; +* var out = bifurcateOwn( obj, {}, predicate ); +* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] +*/ +function bifurcateOwn( obj, opts, predicate ) { + var thisArg; + var bool; + var out; + var key; + var flg; + var v; + + thisArg = opts.thisArg; + out = [ [], [] ]; + flg = true; + for ( key in obj ) { + if ( hasOwnProp( obj, key ) ) { + flg = false; + v = obj[ key ]; + bool = predicate.call( thisArg, v, key ); + if ( bool ) { + out[ 0 ].push( v ); + } else { + out[ 1 ].push( v ); + } + } + } + if ( flg ) { + out.length = 0; + } + return out; +} + + +// EXPORTS // + +module.exports = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/lib/validate.js b/lib/node_modules/@stdlib/object/bifurcate-own/lib/validate.js new file mode 100644 index 000000000000..fd11f5aff1a2 --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/lib/validate.js @@ -0,0 +1,76 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isObject = require( '@stdlib/assert/is-plain-object' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var indexOf = require( '@stdlib/utils/index-of' ); +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var returns = [ 'values', 'keys', '*' ]; + + +// MAIN // + +/** +* Validates function options. +* +* @private +* @param {Object} opts - destination object +* @param {Options} options - function options +* @param {*} [options.thisArg] - execution context +* @param {string} [options.returns] - output format +* @returns {(Error|null)} null or an error object +* +* @example +* var opts = {}; +* var options = { +* 'returns': '*', +* 'thisArg': {} +* }; +* var err = validate( opts, options ); +* if ( err ) { +* throw err; +* } +*/ +function validate( opts, options ) { + if ( !isObject( options ) ) { + return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'thisArg' ) ) { + opts.thisArg = options.thisArg; + } + if ( hasOwnProp( options, 'returns' ) ) { + opts.returns = options.returns; + if ( indexOf( returns, opts.returns ) === -1 ) { + return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'returns', returns.join( '", "' ), opts.returns ) ); + } + } + return null; +} + + +// EXPORTS // + +module.exports = validate; diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/package.json b/lib/node_modules/@stdlib/object/bifurcate-own/package.json new file mode 100644 index 000000000000..2b2378fa1ab8 --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/object/bifurcate-own", + "version": "0.0.0", + "description": "Split an object's own property values into two groups according to a predicate function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "group", + "groupby", + "group-by", + "bifurcate", + "bifurcation", + "aggregate", + "partition", + "split", + "object", + "obj", + "own" + ] +} diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/test/test.js b/lib/node_modules/@stdlib/object/bifurcate-own/test/test.js new file mode 100644 index 000000000000..273bae8eb06e --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/test/test.js @@ -0,0 +1,733 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var bifurcateOwn = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof bifurcateOwn, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + bifurcateOwn( value, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a predicate function (no options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + /.*/, + new Date() + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + bifurcateOwn( obj, value ); + }; + } +}); + +tape( 'the function throws an error if not provided a predicate function (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + /.*/, + new Date() + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + bifurcateOwn( obj, {}, value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid options argument', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {}, + /.*/, + new Date() + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + bifurcateOwn( obj, value, noop ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid option', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {}, + /.*/, + new Date() + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var opts; + var obj; + + obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + opts = { + 'returns': value + }; + bifurcateOwn( obj, opts, noop ); + }; + } +}); + +tape( 'the function splits object values into two groups according to a predicate function', function test( t ) { + var expected; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar' + }; + + expected = [ + [ 'beep', 'boop', 'bar' ], + [ 'foo' ] + ]; + out = bifurcateOwn( obj, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort(); + out[ 1 ].sort(); + expected[ 0 ].sort(); + expected[ 1 ].sort(); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); +}); + +tape( 'the function splits object values into two groups according to a predicate function (own)', function test( t ) { + var expected; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + function Foo() { + this.a = 'beep'; + this.b = 'boop'; + this.c = 'foo'; + this.d = 'bar'; + return this; + } + + Foo.prototype.e = 'beep'; + Foo.prototype.f = 'boop'; + + obj = new Foo(); + + expected = [ + [ 'beep', 'boop', 'bar' ], + [ 'foo' ] + ]; + out = bifurcateOwn( obj, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort(); + out[ 1 ].sort(); + expected[ 0 ].sort(); + expected[ 1 ].sort(); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); +}); + +tape( 'the function splits object values into two groups according to a predicate function (values)', function test( t ) { + var expected; + var opts; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar' + }; + + opts = { + 'returns': 'values' + }; + + expected = [ + [ 'beep', 'boop', 'bar' ], + [ 'foo' ] + ]; + out = bifurcateOwn( obj, opts, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort(); + out[ 1 ].sort(); + expected[ 0 ].sort(); + expected[ 1 ].sort(); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); +}); + +tape( 'the function splits object values into two groups according to a predicate function (values; own)', function test( t ) { + var expected; + var opts; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + function Foo() { + this.a = 'beep'; + this.b = 'boop'; + this.c = 'foo'; + this.d = 'bar'; + return this; + } + + Foo.prototype.e = 'beep'; + Foo.prototype.f = 'boop'; + + obj = new Foo(); + + opts = { + 'returns': 'values' + }; + + expected = [ + [ 'beep', 'boop', 'bar' ], + [ 'foo' ] + ]; + out = bifurcateOwn( obj, opts, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort(); + out[ 1 ].sort(); + expected[ 0 ].sort(); + expected[ 1 ].sort(); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); +}); + +tape( 'the function splits object values into two groups according to a predicate function (keys)', function test( t ) { + var expected; + var opts; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar' + }; + + opts = { + 'returns': 'keys' + }; + + expected = [ + [ 'a', 'b', 'd' ], + [ 'c' ] + ]; + out = bifurcateOwn( obj, opts, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort(); + out[ 1 ].sort(); + expected[ 0 ].sort(); + expected[ 1 ].sort(); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); +}); + +tape( 'the function splits object values into two groups according to a predicate function (keys; own)', function test( t ) { + var expected; + var opts; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + function Foo() { + this.a = 'beep'; + this.b = 'boop'; + this.c = 'foo'; + this.d = 'bar'; + return this; + } + + Foo.prototype.e = 'beep'; + Foo.prototype.f = 'boop'; + + obj = new Foo(); + + opts = { + 'returns': 'keys' + }; + + expected = [ + [ 'a', 'b', 'd' ], + [ 'c' ] + ]; + out = bifurcateOwn( obj, opts, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort(); + out[ 1 ].sort(); + expected[ 0 ].sort(); + expected[ 1 ].sort(); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); +}); + +tape( 'the function splits object values into two groups according to a predicate function (pairs)', function test( t ) { + var expected; + var opts; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar' + }; + + opts = { + 'returns': '*' + }; + + expected = [ + [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], + [ [ 'c', 'foo' ] ] + ]; + out = bifurcateOwn( obj, opts, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort( sort ); + out[ 1 ].sort( sort ); + expected[ 0 ].sort( sort ); + expected[ 1 ].sort( sort ); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); + + function sort( a, b ) { + return a[ 0 ] < b[ 0 ]; + } +}); + +tape( 'the function splits object values into two groups according to a predicate function (pairs; own)', function test( t ) { + var expected; + var opts; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + function Foo() { + this.a = 'beep'; + this.b = 'boop'; + this.c = 'foo'; + this.d = 'bar'; + return this; + } + + Foo.prototype.e = 'beep'; + Foo.prototype.f = 'boop'; + + obj = new Foo(); + + opts = { + 'returns': '*' + }; + + expected = [ + [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], + [ [ 'c', 'foo' ] ] + ]; + out = bifurcateOwn( obj, opts, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort( sort ); + out[ 1 ].sort( sort ); + expected[ 0 ].sort( sort ); + expected[ 1 ].sort( sort ); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); + + function sort( a, b ) { + return a[ 0 ] < b[ 0 ]; + } +}); + +tape( 'the function splits object values into two groups according to a predicate function (array-like object)', function test( t ) { + var expected; + var opts; + var out; + var arr; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + arr = { + 'length': 4, + '0': 'beep', + '1': 'boop', + '2': 'foo', + '3': 'bar' + }; + opts = { + 'returns': 'values' + }; + + // Note: `length` is an own property and thus is included in key iteration. + expected = [ + [ 'beep', 'boop', 'bar' ], + [ 'foo', 4 ] + ]; + out = bifurcateOwn( arr, opts, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort(); + out[ 1 ].sort(); + expected[ 0 ].sort(); + expected[ 1 ].sort(); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var opts; + var ctx; + var out; + var arr; + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v === 0.0 ); + } + + ctx = { + 'count': 0 + }; + + arr = [ 0.0, 1.0, 1.0, 0.0 ]; + + opts = { + 'thisArg': ctx + }; + expected = [ + [ 0.0, 0.0 ], + [ 1.0, 1.0 ] + ]; + out = bifurcateOwn( arr, opts, predicate ); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.strictEqual( ctx.count, 4, 'updates context' ); + + t.end(); +}); + +tape( 'the function invokes the predicate function with both the object value and the object key', function test( t ) { + var expected; + var out; + var arr; + + function predicate( v, k ) { + return ( parseInt( k, 10 ) < 2 ); + } + + arr = [ 5, 5, 1, 1 ]; + + expected = [ + [ 5, 5 ], + [ 1, 1 ] + ]; + out = bifurcateOwn( arr, predicate ); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); +}); + +tape( 'if provided an empty object, the function returns an empty array', function test( t ) { + var expected; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + obj = {}; + expected = []; + + out = bifurcateOwn( obj, predicate ); + + t.deepEqual( out, expected, 'returns expected results' ); + t.end(); +}); + +tape( 'if provided an empty object, the function returns an empty array (values)', function test( t ) { + var expected; + var opts; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + obj = {}; + expected = []; + + opts = { + 'returns': 'values' + }; + + out = bifurcateOwn( obj, opts, predicate ); + + t.deepEqual( out, expected, 'returns expected results' ); + t.end(); +}); + +tape( 'if provided an empty object, the function returns an empty array (keys)', function test( t ) { + var expected; + var opts; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + obj = {}; + expected = []; + + opts = { + 'returns': 'keys' + }; + + out = bifurcateOwn( obj, opts, predicate ); + + t.deepEqual( out, expected, 'returns expected results' ); + t.end(); +}); + +tape( 'if provided an empty object, the function returns an empty array (pairs)', function test( t ) { + var expected; + var opts; + var out; + var obj; + + function predicate( v ) { + return v[ 0 ] === 'b'; + } + + obj = {}; + expected = []; + + opts = { + 'returns': '*' + }; + + out = bifurcateOwn( obj, opts, predicate ); + + t.deepEqual( out, expected, 'returns expected results' ); + t.end(); +}); + +tape( 'the function does not account for dynamic addition and removal of object properties', function test( t ) { + var expected; + var out; + var arr; + + function predicate( v, i ) { + arr.push( 'beep' ); + arr[ 'a'+i ] = 'boop'; + return v[ 0 ] === 'b'; + } + + arr = [ 'beep', 'boop', 'foo', 'bar' ]; + + expected = [ + [ 'beep', 'boop', 'bar' ], + [ 'foo' ] + ]; + out = bifurcateOwn( arr, predicate ); + + // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... + out[ 0 ].sort(); + out[ 1 ].sort(); + expected[ 0 ].sort(); + expected[ 1 ].sort(); + + t.deepEqual( out, expected, 'returns expected groups' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/object/bifurcate-own/test/test.validate.js b/lib/node_modules/@stdlib/object/bifurcate-own/test/test.validate.js new file mode 100644 index 000000000000..62aaafde6d70 --- /dev/null +++ b/lib/node_modules/@stdlib/object/bifurcate-own/test/test.validate.js @@ -0,0 +1,163 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var validate = require( './../lib/validate.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof validate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { + var values; + var err; + var i; + + values = [ + '5', + 5, + true, + false, + void 0, + null, + NaN, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, values[ i ] ); + t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns an error if provided an unsupported `returns` option', function test( t ) { + var values; + var opts; + var err; + var i; + + values = [ + 'both', + 'pairs', + 'beep', + 'boop', + 'index', + 'indexes', + 'key', + 'properties', + 'props', + 'prop', + 'vals', + 'value', + '5', + 5, + true, + false, + void 0, + null, + NaN, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + opts = { + 'returns': values[ i ] + }; + err = validate( {}, opts ); + t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function supports any `thisArg`', function test( t ) { + var values; + var opts; + var err; + var i; + + values = [ + '5', + 5, + true, + false, + void 0, + null, + NaN, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + opts = { + 'thisArg': values[ i ] + }; + err = validate( {}, opts ); + t.strictEqual( err, null, 'returns null when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns `null` if all options are valid', function test( t ) { + var options; + var opts; + var err; + + opts = {}; + options = { + 'thisArg': {}, + 'returns': '*' + }; + + err = validate( opts, options ); + t.strictEqual( err, null, 'returns expected value' ); + t.deepEqual( opts, options, 'sets options' ); + + t.end(); +}); + +tape( 'the function will ignore unrecognized options', function test( t ) { + var options; + var opts; + var err; + + opts = {}; + options = { + 'beep': true, + 'boop': 'bop' + }; + + err = validate( opts, options ); + t.strictEqual( err, null, 'returns expected value' ); + t.deepEqual( opts, {}, 'ignores unrecognized options' ); + + t.end(); +}); From 72192cc26db55c5b8fb756cc0c611a183b7ecb37 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 7 Jan 2026 10:17:04 +0530 Subject: [PATCH 2/4] remove: remove `bifurcateOwn` from namespace This commit removes the `bifurcateOwn` symbol from the `@stdlib/utils` namespace due to a package migration. BREAKING CHANGE: remove `bifurcateOwn` To migrate, users should access the same symbol via the `@stdlib/object` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/utils/docs/types/index.d.ts | 58 ------------------- lib/node_modules/@stdlib/utils/lib/index.js | 9 --- 2 files changed, 67 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/docs/types/index.d.ts index 79701d5075b3..4fccf7b25ab5 100644 --- a/lib/node_modules/@stdlib/utils/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/docs/types/index.d.ts @@ -28,7 +28,6 @@ import argumentFunction = require( '@stdlib/utils/argument-function' ); import async = require( '@stdlib/utils/async' ); import bifurcate = require( '@stdlib/utils/bifurcate' ); import bifurcateBy = require( '@stdlib/utils/bifurcate-by' ); -import bifurcateOwn = require( '@stdlib/utils/bifurcate-own' ); import compose = require( '@stdlib/utils/compose' ); import constantFunction = require( '@stdlib/utils/constant-function' ); import constructorName = require( '@stdlib/utils/constructor-name' ); @@ -436,63 +435,6 @@ interface Namespace { */ bifurcateBy: typeof bifurcateBy; - /** - * Splits an object's own property values into two groups according to a predicate function. - * - * @param obj - input object - * @param options - function options - * @param options.thisArg - execution context - * @param options.returns - if `'values'`, values are returned; if `'keys'`, keys are returned; if `'*'`, both keys and values are returned - * @param predicate - predicate function indicating which group an element in the input object belongs to - * @returns group results - * - * @example - * function predicate( v ) { - * return v[ 0 ] === 'b'; - * } - * var obj = { - * 'a': 'beep', - * 'b': 'boop', - * 'c': 'foo', - * 'd': 'bar' - * }; - * var out = ns.bifurcateOwn( obj, predicate ); - * // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] - * - * @example - * function predicate( v ) { - * return v[ 0 ] === 'b'; - * } - * var obj = { - * 'a': 'beep', - * 'b': 'boop', - * 'c': 'foo', - * 'd': 'bar' - * }; - * var opts = { - * 'returns': 'keys' - * }; - * var out = ns.bifurcateOwn( obj, opts, predicate ); - * // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] - * - * @example - * function predicate( v ) { - * return v[ 0 ] === 'b'; - * } - * var obj = { - * 'a': 'beep', - * 'b': 'boop', - * 'c': 'foo', - * 'd': 'bar' - * }; - * var opts = { - * 'returns': '*' - * }; - * var out = ns.bifurcateOwn( obj, opts, predicate ); - * // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] - */ - bifurcateOwn: typeof bifurcateOwn; - /** * Function composition. * diff --git a/lib/node_modules/@stdlib/utils/lib/index.js b/lib/node_modules/@stdlib/utils/lib/index.js index 22b786160866..61ddbdb49f21 100644 --- a/lib/node_modules/@stdlib/utils/lib/index.js +++ b/lib/node_modules/@stdlib/utils/lib/index.js @@ -112,15 +112,6 @@ setReadOnly( utils, 'bifurcate', require( '@stdlib/utils/bifurcate' ) ); */ setReadOnly( utils, 'bifurcateBy', require( '@stdlib/utils/bifurcate-by' ) ); -/** -* @name bifurcateOwn -* @memberof utils -* @readonly -* @type {Function} -* @see {@link module:@stdlib/utils/bifurcate-own} -*/ -setReadOnly( utils, 'bifurcateOwn', require( '@stdlib/utils/bifurcate-own' ) ); - /** * @name compose * @memberof utils From af71e70a197a5ea44813e6b86a9e8050f2f652fa Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 7 Jan 2026 10:24:23 +0530 Subject: [PATCH 3/4] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/namespace/alias2pkg/data/data.csv | 2 +- lib/node_modules/@stdlib/namespace/lib/namespace/b.js | 8 ++++---- lib/node_modules/@stdlib/namespace/lib/namespace/g.js | 2 +- .../@stdlib/namespace/pkg2alias/data/data.csv | 2 +- .../@stdlib/namespace/pkg2related/data/data.csv | 8 ++++---- .../@stdlib/namespace/pkg2standalone/data/data.csv | 2 +- .../@stdlib/namespace/standalone2pkg/data/data.csv | 2 +- lib/node_modules/@stdlib/object/bifurcate-in/README.md | 4 ++-- lib/node_modules/@stdlib/utils/bifurcate/README.md | 4 ++-- lib/node_modules/@stdlib/utils/group-own/README.md | 4 ++-- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv index 06c673fbfd0b..4d19584d813b 100644 --- a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv @@ -1499,7 +1499,7 @@ bifurcate,"@stdlib/utils/bifurcate" bifurcateBy,"@stdlib/utils/bifurcate-by" bifurcateByAsync,"@stdlib/utils/async/bifurcate-by" bifurcateIn,"@stdlib/object/bifurcate-in" -bifurcateOwn,"@stdlib/utils/bifurcate-own" +bifurcateOwn,"@stdlib/object/bifurcate-own" BigInt,"@stdlib/bigint/ctor" binomialTest,"@stdlib/stats/binomial-test" Boolean,"@stdlib/boolean/ctor" diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/b.js b/lib/node_modules/@stdlib/namespace/lib/namespace/b.js index 3ed875fe0640..07b8eddbc995 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/b.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/b.js @@ -73,7 +73,7 @@ ns.push({ 'type': 'Function', 'related': [ '@stdlib/utils/bifurcate-by', - '@stdlib/utils/bifurcate-own', + '@stdlib/object/bifurcate-own', '@stdlib/utils/group' ] }); @@ -108,15 +108,15 @@ ns.push({ 'related': [ '@stdlib/utils/bifurcate', '@stdlib/utils/bifurcate-by', - '@stdlib/utils/bifurcate-own', + '@stdlib/object/bifurcate-own', '@stdlib/utils/group-in' ] }); ns.push({ 'alias': 'bifurcateOwn', - 'path': '@stdlib/utils/bifurcate-own', - 'value': require( '@stdlib/utils/bifurcate-own' ), + 'path': '@stdlib/object/bifurcate-own', + 'value': require( '@stdlib/object/bifurcate-own' ), 'type': 'Function', 'related': [ '@stdlib/utils/bifurcate', diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/g.js b/lib/node_modules/@stdlib/namespace/lib/namespace/g.js index 2ef03b27aee7..a65004359351 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/g.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/g.js @@ -209,7 +209,7 @@ ns.push({ 'value': require( '@stdlib/utils/group-own' ), 'type': 'Function', 'related': [ - '@stdlib/utils/bifurcate-own', + '@stdlib/object/bifurcate-own', '@stdlib/utils/count-own', '@stdlib/utils/group', '@stdlib/utils/group-by' diff --git a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv index f432e319c808..ecf0493a3d89 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv @@ -1499,7 +1499,7 @@ "@stdlib/utils/bifurcate-by",bifurcateBy "@stdlib/utils/async/bifurcate-by",bifurcateByAsync "@stdlib/object/bifurcate-in",bifurcateIn -"@stdlib/utils/bifurcate-own",bifurcateOwn +"@stdlib/object/bifurcate-own",bifurcateOwn "@stdlib/bigint/ctor",BigInt "@stdlib/stats/binomial-test",binomialTest "@stdlib/boolean/ctor",Boolean diff --git a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv index 76da48b5dcc1..4267979b7217 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv @@ -1495,11 +1495,11 @@ "@stdlib/math/base/special/riemann-zeta","" "@stdlib/bench","@stdlib/utils/timeit" "@stdlib/datasets/berndt-cps-wages-1985","" -"@stdlib/utils/bifurcate","@stdlib/utils/bifurcate-by,@stdlib/utils/bifurcate-own,@stdlib/utils/group" +"@stdlib/utils/bifurcate","@stdlib/utils/bifurcate-by,@stdlib/object/bifurcate-own,@stdlib/utils/group" "@stdlib/utils/bifurcate-by","@stdlib/utils/bifurcate,@stdlib/utils/group-by" "@stdlib/utils/async/bifurcate-by","@stdlib/utils/bifurcate-by,@stdlib/utils/async/group-by" -"@stdlib/object/bifurcate-in","@stdlib/utils/bifurcate,@stdlib/utils/bifurcate-by,@stdlib/utils/bifurcate-own,@stdlib/utils/group-in" -"@stdlib/utils/bifurcate-own","@stdlib/utils/bifurcate,@stdlib/utils/bifurcate-by,@stdlib/object/bifurcate-in,@stdlib/utils/group-own" +"@stdlib/object/bifurcate-in","@stdlib/utils/bifurcate,@stdlib/utils/bifurcate-by,@stdlib/object/bifurcate-own,@stdlib/utils/group-in" +"@stdlib/object/bifurcate-own","@stdlib/utils/bifurcate,@stdlib/utils/bifurcate-by,@stdlib/object/bifurcate-in,@stdlib/utils/group-own" "@stdlib/bigint/ctor","" "@stdlib/stats/binomial-test","" "@stdlib/boolean/ctor","" @@ -1777,7 +1777,7 @@ "@stdlib/utils/group-by","@stdlib/utils/bifurcate-by,@stdlib/utils/count-by,@stdlib/utils/group" "@stdlib/utils/async/group-by","@stdlib/utils/async/bifurcate-by,@stdlib/utils/async/count-by,@stdlib/utils/group-by" "@stdlib/utils/group-in","@stdlib/object/bifurcate-in,@stdlib/utils/group-by,@stdlib/utils/group-own" -"@stdlib/utils/group-own","@stdlib/utils/bifurcate-own,@stdlib/utils/group,@stdlib/utils/group-by" +"@stdlib/utils/group-own","@stdlib/object/bifurcate-own,@stdlib/utils/group,@stdlib/utils/group-by" "@stdlib/blas/gswap","@stdlib/blas/base/gswap,@stdlib/blas/dswap,@stdlib/blas/sswap" "@stdlib/constants/float64/half-ln-two","@stdlib/constants/float64/ln-two" "@stdlib/constants/float64/half-pi","@stdlib/constants/float64/pi" diff --git a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv index 3dcd64efe10c..d54d1926a880 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv @@ -1499,7 +1499,7 @@ "@stdlib/utils/bifurcate-by","@stdlib/utils-bifurcate-by" "@stdlib/utils/async/bifurcate-by","@stdlib/utils-async-bifurcate-by" "@stdlib/object/bifurcate-in","@stdlib/object-bifurcate-in" -"@stdlib/utils/bifurcate-own","@stdlib/utils-bifurcate-own" +"@stdlib/object/bifurcate-own","@stdlib/object-bifurcate-own" "@stdlib/bigint/ctor","@stdlib/bigint-ctor" "@stdlib/stats/binomial-test","@stdlib/stats-binomial-test" "@stdlib/boolean/ctor","@stdlib/boolean-ctor" diff --git a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv index 9cbddfc8802f..13d826b5e006 100644 --- a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv @@ -1499,7 +1499,7 @@ "@stdlib/utils-bifurcate-by","@stdlib/utils/bifurcate-by" "@stdlib/utils-async-bifurcate-by","@stdlib/utils/async/bifurcate-by" "@stdlib/object-bifurcate-in","@stdlib/object/bifurcate-in" -"@stdlib/utils-bifurcate-own","@stdlib/utils/bifurcate-own" +"@stdlib/object-bifurcate-own","@stdlib/object/bifurcate-own" "@stdlib/bigint-ctor","@stdlib/bigint/ctor" "@stdlib/stats-binomial-test","@stdlib/stats/binomial-test" "@stdlib/boolean-ctor","@stdlib/boolean/ctor" diff --git a/lib/node_modules/@stdlib/object/bifurcate-in/README.md b/lib/node_modules/@stdlib/object/bifurcate-in/README.md index 0e63280876a3..c95d9f2c3b3a 100644 --- a/lib/node_modules/@stdlib/object/bifurcate-in/README.md +++ b/lib/node_modules/@stdlib/object/bifurcate-in/README.md @@ -268,7 +268,7 @@ console.log( out ); - [`@stdlib/utils/bifurcate`][@stdlib/utils/bifurcate]: split values into two groups. - [`@stdlib/utils/bifurcate-by`][@stdlib/utils/bifurcate-by]: split values into two groups according to a predicate function. -- [`@stdlib/utils/bifurcate-own`][@stdlib/utils/bifurcate-own]: split an object's own property values into two groups according to a predicate function. +- [`@stdlib/object/bifurcate-own`][@stdlib/object/bifurcate-own]: split an object's own property values into two groups according to a predicate function. - [`@stdlib/utils/group-in`][@stdlib/utils/group-in]: group an object's own and inherited property values according to an indicator function. @@ -287,7 +287,7 @@ console.log( out ); [@stdlib/utils/bifurcate-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/bifurcate-by -[@stdlib/utils/bifurcate-own]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/bifurcate-own +[@stdlib/object/bifurcate-own]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/bifurcate-own [@stdlib/utils/group-in]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/group-in diff --git a/lib/node_modules/@stdlib/utils/bifurcate/README.md b/lib/node_modules/@stdlib/utils/bifurcate/README.md index db3fff87f030..b3eeb176db59 100644 --- a/lib/node_modules/@stdlib/utils/bifurcate/README.md +++ b/lib/node_modules/@stdlib/utils/bifurcate/README.md @@ -159,7 +159,7 @@ console.log( out ); ## See Also - [`@stdlib/utils/bifurcate-by`][@stdlib/utils/bifurcate-by]: split values into two groups according to a predicate function. -- [`@stdlib/utils/bifurcate-own`][@stdlib/utils/bifurcate-own]: split an object's own property values into two groups according to a predicate function. +- [`@stdlib/object/bifurcate-own`][@stdlib/object/bifurcate-own]: split an object's own property values into two groups according to a predicate function. - [`@stdlib/utils/group`][@stdlib/utils/group]: group values as arrays associated with distinct keys. @@ -180,7 +180,7 @@ console.log( out ); [@stdlib/utils/bifurcate-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/bifurcate-by -[@stdlib/utils/bifurcate-own]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/bifurcate-own +[@stdlib/object/bifurcate-own]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/bifurcate-own [@stdlib/utils/group]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/group diff --git a/lib/node_modules/@stdlib/utils/group-own/README.md b/lib/node_modules/@stdlib/utils/group-own/README.md index 1de74db542cb..644e3079471c 100644 --- a/lib/node_modules/@stdlib/utils/group-own/README.md +++ b/lib/node_modules/@stdlib/utils/group-own/README.md @@ -246,7 +246,7 @@ console.log( out ); ## See Also -- [`@stdlib/utils/bifurcate-own`][@stdlib/utils/bifurcate-own]: split an object's own property values into two groups according to a predicate function. +- [`@stdlib/object/bifurcate-own`][@stdlib/object/bifurcate-own]: split an object's own property values into two groups according to a predicate function. - [`@stdlib/utils/group`][@stdlib/utils/group]: group values as arrays associated with distinct keys. - [`@stdlib/utils/group-by`][@stdlib/utils/group-by]: group values according to an indicator function. @@ -262,7 +262,7 @@ console.log( out ); -[@stdlib/utils/bifurcate-own]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/bifurcate-own +[@stdlib/object/bifurcate-own]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/bifurcate-own [@stdlib/utils/group]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/group From dde576c51ebd5a1a2bcb0012c9bfbbb9af46fada Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Wed, 7 Jan 2026 10:25:35 +0530 Subject: [PATCH 4/4] remove: remove `utils/bifurcate-own` This commit removes `@stdlib/utils/bifurcate-own` in favor of `@stdlib/object/bifurcate-own`. BREAKING CHANGE: remove `utils/bifurcate-own` To migrate, users should update their require/import paths to use `@stdlib/object/bifurcate-own` which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/utils/bifurcate-own/README.md | 255 ------ .../bifurcate-own/benchmark/benchmark.js | 206 ----- .../@stdlib/utils/bifurcate-own/docs/repl.txt | 63 -- .../utils/bifurcate-own/docs/types/index.d.ts | 183 ----- .../utils/bifurcate-own/docs/types/test.ts | 97 --- .../utils/bifurcate-own/examples/index.js | 43 - .../@stdlib/utils/bifurcate-own/lib/index.js | 87 --- .../@stdlib/utils/bifurcate-own/lib/main.js | 127 --- .../utils/bifurcate-own/lib/return_keys.js | 81 -- .../utils/bifurcate-own/lib/return_pairs.js | 87 --- .../utils/bifurcate-own/lib/return_values.js | 87 --- .../utils/bifurcate-own/lib/validate.js | 76 -- .../@stdlib/utils/bifurcate-own/package.json | 71 -- .../@stdlib/utils/bifurcate-own/test/test.js | 733 ------------------ .../utils/bifurcate-own/test/test.validate.js | 163 ---- 15 files changed, 2359 deletions(-) delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/README.md delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/examples/index.js delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/lib/index.js delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/lib/main.js delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_keys.js delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_pairs.js delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_values.js delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/lib/validate.js delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/package.json delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/test/test.js delete mode 100644 lib/node_modules/@stdlib/utils/bifurcate-own/test/test.validate.js diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/README.md b/lib/node_modules/@stdlib/utils/bifurcate-own/README.md deleted file mode 100644 index c31af8d95a74..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/README.md +++ /dev/null @@ -1,255 +0,0 @@ - - -# bifurcateOwn - -> Split an object's **own** property values into two groups according to a predicate function. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var bifurcateOwn = require( '@stdlib/utils/bifurcate-own' ); -``` - -#### bifurcateOwn( obj, \[options,] predicate ) - -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. - -```javascript -function predicate( v ) { - return v[ 0 ] === 'b'; -} -var obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar' -}; - -var out = bifurcateOwn( obj, predicate ); -// e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] -``` - -A `predicate` function is provided two arguments: - -- **value**: object value. -- **key**: object index. - -```javascript -function predicate( v, k ) { - console.log( '%s: %s', k, v ); - return v[ 0 ] === 'b'; -} -var obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar' -}; - -var out = bifurcateOwn( obj, predicate ); -// e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] -``` - -The function accepts the following `options`: - -- **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'`. -- **thisArg**: execution context. - -By default, the function returns object values. To return object keys, set the `returns` option to `'keys'`. - -```javascript -function predicate( v ) { - return v[ 0 ] === 'b'; -} -var obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar' -}; - -var opts = { - 'returns': 'keys' -}; -var out = bifurcateOwn( obj, opts, predicate ); -// e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] -``` - -To return key-value pairs, set the `returns` option to `'*'`. - -```javascript -function predicate( v ) { - return v[ 0 ] === 'b'; -} -var obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar' -}; - -var opts = { - 'returns': '*' -}; -var out = bifurcateOwn( obj, opts, predicate ); -// e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] -``` - -To set the `predicate` execution context, provide a `thisArg`. - -```javascript -function predicate( v ) { - this.count += 1; - return v[ 0 ] === 'b'; -} -var context = { - 'count': 0 -}; -var opts = { - 'thisArg': context -}; -var obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar' -}; -var out = bifurcateOwn( obj, opts, predicate ); -// e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] - -console.log( context.count ); -// => 4 -``` - -
- - - - - -
- -## Notes - -- 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. -- Because iteration order is **not** guaranteed, result order is **not** guaranteed. -- 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. - -
- - - - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var fromCodePoint = require( '@stdlib/string/from-code-point' ); -var bifurcateOwn = require( '@stdlib/utils/bifurcate-own' ); - -var key; -var obj; -var out; -var i; - -// Generate a random object... -obj = {}; -for ( i = 0; i < 100; i++ ) { - key = fromCodePoint( 97+i ); - obj[ key ] = randu(); -} - -function predicate( v ) { - return ( v < 0.5 ); -} - -// Compute the groups: -out = bifurcateOwn( obj, predicate ); -console.log( out ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/bifurcate-own/benchmark/benchmark.js deleted file mode 100644 index e598a156fadb..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/benchmark/benchmark.js +++ /dev/null @@ -1,206 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var isArray = require( '@stdlib/assert/is-array' ); -var pkg = require( './../package.json' ).name; -var bifurcateOwn = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var key; - var obj; - var o; - var i; - - function predicate( v ) { - return v < 0.5; - } - - key = ''; - obj = {}; - for ( i = 0; i < 100; i++ ) { - key += 'a'; - obj[ key ] = randu(); - } - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj.a = randu(); - o = bifurcateOwn( obj, predicate ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( o ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::values', function benchmark( b ) { - var opts; - var key; - var obj; - var o; - var i; - - function predicate( v ) { - return v < 0.5; - } - - opts = { - 'returns': 'values' - }; - key = ''; - obj = {}; - for ( i = 0; i < 100; i++ ) { - key += 'a'; - obj[ key ] = randu(); - } - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj.a = randu(); - o = bifurcateOwn( obj, opts, predicate ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( o ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::keys', function benchmark( b ) { - var opts; - var key; - var obj; - var o; - var i; - - function predicate( v ) { - return v < 0.5; - } - - opts = { - 'returns': 'keys' - }; - key = ''; - obj = {}; - for ( i = 0; i < 100; i++ ) { - key += 'a'; - obj[ key ] = randu(); - } - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj.a = randu(); - o = bifurcateOwn( obj, opts, predicate ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( o ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::pairs', function benchmark( b ) { - var opts; - var key; - var obj; - var o; - var i; - - function predicate( v ) { - return v < 0.5; - } - - opts = { - 'returns': '*' - }; - key = ''; - obj = {}; - for ( i = 0; i < 100; i++ ) { - key += 'a'; - obj[ key ] = randu(); - } - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj.a = randu(); - o = bifurcateOwn( obj, opts, predicate ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( o ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::this_context', function benchmark( b ) { - var opts; - var key; - var obj; - var o; - var i; - - function predicate( v ) { - return v < 0.5; - } - - opts = { - 'thisArg': {} - }; - key = ''; - obj = {}; - for ( i = 0; i < 100; i++ ) { - key += 'a'; - obj[ key ] = randu(); - } - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj.a = randu(); - o = bifurcateOwn( obj, opts, predicate ); - if ( typeof o !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isArray( o ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/docs/repl.txt b/lib/node_modules/@stdlib/utils/bifurcate-own/docs/repl.txt deleted file mode 100644 index 32e5021f2233..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/docs/repl.txt +++ /dev/null @@ -1,63 +0,0 @@ - -{{alias}}( obj, [options,] predicate ) - Splits values into two groups according to a predicate function. - - When invoked, the predicate function is provided two arguments: - - - value: object value. - - key: object key. - - If a predicate function returns a truthy value, a value is placed in the - first group; otherwise, a value is placed in the second group. - - If provided an empty object, the function returns an empty array. - - The function iterates over an object's own properties. - - Key iteration order is *not* guaranteed, and, thus, result order is *not* - guaranteed. - - Parameters - ---------- - obj: Object|Array|TypedArray - Input object to group. - - options: Object (optional) - Options. - - options.thisArg: any (optional) - Execution context. - - options.returns: string (optional) - If `values`, values are returned; if `keys`, keys are returned; if `*`, - both keys and values are returned. Default: 'values'. - - predicate: Function - Predicate function indicating which group a value in the input object - belongs to. - - Returns - ------- - out: Array|Array - Group results. - - Examples - -------- - > function predicate( v ) { return v[ 0 ] === 'b'; }; - > var obj = { 'a': 'beep', 'b': 'boop', 'c': 'foo', 'd': 'bar' }; - > var out = {{alias}}( obj, predicate ) - [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] - - // Output group results as keys: - > var opts = { 'returns': 'keys' }; - > out = {{alias}}( obj, opts, predicate ) - [ [ 'a', 'b', 'd' ], [ 'c' ] ] - - // Output group results as key-value pairs: - > opts = { 'returns': '*' }; - > out = {{alias}}( obj, opts, predicate ) - [ [ ['a', 'beep'], ['b', 'boop'], ['d', 'bar'] ], [ ['c', 'foo' ] ] ] - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/bifurcate-own/docs/types/index.d.ts deleted file mode 100644 index 726ee7b79dfd..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/docs/types/index.d.ts +++ /dev/null @@ -1,183 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Execution context. - */ - thisArg?: any; - - /** - * If `'values'`, values are returned; if `'keys'`, keys are returned; if `'*'`, both keys and values are returned. - */ - returns?: 'values' | 'keys' | '*'; -} - -/** -* Returns a boolean indicating which group an object's own and inherited property values belongs to. -* -* @returns boolean indicating whether a property value should be placed in the first or second group -*/ -type Nullary = () => boolean; - -/** -* Returns a boolean indicating which group an object's own and inherited property values belongs to. -* -* @param value - object value -* @returns boolean indicating whether a property value should be placed in the first or second group -*/ -type Unary = ( value: any ) => boolean; - -/** -* Returns a boolean indicating which group an object's own and inherited property values belongs to. -* -* @param value - object value -* @param key - object key -* @returns boolean indicating whether a property value should be placed in the first or second group -*/ -type Binary = ( value: any, key: string | symbol ) => boolean; - -/** -* Returns a boolean indicating which group an object's own and inherited property values belongs to. -* -* @param value - object value -* @param key - object key -* @returns boolean indicating whether a property value should be placed in the first or second group -*/ -type Predicate = Nullary | Unary | Binary; - -/** -* Splits an object's own property values into two groups according to a predicate function. -* -* @param obj - input object -* @param predicate - predicate function indicating which group an element in the input object belongs to -* @returns group results -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var out = bifurcateOwn( obj, predicate ); -* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var opts = { -* 'returns': 'keys' -* }; -* var out = bifurcateOwn( obj, opts, predicate ); -* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var opts = { -* 'returns': '*' -* }; -* var out = bifurcateOwn( obj, opts, predicate ); -* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] -*/ -declare function bifurcateOwn( obj: any, predicate: Predicate ): Array>; - -/** -* Splits an object's own property values into two groups according to a predicate function. -* -* @param obj - input object -* @param options - function options -* @param options.thisArg - execution context -* @param options.returns - if `'values'`, values are returned; if `'keys'`, keys are returned; if `'*'`, both keys and values are returned -* @param predicate - predicate function indicating which group an element in the input object belongs to -* @returns group results -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var out = bifurcateOwn( obj, predicate ); -* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var opts = { -* 'returns': 'keys' -* }; -* var out = bifurcateOwn( obj, opts, predicate ); -* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var opts = { -* 'returns': '*' -* }; -* var out = bifurcateOwn( obj, opts, predicate ); -* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] -*/ -declare function bifurcateOwn( obj: any, options: Options, predicate: Predicate ): Array>; - - -// EXPORTS // - -export = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/docs/types/test.ts b/lib/node_modules/@stdlib/utils/bifurcate-own/docs/types/test.ts deleted file mode 100644 index 7217e1bec168..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/docs/types/test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import bifurcateOwn = require( './index' ); - -const predicate = ( v: Array ): boolean => v[ 0 ] === 'b'; - -/** -* A class for instantiating objects with `a` and `b` dummy properties. -*/ -class Foo { - /** - * String property. - */ - a: string; - - /** - * String property. - */ - b: string; - - constructor() { - this.a = 'beep'; - this.b = 'boop'; - } -} - - -// TESTS // - -// The function return an array of arrays... -{ - const obj = new Foo(); - bifurcateOwn( obj, predicate ); // $ExpectType any[][] - bifurcateOwn( {}, predicate ); // $ExpectType any[][] - const opts = { - 'returns': 'keys' as 'keys' - }; - bifurcateOwn( obj, opts, predicate ); // $ExpectType any[][] -} - -// The compiler throws an error if the function is provided a last argument which is not a function... -{ - const obj = new Foo(); - bifurcateOwn( obj, false ); // $ExpectError - bifurcateOwn( obj, true ); // $ExpectError - bifurcateOwn( obj, 32 ); // $ExpectError - bifurcateOwn( obj, 'abc' ); // $ExpectError - bifurcateOwn( obj, [] ); // $ExpectError - bifurcateOwn( obj, {} ); // $ExpectError - - bifurcateOwn( obj, {}, false ); // $ExpectError - bifurcateOwn( obj, {}, true ); // $ExpectError - bifurcateOwn( obj, {}, 32 ); // $ExpectError - bifurcateOwn( obj, {}, 'abc' ); // $ExpectError - bifurcateOwn( obj, {}, [] ); // $ExpectError - bifurcateOwn( obj, {}, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an options argument which is not an object... -{ - const obj = new Foo(); - bifurcateOwn( obj, null, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `returns` option which is not one of 'keys', 'values', or '*'... -{ - const obj = new Foo(); - bifurcateOwn( obj, { 'returns': '5' }, predicate ); // $ExpectError - bifurcateOwn( obj, { 'returns': 123 }, predicate ); // $ExpectError - bifurcateOwn( obj, { 'returns': [] }, predicate ); // $ExpectError - bifurcateOwn( obj, { 'returns': {} }, predicate ); // $ExpectError - bifurcateOwn( obj, { 'returns': ( x: number ): number => x }, predicate ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const obj = new Foo(); - bifurcateOwn(); // $ExpectError - bifurcateOwn( obj ); // $ExpectError - bifurcateOwn( obj, {}, predicate, 16 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/examples/index.js b/lib/node_modules/@stdlib/utils/bifurcate-own/examples/index.js deleted file mode 100644 index e10f65a4d381..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/examples/index.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var randu = require( '@stdlib/random/base/randu' ); -var fromCodePoint = require( '@stdlib/string/from-code-point' ); -var bifurcateOwn = require( './../lib' ); - -var key; -var obj; -var out; -var i; - -// Generate a random object... -obj = {}; -for ( i = 0; i < 100; i++ ) { - key = fromCodePoint( 97+i ); - obj[ key ] = randu(); -} - -function predicate( v ) { - return ( v < 0.5 ); -} - -// Compute the groups: -out = bifurcateOwn( obj, predicate ); -console.log( out ); diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/index.js b/lib/node_modules/@stdlib/utils/bifurcate-own/lib/index.js deleted file mode 100644 index cc02f48aa28b..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/index.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Split an object's own property values into two groups according to a predicate function. -* -* @module @stdlib/utils/bifurcate-own -* -* @example -* var bifurcateOwn = require( '@stdlib/utils/bifurcate-own' ); -* -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* -* var out = bifurcateOwn( obj, predicate ); -* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] -* -* @example -* var bifurcateOwn = require( '@stdlib/utils/bifurcate-own' ); -* -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* -* var opts = { -* 'returns': 'keys' -* }; -* var out = bifurcateOwn( obj, opts, predicate ); -* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] -* -* @example -* var bifurcateOwn = require( '@stdlib/utils/bifurcate-own' ); -* -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var opts = { -* 'returns': '*' -* }; -* var out = bifurcateOwn( obj, opts, predicate ); -* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/main.js b/lib/node_modules/@stdlib/utils/bifurcate-own/lib/main.js deleted file mode 100644 index ced113ca2a7c..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/main.js +++ /dev/null @@ -1,127 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObjectLike = require( '@stdlib/assert/is-object-like' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var format = require( '@stdlib/string/format' ); -var validate = require( './validate.js' ); -var returnValues = require( './return_values.js' ); -var returnKeys = require( './return_keys.js' ); -var returnPairs = require( './return_pairs.js' ); - - -// MAIN // - -/** -* Splits an object's own property values into two groups according to a predicate function. -* -* @param {(Object|Array|TypedArray)} obj - input object -* @param {Options} [options] - function options -* @param {*} [options.thisArg] - execution context -* @param {string} [options.returns="values"] - if `values`, values are returned; if `keys`, keys are returned; if `*`, both keys and values are returned -* @param {Function} predicate - predicate function indicating which group an element in the input object belongs to -* @throws {TypeError} first argument must be an object, array, or typed array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} last argument must be a function -* @throws {TypeError} must provide valid options -* @returns {(Array|Array)} group results -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var out = bifurcateOwn( obj, predicate ); -* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var opts = { -* 'returns': 'keys' -* }; -* var out = bifurcateOwn( obj, opts, predicate ); -* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var opts = { -* 'returns': '*' -* }; -* var out = bifurcateOwn( obj, opts, predicate ); -* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] -*/ -function bifurcateOwn( obj, options, predicate ) { - var opts; - var err; - var cb; - if ( !isObjectLike( obj ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); - } - opts = { - 'returns': 'values' - }; - if ( arguments.length === 2 ) { - cb = options; - } else { - err = validate( opts, options ); - if ( err ) { - throw err; - } - cb = predicate; - } - if ( !isFunction( cb ) ) { - throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', cb ) ); - } - if ( opts.returns === 'values' ) { - return returnValues( obj, opts, cb ); - } - if ( opts.returns === 'keys' ) { - return returnKeys( obj, opts, cb ); - } - return returnPairs( obj, opts, cb ); -} - - -// EXPORTS // - -module.exports = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_keys.js b/lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_keys.js deleted file mode 100644 index 9f1766dc362c..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_keys.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); - - -// MAIN // - -/** -* Splits values into two groups according to a predicate function and outputs results as keys. -* -* @private -* @param {(Object|Array|TypedArray)} obj - input object -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {Function} predicate - predicate function specifying which group an element in the input object belongs to -* @returns {(Array|Array)} results -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var out = bifurcateOwn( obj, {}, predicate ); -* // e.g., returns [ [ 'a', 'b', 'd' ], [ 'c' ] ] -*/ -function bifurcateOwn( obj, opts, predicate ) { - var thisArg; - var bool; - var out; - var key; - var flg; - - thisArg = opts.thisArg; - out = [ [], [] ]; - flg = true; - for ( key in obj ) { - if ( hasOwnProp( obj, key ) ) { - flg = false; - bool = predicate.call( thisArg, obj[ key ], key ); - if ( bool ) { - out[ 0 ].push( key ); - } else { - out[ 1 ].push( key ); - } - } - } - if ( flg ) { - out.length = 0; - } - return out; -} - - -// EXPORTS // - -module.exports = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_pairs.js b/lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_pairs.js deleted file mode 100644 index 1e5d8614ffdc..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_pairs.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); - - -// MAIN // - -/** -* Splits values into two groups according to a predicate function and outputs results as key-value values. -* -* ## Notes -* -* - 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. -* -* @private -* @param {(Object|Array|TypedArray)} obj - input object -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {Function} predicate - predicate function indicating which group an element in the input object belongs to -* @returns {(Array|Array)} results -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var out = bifurcateOwn( obj, {}, predicate ); -* // e.g., returns [ [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], [ [ 'c', 'foo' ] ] ] -*/ -function bifurcateOwn( obj, opts, predicate ) { - var thisArg; - var bool; - var out; - var key; - var flg; - var v; - - thisArg = opts.thisArg; - out = [ [], [] ]; - flg = true; - for ( key in obj ) { - if ( hasOwnProp( obj, key ) ) { - flg = false; - v = obj[ key ]; - bool = predicate.call( thisArg, v, key ); - if ( bool ) { - out[ 0 ].push( [ key, v ] ); - } else { - out[ 1 ].push( [ key, v ] ); - } - } - } - if ( flg ) { - out.length = 0; - } - return out; -} - - -// EXPORTS // - -module.exports = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_values.js b/lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_values.js deleted file mode 100644 index f58cda18f453..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/return_values.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); - - -// MAIN // - -/** -* Splits values into two groups according to a predicate function and outputs results as object values. -* -* ## Notes -* -* - 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. -* -* @private -* @param {(Object|Array|TypedArray)} obj - input object -* @param {Options} opts - function options -* @param {*} [opts.thisArg] - execution context -* @param {Function} predicate - predicate function indicating which group an element in the input object belongs to -* @returns {(Array|Array)} results -* -* @example -* function predicate( v ) { -* return v[ 0 ] === 'b'; -* } -* var obj = { -* 'a': 'beep', -* 'b': 'boop', -* 'c': 'foo', -* 'd': 'bar' -* }; -* var out = bifurcateOwn( obj, {}, predicate ); -* // e.g., returns [ [ 'beep', 'boop', 'bar' ], [ 'foo' ] ] -*/ -function bifurcateOwn( obj, opts, predicate ) { - var thisArg; - var bool; - var out; - var key; - var flg; - var v; - - thisArg = opts.thisArg; - out = [ [], [] ]; - flg = true; - for ( key in obj ) { - if ( hasOwnProp( obj, key ) ) { - flg = false; - v = obj[ key ]; - bool = predicate.call( thisArg, v, key ); - if ( bool ) { - out[ 0 ].push( v ); - } else { - out[ 1 ].push( v ); - } - } - } - if ( flg ) { - out.length = 0; - } - return out; -} - - -// EXPORTS // - -module.exports = bifurcateOwn; diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/validate.js b/lib/node_modules/@stdlib/utils/bifurcate-own/lib/validate.js deleted file mode 100644 index fd11f5aff1a2..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/lib/validate.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isObject = require( '@stdlib/assert/is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var indexOf = require( '@stdlib/utils/index-of' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var returns = [ 'values', 'keys', '*' ]; - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {*} [options.thisArg] - execution context -* @param {string} [options.returns] - output format -* @returns {(Error|null)} null or an error object -* -* @example -* var opts = {}; -* var options = { -* 'returns': '*', -* 'thisArg': {} -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'thisArg' ) ) { - opts.thisArg = options.thisArg; - } - if ( hasOwnProp( options, 'returns' ) ) { - opts.returns = options.returns; - if ( indexOf( returns, opts.returns ) === -1 ) { - return new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'returns', returns.join( '", "' ), opts.returns ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/package.json b/lib/node_modules/@stdlib/utils/bifurcate-own/package.json deleted file mode 100644 index c8648456d688..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/package.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "name": "@stdlib/utils/bifurcate-own", - "version": "0.0.0", - "description": "Split an object's own property values into two groups according to a predicate function.", - "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdutils", - "stdutil", - "utilities", - "utility", - "utils", - "util", - "group", - "groupby", - "group-by", - "bifurcate", - "bifurcation", - "aggregate", - "partition", - "split", - "object", - "obj", - "own" - ] -} diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/test/test.js b/lib/node_modules/@stdlib/utils/bifurcate-own/test/test.js deleted file mode 100644 index 273bae8eb06e..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/test/test.js +++ /dev/null @@ -1,733 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils/noop' ); -var bifurcateOwn = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof bifurcateOwn, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - bifurcateOwn( value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a predicate function (no options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - bifurcateOwn( obj, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a predicate function (options)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - bifurcateOwn( obj, {}, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid options argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - bifurcateOwn( obj, value, noop ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - [], - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - opts = { - 'returns': value - }; - bifurcateOwn( obj, opts, noop ); - }; - } -}); - -tape( 'the function splits object values into two groups according to a predicate function', function test( t ) { - var expected; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar' - }; - - expected = [ - [ 'beep', 'boop', 'bar' ], - [ 'foo' ] - ]; - out = bifurcateOwn( obj, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort(); - out[ 1 ].sort(); - expected[ 0 ].sort(); - expected[ 1 ].sort(); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); -}); - -tape( 'the function splits object values into two groups according to a predicate function (own)', function test( t ) { - var expected; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - function Foo() { - this.a = 'beep'; - this.b = 'boop'; - this.c = 'foo'; - this.d = 'bar'; - return this; - } - - Foo.prototype.e = 'beep'; - Foo.prototype.f = 'boop'; - - obj = new Foo(); - - expected = [ - [ 'beep', 'boop', 'bar' ], - [ 'foo' ] - ]; - out = bifurcateOwn( obj, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort(); - out[ 1 ].sort(); - expected[ 0 ].sort(); - expected[ 1 ].sort(); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); -}); - -tape( 'the function splits object values into two groups according to a predicate function (values)', function test( t ) { - var expected; - var opts; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar' - }; - - opts = { - 'returns': 'values' - }; - - expected = [ - [ 'beep', 'boop', 'bar' ], - [ 'foo' ] - ]; - out = bifurcateOwn( obj, opts, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort(); - out[ 1 ].sort(); - expected[ 0 ].sort(); - expected[ 1 ].sort(); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); -}); - -tape( 'the function splits object values into two groups according to a predicate function (values; own)', function test( t ) { - var expected; - var opts; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - function Foo() { - this.a = 'beep'; - this.b = 'boop'; - this.c = 'foo'; - this.d = 'bar'; - return this; - } - - Foo.prototype.e = 'beep'; - Foo.prototype.f = 'boop'; - - obj = new Foo(); - - opts = { - 'returns': 'values' - }; - - expected = [ - [ 'beep', 'boop', 'bar' ], - [ 'foo' ] - ]; - out = bifurcateOwn( obj, opts, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort(); - out[ 1 ].sort(); - expected[ 0 ].sort(); - expected[ 1 ].sort(); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); -}); - -tape( 'the function splits object values into two groups according to a predicate function (keys)', function test( t ) { - var expected; - var opts; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar' - }; - - opts = { - 'returns': 'keys' - }; - - expected = [ - [ 'a', 'b', 'd' ], - [ 'c' ] - ]; - out = bifurcateOwn( obj, opts, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort(); - out[ 1 ].sort(); - expected[ 0 ].sort(); - expected[ 1 ].sort(); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); -}); - -tape( 'the function splits object values into two groups according to a predicate function (keys; own)', function test( t ) { - var expected; - var opts; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - function Foo() { - this.a = 'beep'; - this.b = 'boop'; - this.c = 'foo'; - this.d = 'bar'; - return this; - } - - Foo.prototype.e = 'beep'; - Foo.prototype.f = 'boop'; - - obj = new Foo(); - - opts = { - 'returns': 'keys' - }; - - expected = [ - [ 'a', 'b', 'd' ], - [ 'c' ] - ]; - out = bifurcateOwn( obj, opts, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort(); - out[ 1 ].sort(); - expected[ 0 ].sort(); - expected[ 1 ].sort(); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); -}); - -tape( 'the function splits object values into two groups according to a predicate function (pairs)', function test( t ) { - var expected; - var opts; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - obj = { - 'a': 'beep', - 'b': 'boop', - 'c': 'foo', - 'd': 'bar' - }; - - opts = { - 'returns': '*' - }; - - expected = [ - [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], - [ [ 'c', 'foo' ] ] - ]; - out = bifurcateOwn( obj, opts, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort( sort ); - out[ 1 ].sort( sort ); - expected[ 0 ].sort( sort ); - expected[ 1 ].sort( sort ); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); - - function sort( a, b ) { - return a[ 0 ] < b[ 0 ]; - } -}); - -tape( 'the function splits object values into two groups according to a predicate function (pairs; own)', function test( t ) { - var expected; - var opts; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - function Foo() { - this.a = 'beep'; - this.b = 'boop'; - this.c = 'foo'; - this.d = 'bar'; - return this; - } - - Foo.prototype.e = 'beep'; - Foo.prototype.f = 'boop'; - - obj = new Foo(); - - opts = { - 'returns': '*' - }; - - expected = [ - [ [ 'a', 'beep' ], [ 'b', 'boop' ], [ 'd', 'bar' ] ], - [ [ 'c', 'foo' ] ] - ]; - out = bifurcateOwn( obj, opts, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort( sort ); - out[ 1 ].sort( sort ); - expected[ 0 ].sort( sort ); - expected[ 1 ].sort( sort ); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); - - function sort( a, b ) { - return a[ 0 ] < b[ 0 ]; - } -}); - -tape( 'the function splits object values into two groups according to a predicate function (array-like object)', function test( t ) { - var expected; - var opts; - var out; - var arr; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - arr = { - 'length': 4, - '0': 'beep', - '1': 'boop', - '2': 'foo', - '3': 'bar' - }; - opts = { - 'returns': 'values' - }; - - // Note: `length` is an own property and thus is included in key iteration. - expected = [ - [ 'beep', 'boop', 'bar' ], - [ 'foo', 4 ] - ]; - out = bifurcateOwn( arr, opts, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort(); - out[ 1 ].sort(); - expected[ 0 ].sort(); - expected[ 1 ].sort(); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); -}); - -tape( 'the function supports providing an execution context', function test( t ) { - var expected; - var opts; - var ctx; - var out; - var arr; - - function predicate( v ) { - this.count += 1; // eslint-disable-line no-invalid-this - return ( v === 0.0 ); - } - - ctx = { - 'count': 0 - }; - - arr = [ 0.0, 1.0, 1.0, 0.0 ]; - - opts = { - 'thisArg': ctx - }; - expected = [ - [ 0.0, 0.0 ], - [ 1.0, 1.0 ] - ]; - out = bifurcateOwn( arr, opts, predicate ); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.strictEqual( ctx.count, 4, 'updates context' ); - - t.end(); -}); - -tape( 'the function invokes the predicate function with both the object value and the object key', function test( t ) { - var expected; - var out; - var arr; - - function predicate( v, k ) { - return ( parseInt( k, 10 ) < 2 ); - } - - arr = [ 5, 5, 1, 1 ]; - - expected = [ - [ 5, 5 ], - [ 1, 1 ] - ]; - out = bifurcateOwn( arr, predicate ); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); -}); - -tape( 'if provided an empty object, the function returns an empty array', function test( t ) { - var expected; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - obj = {}; - expected = []; - - out = bifurcateOwn( obj, predicate ); - - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); -}); - -tape( 'if provided an empty object, the function returns an empty array (values)', function test( t ) { - var expected; - var opts; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - obj = {}; - expected = []; - - opts = { - 'returns': 'values' - }; - - out = bifurcateOwn( obj, opts, predicate ); - - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); -}); - -tape( 'if provided an empty object, the function returns an empty array (keys)', function test( t ) { - var expected; - var opts; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - obj = {}; - expected = []; - - opts = { - 'returns': 'keys' - }; - - out = bifurcateOwn( obj, opts, predicate ); - - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); -}); - -tape( 'if provided an empty object, the function returns an empty array (pairs)', function test( t ) { - var expected; - var opts; - var out; - var obj; - - function predicate( v ) { - return v[ 0 ] === 'b'; - } - - obj = {}; - expected = []; - - opts = { - 'returns': '*' - }; - - out = bifurcateOwn( obj, opts, predicate ); - - t.deepEqual( out, expected, 'returns expected results' ); - t.end(); -}); - -tape( 'the function does not account for dynamic addition and removal of object properties', function test( t ) { - var expected; - var out; - var arr; - - function predicate( v, i ) { - arr.push( 'beep' ); - arr[ 'a'+i ] = 'boop'; - return v[ 0 ] === 'b'; - } - - arr = [ 'beep', 'boop', 'foo', 'bar' ]; - - expected = [ - [ 'beep', 'boop', 'bar' ], - [ 'foo' ] - ]; - out = bifurcateOwn( arr, predicate ); - - // To ensure stable comparison due to iteration order instability, we only want to test that the sets are the same, not the order... - out[ 0 ].sort(); - out[ 1 ].sort(); - expected[ 0 ].sort(); - expected[ 1 ].sort(); - - t.deepEqual( out, expected, 'returns expected groups' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/bifurcate-own/test/test.validate.js b/lib/node_modules/@stdlib/utils/bifurcate-own/test/test.validate.js deleted file mode 100644 index 62aaafde6d70..000000000000 --- a/lib/node_modules/@stdlib/utils/bifurcate-own/test/test.validate.js +++ /dev/null @@ -1,163 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if provided an `options` argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided an unsupported `returns` option', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - 'both', - 'pairs', - 'beep', - 'boop', - 'index', - 'indexes', - 'key', - 'properties', - 'props', - 'prop', - 'vals', - 'value', - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'returns': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function supports any `thisArg`', function test( t ) { - var values; - var opts; - var err; - var i; - - values = [ - '5', - 5, - true, - false, - void 0, - null, - NaN, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - opts = { - 'thisArg': values[ i ] - }; - err = validate( {}, opts ); - t.strictEqual( err, null, 'returns null when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'thisArg': {}, - 'returns': '*' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, options, 'sets options' ); - - t.end(); -}); - -tape( 'the function will ignore unrecognized options', function test( t ) { - var options; - var opts; - var err; - - opts = {}; - options = { - 'beep': true, - 'boop': 'bop' - }; - - err = validate( opts, options ); - t.strictEqual( err, null, 'returns expected value' ); - t.deepEqual( opts, {}, 'ignores unrecognized options' ); - - t.end(); -});