From 9764a3e691011e9f2d957b51fc0b5766b1df9989 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sun, 20 Apr 2025 22:41:42 +0530 Subject: [PATCH 1/3] feat: add `object/every-own-by` Ref: https://github.com/stdlib-js/stdlib/issues/6752 --- .../@stdlib/object/every-own-by/README.md | 224 ++++++++++++++++++ .../every-own-by/benchmark/benchmark.js | 97 ++++++++ .../@stdlib/object/every-own-by/docs/repl.txt | 43 ++++ .../object/every-own-by/docs/types/index.d.ts | 102 ++++++++ .../object/every-own-by/docs/types/test.ts | 62 +++++ .../object/every-own-by/examples/index.js | 37 +++ .../@stdlib/object/every-own-by/lib/index.js | 46 ++++ .../@stdlib/object/every-own-by/lib/main.js | 77 ++++++ .../@stdlib/object/every-own-by/package.json | 68 ++++++ .../@stdlib/object/every-own-by/test/test.js | 179 ++++++++++++++ 10 files changed, 935 insertions(+) create mode 100644 lib/node_modules/@stdlib/object/every-own-by/README.md create mode 100644 lib/node_modules/@stdlib/object/every-own-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/object/every-own-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/object/every-own-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/object/every-own-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/object/every-own-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/object/every-own-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/object/every-own-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/object/every-own-by/package.json create mode 100644 lib/node_modules/@stdlib/object/every-own-by/test/test.js diff --git a/lib/node_modules/@stdlib/object/every-own-by/README.md b/lib/node_modules/@stdlib/object/every-own-by/README.md new file mode 100644 index 000000000000..1b26594d4505 --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-own-by/README.md @@ -0,0 +1,224 @@ + + +# everyOwnBy + +> Test whether all own propertes of an object pass a test implemented by a predicate function. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var everyOwnBy = require( '@stdlib/object/every-own-by' ); +``` + +#### everyOwnBy( object, predicate\[, thisArg ] ) + +Tests whether all `own` properties of an object pass a test implemented by a `predicate` function. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var obj = { + 'a': 1, + 'b': 2, + 'c': 3, + 'd': 4 +}; + +var bool = everyOwnBy( obj, isPositive ); +// returns true +``` + +If a `predicate` function returns a non-truthy value, the function **immediately** returns `false`. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var obj = { + 'a': 1, + 'b': -2, + 'c': 3, + 'd': 4 +}; + +var bool = everyOwnBy( obj, isPositive ); +// returns false +``` + +The invoked `function` is provided three arguments: + +- **value**: property value. +- **key**: property key. +- **obj**: input object. + +To set the function execution context, provide a `thisArg`. + +```javascript +function sum( value ) { + if ( value < 0 ) { + return false; + } + this.sum += value; + this.count += 1; + return true; +} + +var obj = { + 'a': 1, + 'b': 2, + 'c': 3 +}; + +var context = { + 'sum': 0, + 'count': 0 +}; + +var bool = everyOwnBy( obj, sum, context ); +// returns true + +var mean = context.sum / context.count; +// returns 2 +``` + +
+ + + + + +
+ +## Notes + +- If the 1st argument is not an [`object`][mdn-object] or the second argument is not a fuction , the + function throws a Type Error. + +- If provided an empty object, the function returns `true`. + + ```javascript + function untrue() { + return false; + } + var bool = everyOwnBy( {}, untrue ); + // returns true + ``` + +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var everyOwnBy = require( '@stdlib/object/every-own-by' ); + +function isPositive( value ) { + return ( value > 0 ); +} + +var obj = {}; +var i; + +// Populate object with random values +for ( i = 0; i < 100; i++ ) { + obj[ 'prop_' + i ] = randu(); +} + +var bool = everyOwnBy( obj, isPositive ); +// returns +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/object/every-own-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/object/every-own-by/benchmark/benchmark.js new file mode 100644 index 000000000000..7536111af4c6 --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-own-by/benchmark/benchmark.js @@ -0,0 +1,97 @@ +/** +* @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 everyOwnBy = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var bool; + var obj; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = { + 'a': i, + 'b': i+1, + 'c': i+2, + 'd': i+3, + 'e': i+4 + }; + bool = everyOwnBy( obj, 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(); + + function predicate( v ) { + return !isnan( v ); + } +}); + +bench( pkg+'::loop', function benchmark( b ) { + var bool; + var keys; + var obj; + var i; + var j; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = { + 'a': i, + 'b': i+1, + 'c': i+2, + 'd': i+3, + 'e': i+4 + }; + keys = Object.keys( obj ); + bool = true; + for ( j = 0; j < keys.length; j++ ) { + if ( isnan( obj[ keys[j] ] ) ) { + bool = false; + break; + } + } + 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(); +}); diff --git a/lib/node_modules/@stdlib/object/every-own-by/docs/repl.txt b/lib/node_modules/@stdlib/object/every-own-by/docs/repl.txt new file mode 100644 index 000000000000..1397d5a346d9 --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-own-by/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( object, predicate[, thisArg ] ) + Tests whether every own property of an object pass a test implemented by a + predicate function. + + The predicate function is provided three arguments: + + - value: property value. + - index: property key. + - object: the input object. + + The function immediately returns upon encountering a non-truthy return + value. + + If provided an empty object, the function returns `true`. + + Parameters + ---------- + object: Object + Input object. + + predicate: Function + Test function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + bool: boolean + The function returns `true` if the predicate function returns a truthy + value for all elements; otherwise, the function returns `false`. + + Examples + -------- + > function positive( v ) { return ( v > 0 ); }; + > var obj = { 'a': 1, 'b': 2, 'c': 3 }; + > var bool = {{alias}}( obj, positive ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/object/every-own-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/object/every-own-by/docs/types/index.d.ts new file mode 100644 index 000000000000..b133bceac8e6 --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-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 of the object passes the test. +* +* @returns boolean indicating whether an own property of the object passes the test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether an own property of the object passes the test. +* +* @param value - collection value +* @returns boolean indicating whether an own property of the object passes the test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether an own property of the object passes the test. +* +* @param value - property value +* @param key - property key +* @returns boolean indicating whether an own property of the object passes the test +*/ +type Binary = ( this: U, value: T, key: number ) => boolean; + +/** +* Checks whether an own property of the object passes the test. +* +* @param value - property value +* @param key - property key +* @param object - input object +* @returns boolean indicating whether an own property of the object passes the test +*/ +type Ternary = ( this: U, value: T, key: number, object: Object ) => boolean; + +/** +* Checks whether an own property of the object passes the test. +* +* @param value - property value +* @param key - property key +* @param object - input object +* @returns boolean indicating whether an own property of the object passes the tests +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + +/** +* Tests whether every property of an object passes a test implemented by a predicate function. +* +* ## Notes +* +* - The predicate function is provided three arguments: +* +* - `value`: collection value +* - `key`: collection key +* - `object`: the input object +* +* - The function immediately returns upon encountering a truthy return value. +* - If provided an empty object, the function returns `true`. +* +* @param object - input object +* @param predicate - test function +* @param thisArg - execution context +* @returns boolean indicating whether all own elements pass a test +* +* @example +* function isPositive( v ) { +* return ( v > 0 ); +* } +* +* var obj = { 'a': 1, 'b': 2, 'c': 3 }; +* +* var bool = everyOwnBy( obj, isPositive ); +* // returns true +*/ +declare function everyOwnBy( object: Record, predicate: Predicate, thisArg?: ThisParameterType> ): boolean; + + +// EXPORTS // + +export = everyOwnBy; diff --git a/lib/node_modules/@stdlib/object/every-own-by/docs/types/test.ts b/lib/node_modules/@stdlib/object/every-own-by/docs/types/test.ts new file mode 100644 index 000000000000..a839c1192f3b --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-own-by/docs/types/test.ts @@ -0,0 +1,62 @@ +/* +* @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 everyOwnBy = require( './index' ); + +const isPositive = ( v: number ): boolean => { + return ( v > 0 ); +}; + +// TESTS // + +var obj = { + 'a':1, + 'b':2, + 'c':3 +}; + +// The function returns a boolean... +{ + everyOwnBy( obj, isPositive ); // $ExpectType boolean + everyOwnBy( obj, isPositive ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided a first argument which is not an object... +{ + everyOwnBy( 2, isPositive ); // $ExpectError + everyOwnBy( false, isPositive ); // $ExpectError + everyOwnBy( true, isPositive ); // $ExpectError + everyOwnBy( [ 1, 2 ], isPositive ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a function... +{ + everyOwnBy( obj , 2 ); // $ExpectError + everyOwnBy( obj , false ); // $ExpectError + everyOwnBy( obj , true ); // $ExpectError + everyOwnBy( obj , 'abc' ); // $ExpectError + everyOwnBy( obj , {} ); // $ExpectError + everyOwnBy( obj , [] ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + everyOwnBy(); // $ExpectError + everyOwnBy( [ 1, 2, 3 ] ); // $ExpectError + everyOwnBy( [ 1, 2, 3 ], isPositive, {}, 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/object/every-own-by/examples/index.js b/lib/node_modules/@stdlib/object/every-own-by/examples/index.js new file mode 100644 index 000000000000..421313d0ffc5 --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-own-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 everyOwnBy = require( './../lib' ); + +function isPositive( value ) { + return ( value > 0 ); +} + +var bool; +var obj = {}; +var keys = [ 'a', 'b', 'c', 'd', 'e' ]; +var i; +for ( i = 0; i < keys.length; i++ ) { + obj[ keys[ i ] ] = randu(); +} + +bool = everyOwnBy( obj, isPositive ); +console.log( bool ); diff --git a/lib/node_modules/@stdlib/object/every-own-by/lib/index.js b/lib/node_modules/@stdlib/object/every-own-by/lib/index.js new file mode 100644 index 000000000000..a50a2a642d68 --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-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 every "own" property of a provided object passes a test implemented by a predicate function. +* +* @module @stdlib/object/every-own-by +* +* @example +* var every = require( '@stdlib/object/every-own-by' ); +* +* function isPositive( v ) { +* return ( v > 0 ); +* } +* +* var obj = { 'a': 1, 'b': 2, 'c': 3 }; +* +* var bool = everyOwnBy( obj, isPositive ); +* // returns true +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/object/every-own-by/lib/main.js b/lib/node_modules/@stdlib/object/every-own-by/lib/main.js new file mode 100644 index 000000000000..ae590a40a651 --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-own-by/lib/main.js @@ -0,0 +1,77 @@ +/** +* @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 isFunction = require( '@stdlib/assert/is-function' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Tests whether all own elements in a collection pass a test implemented by a predicate function. +* +* @param {Object} obj - input object +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @throws {TypeError} first argument must be an object +* @throws {TypeError} second argument must be a function +* @returns {boolean} boolean indicating whether all own elements pass a test +* +* @example +* function isPositive( v ) { +* return ( v > 0 ); +* } +* +* var obj = { +* 'a': 1, +* 'b': 2, +* 'c': 3 +* }; +* +* var bool = everyOwnBy( obj, isPositive ); +* // returns true +*/ +function everyOwnBy( obj, predicate, thisArg ) { + var key; + if ( !isObject( obj ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) ); + } + + for ( key in obj ) { + if ( hasOwnProp( obj, key ) ) { + if ( !predicate.call( thisArg, obj[ key ], key, obj ) ) { + return false; + } + } + } + return true; +} + + +// EXPORTS // + +module.exports = everyOwnBy; diff --git a/lib/node_modules/@stdlib/object/every-own-by/package.json b/lib/node_modules/@stdlib/object/every-own-by/package.json new file mode 100644 index 000000000000..872ee06eec7e --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-own-by/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/object/every-own-by", + "version": "0.0.0", + "description": "Test whether all own properties of an object 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", + "every", + "all", + "object.every", + "everyownby", + "iterate", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/object/every-own-by/test/test.js b/lib/node_modules/@stdlib/object/every-own-by/test/test.js new file mode 100644 index 000000000000..992a865add47 --- /dev/null +++ b/lib/node_modules/@stdlib/object/every-own-by/test/test.js @@ -0,0 +1,179 @@ +/** +* @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 everyOwnBy = require( './../lib' ); + + +// FUNCTIONS // + +function isPositive( value ) { + return ( value > 0 ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof everyOwnBy, '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() {}, + /.*/, + new Date() + ]; + for ( i =0; i < values.length; i++ ) { + t.throws( badValue( values ), TypeError, 'throws a type error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + everyOwnBy( 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() { + everyOwnBy( {}, value ); + }; + } +}); + +tape( 'if provided an empty object, the function returns `true`', function test( t ) { + var bool; + var obj; + + function foo() { + t.fail( 'should not be invoked' ); + } + obj = {}; + bool = everyOwnBy( obj, foo ); + + t.strictEqual( bool, true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `true` if all properties pass a test', function test( t ) { + var bool; + var obj; + + obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + + bool = everyOwnBy( obj, isPositive ); + + t.strictEqual( bool, true, 'returns true' ); + t.end(); +}); + +tape( 'the function returns `false` if one or more properties fail a test', function test( t ) { + var bool; + var obj; + + obj = { + 'a': 1, + 'b': -2, + 'c': 3 + }; + + bool = everyOwnBy( obj, 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 */ + if ( value < 0 ) { + return false; + } + this.sum += value; + this.count += 1; + return true; + } + + ctx = { + 'sum': 0, + 'count': 0 + }; + obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + + bool = everyOwnBy( obj, sum, ctx ); + + t.strictEqual( bool, true, 'returns true' ); + t.strictEqual( ctx.sum/ctx.count, 2.0, 'expected result' ); + + t.end(); +}); From 35b281999025fcd8236f7ca446cf44572cbb00f5 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sun, 20 Apr 2025 22:57:45 +0530 Subject: [PATCH 2/3] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/6752 --- .../@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 | 6 +++--- lib/node_modules/@stdlib/namespace/lib/namespace/n.js | 2 +- lib/node_modules/@stdlib/namespace/lib/namespace/s.js | 2 +- .../@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/utils/any-own-by/README.md | 4 ++-- lib/node_modules/@stdlib/utils/none-own-by/README.md | 4 ++-- lib/node_modules/@stdlib/utils/some-own-by/README.md | 4 ++-- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv index ba91e8f82c6d..9145e6b7440b 100644 --- a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv @@ -1617,7 +1617,7 @@ everyByAsync,"@stdlib/utils/async/every-by" everyByRight,"@stdlib/utils/every-by-right" everyByRightAsync,"@stdlib/utils/async/every-by-right" everyInBy,"@stdlib/object/every-in-by" -everyOwnBy,"@stdlib/utils/every-own-by" +everyOwnBy,"@stdlib/object/every-own-by" evil,"@stdlib/utils/eval" EXEC_PATH,"@stdlib/process/exec-path" exists,"@stdlib/fs/exists" diff --git a/lib/node_modules/@stdlib/namespace/alias2standalone/data/data.csv b/lib/node_modules/@stdlib/namespace/alias2standalone/data/data.csv index 1823ae842e33..05aeb5c7c91a 100644 --- a/lib/node_modules/@stdlib/namespace/alias2standalone/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/alias2standalone/data/data.csv @@ -1617,7 +1617,7 @@ everyByAsync,"@stdlib/utils-async-every-by" everyByRight,"@stdlib/utils-every-by-right" everyByRightAsync,"@stdlib/utils-async-every-by-right" everyInBy,"@stdlib/object-every-in-by" -everyOwnBy,"@stdlib/utils-every-own-by" +everyOwnBy,"@stdlib/object-every-own-by" evil,"@stdlib/utils-eval" EXEC_PATH,"@stdlib/process-exec-path" exists,"@stdlib/fs-exists" diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/a.js b/lib/node_modules/@stdlib/namespace/lib/namespace/a.js index 97f3c466e0b0..98e7e7ecc002 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/a.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/a.js @@ -393,7 +393,7 @@ ns.push({ 'related': [ '@stdlib/utils/any-by', '@stdlib/utils/any-in-by', - '@stdlib/utils/every-own-by', + '@stdlib/object/every-own-by', '@stdlib/utils/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 0770f5245b28..4e4dd700a642 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/e.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/e.js @@ -266,14 +266,14 @@ ns.push({ '@stdlib/utils/none-in-by', '@stdlib/utils/some-in-by', '@stdlib/utils/every-by', - '@stdlib/utils/every-own-by' + '@stdlib/object/every-own-by' ] }); ns.push({ 'alias': 'everyOwnBy', - 'path': '@stdlib/utils/every-own-by', - 'value': require( '@stdlib/utils/every-own-by' ), + 'path': '@stdlib/object/every-own-by', + 'value': require( '@stdlib/object/every-own-by' ), 'type': 'Function', 'related': [ '@stdlib/utils/any-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..8e0b94d60e60 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/n.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/n.js @@ -1062,7 +1062,7 @@ ns.push({ 'type': 'Function', 'related': [ '@stdlib/utils/any-own-by', - '@stdlib/utils/every-own-by', + '@stdlib/object/every-own-by', '@stdlib/utils/for-own', '@stdlib/utils/none-by', '@stdlib/utils/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 6acba8fdbab8..c850514cf5ee 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/s.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/s.js @@ -598,7 +598,7 @@ ns.push({ 'type': 'Function', 'related': [ '@stdlib/utils/any-own-by', - '@stdlib/utils/every-own-by', + '@stdlib/object/every-own-by', '@stdlib/utils/some-by', '@stdlib/utils/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 efd3cd8b0a4b..b932e51a4570 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv @@ -1617,7 +1617,7 @@ "@stdlib/utils/every-by-right",everyByRight "@stdlib/utils/async/every-by-right",everyByRightAsync "@stdlib/object/every-in-by",everyInBy -"@stdlib/utils/every-own-by",everyOwnBy +"@stdlib/object/every-own-by",everyOwnBy "@stdlib/utils/eval",evil "@stdlib/process/exec-path",EXEC_PATH "@stdlib/fs/exists",exists diff --git a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv index a81675e56ed2..e9a43ee3bcea 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/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-own-by","@stdlib/utils/any-by,@stdlib/utils/any-in-by,@stdlib/utils/every-own-by,@stdlib/utils/some-own-by" +"@stdlib/utils/any-own-by","@stdlib/utils/any-by,@stdlib/utils/any-in-by,@stdlib/object/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" "@stdlib/array/one-to","@stdlib/array/full,@stdlib/array/ones,@stdlib/array/one-to-like,@stdlib/array/zero-to" @@ -1616,8 +1616,8 @@ "@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/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/object/every-in-by","@stdlib/utils/any-in-by,@stdlib/utils/none-in-by,@stdlib/utils/some-in-by,@stdlib/utils/every-by,@stdlib/object/every-own-by" +"@stdlib/object/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","" "@stdlib/fs/exists","@stdlib/fs/read-file,@stdlib/fs/read-dir" @@ -2642,7 +2642,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/utils/none-own-by","@stdlib/utils/any-own-by,@stdlib/utils/every-own-by,@stdlib/utils/for-own,@stdlib/utils/none-by,@stdlib/utils/some-own-by" +"@stdlib/utils/none-own-by","@stdlib/utils/any-own-by,@stdlib/object/every-own-by,@stdlib/utils/for-own,@stdlib/utils/none-by,@stdlib/utils/some-own-by" "@stdlib/utils/nonindex-keys","@stdlib/utils/entries,@stdlib/utils/keys,@stdlib/utils/values" "@stdlib/utils/noop","" "@stdlib/time/now","" @@ -2978,7 +2978,7 @@ "@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/utils/some-own-by","@stdlib/utils/any-own-by,@stdlib/object/every-own-by,@stdlib/utils/some-by,@stdlib/utils/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 a006ae007f15..ec53489e31d3 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv @@ -1617,7 +1617,7 @@ "@stdlib/utils/every-by-right","@stdlib/utils-every-by-right" "@stdlib/utils/async/every-by-right","@stdlib/utils-async-every-by-right" "@stdlib/object/every-in-by","@stdlib/object-every-in-by" -"@stdlib/utils/every-own-by","@stdlib/utils-every-own-by" +"@stdlib/object/every-own-by","@stdlib/object-every-own-by" "@stdlib/utils/eval","@stdlib/utils-eval" "@stdlib/process/exec-path","@stdlib/process-exec-path" "@stdlib/fs/exists","@stdlib/fs-exists" diff --git a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv index 271a3a296207..57cda1b7c9d3 100644 --- a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv @@ -1617,7 +1617,7 @@ "@stdlib/utils-every-by-right","@stdlib/utils/every-by-right" "@stdlib/utils-async-every-by-right","@stdlib/utils/async/every-by-right" "@stdlib/object-every-in-by","@stdlib/object/every-in-by" -"@stdlib/utils-every-own-by","@stdlib/utils/every-own-by" +"@stdlib/object-every-own-by","@stdlib/object/every-own-by" "@stdlib/utils-eval","@stdlib/utils/eval" "@stdlib/process-exec-path","@stdlib/process/exec-path" "@stdlib/fs-exists","@stdlib/fs/exists" diff --git a/lib/node_modules/@stdlib/utils/any-own-by/README.md b/lib/node_modules/@stdlib/utils/any-own-by/README.md index 32785b274d7a..a753aa84d501 100644 --- a/lib/node_modules/@stdlib/utils/any-own-by/README.md +++ b/lib/node_modules/@stdlib/utils/any-own-by/README.md @@ -191,7 +191,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/utils/any-in-by`][@stdlib/utils/any-in-by]: test whether at least one property in an object passes a test implemented by a predicate function. -- [`@stdlib/utils/every-own-by`][@stdlib/utils/every-own-by]: test whether all own properties of an object pass 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. @@ -210,7 +210,7 @@ bool = anyOwnBy( obj, threshold ); [@stdlib/utils/any-in-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/any-in-by -[@stdlib/utils/every-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/every-own-by +[@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 diff --git a/lib/node_modules/@stdlib/utils/none-own-by/README.md b/lib/node_modules/@stdlib/utils/none-own-by/README.md index bec03b9b204d..aa9e23aa1283 100644 --- a/lib/node_modules/@stdlib/utils/none-own-by/README.md +++ b/lib/node_modules/@stdlib/utils/none-own-by/README.md @@ -148,7 +148,7 @@ var bool = noneOwnBy( obj, isUnderage ); ## See Also - [`@stdlib/utils/any-own-by`][@stdlib/utils/any-own-by]: test whether whether any 'own' property of a provided object satisfies a predicate function. -- [`@stdlib/utils/every-own-by`][@stdlib/utils/every-own-by]: test whether all own properties of an object pass 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/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. @@ -165,7 +165,7 @@ var bool = noneOwnBy( obj, isUnderage ); [@stdlib/utils/any-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/any-own-by -[@stdlib/utils/every-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/every-own-by +[@stdlib/object/every-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/every-own-by [@stdlib/utils/for-own]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/for-own diff --git a/lib/node_modules/@stdlib/utils/some-own-by/README.md b/lib/node_modules/@stdlib/utils/some-own-by/README.md index 165225506522..38c90d246b78 100644 --- a/lib/node_modules/@stdlib/utils/some-own-by/README.md +++ b/lib/node_modules/@stdlib/utils/some-own-by/README.md @@ -220,7 +220,7 @@ bool = someOwnBy( obj, 5, threshold ); ## See Also - [`@stdlib/utils/any-own-by`][@stdlib/utils/any-own-by]: test whether whether any 'own' property of a provided object satisfies a predicate function. -- [`@stdlib/utils/every-own-by`][@stdlib/utils/every-own-by]: test whether all own properties of an object pass 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-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-in-by`][@stdlib/utils/some-in-by]: test whether an object contains at least n properties (own and inherited) which pass a test implemented by a predicate function. @@ -238,7 +238,7 @@ bool = someOwnBy( obj, 5, threshold ); [@stdlib/utils/any-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/any-own-by -[@stdlib/utils/every-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/every-own-by +[@stdlib/object/every-own-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/every-own-by [@stdlib/utils/some-by]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/some-by From 4817affe594ef1e952c523e8d3aa0911e8fa0983 Mon Sep 17 00:00:00 2001 From: Neerajpathak07 Date: Sun, 20 Apr 2025 22:58:35 +0530 Subject: [PATCH 3/3] remove: remove `utils/every-own-by` This commit removes `@stdlib/utils/every-own-by` in favor of `@stdlib/object/every-own-by`. BREAKING CHANGE: remove `utils/every-own-by` To migrate, users should update their require/import paths to use `@stdlib/object/every-own-by` which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/6752 --- .../@stdlib/utils/every-own-by/README.md | 224 ------------------ .../utils/every-own-by/benchmark/benchmark.js | 97 -------- .../@stdlib/utils/every-own-by/docs/repl.txt | 43 ---- .../utils/every-own-by/docs/types/index.d.ts | 102 -------- .../utils/every-own-by/docs/types/test.ts | 62 ----- .../utils/every-own-by/examples/index.js | 37 --- .../@stdlib/utils/every-own-by/lib/index.js | 46 ---- .../@stdlib/utils/every-own-by/lib/main.js | 77 ------ .../@stdlib/utils/every-own-by/package.json | 68 ------ .../@stdlib/utils/every-own-by/test/test.js | 179 -------------- 10 files changed, 935 deletions(-) delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/README.md delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/examples/index.js delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/lib/index.js delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/lib/main.js delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/package.json delete mode 100644 lib/node_modules/@stdlib/utils/every-own-by/test/test.js diff --git a/lib/node_modules/@stdlib/utils/every-own-by/README.md b/lib/node_modules/@stdlib/utils/every-own-by/README.md deleted file mode 100644 index c9bf66eff053..000000000000 --- a/lib/node_modules/@stdlib/utils/every-own-by/README.md +++ /dev/null @@ -1,224 +0,0 @@ - - -# everyOwnBy - -> Test whether all own propertes of an object pass a test implemented by a predicate function. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var everyOwnBy = require( '@stdlib/utils/every-own-by' ); -``` - -#### everyOwnBy( object, predicate\[, thisArg ] ) - -Tests whether all `own` properties of an object pass a test implemented by a `predicate` function. - -```javascript -function isPositive( value ) { - return ( value > 0 ); -} - -var obj = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4 -}; - -var bool = everyOwnBy( obj, isPositive ); -// returns true -``` - -If a `predicate` function returns a non-truthy value, the function **immediately** returns `false`. - -```javascript -function isPositive( value ) { - return ( value > 0 ); -} - -var obj = { - 'a': 1, - 'b': -2, - 'c': 3, - 'd': 4 -}; - -var bool = everyOwnBy( obj, isPositive ); -// returns false -``` - -The invoked `function` is provided three arguments: - -- **value**: property value. -- **key**: property key. -- **obj**: input object. - -To set the function execution context, provide a `thisArg`. - -```javascript -function sum( value ) { - if ( value < 0 ) { - return false; - } - this.sum += value; - this.count += 1; - return true; -} - -var obj = { - 'a': 1, - 'b': 2, - 'c': 3 -}; - -var context = { - 'sum': 0, - 'count': 0 -}; - -var bool = everyOwnBy( obj, sum, context ); -// returns true - -var mean = context.sum / context.count; -// returns 2 -``` - -
- - - - - -
- -## Notes - -- If the 1st argument is not an [`object`][mdn-object] or the second argument is not a fuction , the - function throws a Type Error. - -- If provided an empty object, the function returns `true`. - - ```javascript - function untrue() { - return false; - } - var bool = everyOwnBy( {}, untrue ); - // returns true - ``` - -
- - - - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var everyOwnBy = require( '@stdlib/utils/every-own-by' ); - -function isPositive( value ) { - return ( value > 0 ); -} - -var obj = {}; -var i; - -// Populate object with random values -for ( i = 0; i < 100; i++ ) { - obj[ 'prop_' + i ] = randu(); -} - -var bool = everyOwnBy( obj, isPositive ); -// returns -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/utils/every-own-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/every-own-by/benchmark/benchmark.js deleted file mode 100644 index 7536111af4c6..000000000000 --- a/lib/node_modules/@stdlib/utils/every-own-by/benchmark/benchmark.js +++ /dev/null @@ -1,97 +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 everyOwnBy = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj = { - 'a': i, - 'b': i+1, - 'c': i+2, - 'd': i+3, - 'e': i+4 - }; - bool = everyOwnBy( obj, 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(); - - function predicate( v ) { - return !isnan( v ); - } -}); - -bench( pkg+'::loop', function benchmark( b ) { - var bool; - var keys; - var obj; - var i; - var j; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj = { - 'a': i, - 'b': i+1, - 'c': i+2, - 'd': i+3, - 'e': i+4 - }; - keys = Object.keys( obj ); - bool = true; - for ( j = 0; j < keys.length; j++ ) { - if ( isnan( obj[ keys[j] ] ) ) { - bool = false; - break; - } - } - 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(); -}); diff --git a/lib/node_modules/@stdlib/utils/every-own-by/docs/repl.txt b/lib/node_modules/@stdlib/utils/every-own-by/docs/repl.txt deleted file mode 100644 index 1397d5a346d9..000000000000 --- a/lib/node_modules/@stdlib/utils/every-own-by/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( object, predicate[, thisArg ] ) - Tests whether every own property of an object pass a test implemented by a - predicate function. - - The predicate function is provided three arguments: - - - value: property value. - - index: property key. - - object: the input object. - - The function immediately returns upon encountering a non-truthy return - value. - - If provided an empty object, the function returns `true`. - - Parameters - ---------- - object: Object - Input object. - - predicate: Function - Test function. - - thisArg: any (optional) - Execution context. - - Returns - ------- - bool: boolean - The function returns `true` if the predicate function returns a truthy - value for all elements; otherwise, the function returns `false`. - - Examples - -------- - > function positive( v ) { return ( v > 0 ); }; - > var obj = { 'a': 1, 'b': 2, 'c': 3 }; - > var bool = {{alias}}( obj, positive ) - true - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/utils/every-own-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/every-own-by/docs/types/index.d.ts deleted file mode 100644 index b133bceac8e6..000000000000 --- a/lib/node_modules/@stdlib/utils/every-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 of the object passes the test. -* -* @returns boolean indicating whether an own property of the object passes the test -*/ -type Nullary = ( this: U ) => boolean; - -/** -* Checks whether an own property of the object passes the test. -* -* @param value - collection value -* @returns boolean indicating whether an own property of the object passes the test -*/ -type Unary = ( this: U, value: T ) => boolean; - -/** -* Checks whether an own property of the object passes the test. -* -* @param value - property value -* @param key - property key -* @returns boolean indicating whether an own property of the object passes the test -*/ -type Binary = ( this: U, value: T, key: number ) => boolean; - -/** -* Checks whether an own property of the object passes the test. -* -* @param value - property value -* @param key - property key -* @param object - input object -* @returns boolean indicating whether an own property of the object passes the test -*/ -type Ternary = ( this: U, value: T, key: number, object: Object ) => boolean; - -/** -* Checks whether an own property of the object passes the test. -* -* @param value - property value -* @param key - property key -* @param object - input object -* @returns boolean indicating whether an own property of the object passes the tests -*/ -type Predicate = Nullary | Unary | Binary | Ternary; - -/** -* Tests whether every property of an object passes a test implemented by a predicate function. -* -* ## Notes -* -* - The predicate function is provided three arguments: -* -* - `value`: collection value -* - `key`: collection key -* - `object`: the input object -* -* - The function immediately returns upon encountering a truthy return value. -* - If provided an empty object, the function returns `true`. -* -* @param object - input object -* @param predicate - test function -* @param thisArg - execution context -* @returns boolean indicating whether all own elements pass a test -* -* @example -* function isPositive( v ) { -* return ( v > 0 ); -* } -* -* var obj = { 'a': 1, 'b': 2, 'c': 3 }; -* -* var bool = everyOwnBy( obj, isPositive ); -* // returns true -*/ -declare function everyOwnBy( object: Record, predicate: Predicate, thisArg?: ThisParameterType> ): boolean; - - -// EXPORTS // - -export = everyOwnBy; diff --git a/lib/node_modules/@stdlib/utils/every-own-by/docs/types/test.ts b/lib/node_modules/@stdlib/utils/every-own-by/docs/types/test.ts deleted file mode 100644 index a839c1192f3b..000000000000 --- a/lib/node_modules/@stdlib/utils/every-own-by/docs/types/test.ts +++ /dev/null @@ -1,62 +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 everyOwnBy = require( './index' ); - -const isPositive = ( v: number ): boolean => { - return ( v > 0 ); -}; - -// TESTS // - -var obj = { - 'a':1, - 'b':2, - 'c':3 -}; - -// The function returns a boolean... -{ - everyOwnBy( obj, isPositive ); // $ExpectType boolean - everyOwnBy( obj, isPositive ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a first argument which is not an object... -{ - everyOwnBy( 2, isPositive ); // $ExpectError - everyOwnBy( false, isPositive ); // $ExpectError - everyOwnBy( true, isPositive ); // $ExpectError - everyOwnBy( [ 1, 2 ], isPositive ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a function... -{ - everyOwnBy( obj , 2 ); // $ExpectError - everyOwnBy( obj , false ); // $ExpectError - everyOwnBy( obj , true ); // $ExpectError - everyOwnBy( obj , 'abc' ); // $ExpectError - everyOwnBy( obj , {} ); // $ExpectError - everyOwnBy( obj , [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - everyOwnBy(); // $ExpectError - everyOwnBy( [ 1, 2, 3 ] ); // $ExpectError - everyOwnBy( [ 1, 2, 3 ], isPositive, {}, 3 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/utils/every-own-by/examples/index.js b/lib/node_modules/@stdlib/utils/every-own-by/examples/index.js deleted file mode 100644 index 421313d0ffc5..000000000000 --- a/lib/node_modules/@stdlib/utils/every-own-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 everyOwnBy = require( './../lib' ); - -function isPositive( value ) { - return ( value > 0 ); -} - -var bool; -var obj = {}; -var keys = [ 'a', 'b', 'c', 'd', 'e' ]; -var i; -for ( i = 0; i < keys.length; i++ ) { - obj[ keys[ i ] ] = randu(); -} - -bool = everyOwnBy( obj, isPositive ); -console.log( bool ); diff --git a/lib/node_modules/@stdlib/utils/every-own-by/lib/index.js b/lib/node_modules/@stdlib/utils/every-own-by/lib/index.js deleted file mode 100644 index c969974ef4b3..000000000000 --- a/lib/node_modules/@stdlib/utils/every-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 every "own" property of a provided object passes a test implemented by a predicate function. -* -* @module @stdlib/utils/every-own-by -* -* @example -* var every = require( '@stdlib/utils/every-own-by' ); -* -* function isPositive( v ) { -* return ( v > 0 ); -* } -* -* var obj = { 'a': 1, 'b': 2, 'c': 3 }; -* -* var bool = everyOwnBy( obj, isPositive ); -* // returns true -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/every-own-by/lib/main.js b/lib/node_modules/@stdlib/utils/every-own-by/lib/main.js deleted file mode 100644 index ae590a40a651..000000000000 --- a/lib/node_modules/@stdlib/utils/every-own-by/lib/main.js +++ /dev/null @@ -1,77 +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 isFunction = require( '@stdlib/assert/is-function' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Tests whether all own elements in a collection pass a test implemented by a predicate function. -* -* @param {Object} obj - input object -* @param {Function} predicate - test function -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an object -* @throws {TypeError} second argument must be a function -* @returns {boolean} boolean indicating whether all own elements pass a test -* -* @example -* function isPositive( v ) { -* return ( v > 0 ); -* } -* -* var obj = { -* 'a': 1, -* 'b': 2, -* 'c': 3 -* }; -* -* var bool = everyOwnBy( obj, isPositive ); -* // returns true -*/ -function everyOwnBy( obj, predicate, thisArg ) { - var key; - if ( !isObject( obj ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); - } - if ( !isFunction( predicate ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) ); - } - - for ( key in obj ) { - if ( hasOwnProp( obj, key ) ) { - if ( !predicate.call( thisArg, obj[ key ], key, obj ) ) { - return false; - } - } - } - return true; -} - - -// EXPORTS // - -module.exports = everyOwnBy; diff --git a/lib/node_modules/@stdlib/utils/every-own-by/package.json b/lib/node_modules/@stdlib/utils/every-own-by/package.json deleted file mode 100644 index 9a5a3d061e5e..000000000000 --- a/lib/node_modules/@stdlib/utils/every-own-by/package.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "name": "@stdlib/utils/every-own-by", - "version": "0.0.0", - "description": "Test whether all own properties of an object 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", - "every", - "all", - "object.every", - "everyownby", - "iterate", - "validate" - ] -} diff --git a/lib/node_modules/@stdlib/utils/every-own-by/test/test.js b/lib/node_modules/@stdlib/utils/every-own-by/test/test.js deleted file mode 100644 index 992a865add47..000000000000 --- a/lib/node_modules/@stdlib/utils/every-own-by/test/test.js +++ /dev/null @@ -1,179 +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 everyOwnBy = require( './../lib' ); - - -// FUNCTIONS // - -function isPositive( value ) { - return ( value > 0 ); -} - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof everyOwnBy, '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() {}, - /.*/, - new Date() - ]; - for ( i =0; i < values.length; i++ ) { - t.throws( badValue( values ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - everyOwnBy( 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() { - everyOwnBy( {}, value ); - }; - } -}); - -tape( 'if provided an empty object, the function returns `true`', function test( t ) { - var bool; - var obj; - - function foo() { - t.fail( 'should not be invoked' ); - } - obj = {}; - bool = everyOwnBy( obj, foo ); - - t.strictEqual( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `true` if all properties pass a test', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - - bool = everyOwnBy( obj, isPositive ); - - t.strictEqual( bool, true, 'returns true' ); - t.end(); -}); - -tape( 'the function returns `false` if one or more properties fail a test', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 1, - 'b': -2, - 'c': 3 - }; - - bool = everyOwnBy( obj, 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 */ - if ( value < 0 ) { - return false; - } - this.sum += value; - this.count += 1; - return true; - } - - ctx = { - 'sum': 0, - 'count': 0 - }; - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - - bool = everyOwnBy( obj, sum, ctx ); - - t.strictEqual( bool, true, 'returns true' ); - t.strictEqual( ctx.sum/ctx.count, 2.0, 'expected result' ); - - t.end(); -});