From 82b37c156f2332fcaab32067c1448fe5e69c8e9a Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Wed, 3 Dec 2025 15:08:33 +0530 Subject: [PATCH 1/4] feat: add `object/some-own-by` Ref: https://github.com/stdlib-js/stdlib/issues/7374 --- .../@stdlib/object/some-own-by/README.md | 251 +++++++++++++++++ .../object/some-own-by/benchmark/benchmark.js | 109 ++++++++ .../@stdlib/object/some-own-by/docs/repl.txt | 45 ++++ .../object/some-own-by/docs/types/index.d.ts | 102 +++++++ .../object/some-own-by/docs/types/test.ts | 66 +++++ .../object/some-own-by/examples/index.js | 38 +++ .../@stdlib/object/some-own-by/lib/index.js | 46 ++++ .../@stdlib/object/some-own-by/lib/main.js | 85 ++++++ .../@stdlib/object/some-own-by/package.json | 72 +++++ .../@stdlib/object/some-own-by/test/test.js | 255 ++++++++++++++++++ 10 files changed, 1069 insertions(+) create mode 100644 lib/node_modules/@stdlib/object/some-own-by/README.md create mode 100644 lib/node_modules/@stdlib/object/some-own-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/object/some-own-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/object/some-own-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/object/some-own-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/object/some-own-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/object/some-own-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/object/some-own-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/object/some-own-by/package.json create mode 100644 lib/node_modules/@stdlib/object/some-own-by/test/test.js diff --git a/lib/node_modules/@stdlib/object/some-own-by/README.md b/lib/node_modules/@stdlib/object/some-own-by/README.md new file mode 100644 index 000000000000..f7b4f906c2fa --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-by/README.md @@ -0,0 +1,251 @@ + + +# someOwnBy + +> Test whether an object contains at least `n` own properties which pass a test implemented by a predicate function. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var someOwnBy = require( '@stdlib/object/some-own-by' ); +``` + +#### someOwnBy( obj, n, predicate\[, thisArg ] ) + +Tests whether an `object` contains at least `n` own 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 = someOwnBy( 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 = someOwnBy( 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 = someOwnBy( obj, 1, sum, context ); +// returns true + +var mean = context.sum / context.count; +// returns 0.25 +``` + +
+ + + + + +
+ +## Notes + +- An [`Object`][mdn-object] refers to a JavaScript object, which is a collection of properties. Each property is an association between a key (or name) and a value. The key can be a string or a symbol, and the value can be any JavaScript value, including functions and other objects + +- If provided an empty `object`, the function returns `false`. + + ```javascript + function alwaysTrue() { + return true; + } + var bool = someOwnBy( {}, 1, alwaysTrue ); + // returns false + ``` + +- The function does **not** skip `undefined` elements. + + + + ```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 = someOwnBy( obj, 1, log ); + /* => + a: 1 + b: void 0 + c: void 0 + d: 4 + e: -1 + */ + ``` + +- The function provides limited support for dynamic objects (i.e., objects whose `length` changes during execution). + +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var someOwnBy = require( '@stdlib/object/some-own-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 = someOwnBy( obj, 5, threshold ); +// returns +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/object/some-own-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/object/some-own-by/benchmark/benchmark.js new file mode 100644 index 000000000000..87ce4fbc36d3 --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-by/benchmark/benchmark.js @@ -0,0 +1,109 @@ +/** +* @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 someOwnBy = 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 = someOwnBy( 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 keys; + var obj; + var key; + var i; + var j; + + 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; + keys = Object.keys( obj ); + for ( j = 0; j < keys.length; j++ ) { + key = keys[ j ]; + if ( 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-own-by/docs/repl.txt b/lib/node_modules/@stdlib/object/some-own-by/docs/repl.txt new file mode 100644 index 000000000000..05adb4c01412 --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-by/docs/repl.txt @@ -0,0 +1,45 @@ + +{{alias}}( obj, n, predicate[, thisArg ] ) + Tests whether some `own` properties of a provided object + satisfy a predicate function for at least `n` properties. + + 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's own properties satisfy a + predicate for at least `n` 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-own-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/object/some-own-by/docs/types/index.d.ts new file mode 100644 index 000000000000..81a19241b30c --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-by/docs/types/index.d.ts @@ -0,0 +1,102 @@ +/* +* @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 an own property in an object passes a test. +* +* @returns boolean indicating whether an own property in an object passes a test +*/ +type Nullary = () => boolean; + +/** +* Checks whether an own property in an object passes a test. +* +* @param value - object value +* @returns boolean indicating whether an own property in an object passes a test +*/ +type Unary = ( value: T ) => boolean; + +/** +* Checks whether an own property in an object passes a test. +* +* @param value - object value +* @param key - object key +* @returns boolean indicating whether an own property in an object passes a test +*/ +type Binary = ( value: T, key: keyof any ) => boolean; + +/** +* Checks whether an own property in an object passes a test. +* +* @param value - object value +* @param key - object key +* @param obj - input object +* @returns boolean indicating whether an own property in an object passes a test +*/ +type Ternary = ( value: T, key: keyof any, obj: Record ) => boolean; + +/** +* Checks whether an own property in an object passes a test. +* +* @param value - object value +* @param key - object key +* @param obj - input object +* @returns boolean indicating whether an own property in an object passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + +/** +* Tests whether an object contains at least `n` own properties 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 +* @returns boolean indicating whether an object contains at least `n` own 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 = someOwnBy( obj, 2, isNegative ); +* // returns true +*/ +declare function someOwnBy( obj: Record, n: number, predicate: Predicate ): boolean; + + +// EXPORTS // + +export = someOwnBy; diff --git a/lib/node_modules/@stdlib/object/some-own-by/docs/types/test.ts b/lib/node_modules/@stdlib/object/some-own-by/docs/types/test.ts new file mode 100644 index 000000000000..77fe05b56ee9 --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-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 someOwnBy = require( './index' ); + +const isPositive = ( v: number ): boolean => { + return ( v > 0 ); +}; + +// TESTS // + +// The function returns a boolean... +{ + someOwnBy( { 'a': 0, 'b': 1, 'c': 1 }, 2, isPositive ); // $ExpectType boolean + someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, 3, isPositive, {} ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided a first argument which is not an object... +{ + someOwnBy( 2, 2, isPositive ); // $ExpectError + someOwnBy( false, 2, isPositive ); // $ExpectError + someOwnBy( true, 2, isPositive ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, ( x: number ): number => x, isPositive ); // $ExpectError + someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, false, isPositive ); // $ExpectError + someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, true, isPositive ); // $ExpectError + someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, 'abc', isPositive ); // $ExpectError + someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, {}, isPositive ); // $ExpectError + someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, [], isPositive ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a function... +{ + someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, 2 ); // $ExpectError + someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, false ); // $ExpectError + someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, true ); // $ExpectError + someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, 'abc' ); // $ExpectError + someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, {} ); // $ExpectError + someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, [] ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + someOwnBy(); // $ExpectError + someOwnBy( { 'a': 1, 'b': 2, 'c': 3 } ); // $ExpectError + someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1 ); // $ExpectError + someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, isPositive, {}, 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/object/some-own-by/examples/index.js b/lib/node_modules/@stdlib/object/some-own-by/examples/index.js new file mode 100644 index 000000000000..dd2d2cf3ec3e --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-by/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 someOwnBy = require( './../lib' ); + +function threshold( value ) { + return ( value > 0.95 ); +} + +var bool; +var obj; +var i; + +obj = {}; +for ( i = 0; i < 100; i++ ) { + obj[ 'key' + i ] = randu(); +} + +bool = someOwnBy( obj, 5, threshold ); +console.log( bool ); diff --git a/lib/node_modules/@stdlib/object/some-own-by/lib/index.js b/lib/node_modules/@stdlib/object/some-own-by/lib/index.js new file mode 100644 index 000000000000..6377dfa70a4c --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-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 some own properties of a provided object satisfy a predicate function. +* +* @module @stdlib/object/some-own-by +* +* @example +* var someOwnBy = require( '@stdlib/object/some-own-by' ); +* +* function isNegative( v ) { +* return ( v < 0 ); +* } +* +* var obj = { a: 1, b: 2, c: -3, d: 4, e: -1 }; +* +* var bool = someOwnBy( obj, 2, isNegative ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/object/some-own-by/lib/main.js b/lib/node_modules/@stdlib/object/some-own-by/lib/main.js new file mode 100644 index 000000000000..3231f0f66b3c --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-by/lib/main.js @@ -0,0 +1,85 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Tests whether some own properties of a provided object satisfy 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 = someOwnBy( obj, 2, isNegative ); +* // returns true +*/ +function someOwnBy( 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 ( hasOwnProp( obj, key ) ) { + out = predicate.call( thisArg, obj[ key ], key, obj ); + if ( out ) { + count += 1; + if ( count === n ) { + return true; + } + } + } + } + return false; +} + + +// EXPORTS // + +module.exports = someOwnBy; diff --git a/lib/node_modules/@stdlib/object/some-own-by/package.json b/lib/node_modules/@stdlib/object/some-own-by/package.json new file mode 100644 index 000000000000..9a790b987f80 --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-by/package.json @@ -0,0 +1,72 @@ +{ + "name": "@stdlib/object/some-own-by", + "version": "0.0.0", + "description": "Test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties.", + "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", + "any", + "every", + "all", + "object", + "object.keys", + "iterate", + "predicate", + "own", + "some", + "values", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/object/some-own-by/test/test.js b/lib/node_modules/@stdlib/object/some-own-by/test/test.js new file mode 100644 index 000000000000..97ae50803b51 --- /dev/null +++ b/lib/node_modules/@stdlib/object/some-own-by/test/test.js @@ -0,0 +1,255 @@ +/** +* @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 someOwnBy = 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 someOwnBy, '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() { + someOwnBy( 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() { + someOwnBy({ + '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() { + someOwnBy({ + '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 = someOwnBy( obj, 1, foo ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `true` if an object contains at least `n` own properties which pass a test', function test( t ) { + var bool; + var obj; + + obj = { + 'a': 1, + 'b': -2, + 'c': 3, + 'd': -1 + }; + + bool = someOwnBy( obj, 2, isNegative ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `false` if an object does not contain at least `n` own properties which pass a test', function test( t ) { + var bool; + var obj; + + obj = { + 'a': -1, + 'b': -2, + 'c': -3 + }; + + bool = someOwnBy( obj, 1, isPositive ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `false` if an object does not contain at least `n` own properties which pass a test', function test( t ) { + var bool; + var obj; + + obj = { + 'a': -1.0, + 'b': -2.0, + 'c': -3.0 + }; + + bool = someOwnBy( obj, 4, isPositive ); + + t.strictEqual( bool, false, 'returns expected value' ); + 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 = someOwnBy( obj, 2, sum, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.sum/ctx.count, 0.25, 'expected result' ); + + t.end(); +}); + +tape( 'the function returns `false` if provided a regular expression or a date object (no own properties to test)', function test( t ) { + var values; + var i; + + values = [ + /.*/, + new Date() + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( someOwnBy( values[ i ], 1, threshold ), false, 'returns false when provided ' + values[ i ] ); + } + t.end(); + + function threshold( value ) { + return ( typeof value === 'number' ); + } +}); From d277d8a6e0118906fe6b2b35a3380593e7e59c8e Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Wed, 3 Dec 2025 15:11:38 +0530 Subject: [PATCH 2/4] remove: remove `someOwnBy` from namespace This commit removes the `someOwnBy` symbol from the `@stdlib/utils` namespace due to a package migration. BREAKING CHANGE: remove `someOwnBy` To migrate, users should access the same symbol via the `@stdlib/object` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/7374 --- .../@stdlib/utils/docs/types/index.d.ts | 33 ------------------- lib/node_modules/@stdlib/utils/lib/index.js | 9 ----- 2 files changed, 42 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 238d43883d90..03c94d10e478 100644 --- a/lib/node_modules/@stdlib/utils/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/docs/types/index.d.ts @@ -201,7 +201,6 @@ import sizeOf = require( '@stdlib/utils/size-of' ); import some = require( '@stdlib/utils/some' ); import someBy = require( '@stdlib/utils/some-by' ); import someByRight = require( '@stdlib/utils/some-by-right' ); -import someOwnBy = require( '@stdlib/utils/some-own-by' ); import tabulate = require( '@stdlib/utils/tabulate' ); import tabulateBy = require( '@stdlib/utils/tabulate-by' ); import timeit = require( '@stdlib/utils/timeit' ); @@ -5340,38 +5339,6 @@ interface Namespace { */ someByRight: typeof someByRight; - /** - * Tests whether an object contains at least `n` own properties 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 - * @returns boolean indicating whether an object contains at least `n` own 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 = ns.someOwnBy( obj, 2, isNegative ); - * // returns true - */ - someOwnBy: typeof someOwnBy; - /** * Generates a frequency table. * diff --git a/lib/node_modules/@stdlib/utils/lib/index.js b/lib/node_modules/@stdlib/utils/lib/index.js index 36f95b34573d..282601af296e 100644 --- a/lib/node_modules/@stdlib/utils/lib/index.js +++ b/lib/node_modules/@stdlib/utils/lib/index.js @@ -1669,15 +1669,6 @@ setReadOnly( utils, 'someBy', require( '@stdlib/utils/some-by' ) ); */ setReadOnly( utils, 'someByRight', require( '@stdlib/utils/some-by-right' ) ); -/** -* @name someOwnBy -* @memberof utils -* @readonly -* @type {Function} -* @see {@link module:@stdlib/utils/some-own-by} -*/ -setReadOnly( utils, 'someOwnBy', require( '@stdlib/utils/some-own-by' ) ); - /** * @name tabulate * @memberof utils From 845a526f3e29f2f8e5965fae8c13191be69bfbcd Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Wed, 3 Dec 2025 15:23:24 +0530 Subject: [PATCH 3/4] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/7374 --- .../@stdlib/namespace/alias2pkg/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 +- lib/node_modules/@stdlib/object/any-own-by/README.md | 4 ++-- lib/node_modules/@stdlib/object/every-own-by/README.md | 4 ++-- lib/node_modules/@stdlib/object/none-own-by/README.md | 4 ++-- lib/node_modules/@stdlib/object/some-in-by/README.md | 4 ++-- 13 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv index 5dd58d639665..22ed37f41e7e 100644 --- a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv @@ -2984,7 +2984,7 @@ someByAsync,"@stdlib/utils/async/some-by" someByRight,"@stdlib/utils/some-by-right" someByRightAsync,"@stdlib/utils/async/some-by-right" someInBy,"@stdlib/object/some-in-by" -someOwnBy,"@stdlib/utils/some-own-by" +someOwnBy,"@stdlib/object/some-own-by" SOTU,"@stdlib/datasets/sotu" SPACHE_REVISED,"@stdlib/datasets/spache-revised" SPAM_ASSASSIN,"@stdlib/datasets/spam-assassin" diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/a.js b/lib/node_modules/@stdlib/namespace/lib/namespace/a.js index 025a6f8a73ee..ce39f3f91f58 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/a.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/a.js @@ -394,7 +394,7 @@ ns.push({ '@stdlib/utils/any-by', '@stdlib/object/any-in-by', '@stdlib/object/every-own-by', - '@stdlib/utils/some-own-by' + '@stdlib/object/some-own-by' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/e.js b/lib/node_modules/@stdlib/namespace/lib/namespace/e.js index 1bf91b4a7b8f..c2e91e35295c 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/e.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/e.js @@ -279,7 +279,7 @@ ns.push({ '@stdlib/object/any-own-by', '@stdlib/object/every-in-by', '@stdlib/object/none-own-by', - '@stdlib/utils/some-own-by', + '@stdlib/object/some-own-by', '@stdlib/utils/every-by' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/n.js b/lib/node_modules/@stdlib/namespace/lib/namespace/n.js index a3032ece55e5..f4f19fae835e 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/n.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/n.js @@ -1065,7 +1065,7 @@ ns.push({ '@stdlib/object/every-own-by', '@stdlib/utils/for-own', '@stdlib/utils/none-by', - '@stdlib/utils/some-own-by' + '@stdlib/object/some-own-by' ] }); diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/s.js b/lib/node_modules/@stdlib/namespace/lib/namespace/s.js index 119bcce6fd9c..24b893bedb6e 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/s.js @@ -587,14 +587,14 @@ ns.push({ '@stdlib/object/any-in-by', '@stdlib/object/every-in-by', '@stdlib/utils/some-by', - '@stdlib/utils/some-own-by' + '@stdlib/object/some-own-by' ] }); ns.push({ 'alias': 'someOwnBy', - 'path': '@stdlib/utils/some-own-by', - 'value': require( '@stdlib/utils/some-own-by' ), + 'path': '@stdlib/object/some-own-by', + 'value': require( '@stdlib/object/some-own-by' ), 'type': 'Function', 'related': [ '@stdlib/object/any-own-by', diff --git a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv index 564b4fdebce5..90d807b0f21f 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv @@ -2984,7 +2984,7 @@ "@stdlib/utils/some-by-right",someByRight "@stdlib/utils/async/some-by-right",someByRightAsync "@stdlib/object/some-in-by",someInBy -"@stdlib/utils/some-own-by",someOwnBy +"@stdlib/object/some-own-by",someOwnBy "@stdlib/datasets/sotu",SOTU "@stdlib/datasets/spache-revised",SPACHE_REVISED "@stdlib/datasets/spam-assassin",SPAM_ASSASSIN diff --git a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv index 9be9a4d69161..2a9923697e8c 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv @@ -27,7 +27,7 @@ "@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/object/any-in-by","@stdlib/utils/any-by,@stdlib/object/any-own-by,@stdlib/object/every-in-by,@stdlib/object/some-in-by" -"@stdlib/object/any-own-by","@stdlib/utils/any-by,@stdlib/object/any-in-by,@stdlib/object/every-own-by,@stdlib/utils/some-own-by" +"@stdlib/object/any-own-by","@stdlib/utils/any-by,@stdlib/object/any-in-by,@stdlib/object/every-own-by,@stdlib/object/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" "@stdlib/array/one-to","@stdlib/array/full,@stdlib/array/ones,@stdlib/array/one-to-like,@stdlib/array/zero-to" @@ -1621,7 +1621,7 @@ "@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/object/any-in-by,@stdlib/object/none-in-by,@stdlib/object/some-in-by,@stdlib/object/every-own-by" -"@stdlib/object/every-own-by","@stdlib/object/any-own-by,@stdlib/object/every-in-by,@stdlib/object/none-own-by,@stdlib/utils/some-own-by,@stdlib/utils/every-by" +"@stdlib/object/every-own-by","@stdlib/object/any-own-by,@stdlib/object/every-in-by,@stdlib/object/none-own-by,@stdlib/object/some-own-by,@stdlib/utils/every-by" "@stdlib/utils/eval","" "@stdlib/process/exec-path","" "@stdlib/fs/exists","@stdlib/fs/read-file,@stdlib/fs/read-dir" @@ -2648,7 +2648,7 @@ "@stdlib/utils/nonenumerable-property-names-in","@stdlib/utils/keys-in,@stdlib/utils/inherited-nonenumerable-property-names,@stdlib/utils/nonenumerable-property-names,@stdlib/utils/property-names-in" "@stdlib/utils/nonenumerable-property-symbols","@stdlib/utils/enumerable-property-symbols,@stdlib/utils/inherited-nonenumerable-property-symbols,@stdlib/utils/nonenumerable-property-names,@stdlib/utils/nonenumerable-property-symbols-in,@stdlib/utils/property-symbols" "@stdlib/utils/nonenumerable-property-symbols-in","@stdlib/utils/enumerable-property-symbols-in,@stdlib/utils/inherited-nonenumerable-property-symbols,@stdlib/utils/nonenumerable-property-names-in,@stdlib/utils/nonenumerable-property-symbols,@stdlib/utils/property-symbols-in" -"@stdlib/object/none-own-by","@stdlib/object/any-own-by,@stdlib/object/every-own-by,@stdlib/utils/for-own,@stdlib/utils/none-by,@stdlib/utils/some-own-by" +"@stdlib/object/none-own-by","@stdlib/object/any-own-by,@stdlib/object/every-own-by,@stdlib/utils/for-own,@stdlib/utils/none-by,@stdlib/object/some-own-by" "@stdlib/utils/nonindex-keys","@stdlib/utils/entries,@stdlib/utils/keys,@stdlib/utils/values" "@stdlib/utils/noop","" "@stdlib/time/now","" @@ -2983,8 +2983,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/object/some-in-by","@stdlib/object/any-in-by,@stdlib/object/every-in-by,@stdlib/utils/some-by,@stdlib/utils/some-own-by" -"@stdlib/utils/some-own-by","@stdlib/object/any-own-by,@stdlib/object/every-own-by,@stdlib/utils/some-by,@stdlib/object/some-in-by" +"@stdlib/object/some-in-by","@stdlib/object/any-in-by,@stdlib/object/every-in-by,@stdlib/utils/some-by,@stdlib/object/some-own-by" +"@stdlib/object/some-own-by","@stdlib/object/any-own-by,@stdlib/object/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 78b62f8b83fb..8a7c9d619703 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv @@ -2984,7 +2984,7 @@ "@stdlib/utils/some-by-right","@stdlib/utils-some-by-right" "@stdlib/utils/async/some-by-right","@stdlib/utils-async-some-by-right" "@stdlib/object/some-in-by","@stdlib/object-some-in-by" -"@stdlib/utils/some-own-by","@stdlib/utils-some-own-by" +"@stdlib/object/some-own-by","@stdlib/object-some-own-by" "@stdlib/datasets/sotu","@stdlib/datasets-sotu" "@stdlib/datasets/spache-revised","@stdlib/datasets-spache-revised" "@stdlib/datasets/spam-assassin","@stdlib/datasets-spam-assassin" diff --git a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv index 3f383176be76..829dfec5e247 100644 --- a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv @@ -2984,7 +2984,7 @@ "@stdlib/utils-some-by-right","@stdlib/utils/some-by-right" "@stdlib/utils-async-some-by-right","@stdlib/utils/async/some-by-right" "@stdlib/object-some-in-by","@stdlib/object/some-in-by" -"@stdlib/utils-some-own-by","@stdlib/utils/some-own-by" +"@stdlib/object-some-own-by","@stdlib/object/some-own-by" "@stdlib/datasets-sotu","@stdlib/datasets/sotu" "@stdlib/datasets-spache-revised","@stdlib/datasets/spache-revised" "@stdlib/datasets-spam-assassin","@stdlib/datasets/spam-assassin" diff --git a/lib/node_modules/@stdlib/object/any-own-by/README.md b/lib/node_modules/@stdlib/object/any-own-by/README.md index 75215c005f54..827ddd648782 100644 --- a/lib/node_modules/@stdlib/object/any-own-by/README.md +++ b/lib/node_modules/@stdlib/object/any-own-by/README.md @@ -192,7 +192,7 @@ bool = anyOwnBy( obj, threshold ); - [`@stdlib/utils/any-by`][@stdlib/utils/any-by]: test whether at least one element in a collection passes a test implemented by a predicate function. - [`@stdlib/object/any-in-by`][@stdlib/object/any-in-by]: test whether at least one property in an object passes a test implemented by a predicate function. - [`@stdlib/object/every-own-by`][@stdlib/object/every-own-by]: test whether all own properties of an object pass a test implemented by a predicate function. -- [`@stdlib/utils/some-own-by`][@stdlib/utils/some-own-by]: test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties. +- [`@stdlib/object/some-own-by`][@stdlib/object/some-own-by]: test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties. @@ -212,7 +212,7 @@ bool = anyOwnBy( obj, threshold ); [@stdlib/object/every-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/every-own-by -[@stdlib/utils/some-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/some-own-by +[@stdlib/object/some-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/some-own-by diff --git a/lib/node_modules/@stdlib/object/every-own-by/README.md b/lib/node_modules/@stdlib/object/every-own-by/README.md index 7dda54f03abf..db3ef5965603 100644 --- a/lib/node_modules/@stdlib/object/every-own-by/README.md +++ b/lib/node_modules/@stdlib/object/every-own-by/README.md @@ -191,7 +191,7 @@ var bool = everyOwnBy( obj, isPositive ); - [`@stdlib/object/any-own-by`][@stdlib/object/any-own-by]: test whether whether any 'own' property of a provided object satisfies a predicate function. - [`@stdlib/object/every-in-by`][@stdlib/object/every-in-by]: test whether all properties (own and inherited) of an object pass a test implemented by a predicate function. - [`@stdlib/object/none-own-by`][@stdlib/object/none-own-by]: tests whether every own property of an object fails a test implemented by a predicate function. -- [`@stdlib/utils/some-own-by`][@stdlib/utils/some-own-by]: test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties. +- [`@stdlib/object/some-own-by`][@stdlib/object/some-own-by]: test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties. - [`@stdlib/utils/every-by`][@stdlib/utils/every-by]: test whether all elements in a collection pass a test implemented by a predicate function. @@ -212,7 +212,7 @@ var bool = everyOwnBy( obj, isPositive ); [@stdlib/object/none-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/none-own-by -[@stdlib/utils/some-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/some-own-by +[@stdlib/object/some-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/some-own-by [@stdlib/utils/every-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/every-by diff --git a/lib/node_modules/@stdlib/object/none-own-by/README.md b/lib/node_modules/@stdlib/object/none-own-by/README.md index d51f12e5cdd9..1bf7dedcdfe8 100644 --- a/lib/node_modules/@stdlib/object/none-own-by/README.md +++ b/lib/node_modules/@stdlib/object/none-own-by/README.md @@ -151,7 +151,7 @@ var bool = noneOwnBy( obj, isUnderage ); - [`@stdlib/object/every-own-by`][@stdlib/object/every-own-by]: test whether all own properties of an object pass a test implemented by a predicate function. - [`@stdlib/utils/for-own`][@stdlib/utils/for-own]: invoke a function for each own enumerable property of an object. - [`@stdlib/utils/none-by`][@stdlib/utils/none-by]: test whether all elements in a collection fail a test implemented by a predicate function. -- [`@stdlib/utils/some-own-by`][@stdlib/utils/some-own-by]: test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties. +- [`@stdlib/object/some-own-by`][@stdlib/object/some-own-by]: test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties. @@ -171,7 +171,7 @@ var bool = noneOwnBy( obj, isUnderage ); [@stdlib/utils/none-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/none-by -[@stdlib/utils/some-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/some-own-by +[@stdlib/object/some-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/some-own-by diff --git a/lib/node_modules/@stdlib/object/some-in-by/README.md b/lib/node_modules/@stdlib/object/some-in-by/README.md index 7b180471a73b..ffd44db38e3b 100644 --- a/lib/node_modules/@stdlib/object/some-in-by/README.md +++ b/lib/node_modules/@stdlib/object/some-in-by/README.md @@ -205,7 +205,7 @@ bool = someInBy( obj, 5, threshold ); - [`@stdlib/object/any-in-by`][@stdlib/object/any-in-by]: test whether at least one property in an object passes a test implemented by a predicate function. - [`@stdlib/object/every-in-by`][@stdlib/object/every-in-by]: test whether all properties (own and inherited) of an object pass a test implemented by a predicate function. - [`@stdlib/utils/some-by`][@stdlib/utils/some-by]: test whether a collection contains at least `n` elements which pass a test implemented by a predicate function. -- [`@stdlib/utils/some-own-by`][@stdlib/utils/some-own-by]: test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties. +- [`@stdlib/object/some-own-by`][@stdlib/object/some-own-by]: test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties. @@ -223,7 +223,7 @@ bool = someInBy( obj, 5, threshold ); [@stdlib/utils/some-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/some-by -[@stdlib/utils/some-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/some-own-by +[@stdlib/object/some-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/some-own-by From f130d779455d53286e091363adce9774fe2e7e6a Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Wed, 3 Dec 2025 15:26:30 +0530 Subject: [PATCH 4/4] remove: remove `utils/some-own-by` This commit removes `@stdlib/utils/some-own-by` in favor of `@stdlib/object/some-own-by`. BREAKING CHANGE: remove `utils/some-own-by` To migrate, users should update their require/import paths to use `@stdlib/object/some-own-by` which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/7374 --- .../@stdlib/utils/some-own-by/README.md | 251 ----------------- .../utils/some-own-by/benchmark/benchmark.js | 109 -------- .../@stdlib/utils/some-own-by/docs/repl.txt | 45 ---- .../utils/some-own-by/docs/types/index.d.ts | 102 ------- .../utils/some-own-by/docs/types/test.ts | 66 ----- .../utils/some-own-by/examples/index.js | 38 --- .../@stdlib/utils/some-own-by/lib/index.js | 46 ---- .../@stdlib/utils/some-own-by/lib/main.js | 85 ------ .../@stdlib/utils/some-own-by/package.json | 72 ----- .../@stdlib/utils/some-own-by/test/test.js | 255 ------------------ 10 files changed, 1069 deletions(-) delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/README.md delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/examples/index.js delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/lib/index.js delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/lib/main.js delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/package.json delete mode 100644 lib/node_modules/@stdlib/utils/some-own-by/test/test.js diff --git a/lib/node_modules/@stdlib/utils/some-own-by/README.md b/lib/node_modules/@stdlib/utils/some-own-by/README.md deleted file mode 100644 index a6577104f270..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-by/README.md +++ /dev/null @@ -1,251 +0,0 @@ - - -# someOwnBy - -> Test whether an object contains at least `n` own properties which pass a test implemented by a predicate function. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var someOwnBy = require( '@stdlib/utils/some-own-by' ); -``` - -#### someOwnBy( obj, n, predicate\[, thisArg ] ) - -Tests whether an `object` contains at least `n` own 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 = someOwnBy( 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 = someOwnBy( 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 = someOwnBy( obj, 1, sum, context ); -// returns true - -var mean = context.sum / context.count; -// returns 0.25 -``` - -
- - - - - -
- -## Notes - -- An [`Object`][mdn-object] refers to a JavaScript object, which is a collection of properties. Each property is an association between a key (or name) and a value. The key can be a string or a symbol, and the value can be any JavaScript value, including functions and other objects - -- If provided an empty `object`, the function returns `false`. - - ```javascript - function alwaysTrue() { - return true; - } - var bool = someOwnBy( {}, 1, alwaysTrue ); - // returns false - ``` - -- The function does **not** skip `undefined` elements. - - - - ```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 = someOwnBy( obj, 1, log ); - /* => - a: 1 - b: void 0 - c: void 0 - d: 4 - e: -1 - */ - ``` - -- The function provides limited support for dynamic objects (i.e., objects whose `length` changes during execution). - -
- - - - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var someOwnBy = require( '@stdlib/utils/some-own-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 = someOwnBy( obj, 5, threshold ); -// returns -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/utils/some-own-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/some-own-by/benchmark/benchmark.js deleted file mode 100644 index 87ce4fbc36d3..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-by/benchmark/benchmark.js +++ /dev/null @@ -1,109 +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 someOwnBy = 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 = someOwnBy( 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 keys; - var obj; - var key; - var i; - var j; - - 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; - keys = Object.keys( obj ); - for ( j = 0; j < keys.length; j++ ) { - key = keys[ j ]; - if ( 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-own-by/docs/repl.txt b/lib/node_modules/@stdlib/utils/some-own-by/docs/repl.txt deleted file mode 100644 index 05adb4c01412..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-by/docs/repl.txt +++ /dev/null @@ -1,45 +0,0 @@ - -{{alias}}( obj, n, predicate[, thisArg ] ) - Tests whether some `own` properties of a provided object - satisfy a predicate function for at least `n` properties. - - 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's own properties satisfy a - predicate for at least `n` 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-own-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/some-own-by/docs/types/index.d.ts deleted file mode 100644 index 81a19241b30c..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-by/docs/types/index.d.ts +++ /dev/null @@ -1,102 +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 an own property in an object passes a test. -* -* @returns boolean indicating whether an own property in an object passes a test -*/ -type Nullary = () => boolean; - -/** -* Checks whether an own property in an object passes a test. -* -* @param value - object value -* @returns boolean indicating whether an own property in an object passes a test -*/ -type Unary = ( value: T ) => boolean; - -/** -* Checks whether an own property in an object passes a test. -* -* @param value - object value -* @param key - object key -* @returns boolean indicating whether an own property in an object passes a test -*/ -type Binary = ( value: T, key: keyof any ) => boolean; - -/** -* Checks whether an own property in an object passes a test. -* -* @param value - object value -* @param key - object key -* @param obj - input object -* @returns boolean indicating whether an own property in an object passes a test -*/ -type Ternary = ( value: T, key: keyof any, obj: Record ) => boolean; - -/** -* Checks whether an own property in an object passes a test. -* -* @param value - object value -* @param key - object key -* @param obj - input object -* @returns boolean indicating whether an own property in an object passes a test -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Tests whether an object contains at least `n` own properties 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 -* @returns boolean indicating whether an object contains at least `n` own 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 = someOwnBy( obj, 2, isNegative ); -* // returns true -*/ -declare function someOwnBy( obj: Record, n: number, predicate: Predicate ): boolean; - - -// EXPORTS // - -export = someOwnBy; diff --git a/lib/node_modules/@stdlib/utils/some-own-by/docs/types/test.ts b/lib/node_modules/@stdlib/utils/some-own-by/docs/types/test.ts deleted file mode 100644 index 77fe05b56ee9..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-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 someOwnBy = require( './index' ); - -const isPositive = ( v: number ): boolean => { - return ( v > 0 ); -}; - -// TESTS // - -// The function returns a boolean... -{ - someOwnBy( { 'a': 0, 'b': 1, 'c': 1 }, 2, isPositive ); // $ExpectType boolean - someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, 3, isPositive, {} ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a first argument which is not an object... -{ - someOwnBy( 2, 2, isPositive ); // $ExpectError - someOwnBy( false, 2, isPositive ); // $ExpectError - someOwnBy( true, 2, isPositive ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, ( x: number ): number => x, isPositive ); // $ExpectError - someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, false, isPositive ); // $ExpectError - someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, true, isPositive ); // $ExpectError - someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, 'abc', isPositive ); // $ExpectError - someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, {}, isPositive ); // $ExpectError - someOwnBy( { 'a': -1, 'b': 1, 'c': 2 }, [], isPositive ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function... -{ - someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, 2 ); // $ExpectError - someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, false ); // $ExpectError - someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, true ); // $ExpectError - someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, 'abc' ); // $ExpectError - someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, {} ); // $ExpectError - someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - someOwnBy(); // $ExpectError - someOwnBy( { 'a': 1, 'b': 2, 'c': 3 } ); // $ExpectError - someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1 ); // $ExpectError - someOwnBy( { 'a': 1, 'b': 2, 'c': 3 }, 1, isPositive, {}, 3 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/utils/some-own-by/examples/index.js b/lib/node_modules/@stdlib/utils/some-own-by/examples/index.js deleted file mode 100644 index dd2d2cf3ec3e..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-by/examples/index.js +++ /dev/null @@ -1,38 +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 someOwnBy = require( './../lib' ); - -function threshold( value ) { - return ( value > 0.95 ); -} - -var bool; -var obj; -var i; - -obj = {}; -for ( i = 0; i < 100; i++ ) { - obj[ 'key' + i ] = randu(); -} - -bool = someOwnBy( obj, 5, threshold ); -console.log( bool ); diff --git a/lib/node_modules/@stdlib/utils/some-own-by/lib/index.js b/lib/node_modules/@stdlib/utils/some-own-by/lib/index.js deleted file mode 100644 index 10cb14d3d4f8..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-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 some own properties of a provided object satisfy a predicate function. -* -* @module @stdlib/utils/some-own-by -* -* @example -* var someOwnBy = require( '@stdlib/utils/some-own-by' ); -* -* function isNegative( v ) { -* return ( v < 0 ); -* } -* -* var obj = { a: 1, b: 2, c: -3, d: 4, e: -1 }; -* -* var bool = someOwnBy( obj, 2, isNegative ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/some-own-by/lib/main.js b/lib/node_modules/@stdlib/utils/some-own-by/lib/main.js deleted file mode 100644 index 3231f0f66b3c..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-by/lib/main.js +++ /dev/null @@ -1,85 +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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Tests whether some own properties of a provided object satisfy 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 = someOwnBy( obj, 2, isNegative ); -* // returns true -*/ -function someOwnBy( 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 ( hasOwnProp( obj, key ) ) { - out = predicate.call( thisArg, obj[ key ], key, obj ); - if ( out ) { - count += 1; - if ( count === n ) { - return true; - } - } - } - } - return false; -} - - -// EXPORTS // - -module.exports = someOwnBy; diff --git a/lib/node_modules/@stdlib/utils/some-own-by/package.json b/lib/node_modules/@stdlib/utils/some-own-by/package.json deleted file mode 100644 index 633e692baf29..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-by/package.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "name": "@stdlib/utils/some-own-by", - "version": "0.0.0", - "description": "Test whether some `own` properties of a provided object satisfy a predicate function for at least `n` properties.", - "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", - "any", - "every", - "all", - "object", - "object.keys", - "iterate", - "predicate", - "own", - "some", - "values", - "validate" - ] -} diff --git a/lib/node_modules/@stdlib/utils/some-own-by/test/test.js b/lib/node_modules/@stdlib/utils/some-own-by/test/test.js deleted file mode 100644 index 97ae50803b51..000000000000 --- a/lib/node_modules/@stdlib/utils/some-own-by/test/test.js +++ /dev/null @@ -1,255 +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 someOwnBy = 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 someOwnBy, '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() { - someOwnBy( 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() { - someOwnBy({ - '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() { - someOwnBy({ - '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 = someOwnBy( obj, 1, foo ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `true` if an object contains at least `n` own properties which pass a test', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 1, - 'b': -2, - 'c': 3, - 'd': -1 - }; - - bool = someOwnBy( obj, 2, isNegative ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `false` if an object does not contain at least `n` own properties which pass a test', function test( t ) { - var bool; - var obj; - - obj = { - 'a': -1, - 'b': -2, - 'c': -3 - }; - - bool = someOwnBy( obj, 1, isPositive ); - - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `false` if an object does not contain at least `n` own properties which pass a test', function test( t ) { - var bool; - var obj; - - obj = { - 'a': -1.0, - 'b': -2.0, - 'c': -3.0 - }; - - bool = someOwnBy( obj, 4, isPositive ); - - t.strictEqual( bool, false, 'returns expected value' ); - 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 = someOwnBy( obj, 2, sum, ctx ); - - t.strictEqual( bool, true, 'returns expected value' ); - t.strictEqual( ctx.sum/ctx.count, 0.25, 'expected result' ); - - t.end(); -}); - -tape( 'the function returns `false` if provided a regular expression or a date object (no own properties to test)', function test( t ) { - var values; - var i; - - values = [ - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.strictEqual( someOwnBy( values[ i ], 1, threshold ), false, 'returns false when provided ' + values[ i ] ); - } - t.end(); - - function threshold( value ) { - return ( typeof value === 'number' ); - } -});