From f618ac82ab8c73954dba8a13561713240effe616 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Mon, 16 Jun 2025 21:02:41 +0530 Subject: [PATCH 1/3] feat: add `object/some-in-by` Ref: https://github.com/stdlib-js/stdlib/issues/7372 --- .../@stdlib/object/some-in-by/README.md | 232 +++++++++++++ .../object/some-in-by/benchmark/benchmark.js | 105 ++++++ .../@stdlib/object/some-in-by/docs/repl.txt | 45 +++ .../object/some-in-by/docs/types/index.d.ts | 104 ++++++ .../object/some-in-by/docs/types/test.ts | 66 ++++ .../object/some-in-by/examples/index.js | 37 ++ .../@stdlib/object/some-in-by/lib/index.js | 46 +++ .../@stdlib/object/some-in-by/lib/main.js | 87 +++++ .../@stdlib/object/some-in-by/package.json | 75 +++++ .../@stdlib/object/some-in-by/test/test.js | 316 ++++++++++++++++++ 10 files changed, 1113 insertions(+) create mode 100644 lib/node_modules/@stdlib/object/some-in-by/README.md create mode 100644 lib/node_modules/@stdlib/object/some-in-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/object/some-in-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/object/some-in-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/object/some-in-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/object/some-in-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/object/some-in-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/object/some-in-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/object/some-in-by/package.json create mode 100644 lib/node_modules/@stdlib/object/some-in-by/test/test.js diff --git a/lib/node_modules/@stdlib/object/some-in-by/README.md b/lib/node_modules/@stdlib/object/some-in-by/README.md new file mode 100644 index 000000000000..dd9b28b3d37d --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/README.md @@ -0,0 +1,232 @@ + + +# someInBy + +> Test whether an object contains at least `n` properties which pass a test implemented by a predicate function. + +
+ +
+ + + +
+ +## Usage + +```javascript +var someInBy = require( '@stdlib/object/some-in-by' ); +``` + +#### someInBy( obj, n, predicate\[, thisArg ] ) + +Tests whether an `obj` contains at least `n` properties which pass a test implemented by a `predicate` function. + +```javascript +function isNegative( value ) { + return ( value < 0 ); +} + +var obj = { + 'a': 1, + 'b': -2, + 'c': 3, + 'd': -1 +}; + +var bool = someInBy( obj, 2, isNegative ); +// returns true +``` + +Once the function finds `n` successful properties, the function **immediately** returns `true`. + +```javascript +function isPositive( value ) { + if ( value < 0 ) { + throw new Error( 'should never reach this line' ); + } + return ( value > 0 ); +} + +var obj = { + 'a': 1, + 'b': 2, + 'c': -3, + 'd': 4 +}; + +var bool = someInBy( obj, 2, isPositive ); +// returns true +``` + +The invoked `function` is provided three arguments: + +- **value**: object property value. +- **key**: object property key. +- **obj**: input object. + +To set the function execution context, provide a `thisArg`. + +```javascript +function sum( value ) { + this.sum += value; + this.count += 1; + return ( value < 0 ); +} + +var obj = { + 'a': 1, + 'b': 2, + 'c': 3, + 'd': -5 +}; + +var context = { + 'sum': 0, + 'count': 0 +}; + +var bool = someInBy( obj, 1, sum, context ); +// returns true + +var mean = context.sum / context.count; +// returns 0.25 +``` + +
+ + + +
+ +## Notes + +- If provided an empty `obj`, the function returns `false`. + + ```javascript + function alwaysTrue() { + return true; + } + var bool = someInBy( {}, 1, alwaysTrue ); + // returns false + ``` + +- The function does **not** skip `undefined` properties. + + ```javascript + function log( value, key ) { + console.log( '%s: %s', key, value ); + return ( value < 0 ); + } + + var obj = { + 'a': 1, + 'b': void 0, + 'c': void 0, + 'd': 4, + 'e': -1 + }; + + var bool = someInBy( obj, 1, log ); + // logs + // a: 1 + // b: void 0 + // c: void 0 + // d: 4 + // e: -1 + ``` + +- The function provides limited support for dynamic objects (i.e., objects whose properties change during execution). + +
+ + + +
+ +## Examples + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var someInBy = require( '@stdlib/object/some-in-by' ); + +function threshold( value ) { + return ( value > 0.95 ); +} + +var bool; +var obj = {}; +var i; + +for ( i = 0; i < 100; i++ ) { + obj[ 'key' + i ] = randu(); +} + +bool = someInBy( obj, 5, threshold ); +// returns +``` + +
+ + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/object/some-in-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/object/some-in-by/benchmark/benchmark.js new file mode 100644 index 000000000000..8e4649695d2d --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/benchmark/benchmark.js @@ -0,0 +1,105 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var someInBy = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var bool; + var obj; + var i; + + function predicate( v ) { + return isnan( v ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = { + 'a': i, + 'b': i + 1, + 'c': i + 2, + 'd': NaN, + 'e': i + 4, + 'f': NaN + }; + bool = someInBy( obj, 2, predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg + '::loop', function benchmark( b ) { + var total; + var count; + var bool; + var obj; + var key; + var i; + + total = 2; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = { + 'a': i, + 'b': i + 1, + 'c': i + 2, + 'd': NaN, + 'e': i + 4, + 'f': NaN + }; + bool = false; + count = 0; + for ( key in obj ) { + if ( Object.prototype.hasOwnProperty.call( obj, key ) && isnan(obj[ key ] ) ) { + count += 1; + if ( count === total ) { + bool = true; + break; + } + } + } + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should be a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/object/some-in-by/docs/repl.txt b/lib/node_modules/@stdlib/object/some-in-by/docs/repl.txt new file mode 100644 index 000000000000..f326e9a5b3fb --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/docs/repl.txt @@ -0,0 +1,45 @@ + +{{alias}}( obj, n, predicate[, thisArg ] ) + Tests whether an object contains at least `n` properties + (own and inherited) which pass a test + implemented by a predicate function. + + The predicate function is provided three arguments: + + - value: object value. + - key: object key. + - obj: the input object. + + The function immediately returns upon finding `n` successful properties. + + If provided an empty object, the function returns `false`. + + Parameters + ---------- + obj: Object + Input object over which to iterate. + + n: number + Minimum number of successful properties. + + predicate: Function + Test function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + bool: boolean + The function returns `true` if an object contains at least `n` + successful properties; otherwise, the function returns `false`. + + Examples + -------- + > function negative( v ) { return ( v < 0 ); }; + > var obj = { 'a': 1, 'b': 2, 'c': -3, 'd': 4, 'e': -1 }; + > var bool = {{alias}}( obj, 2, negative ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/object/some-in-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/object/some-in-by/docs/types/index.d.ts new file mode 100644 index 000000000000..caa9a26c50dd --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/docs/types/index.d.ts @@ -0,0 +1,104 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 + +/// + +/** +* Checks whether a property in an object passes a test. +* +* @returns boolean indicating whether a property in an object passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether a property in an object passes a test. +* +* @param value - object value +* @returns boolean indicating whether a property in an object passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether a property in an object passes a test. +* +* @param value - object value +* @param key - object key +* @returns boolean indicating whether a property in an object passes a test +*/ +type Binary = ( this: U, value: T, key: string ) => boolean; + +/** +* Checks whether a property in an object passes a test. +* +* @param value - object value +* @param key - object key +* @param obj - input object +* @returns boolean indicating whether a property in an object passes a test +*/ +type Ternary = ( this: U, value: T, key: string, obj: Record ) => boolean; + +/** +* Checks whether a property in an object passes a test. +* +* @param value - object value +* @param key - object key +* @param obj - input object +* @returns boolean indicating whether a property in an object passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + +/** +* Tests whether an object contains at least `n` properties (own and inherited) which pass a test implemented by a predicate function. +* +* ## Notes +* +* - The predicate function is provided three arguments: +* +* - `value`: object value +* - `key`: object key +* - `obj`: the input object +* +* - The function immediately returns upon finding `n` successful properties. +* +* - If provided an empty object, the function returns `false`. +* +* @param obj - input object +* @param n - number of properties +* @param predicate - test function +* @param thisArg - execution context +* @throws second argument must be a positive integer +* @returns boolean indicating whether an object contains at least `n` properties which pass a test +* +* @example +* function isNegative( v ) { +* return ( v < 0 ); +* } +* +* var obj = { 'a': 1, 'b': 2, 'c': -3, 'd': 4, 'e': -1 }; +* +* var bool = someInBy( obj, 2, isNegative ); +* // returns true +*/ +declare function someInBy( obj: Record, n: number, predicate: Predicate, thisArg?: ThisParameterType> ): boolean; + + +// EXPORTS // + +export = someInBy; diff --git a/lib/node_modules/@stdlib/object/some-in-by/docs/types/test.ts b/lib/node_modules/@stdlib/object/some-in-by/docs/types/test.ts new file mode 100644 index 000000000000..f519796ddaee --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/docs/types/test.ts @@ -0,0 +1,66 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 someInBy = require( './index' ); + +const hasUpperCase = ( v: string, key: string ): boolean => { + return ( key.toUpperCase() === key ); +}; + +// TESTS // + +// The function returns a boolean... +{ + someInBy( { 'a': 0, 'B': 1, 'C': 1 }, 2, hasUpperCase ); // $ExpectType boolean + someInBy( { 'a': -1, 'B': 1, 'c': 2 }, 3, hasUpperCase, {} ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided a first argument which is not an object... +{ + someInBy( 2, 2, hasUpperCase ); // $ExpectError + someInBy( false, 2, hasUpperCase ); // $ExpectError + someInBy( true, 2, hasUpperCase ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + someInBy( { 'a': -1, 'B': 1, 'c': 2 }, ( x: number ): number => x, hasUpperCase ); // $ExpectError + someInBy( { 'a': -1, 'B': 1, 'c': 2 }, false, hasUpperCase ); // $ExpectError + someInBy( { 'a': -1, 'B': 1, 'c': 2 }, true, hasUpperCase ); // $ExpectError + someInBy( { 'a': -1, 'B': 1, 'c': 2 }, 'abc', hasUpperCase ); // $ExpectError + someInBy( { 'a': -1, 'B': 1, 'c': 2 }, {}, hasUpperCase ); // $ExpectError + someInBy( { 'a': -1, 'B': 1, 'c': 2 }, [], hasUpperCase ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a function... +{ + someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, 2 ); // $ExpectError + someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, false ); // $ExpectError + someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, true ); // $ExpectError + someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, 'abc' ); // $ExpectError + someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, {} ); // $ExpectError + someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, [] ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + someInBy(); // $ExpectError + someInBy( { 'a': 1, 'B': 2, 'c': 3 } ); // $ExpectError + someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1 ); // $ExpectError + someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, hasUpperCase, {}, 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/object/some-in-by/examples/index.js b/lib/node_modules/@stdlib/object/some-in-by/examples/index.js new file mode 100644 index 000000000000..dd2e214f8a0f --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/examples/index.js @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 someInBy = require( './../lib' ); + +function threshold( value ) { + return ( value > 0.95 ); +} + +var bool; +var obj = {}; +var i; + +for ( i = 0; i < 100; i++ ) { + obj[ 'key' + i ] = randu(); +} + +bool = someInBy( obj, 5, threshold ); +console.log( bool ); diff --git a/lib/node_modules/@stdlib/object/some-in-by/lib/index.js b/lib/node_modules/@stdlib/object/some-in-by/lib/index.js new file mode 100644 index 000000000000..8a237719d381 --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/lib/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +/** +* Test whether an object contains at least `n` properties (own or inherited) which pass a test implemented by a predicate function. +* +* @module @stdlib/object/some-in-by +* +* @example +* var someInBy = require( '@stdlib/object/some-in-by' ); +* +* function isNegative( v ) { +* return ( v < 0 ); +* } +* +* var obj = { a: 1, b: -2, c: 3, d: 4, e: -1 }; +* +* var bool = someInBy( obj, 2, isNegative ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/object/some-in-by/lib/main.js b/lib/node_modules/@stdlib/object/some-in-by/lib/main.js new file mode 100644 index 000000000000..f7285ef25bdf --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/lib/main.js @@ -0,0 +1,87 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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-object' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var isFunction = require( '@stdlib/assert/is-function' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Tests whether an object contains at least `n` properties (own or inherited) which pass a test implemented by a predicate function. +* +* @param {Object} obj - input object +* @param {PositiveInteger} n - number of properties +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @throws {TypeError} first argument must be an object +* @throws {TypeError} second argument must be a positive integer +* @throws {TypeError} third argument must be a function +* @returns {boolean} boolean indicating whether an object contains at least `n` properties which pass a test +* +* @example +* function isNegative( v ) { +* return ( v < 0 ); +* } +* +* var obj = { a: 1, b: -2, c: 3, d: 4, e: -1 }; +* +* var bool = someInBy( obj, 2, isNegative ); +* // returns true +*/ +function someInBy( obj, n, predicate, thisArg ) { + var count; + var out; + var key; + if ( !isObject( obj ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + } + if ( !isPositiveInteger( n ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', n ) ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', predicate ) ); + } + count = 0; + for ( key in obj ) { + if ( + Object.prototype.hasOwnProperty.call( obj, key ) || + Object.prototype.hasOwnProperty.call( Object.getPrototypeOf( obj ), key ) + ) { + out = predicate.call( thisArg, obj[ key ], key, obj ); + if ( out ) { + count += 1; + if ( count === n ) { + return true; + } + } + } + } + return false; +} + + +// EXPORTS // + +module.exports = someInBy; diff --git a/lib/node_modules/@stdlib/object/some-in-by/package.json b/lib/node_modules/@stdlib/object/some-in-by/package.json new file mode 100644 index 000000000000..e21ec654d29b --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/object/some-in-by", + "version": "0.0.0", + "description": "Test whether an object contains at least n properties (own and inherited) which pass a test implemented by 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", + "test", + "predicate", + "any", + "every", + "all", + "object.some", + "object.every", + "some", + "property", + "own", + "inherited", + "iterate", + "collection", + "array-like", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/object/some-in-by/test/test.js b/lib/node_modules/@stdlib/object/some-in-by/test/test.js new file mode 100644 index 000000000000..3459fa8c17d8 --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-in-by/test/test.js @@ -0,0 +1,316 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 someInBy = require( './../lib' ); + + +// FUNCTIONS // + +function isNegative( value ) { + return ( value < 0 ); +} + +function isPositive( value ) { + return ( value > 0 ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof someInBy, '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() { + someInBy( value, 2, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a second argument which is a positive integer', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 0, + 3.14, + 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() { + someInBy( { + 'a': 1, + 'b': 2, + 'c': 3 + }, value, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a predicate function', 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() { + someInBy( { + 'a': 1, + 'b': 2, + 'c': 3 + }, 2, value ); + }; + } +}); + +tape( 'if provided an empty object, the function returns `false`', function test( t ) { + var bool; + var obj; + + function foo() { + t.fail( 'should not be invoked' ); + } + obj = {}; + bool = someInBy( obj, 1, foo ); + + t.strictEqual( bool, false, 'returns false' ); + t.end(); +}); + +tape( 'the function returns `true` if an object contains at least `n` properties which pass a test', function test( t ) { + var bool; + var obj; + + obj = { + 'a': 1, + 'b': -2, + 'c': 3, + 'd': -1 + }; + + bool = someInBy( obj, 2, isNegative ); + + t.strictEqual( bool, true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if an object does not contain at least `n` properties which pass a test (case: at least 1)', function test( t ) { + var bool; + var obj; + + obj = { + 'a': -1, + 'b': -2, + 'c': -3 + }; + + bool = someInBy( obj, 1, isPositive ); + + t.strictEqual( bool, false, 'returns false' ); + t.end(); +}); + +tape( 'the function returns `false` if an object does not contain at least `n` properties which pass a test (case: at least 2)', function test( t ) { + var bool; + var obj; + + obj = { + 'a': -1, + 'b': -2, + 'c': -3 + }; + + bool = someInBy( obj, 2, isPositive ); + + t.strictEqual( bool, false, 'returns false' ); + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var bool; + var ctx; + var obj; + + function sum( value ) { + /* eslint-disable no-invalid-this */ + this.sum += value; + this.count += 1; + return ( value < 0 ); + } + + ctx = { + 'sum': 0, + 'count': 0 + }; + obj = { + 'a': 1.0, + 'b': -2.0, + 'c': 3.0, + 'd': -1.0 + }; + + bool = someInBy( obj, 2, sum, ctx ); + + t.strictEqual( bool, true, 'returns true' ); + t.strictEqual( ctx.sum/ctx.count, 0.25, 'expected result' ); + + t.end(); +}); + +tape( 'the function provides basic support for dynamic objects', function test( t ) { + var bool; + var obj; + + obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + + function isNegative( value, key, collection ) { + if ( key === 'c' ) { + collection[ 'd' ] = value-1; + } + return ( value < 0 ); + } + + bool = someInBy( obj, 1, isNegative ); + + t.deepEqual( obj, { + 'a': 1, + 'b': 2, + 'c': 3, + 'd': 2 + }, 'expected result' ); + t.strictEqual( bool, false, 'returns false' ); + + t.end(); +}); + +tape( 'the function does not skip undefined properties', function test( t ) { + var expected; + var bool; + var obj; + + obj = { + 'a': 1, + 'b': void 0, + 'c': void 0, + 'd': 4, + 'e': -1 + }; + expected = { + 'a': 1, + 'b': void 0, + 'c': void 0, + 'd': 4, + 'e': -1 + }; + + function verify( value, key ) { + t.strictEqual( value, expected[ key ], 'provides expected value' ); + return ( value < 0 ); + } + + bool = someInBy( obj, 1, verify ); + + t.strictEqual( bool, true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if provided a regular expression or a date object with no properties passing the test', function test( t ) { + var values; + var i; + + values = [ + /.*/, + new Date() + ]; + + for ( i = 0; i < values.length; i++ ) { + t.equal( someInBy( values[ i ], 1, threshold ), false, 'returns false when provided ' + values[ i ] ); + } + t.end(); + + function threshold( value ) { + return ( typeof value === 'number' ); + } +}); From 0f14931d11cce8ee022ce2a1e46f253967207670 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Mon, 16 Jun 2025 21:06:08 +0530 Subject: [PATCH 2/3] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/7372 --- .../@stdlib/namespace/alias2pkg/data/data.csv | 2 +- .../@stdlib/namespace/alias2standalone/data/data.csv | 2 +- lib/node_modules/@stdlib/namespace/lib/namespace/a.js | 2 +- lib/node_modules/@stdlib/namespace/lib/namespace/e.js | 2 +- lib/node_modules/@stdlib/namespace/lib/namespace/n.js | 2 +- lib/node_modules/@stdlib/namespace/lib/namespace/s.js | 6 +++--- .../@stdlib/namespace/pkg2alias/data/data.csv | 2 +- .../@stdlib/namespace/pkg2related/data/data.csv | 10 +++++----- .../@stdlib/namespace/pkg2standalone/data/data.csv | 2 +- .../@stdlib/namespace/standalone2pkg/data/data.csv | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv index 5086cf5cd76c..5e5212ecf886 100644 --- a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv @@ -2980,7 +2980,7 @@ someBy,"@stdlib/utils/some-by" someByAsync,"@stdlib/utils/async/some-by" someByRight,"@stdlib/utils/some-by-right" someByRightAsync,"@stdlib/utils/async/some-by-right" -someInBy,"@stdlib/utils/some-in-by" +someInBy,"@stdlib/obejct/some-in-by" someOwnBy,"@stdlib/utils/some-own-by" SOTU,"@stdlib/datasets/sotu" SPACHE_REVISED,"@stdlib/datasets/spache-revised" diff --git a/lib/node_modules/@stdlib/namespace/alias2standalone/data/data.csv b/lib/node_modules/@stdlib/namespace/alias2standalone/data/data.csv index 8082c4951f4a..d5e0bf3d7fba 100644 --- a/lib/node_modules/@stdlib/namespace/alias2standalone/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/alias2standalone/data/data.csv @@ -2980,7 +2980,7 @@ someBy,"@stdlib/utils-some-by" someByAsync,"@stdlib/utils-async-some-by" someByRight,"@stdlib/utils-some-by-right" someByRightAsync,"@stdlib/utils-async-some-by-right" -someInBy,"@stdlib/utils-some-in-by" +someInBy,"@stdlib/object-some-in-by" someOwnBy,"@stdlib/utils-some-own-by" SOTU,"@stdlib/datasets-sotu" SPACHE_REVISED,"@stdlib/datasets-spache-revised" diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/a.js b/lib/node_modules/@stdlib/namespace/lib/namespace/a.js index 97f3c466e0b0..784e733ef0f1 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/a.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/a.js @@ -381,7 +381,7 @@ ns.push({ '@stdlib/utils/any-by', '@stdlib/utils/any-own-by', '@stdlib/object/every-in-by', - '@stdlib/utils/some-in-by' + '@stdlib/object/some-in-by' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/e.js b/lib/node_modules/@stdlib/namespace/lib/namespace/e.js index 0770f5245b28..89808345ee9a 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/e.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/e.js @@ -264,7 +264,7 @@ ns.push({ 'related': [ '@stdlib/utils/any-in-by', '@stdlib/utils/none-in-by', - '@stdlib/utils/some-in-by', + '@stdlib/object/some-in-by', '@stdlib/utils/every-by', '@stdlib/utils/every-own-by' ] diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/n.js b/lib/node_modules/@stdlib/namespace/lib/namespace/n.js index 0a6ab4647b39..265b0d411d15 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/n.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/n.js @@ -970,7 +970,7 @@ ns.push({ '@stdlib/object/every-in-by', '@stdlib/utils/for-in', '@stdlib/utils/none-by', - '@stdlib/utils/some-in-by' + '@stdlib/object/some-in-by' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/s.js index 6acba8fdbab8..f201c18c1525 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/s.js @@ -580,8 +580,8 @@ ns.push({ ns.push({ 'alias': 'someInBy', - 'path': '@stdlib/utils/some-in-by', - 'value': require( '@stdlib/utils/some-in-by' ), + 'path': '@stdlib/object/some-in-by', + 'value': require( '@stdlib/object/some-in-by' ), 'type': 'Function', 'related': [ '@stdlib/utils/any-in-by', @@ -600,7 +600,7 @@ ns.push({ '@stdlib/utils/any-own-by', '@stdlib/utils/every-own-by', '@stdlib/utils/some-by', - '@stdlib/utils/some-in-by' + '@stdlib/object/some-in-by' ] }); diff --git a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv index fa4041e8161e..7f5784bb03c1 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv @@ -2980,7 +2980,7 @@ "@stdlib/utils/async/some-by",someByAsync "@stdlib/utils/some-by-right",someByRight "@stdlib/utils/async/some-by-right",someByRightAsync -"@stdlib/utils/some-in-by",someInBy +"@stdlib/object/some-in-by",someInBy "@stdlib/utils/some-own-by",someOwnBy "@stdlib/datasets/sotu",SOTU "@stdlib/datasets/spache-revised",SPACHE_REVISED diff --git a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv index 0225c2231d89..94cf0ae024af 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv @@ -26,7 +26,7 @@ "@stdlib/utils/async/any-by","@stdlib/utils/any-by,@stdlib/utils/async/any-by-right,@stdlib/utils/async/every-by,@stdlib/utils/async/for-each,@stdlib/utils/async/none-by,@stdlib/utils/async/some-by" "@stdlib/utils/any-by-right","@stdlib/utils/any-by,@stdlib/utils/async/any-by-right,@stdlib/utils/every-by-right,@stdlib/utils/for-each-right,@stdlib/utils/none-by-right,@stdlib/utils/some-by-right" "@stdlib/utils/async/any-by-right","@stdlib/utils/async/any-by,@stdlib/utils/any-by-right,@stdlib/utils/async/every-by-right,@stdlib/utils/async/for-each-right,@stdlib/utils/async/none-by-right,@stdlib/utils/async/some-by-right" -"@stdlib/utils/any-in-by","@stdlib/utils/any-by,@stdlib/utils/any-own-by,@stdlib/object/every-in-by,@stdlib/utils/some-in-by" +"@stdlib/utils/any-in-by","@stdlib/utils/any-by,@stdlib/utils/any-own-by,@stdlib/object/every-in-by,@stdlib/object/some-in-by" "@stdlib/utils/any-own-by","@stdlib/utils/any-by,@stdlib/utils/any-in-by,@stdlib/utils/every-own-by,@stdlib/utils/some-own-by" "@stdlib/array/ones","@stdlib/array/full,@stdlib/array/nans,@stdlib/array/ones-like,@stdlib/array/zeros" "@stdlib/array/ones-like","@stdlib/array/full-like,@stdlib/array/nans-like,@stdlib/array/ones,@stdlib/array/zeros-like" @@ -1619,7 +1619,7 @@ "@stdlib/utils/async/every-by","@stdlib/utils/async/any-by,@stdlib/utils/every-by,@stdlib/utils/async/every-by-right,@stdlib/utils/async/for-each,@stdlib/utils/async/none-by,@stdlib/utils/async/some-by" "@stdlib/utils/every-by-right","@stdlib/utils/any-by,@stdlib/utils/every,@stdlib/utils/every-by,@stdlib/utils/for-each-right,@stdlib/utils/none-by-right,@stdlib/utils/some-by-right" "@stdlib/utils/async/every-by-right","@stdlib/utils/async/any-by-right,@stdlib/utils/async/every-by,@stdlib/utils/every-by-right,@stdlib/utils/async/for-each-right,@stdlib/utils/async/none-by-right,@stdlib/utils/async/some-by-right" -"@stdlib/object/every-in-by","@stdlib/utils/any-in-by,@stdlib/utils/none-in-by,@stdlib/utils/some-in-by,@stdlib/utils/every-by,@stdlib/utils/every-own-by" +"@stdlib/object/every-in-by","@stdlib/utils/any-in-by,@stdlib/utils/none-in-by,@stdlib/object/some-in-by,@stdlib/utils/every-by,@stdlib/utils/every-own-by" "@stdlib/utils/every-own-by","@stdlib/utils/any-own-by,@stdlib/object/every-in-by,@stdlib/utils/none-own-by,@stdlib/utils/some-own-by,@stdlib/utils/every-by" "@stdlib/utils/eval","" "@stdlib/process/exec-path","" @@ -2638,7 +2638,7 @@ "@stdlib/utils/async/none-by","@stdlib/utils/async/any-by,@stdlib/utils/async/every-by,@stdlib/utils/async/for-each,@stdlib/utils/none-by,@stdlib/utils/async/none-by-right,@stdlib/utils/async/some-by" "@stdlib/utils/none-by-right","@stdlib/utils/any-by-right,@stdlib/utils/every-by-right,@stdlib/utils/for-each-right,@stdlib/utils/none,@stdlib/utils/none-by,@stdlib/utils/some-by-right" "@stdlib/utils/async/none-by-right","@stdlib/utils/async/any-by-right,@stdlib/utils/async/every-by-right,@stdlib/utils/async/for-each-right,@stdlib/utils/async/none-by,@stdlib/utils/none-by-right,@stdlib/utils/async/some-by-right" -"@stdlib/utils/none-in-by","@stdlib/utils/any-in-by,@stdlib/object/every-in-by,@stdlib/utils/for-in,@stdlib/utils/none-by,@stdlib/utils/some-in-by" +"@stdlib/utils/none-in-by","@stdlib/utils/any-in-by,@stdlib/object/every-in-by,@stdlib/utils/for-in,@stdlib/utils/none-by,@stdlib/object/some-in-by" "@stdlib/utils/nonenumerable-properties","@stdlib/utils/enumerable-properties,@stdlib/utils/inherited-nonenumerable-properties,@stdlib/utils/nonenumerable-properties-in,@stdlib/utils/properties" "@stdlib/utils/nonenumerable-properties-in","@stdlib/utils/enumerable-properties-in,@stdlib/utils/inherited-nonenumerable-properties,@stdlib/utils/nonenumerable-properties,@stdlib/utils/properties-in" "@stdlib/utils/nonenumerable-property-names","@stdlib/utils/keys,@stdlib/utils/inherited-nonenumerable-property-names,@stdlib/utils/nonenumerable-property-names-in,@stdlib/utils/nonenumerable-property-symbols,@stdlib/utils/property-names" @@ -2980,8 +2980,8 @@ "@stdlib/utils/async/some-by","@stdlib/utils/async/any-by,@stdlib/utils/async/every-by,@stdlib/utils/async/for-each,@stdlib/utils/async/none-by,@stdlib/utils/some-by,@stdlib/utils/async/some-by-right" "@stdlib/utils/some-by-right","@stdlib/utils/any-by-right,@stdlib/utils/every-by-right,@stdlib/utils/for-each-right,@stdlib/utils/none-by-right,@stdlib/utils/some-by,@stdlib/utils/async/some-by-right" "@stdlib/utils/async/some-by-right","@stdlib/utils/async/any-by-right,@stdlib/utils/async/every-by-right,@stdlib/utils/async/for-each-right,@stdlib/utils/async/none-by-right,@stdlib/utils/async/some-by,@stdlib/utils/some-by-right" -"@stdlib/utils/some-in-by","@stdlib/utils/any-in-by,@stdlib/object/every-in-by,@stdlib/utils/some-by,@stdlib/utils/some-own-by" -"@stdlib/utils/some-own-by","@stdlib/utils/any-own-by,@stdlib/utils/every-own-by,@stdlib/utils/some-by,@stdlib/utils/some-in-by" +"@stdlib/object/some-in-by","@stdlib/utils/any-in-by,@stdlib/object/every-in-by,@stdlib/utils/some-by,@stdlib/utils/some-own-by" +"@stdlib/utils/some-own-by","@stdlib/utils/any-own-by,@stdlib/utils/every-own-by,@stdlib/utils/some-by,@stdlib/object/some-in-by" "@stdlib/datasets/sotu","" "@stdlib/datasets/spache-revised","" "@stdlib/datasets/spam-assassin","" diff --git a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv index a83fa0a624b3..cea5cfc521ae 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv @@ -2980,7 +2980,7 @@ "@stdlib/utils/async/some-by","@stdlib/utils-async-some-by" "@stdlib/utils/some-by-right","@stdlib/utils-some-by-right" "@stdlib/utils/async/some-by-right","@stdlib/utils-async-some-by-right" -"@stdlib/utils/some-in-by","@stdlib/utils-some-in-by" +"@stdlib/object/some-in-by","@stdlib/object-some-in-by" "@stdlib/utils/some-own-by","@stdlib/utils-some-own-by" "@stdlib/datasets/sotu","@stdlib/datasets-sotu" "@stdlib/datasets/spache-revised","@stdlib/datasets-spache-revised" diff --git a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv index 46f401227545..7b3612642512 100644 --- a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv @@ -2980,7 +2980,7 @@ "@stdlib/utils-async-some-by","@stdlib/utils/async/some-by" "@stdlib/utils-some-by-right","@stdlib/utils/some-by-right" "@stdlib/utils-async-some-by-right","@stdlib/utils/async/some-by-right" -"@stdlib/utils-some-in-by","@stdlib/utils/some-in-by" +"@stdlib/object-some-in-by","@stdlib/object/some-in-by" "@stdlib/utils-some-own-by","@stdlib/utils/some-own-by" "@stdlib/datasets-sotu","@stdlib/datasets/sotu" "@stdlib/datasets-spache-revised","@stdlib/datasets/spache-revised" From ca72369ae47025f180d3ab5e7b4146b7ed6de1f5 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Mon, 16 Jun 2025 21:06:46 +0530 Subject: [PATCH 3/3] remove: remove `utils/some-in-by` This commit removes `@stdlib/utils/some-in-by` in favor of `@stdlib/object/some-in-by`. BREAKING CHANGE: remove `utils/some-in-by` To migrate, users should update their require/import paths to use `@stdlib/object/some-in-by` which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/7372 --- .../@stdlib/utils/some-in-by/README.md | 232 ------------- .../utils/some-in-by/benchmark/benchmark.js | 105 ------ .../@stdlib/utils/some-in-by/docs/repl.txt | 45 --- .../utils/some-in-by/docs/types/index.d.ts | 104 ------ .../utils/some-in-by/docs/types/test.ts | 66 ---- .../utils/some-in-by/examples/index.js | 37 -- .../@stdlib/utils/some-in-by/lib/index.js | 46 --- .../@stdlib/utils/some-in-by/lib/main.js | 87 ----- .../@stdlib/utils/some-in-by/package.json | 75 ----- .../@stdlib/utils/some-in-by/test/test.js | 316 ------------------ 10 files changed, 1113 deletions(-) delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/README.md delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/examples/index.js delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/lib/index.js delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/lib/main.js delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/package.json delete mode 100644 lib/node_modules/@stdlib/utils/some-in-by/test/test.js diff --git a/lib/node_modules/@stdlib/utils/some-in-by/README.md b/lib/node_modules/@stdlib/utils/some-in-by/README.md deleted file mode 100644 index ce1800156c67..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/README.md +++ /dev/null @@ -1,232 +0,0 @@ - - -# someInBy - -> Test whether an object contains at least `n` properties which pass a test implemented by a predicate function. - -
- -
- - - -
- -## Usage - -```javascript -var someInBy = require( '@stdlib/utils/some-in-by' ); -``` - -#### someInBy( obj, n, predicate\[, thisArg ] ) - -Tests whether an `obj` contains at least `n` properties which pass a test implemented by a `predicate` function. - -```javascript -function isNegative( value ) { - return ( value < 0 ); -} - -var obj = { - 'a': 1, - 'b': -2, - 'c': 3, - 'd': -1 -}; - -var bool = someInBy( obj, 2, isNegative ); -// returns true -``` - -Once the function finds `n` successful properties, the function **immediately** returns `true`. - -```javascript -function isPositive( value ) { - if ( value < 0 ) { - throw new Error( 'should never reach this line' ); - } - return ( value > 0 ); -} - -var obj = { - 'a': 1, - 'b': 2, - 'c': -3, - 'd': 4 -}; - -var bool = someInBy( obj, 2, isPositive ); -// returns true -``` - -The invoked `function` is provided three arguments: - -- **value**: object property value. -- **key**: object property key. -- **obj**: input object. - -To set the function execution context, provide a `thisArg`. - -```javascript -function sum( value ) { - this.sum += value; - this.count += 1; - return ( value < 0 ); -} - -var obj = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': -5 -}; - -var context = { - 'sum': 0, - 'count': 0 -}; - -var bool = someInBy( obj, 1, sum, context ); -// returns true - -var mean = context.sum / context.count; -// returns 0.25 -``` - -
- - - -
- -## Notes - -- If provided an empty `obj`, the function returns `false`. - - ```javascript - function alwaysTrue() { - return true; - } - var bool = someInBy( {}, 1, alwaysTrue ); - // returns false - ``` - -- The function does **not** skip `undefined` properties. - - ```javascript - function log( value, key ) { - console.log( '%s: %s', key, value ); - return ( value < 0 ); - } - - var obj = { - 'a': 1, - 'b': void 0, - 'c': void 0, - 'd': 4, - 'e': -1 - }; - - var bool = someInBy( obj, 1, log ); - // logs - // a: 1 - // b: void 0 - // c: void 0 - // d: 4 - // e: -1 - ``` - -- The function provides limited support for dynamic objects (i.e., objects whose properties change during execution). - -
- - - -
- -## Examples - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var someInBy = require( '@stdlib/utils/some-in-by' ); - -function threshold( value ) { - return ( value > 0.95 ); -} - -var bool; -var obj = {}; -var i; - -for ( i = 0; i < 100; i++ ) { - obj[ 'key' + i ] = randu(); -} - -bool = someInBy( obj, 5, threshold ); -// returns -``` - -
- - - -
- -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/utils/some-in-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/some-in-by/benchmark/benchmark.js deleted file mode 100644 index 8e4649695d2d..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/benchmark/benchmark.js +++ /dev/null @@ -1,105 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pkg = require( './../package.json' ).name; -var someInBy = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var i; - - function predicate( v ) { - return isnan( v ); - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj = { - 'a': i, - 'b': i + 1, - 'c': i + 2, - 'd': NaN, - 'e': i + 4, - 'f': NaN - }; - bool = someInBy( obj, 2, predicate ); - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should return a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg + '::loop', function benchmark( b ) { - var total; - var count; - var bool; - var obj; - var key; - var i; - - total = 2; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj = { - 'a': i, - 'b': i + 1, - 'c': i + 2, - 'd': NaN, - 'e': i + 4, - 'f': NaN - }; - bool = false; - count = 0; - for ( key in obj ) { - if ( Object.prototype.hasOwnProperty.call( obj, key ) && isnan(obj[ key ] ) ) { - count += 1; - if ( count === total ) { - bool = true; - break; - } - } - } - if ( typeof bool !== 'boolean' ) { - b.fail( 'should return a boolean' ); - } - } - b.toc(); - if ( !isBoolean( bool ) ) { - b.fail( 'should be a boolean' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/some-in-by/docs/repl.txt b/lib/node_modules/@stdlib/utils/some-in-by/docs/repl.txt deleted file mode 100644 index f326e9a5b3fb..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( obj, n, predicate[, thisArg ] ) - Tests whether an object contains at least `n` properties - (own and inherited) which pass a test - implemented by a predicate function. - - The predicate function is provided three arguments: - - - value: object value. - - key: object key. - - obj: the input object. - - The function immediately returns upon finding `n` successful properties. - - If provided an empty object, the function returns `false`. - - Parameters - ---------- - obj: Object - Input object over which to iterate. - - n: number - Minimum number of successful properties. - - predicate: Function - Test function. - - thisArg: any (optional) - Execution context. - - Returns - ------- - bool: boolean - The function returns `true` if an object contains at least `n` - successful properties; otherwise, the function returns `false`. - - Examples - -------- - > function negative( v ) { return ( v < 0 ); }; - > var obj = { 'a': 1, 'b': 2, 'c': -3, 'd': 4, 'e': -1 }; - > var bool = {{alias}}( obj, 2, negative ) - true - - See Also - -------- diff --git a/lib/node_modules/@stdlib/utils/some-in-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/some-in-by/docs/types/index.d.ts deleted file mode 100644 index caa9a26c50dd..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/docs/types/index.d.ts +++ /dev/null @@ -1,104 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 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 - -/// - -/** -* Checks whether a property in an object passes a test. -* -* @returns boolean indicating whether a property in an object passes a test -*/ -type Nullary = ( this: U ) => boolean; - -/** -* Checks whether a property in an object passes a test. -* -* @param value - object value -* @returns boolean indicating whether a property in an object passes a test -*/ -type Unary = ( this: U, value: T ) => boolean; - -/** -* Checks whether a property in an object passes a test. -* -* @param value - object value -* @param key - object key -* @returns boolean indicating whether a property in an object passes a test -*/ -type Binary = ( this: U, value: T, key: string ) => boolean; - -/** -* Checks whether a property in an object passes a test. -* -* @param value - object value -* @param key - object key -* @param obj - input object -* @returns boolean indicating whether a property in an object passes a test -*/ -type Ternary = ( this: U, value: T, key: string, obj: Record ) => boolean; - -/** -* Checks whether a property in an object passes a test. -* -* @param value - object value -* @param key - object key -* @param obj - input object -* @returns boolean indicating whether a property in an object passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Tests whether an object contains at least `n` properties (own and inherited) which pass a test implemented by a predicate function. -* -* ## Notes -* -* - The predicate function is provided three arguments: -* -* - `value`: object value -* - `key`: object key -* - `obj`: the input object -* -* - The function immediately returns upon finding `n` successful properties. -* -* - If provided an empty object, the function returns `false`. -* -* @param obj - input object -* @param n - number of properties -* @param predicate - test function -* @param thisArg - execution context -* @throws second argument must be a positive integer -* @returns boolean indicating whether an object contains at least `n` properties which pass a test -* -* @example -* function isNegative( v ) { -* return ( v < 0 ); -* } -* -* var obj = { 'a': 1, 'b': 2, 'c': -3, 'd': 4, 'e': -1 }; -* -* var bool = someInBy( obj, 2, isNegative ); -* // returns true -*/ -declare function someInBy( obj: Record, n: number, predicate: Predicate, thisArg?: ThisParameterType> ): boolean; - - -// EXPORTS // - -export = someInBy; diff --git a/lib/node_modules/@stdlib/utils/some-in-by/docs/types/test.ts b/lib/node_modules/@stdlib/utils/some-in-by/docs/types/test.ts deleted file mode 100644 index f519796ddaee..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/docs/types/test.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2024 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 someInBy = require( './index' ); - -const hasUpperCase = ( v: string, key: string ): boolean => { - return ( key.toUpperCase() === key ); -}; - -// TESTS // - -// The function returns a boolean... -{ - someInBy( { 'a': 0, 'B': 1, 'C': 1 }, 2, hasUpperCase ); // $ExpectType boolean - someInBy( { 'a': -1, 'B': 1, 'c': 2 }, 3, hasUpperCase, {} ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a first argument which is not an object... -{ - someInBy( 2, 2, hasUpperCase ); // $ExpectError - someInBy( false, 2, hasUpperCase ); // $ExpectError - someInBy( true, 2, hasUpperCase ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - someInBy( { 'a': -1, 'B': 1, 'c': 2 }, ( x: number ): number => x, hasUpperCase ); // $ExpectError - someInBy( { 'a': -1, 'B': 1, 'c': 2 }, false, hasUpperCase ); // $ExpectError - someInBy( { 'a': -1, 'B': 1, 'c': 2 }, true, hasUpperCase ); // $ExpectError - someInBy( { 'a': -1, 'B': 1, 'c': 2 }, 'abc', hasUpperCase ); // $ExpectError - someInBy( { 'a': -1, 'B': 1, 'c': 2 }, {}, hasUpperCase ); // $ExpectError - someInBy( { 'a': -1, 'B': 1, 'c': 2 }, [], hasUpperCase ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function... -{ - someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, 2 ); // $ExpectError - someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, false ); // $ExpectError - someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, true ); // $ExpectError - someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, 'abc' ); // $ExpectError - someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, {} ); // $ExpectError - someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - someInBy(); // $ExpectError - someInBy( { 'a': 1, 'B': 2, 'c': 3 } ); // $ExpectError - someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1 ); // $ExpectError - someInBy( { 'a': 1, 'B': 2, 'c': 3 }, 1, hasUpperCase, {}, 3 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/utils/some-in-by/examples/index.js b/lib/node_modules/@stdlib/utils/some-in-by/examples/index.js deleted file mode 100644 index dd2e214f8a0f..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/examples/index.js +++ /dev/null @@ -1,37 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 someInBy = require( './../lib' ); - -function threshold( value ) { - return ( value > 0.95 ); -} - -var bool; -var obj = {}; -var i; - -for ( i = 0; i < 100; i++ ) { - obj[ 'key' + i ] = randu(); -} - -bool = someInBy( obj, 5, threshold ); -console.log( bool ); diff --git a/lib/node_modules/@stdlib/utils/some-in-by/lib/index.js b/lib/node_modules/@stdlib/utils/some-in-by/lib/index.js deleted file mode 100644 index d4f09da60a0d..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/lib/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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'; - -/** -* Test whether an object contains at least `n` properties (own or inherited) which pass a test implemented by a predicate function. -* -* @module @stdlib/utils/some-in-by -* -* @example -* var someInBy = require( '@stdlib/utils/some-in-by' ); -* -* function isNegative( v ) { -* return ( v < 0 ); -* } -* -* var obj = { a: 1, b: -2, c: 3, d: 4, e: -1 }; -* -* var bool = someInBy( obj, 2, isNegative ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/some-in-by/lib/main.js b/lib/node_modules/@stdlib/utils/some-in-by/lib/main.js deleted file mode 100644 index f7285ef25bdf..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/lib/main.js +++ /dev/null @@ -1,87 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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-object' ); -var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; -var isFunction = require( '@stdlib/assert/is-function' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Tests whether an object contains at least `n` properties (own or inherited) which pass a test implemented by a predicate function. -* -* @param {Object} obj - input object -* @param {PositiveInteger} n - number of properties -* @param {Function} predicate - test function -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an object -* @throws {TypeError} second argument must be a positive integer -* @throws {TypeError} third argument must be a function -* @returns {boolean} boolean indicating whether an object contains at least `n` properties which pass a test -* -* @example -* function isNegative( v ) { -* return ( v < 0 ); -* } -* -* var obj = { a: 1, b: -2, c: 3, d: 4, e: -1 }; -* -* var bool = someInBy( obj, 2, isNegative ); -* // returns true -*/ -function someInBy( obj, n, predicate, thisArg ) { - var count; - var out; - var key; - if ( !isObject( obj ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); - } - if ( !isPositiveInteger( n ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', n ) ); - } - if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', predicate ) ); - } - count = 0; - for ( key in obj ) { - if ( - Object.prototype.hasOwnProperty.call( obj, key ) || - Object.prototype.hasOwnProperty.call( Object.getPrototypeOf( obj ), key ) - ) { - out = predicate.call( thisArg, obj[ key ], key, obj ); - if ( out ) { - count += 1; - if ( count === n ) { - return true; - } - } - } - } - return false; -} - - -// EXPORTS // - -module.exports = someInBy; diff --git a/lib/node_modules/@stdlib/utils/some-in-by/package.json b/lib/node_modules/@stdlib/utils/some-in-by/package.json deleted file mode 100644 index 72dbcda3fb8d..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/package.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "name": "@stdlib/utils/some-in-by", - "version": "0.0.0", - "description": "Test whether an object contains at least n properties (own and inherited) which pass a test implemented by 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", - "test", - "predicate", - "any", - "every", - "all", - "object.some", - "object.every", - "some", - "property", - "own", - "inherited", - "iterate", - "collection", - "array-like", - "validate" - ] -} diff --git a/lib/node_modules/@stdlib/utils/some-in-by/test/test.js b/lib/node_modules/@stdlib/utils/some-in-by/test/test.js deleted file mode 100644 index 3459fa8c17d8..000000000000 --- a/lib/node_modules/@stdlib/utils/some-in-by/test/test.js +++ /dev/null @@ -1,316 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2024 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 someInBy = require( './../lib' ); - - -// FUNCTIONS // - -function isNegative( value ) { - return ( value < 0 ); -} - -function isPositive( value ) { - return ( value > 0 ); -} - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof someInBy, '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() { - someInBy( value, 2, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a second argument which is a positive integer', function test( t ) { - var values; - var i; - - values = [ - '5', - -5, - 0, - 3.14, - 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() { - someInBy( { - 'a': 1, - 'b': 2, - 'c': 3 - }, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a predicate function', 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() { - someInBy( { - 'a': 1, - 'b': 2, - 'c': 3 - }, 2, value ); - }; - } -}); - -tape( 'if provided an empty object, the function returns `false`', function test( t ) { - var bool; - var obj; - - function foo() { - t.fail( 'should not be invoked' ); - } - obj = {}; - bool = someInBy( obj, 1, foo ); - - t.strictEqual( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function returns `true` if an object contains at least `n` properties which pass a test', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 1, - 'b': -2, - 'c': 3, - 'd': -1 - }; - - bool = someInBy( obj, 2, isNegative ); - - t.strictEqual( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if an object does not contain at least `n` properties which pass a test (case: at least 1)', function test( t ) { - var bool; - var obj; - - obj = { - 'a': -1, - 'b': -2, - 'c': -3 - }; - - bool = someInBy( obj, 1, isPositive ); - - t.strictEqual( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function returns `false` if an object does not contain at least `n` properties which pass a test (case: at least 2)', function test( t ) { - var bool; - var obj; - - obj = { - 'a': -1, - 'b': -2, - 'c': -3 - }; - - bool = someInBy( obj, 2, isPositive ); - - t.strictEqual( bool, false, 'returns false' ); - t.end(); -}); - -tape( 'the function supports providing an execution context', function test( t ) { - var bool; - var ctx; - var obj; - - function sum( value ) { - /* eslint-disable no-invalid-this */ - this.sum += value; - this.count += 1; - return ( value < 0 ); - } - - ctx = { - 'sum': 0, - 'count': 0 - }; - obj = { - 'a': 1.0, - 'b': -2.0, - 'c': 3.0, - 'd': -1.0 - }; - - bool = someInBy( obj, 2, sum, ctx ); - - t.strictEqual( bool, true, 'returns true' ); - t.strictEqual( ctx.sum/ctx.count, 0.25, 'expected result' ); - - t.end(); -}); - -tape( 'the function provides basic support for dynamic objects', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - - function isNegative( value, key, collection ) { - if ( key === 'c' ) { - collection[ 'd' ] = value-1; - } - return ( value < 0 ); - } - - bool = someInBy( obj, 1, isNegative ); - - t.deepEqual( obj, { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 2 - }, 'expected result' ); - t.strictEqual( bool, false, 'returns false' ); - - t.end(); -}); - -tape( 'the function does not skip undefined properties', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': 1, - 'b': void 0, - 'c': void 0, - 'd': 4, - 'e': -1 - }; - expected = { - 'a': 1, - 'b': void 0, - 'c': void 0, - 'd': 4, - 'e': -1 - }; - - function verify( value, key ) { - t.strictEqual( value, expected[ key ], 'provides expected value' ); - return ( value < 0 ); - } - - bool = someInBy( obj, 1, verify ); - - t.strictEqual( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a regular expression or a date object with no properties passing the test', function test( t ) { - var values; - var i; - - values = [ - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.equal( someInBy( values[ i ], 1, threshold ), false, 'returns false when provided ' + values[ i ] ); - } - t.end(); - - function threshold( value ) { - return ( typeof value === 'number' ); - } -});