From 009160a039a0f215e509a648365a58ac7c1141f3 Mon Sep 17 00:00:00 2001 From: the-r3aper7 Date: Wed, 28 Feb 2024 23:44:53 +0530 Subject: [PATCH 01/11] feat: added utils/every-in-by --- .../utils/every-in-by/benchmark/benchmark.js | 64 +++++++ .../@stdlib/utils/every-in-by/docs/repl.txt | 43 +++++ .../utils/every-in-by/docs/types/index.d.ts | 39 ++++ .../utils/every-in-by/docs/types/test.ts | 61 ++++++ .../utils/every-in-by/examples/index.js | 38 ++++ .../@stdlib/utils/every-in-by/lib/index.js | 51 +++++ .../@stdlib/utils/every-in-by/lib/main.js | 71 +++++++ .../@stdlib/utils/every-in-by/package.json | 70 +++++++ .../@stdlib/utils/every-in-by/test/test.js | 180 ++++++++++++++++++ 9 files changed, 617 insertions(+) create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/examples/index.js create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/lib/main.js create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/package.json create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/test/test.js diff --git a/lib/node_modules/@stdlib/utils/every-in-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/every-in-by/benchmark/benchmark.js new file mode 100644 index 000000000000..bb88a5b4f78e --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-by/benchmark/benchmark.js @@ -0,0 +1,64 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var everyInBy = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var bool; + var obj; + var i; + + function predicate( v ) { + return !isnan( v ); + } + + obj = { + 'a': 'beep', + 'b': 'boop', + 'c': 'foo', + 'd': 'bar', + 'e': randu() + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj.e = randu(); + bool = everyInBy( 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(); +}); diff --git a/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt b/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt new file mode 100644 index 000000000000..7e8cc2d26884 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( object, predicate[, thisArg ] ) + Tests whether all elements in a object pass a test implemented by a + predicate function, iterating from right to left. + + The predicate function is provided three arguments: + + - `value`: object value + - `key`: object 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 over which to iterate. + + predicate: Function + The 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 o = {a: 1, b: 2, c: 3}; + > var bool = {{alias}}( o, positive ) + true + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts new file mode 100644 index 000000000000..28460110321a --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts @@ -0,0 +1,39 @@ +/** +* @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. +*/ + +// Define types for functions/arguments +type Predicate = ( value: T, key: string, obj: object ) => boolean; + +/** + * Checks whether all own and inherited properties in an object pass a test implemented by a predicate function. + * + * @param obj - The object to iterate over. + * @param predicate - The test function to apply to each property. + * @param thisArg - Optional execution context for the predicate function. + * @returns boolean indicating whether all properties pass the test. + * + * @throws TypeError if `obj` is not an object or if `predicate` is not a function. + */ +declare function everyInBy( + obj: object, + predicate: Predicate, + thisArg?: ThisParameterType> +): boolean; + +// Export the function +export = everyInBy; diff --git a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/test.ts b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/test.ts new file mode 100644 index 000000000000..5a757d9aba32 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/test.ts @@ -0,0 +1,61 @@ +/** +* @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 everyInBy = require( './index' ); + + +// TESTS // + +function isPositive( v: number ): boolean { + if ( typeof v !== 'object' || v === null ) { + throw new TypeError( 'Expected an object' ); + } + + return v > 0; +} + + +// The function returns a boolean... +{ + everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, isPositive ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided a first argument which is not a object... +{ + everyInBy( 2 ); // $ExpectError + everyInBy( false ); // $ExpectError + everyInBy( true ); // $ExpectError + everyInBy( [1, 2, 3, 4] ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a function... +{ + everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, 2 ); // $ExpectError + everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, false ); // $ExpectError + everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, true ); // $ExpectError + everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, 'abc' ); // $ExpectError + everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, {} ); // $ExpectError + everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, [] ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + everyInBy(); // $ExpectError + everyInBy( { 'a': 1, 'b': 2, 'c': 3} ); // $ExpectError + everyInBy( { 'a': 1, 'b': 2, 'c': 3 }, {}, 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/utils/every-in-by/examples/index.js b/lib/node_modules/@stdlib/utils/every-in-by/examples/index.js new file mode 100644 index 000000000000..9cc41d83f966 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-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 everyInBy = require( './../lib' ); + +function isPositive( value ) { + return ( value > 0 ); +} + +var o; +var i; +var bool; + +o = {}; +for ( i = 0; i < 100; i++ ) { + o[ i ] = randu(); +} + +bool = everyInBy( o, isPositive ); +console.log( bool ); diff --git a/lib/node_modules/@stdlib/utils/every-in-by/lib/index.js b/lib/node_modules/@stdlib/utils/every-in-by/lib/index.js new file mode 100644 index 000000000000..bed108dfe86c --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-by/lib/index.js @@ -0,0 +1,51 @@ +/** +* @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 all elements in a collection pass a test implemented by a predicate function, iterating from left to right. +* +* @module @stdlib/utils/every-in-by +* +* @example +* var everyInBy = require( '@stdlib/utils/every-in-by' ); +* +* function isPositive( v ) { +* return ( v > 0 ); +* } +* +* var o = { a: 1, b: 2, c: 3 } +* +* var bool = everyInBy( o, isPositive ) +* // returns true +* +* o.a = -1 +* +* bool = everyInBy( o, isPositive ) +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js b/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js new file mode 100644 index 000000000000..afadcd6a0eef --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js @@ -0,0 +1,71 @@ +/** +* @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 format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Tests whether all elements in a object 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 a object +* @throws {TypeError} second argument must be a function +* @returns {boolean} boolean indicating whether all elements pass a test +* +* @example +* function isPositive( v ) { +* return ( v > 0 ); +* } +* +* var o = { a: 1, b: 2, c: 3 }; +* +* var bool = everyInBy( o, isPositive ); +* // returns true +*/ +function everyInBy( 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 (!predicate.call(thisArg, obj[key], key, obj)) { + return false; + } + } + + return true; +} + + +// EXPORTS // + +module.exports = everyInBy; diff --git a/lib/node_modules/@stdlib/utils/every-in-by/package.json b/lib/node_modules/@stdlib/utils/every-in-by/package.json new file mode 100644 index 000000000000..2dd5a626df0b --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-by/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/utils/every-in-by", + "version": "0.0.0", + "description": "Test whether all elements in a object pass a test implemented by a predicate function, iterating from left to right.", + "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", + "everyright", + "array.every", + "iterate", + "collection", + "array-like", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/utils/every-in-by/test/test.js b/lib/node_modules/@stdlib/utils/every-in-by/test/test.js new file mode 100644 index 000000000000..6a843060861e --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-by/test/test.js @@ -0,0 +1,180 @@ +/** +* @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 everyInBy = require( './../lib' ); // Replace './lib' with the actual path to your function + + +// TESTS // + +tape('main export is a function', function test(t) { + t.ok(true, __filename); + t.strictEqual(typeof everyInBy, '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[i]), TypeError, 'throws a type error when provided ' + values[i]); + } + t.end(); + + function badValue(value) { + return function badValue() { + everyInBy(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() { + everyInBy({}, value); + }; + } +}); + +tape('if provided an empty object, the function returns `true`', function test(t) { + var bool; + var obj; + + obj = {}; + bool = everyInBy(obj, noop); + + t.strictEqual(bool, true, 'returns true for empty object'); + 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 + }; + + function isPositive(value) { + return value > 0; + } + + bool = everyInBy(obj, isPositive); + + t.strictEqual(bool, true, 'returns true for all positive values'); + 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 + }; + + function isPositive(value) { + return value > 0; + } + + bool = everyInBy(obj, isPositive); + + t.strictEqual(bool, false, 'returns false for negative value'); + t.end(); +}); + +tape('the function considers inherited properties', function test(t) { + var bool; + var obj; + + function Parent() { + this.inherited = 'property'; + } + + obj = new Parent(); + obj.own = 'value'; + + function hasBoth(value, key) { + return key === 'inherited' || key === 'own'; + } + + bool = everyInBy(obj, hasBoth); + + t.strictEqual(bool, true, 'returns true for inherited and own properties'); + t.end(); +}); + +tape('the function supports providing an execution context', function test(t) { + var bool; + var ctx; + var obj; + + function sum(value) { + // eslint-disable-next-line no-invalid-this + this.sum += value; + return true; + } + + ctx = { + 'sum': 0 + }; + + obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + + bool = everyInBy(obj, sum, ctx); + + t.strictEqual(bool, true, 'returns true'); + t.end(); +}); From b3554210b9f15a5d26af3064ef18b7bff8f0ae6d Mon Sep 17 00:00:00 2001 From: the-r3aper7 Date: Thu, 29 Feb 2024 15:20:33 +0530 Subject: [PATCH 02/11] feat: added utils/every-in-by added README.md --- .../@stdlib/utils/every-in-by/README.md | 159 ++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 lib/node_modules/@stdlib/utils/every-in-by/README.md diff --git a/lib/node_modules/@stdlib/utils/every-in-by/README.md b/lib/node_modules/@stdlib/utils/every-in-by/README.md new file mode 100644 index 000000000000..684efd1b1b26 --- /dev/null +++ b/lib/node_modules/@stdlib/utils/every-in-by/README.md @@ -0,0 +1,159 @@ + + +# every in by + +> Test whether all elements in a object are truthy. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var everyInBy = require( '@stdlib/utils/every-in-by' ); +``` + +#### everyInBy( object, predicate\[, thisArg ] ) + +Tests whether all elements in a `object` pass a test implemented by a `predicate` function. + +```javascript +var o; +var bool; + +function isPositive( v ) { + return ( v > 0 ); +} + +o = { + 'a': 1, + 'b': 2, + 'c': 3 +}; + +bool = everyInBy( o, isPositive ); +// returns true +``` + +If provided an empty `object`, the function returns `true`. + +```javascript +function isPositive(v) { + return ( v > 0 ); +} + +var bool = everyInBy( {}, isPositive ); +// returns true +``` + +
+ + + + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var everyInBy = require( '@stdlib/utils/every-in-by' ); + +var bool; +var o; +var i; + +function isPositive(v) { + return ( v > 0 ); +} + +o = {}; +for ( i = 0; i < 100; i++ ) { + o[ i ] = ( randu() < 0.95 ); +} + +bool = everyInBy( o, isPositive ); +// returns +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + From 5000e3073aeb68a44e06fd5e4fed6aa23b7a11ff Mon Sep 17 00:00:00 2001 From: the-r3aper7 Date: Fri, 1 Mar 2024 15:43:04 +0530 Subject: [PATCH 03/11] feat: added utils/every-in-by feedback --- .../utils/every-by/docs/types/index.d.ts | 2 +- .../@stdlib/utils/every-in-by/README.md | 38 ++------------- .../@stdlib/utils/every-in-by/docs/repl.txt | 4 +- .../utils/every-in-by/docs/types/index.d.ts | 48 ++++++++++++++++++- .../@stdlib/utils/every-in-by/lib/index.js | 2 +- .../@stdlib/utils/every-in-by/lib/main.js | 8 ++-- .../@stdlib/utils/every-in-by/package.json | 7 +-- .../@stdlib/utils/every-in-by/test/test.js | 6 +-- 8 files changed, 62 insertions(+), 53 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts index 2ce3ff38efea..b90c1a47e4ca 100644 --- a/lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { Collection } from '@stdlib/types/array'; +import { Collection } from '@stdlib/types/object'; /** * Checks whether an element in a collection passes a test. diff --git a/lib/node_modules/@stdlib/utils/every-in-by/README.md b/lib/node_modules/@stdlib/utils/every-in-by/README.md index 684efd1b1b26..706362cafd15 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/README.md +++ b/lib/node_modules/@stdlib/utils/every-in-by/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# every in by +# everyInBy -> Test whether all elements in a object are truthy. +> Test whether all properties (own and inherited) of an object pass a test implemented by a predicate function. @@ -42,7 +42,7 @@ var everyInBy = require( '@stdlib/utils/every-in-by' ); #### everyInBy( object, predicate\[, thisArg ] ) -Tests whether all elements in a `object` pass a test implemented by a `predicate` function. +Tests whether all properties (own and inherited) of an `object` pass a test implemented by a `predicate` function. ```javascript var o; @@ -122,38 +122,6 @@ bool = everyInBy( o, isPositive ); - - - - - - diff --git a/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt b/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt index 7e8cc2d26884..3e327f9cdde5 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( object, predicate[, thisArg ] ) - Tests whether all elements in a object pass a test implemented by a - predicate function, iterating from right to left. + Test whether all properties (own and inherited) of an object pass a + test implemented by a predicate function. The predicate function is provided three arguments: diff --git a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts index 28460110321a..3b8cbc4f2fe4 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts @@ -16,8 +16,52 @@ * limitations under the License. */ -// Define types for functions/arguments -type Predicate = ( value: T, key: string, obj: object ) => boolean; +import { Collection } from '@stdlib/types/object'; + +/** +* Checks whether an element in a collection passes a test. +* +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @param collection - input collection +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Ternary = ( this: U, value: T, index: number, collection: Collection ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @param collection - input collection +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + /** * Checks whether all own and inherited properties in an object pass a test implemented by a predicate function. diff --git a/lib/node_modules/@stdlib/utils/every-in-by/lib/index.js b/lib/node_modules/@stdlib/utils/every-in-by/lib/index.js index bed108dfe86c..1231584d24f2 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/lib/index.js +++ b/lib/node_modules/@stdlib/utils/every-in-by/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Test whether all elements in a collection pass a test implemented by a predicate function, iterating from left to right. +* Test whether all elements in an object pass a test implemented by a predicate function. * * @module @stdlib/utils/every-in-by * diff --git a/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js b/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js index afadcd6a0eef..9e188ef1dee6 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js +++ b/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js @@ -28,12 +28,12 @@ var format = require( '@stdlib/string/format' ); // MAIN // /** -* Tests whether all elements in a object pass a test implemented by a predicate function. +* Tests whether all properties (own and inherited) of an object 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 a object +* @throws {TypeError} first argument must be an object * @throws {TypeError} second argument must be a function * @returns {boolean} boolean indicating whether all elements pass a test * @@ -56,8 +56,8 @@ function everyInBy( obj, predicate, thisArg ) { throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) ); } - for (key in obj) { - if (!predicate.call(thisArg, obj[key], key, obj)) { + for ( key in obj ) { + if ( !predicate.call( thisArg, obj[ key ], key, obj ) ) { return false; } } diff --git a/lib/node_modules/@stdlib/utils/every-in-by/package.json b/lib/node_modules/@stdlib/utils/every-in-by/package.json index 2dd5a626df0b..78946ae8449b 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/package.json +++ b/lib/node_modules/@stdlib/utils/every-in-by/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/utils/every-in-by", "version": "0.0.0", - "description": "Test whether all elements in a object pass a test implemented by a predicate function, iterating from left to right.", + "description": "Test whether all properties (own and inherited) of an object pass a test implemented by a predicate function.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -60,11 +60,8 @@ "predicate", "every", "all", - "everyright", - "array.every", + "object", "iterate", - "collection", - "array-like", "validate" ] } diff --git a/lib/node_modules/@stdlib/utils/every-in-by/test/test.js b/lib/node_modules/@stdlib/utils/every-in-by/test/test.js index 6a843060861e..5c233570d617 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/test/test.js +++ b/lib/node_modules/@stdlib/utils/every-in-by/test/test.js @@ -20,9 +20,9 @@ // MODULES // -var tape = require('tape'); -var noop = require('@stdlib/utils/noop'); -var everyInBy = require( './../lib' ); // Replace './lib' with the actual path to your function +var tape = require( 'tape' ); +var noop = require( '@stdlib/utils/noop' ); +var everyInBy = require( './../lib' ); // TESTS // From 58c1166b4e55fed0e6a636bcb6ca777a149d8795 Mon Sep 17 00:00:00 2001 From: the-r3aper7 Date: Fri, 1 Mar 2024 16:11:13 +0530 Subject: [PATCH 04/11] feat: added utils/every-in-by updated main.js --- lib/node_modules/@stdlib/utils/every-in-by/lib/main.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js b/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js index 9e188ef1dee6..e6eb7641d122 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js +++ b/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js @@ -20,7 +20,6 @@ // MODULES // -var isObject = require( '@stdlib/assert/is-object' ); var isFunction = require( '@stdlib/assert/is-function' ); var format = require( '@stdlib/string/format' ); @@ -49,8 +48,12 @@ var format = require( '@stdlib/string/format' ); */ function everyInBy( obj, predicate, thisArg ) { var key; - if ( !isObject( obj ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + if ( typeof obj !== 'object' || obj === null ) { + if (obj instanceof RegExp) { + throw new TypeError('everyInBy expects an object but received a regular expression'); + } else { + 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 ) ); From f3ece15e497931e264d6497b0190f9702fea3eec Mon Sep 17 00:00:00 2001 From: the-r3aper7 Date: Fri, 1 Mar 2024 16:13:15 +0530 Subject: [PATCH 05/11] feat: added utils/every-in-by updated main.js --- lib/node_modules/@stdlib/utils/every-in-by/lib/main.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js b/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js index e6eb7641d122..71f3818cb10f 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js +++ b/lib/node_modules/@stdlib/utils/every-in-by/lib/main.js @@ -48,12 +48,8 @@ var format = require( '@stdlib/string/format' ); */ function everyInBy( obj, predicate, thisArg ) { var key; - if ( typeof obj !== 'object' || obj === null ) { - if (obj instanceof RegExp) { - throw new TypeError('everyInBy expects an object but received a regular expression'); - } else { - throw new TypeError(format('invalid argument. First argument must be an object. Value: %s', obj)); - } + if (typeof obj !== 'object' || obj === null) { + 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 ) ); From 1e065833d588dd5e8430f5a94eb1855081ff1665 Mon Sep 17 00:00:00 2001 From: the-r3aper7 Date: Fri, 1 Mar 2024 16:16:29 +0530 Subject: [PATCH 06/11] feat: added utils/every-in-by updated test.js --- .../@stdlib/utils/every-in-by/docs/types/index.d.ts | 6 +++--- lib/node_modules/@stdlib/utils/every-in-by/test/test.js | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts index 3b8cbc4f2fe4..3655433a2470 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts @@ -73,10 +73,10 @@ type Predicate = Nullary | Unary | Binary | Ternary; * * @throws TypeError if `obj` is not an object or if `predicate` is not a function. */ -declare function everyInBy( +declare function everyInBy( obj: object, - predicate: Predicate, - thisArg?: ThisParameterType> + predicate: Predicate, + thisArg?: ThisParameterType> ): boolean; // Export the function diff --git a/lib/node_modules/@stdlib/utils/every-in-by/test/test.js b/lib/node_modules/@stdlib/utils/every-in-by/test/test.js index 5c233570d617..63a0da941734 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/test/test.js +++ b/lib/node_modules/@stdlib/utils/every-in-by/test/test.js @@ -45,9 +45,7 @@ tape('the function throws an error if not provided an object', function test(t) false, null, void 0, - function noop() { }, - /.*/, - new Date() + function noop() { } ]; for (i = 0; i < values.length; i++) { From 24641e5c4499bf73de4217139ec76622dc5e0df3 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 1 Mar 2024 19:18:58 -0500 Subject: [PATCH 07/11] style: add missing spaces Signed-off-by: Philipp Burckhardt --- .../@stdlib/utils/every-in-by/test/test.js | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/every-in-by/test/test.js b/lib/node_modules/@stdlib/utils/every-in-by/test/test.js index 63a0da941734..5cd9af8113ff 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/test/test.js +++ b/lib/node_modules/@stdlib/utils/every-in-by/test/test.js @@ -27,13 +27,13 @@ var everyInBy = require( './../lib' ); // TESTS // -tape('main export is a function', function test(t) { - t.ok(true, __filename); - t.strictEqual(typeof everyInBy, 'function', 'main export is a function'); +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof everyInBy, 'function', 'main export is a function' ); t.end(); }); -tape('the function throws an error if not provided an object', function test(t) { +tape( 'the function throws an error if not provided an object', function test( t ) { var values; var i; @@ -48,48 +48,48 @@ tape('the function throws an error if not provided an object', function test(t) function noop() { } ]; - for (i = 0; i < values.length; i++) { - t.throws(badValue(values[i]), TypeError, 'throws a type error when provided ' + values[i]); + 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) { + function badValue( value ) { return function badValue() { - everyInBy(value, noop); + everyInBy( value, noop ); }; } }); -tape('the function throws an error if not provided a predicate function', function test(t) { +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()]; + 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]); + 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) { + function badValue( value ) { return function badValue() { - everyInBy({}, value); + everyInBy( {}, value ); }; } }); -tape('if provided an empty object, the function returns `true`', function test(t) { +tape( 'if provided an empty object, the function returns `true`', function test( t ) { var bool; var obj; obj = {}; - bool = everyInBy(obj, noop); + bool = everyInBy( obj, noop ); - t.strictEqual(bool, true, 'returns true for empty object'); + t.strictEqual( bool, true, 'returns true for empty object' ); t.end(); }); -tape('the function returns `true` if all properties pass a test', function test(t) { +tape( 'the function returns `true` if all properties pass a test', function test( t ) { var bool; var obj; @@ -99,17 +99,17 @@ tape('the function returns `true` if all properties pass a test', function test( 'c': 3 }; - function isPositive(value) { + function isPositive( value ) { return value > 0; } - bool = everyInBy(obj, isPositive); + bool = everyInBy( obj, isPositive ); - t.strictEqual(bool, true, 'returns true for all positive values'); + t.strictEqual( bool, true, 'returns true for all positive values' ); t.end(); }); -tape('the function returns `false` if one or more properties fail a test', function test(t) { +tape( 'the function returns `false` if one or more properties fail a test', function test( t ) { var bool; var obj; @@ -119,17 +119,17 @@ tape('the function returns `false` if one or more properties fail a test', funct 'c': 3 }; - function isPositive(value) { + function isPositive( value ) { return value > 0; } - bool = everyInBy(obj, isPositive); + bool = everyInBy( obj, isPositive ); - t.strictEqual(bool, false, 'returns false for negative value'); + t.strictEqual( bool, false, 'returns false for negative value' ); t.end(); }); -tape('the function considers inherited properties', function test(t) { +tape( 'the function considers inherited properties', function test( t ) { var bool; var obj; @@ -140,22 +140,22 @@ tape('the function considers inherited properties', function test(t) { obj = new Parent(); obj.own = 'value'; - function hasBoth(value, key) { + function hasBoth( value, key ) { return key === 'inherited' || key === 'own'; } - bool = everyInBy(obj, hasBoth); + bool = everyInBy( obj, hasBoth ); - t.strictEqual(bool, true, 'returns true for inherited and own properties'); + t.strictEqual( bool, true, 'returns true for inherited and own properties' ); t.end(); }); -tape('the function supports providing an execution context', function test(t) { +tape( 'the function supports providing an execution context', function test( t ) { var bool; var ctx; var obj; - function sum(value) { + function sum( value ) { // eslint-disable-next-line no-invalid-this this.sum += value; return true; @@ -171,8 +171,8 @@ tape('the function supports providing an execution context', function test(t) { 'c': 3 }; - bool = everyInBy(obj, sum, ctx); + bool = everyInBy( obj, sum, ctx ); - t.strictEqual(bool, true, 'returns true'); + t.strictEqual( bool, true, 'returns true' ); t.end(); }); From 6e76aa5ace6cd6cd3de3d98f912fccdabc596912 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 1 Mar 2024 19:19:48 -0500 Subject: [PATCH 08/11] Update lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts index b90c1a47e4ca..2ce3ff38efea 100644 --- a/lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/every-by/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { Collection } from '@stdlib/types/object'; +import { Collection } from '@stdlib/types/array'; /** * Checks whether an element in a collection passes a test. From 30a02112c519df87b652f2e2ca460b329f9e6ba1 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 1 Mar 2024 19:19:57 -0500 Subject: [PATCH 09/11] Update lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt b/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt index 3e327f9cdde5..3eb1df9cd9a5 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/every-in-by/docs/repl.txt @@ -20,7 +20,7 @@ Input object over which to iterate. predicate: Function - The test function. + Test function. thisArg: any (optional) Execution context. From 6ccb0b908c1857edf4838fa5328ca3e3af6d8cf4 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 1 Mar 2024 19:20:03 -0500 Subject: [PATCH 10/11] Update lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts Signed-off-by: Philipp Burckhardt --- lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts index 3655433a2470..e82b8e3678f7 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts @@ -62,7 +62,6 @@ type Ternary = ( this: U, value: T, index: number, collection: Collection< */ type Predicate = Nullary | Unary | Binary | Ternary; - /** * Checks whether all own and inherited properties in an object pass a test implemented by a predicate function. * From 818222ed37dac322335622cb7009281328e5fd51 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 1 Mar 2024 19:20:07 -0500 Subject: [PATCH 11/11] Update lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts Signed-off-by: Philipp Burckhardt --- .../@stdlib/utils/every-in-by/docs/types/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts index e82b8e3678f7..10bf34b8c027 100644 --- a/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/every-in-by/docs/types/index.d.ts @@ -78,5 +78,7 @@ declare function everyInBy( thisArg?: ThisParameterType> ): boolean; -// Export the function + +// EXPORTS // + export = everyInBy;