From 1ad94f60553a08421f89d24544e4a6d1e83e8c7e Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Thu, 25 Dec 2025 19:46:07 +0530 Subject: [PATCH 1/4] feat: add `object/for-own` Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/object/for-own/README.md | 209 ++++++++++++++++ .../object/for-own/benchmark/benchmark.js | 91 +++++++ .../@stdlib/object/for-own/docs/repl.txt | 49 ++++ .../object/for-own/docs/types/index.d.ts | 63 +++++ .../@stdlib/object/for-own/docs/types/test.ts | 50 ++++ .../@stdlib/object/for-own/examples/index.js | 40 ++++ .../@stdlib/object/for-own/lib/index.js | 50 ++++ .../@stdlib/object/for-own/lib/main.js | 85 +++++++ .../@stdlib/object/for-own/package.json | 71 ++++++ .../@stdlib/object/for-own/test/test.js | 224 ++++++++++++++++++ 10 files changed, 932 insertions(+) create mode 100644 lib/node_modules/@stdlib/object/for-own/README.md create mode 100644 lib/node_modules/@stdlib/object/for-own/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/object/for-own/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/object/for-own/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/object/for-own/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/object/for-own/examples/index.js create mode 100644 lib/node_modules/@stdlib/object/for-own/lib/index.js create mode 100644 lib/node_modules/@stdlib/object/for-own/lib/main.js create mode 100644 lib/node_modules/@stdlib/object/for-own/package.json create mode 100644 lib/node_modules/@stdlib/object/for-own/test/test.js diff --git a/lib/node_modules/@stdlib/object/for-own/README.md b/lib/node_modules/@stdlib/object/for-own/README.md new file mode 100644 index 000000000000..4287a6b763e0 --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/README.md @@ -0,0 +1,209 @@ + + +# forOwn + +> Invoke a function for each own enumerable property of an object. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var forOwn = require( '@stdlib/object/for-own' ); +``` + +#### forOwn( obj, fcn\[, thisArg ] ) + +Invokes a `function` for each own enumerable property of an `object`. + +```javascript +function log( value, key ) { + console.log( '%s: %d', key, value ); +} + +var obj = { + 'a': 1, + 'b': 2, + 'c': 3, + 'd': 4 +}; + +forOwn( obj, log ); +/* e.g., => + a: 1 + b: 2 + c: 3 + d: 4 +*/ +``` + +The invoked `function` is provided three arguments: + +- **value**: object property value. +- **key**: object property. +- **obj**: the input object. + +To terminate iteration before visiting all properties, the provided function must explicitly return `false`. + +```javascript +function log( value, key ) { + console.log( '%s: %d', key, value ); + return false; +} + +var obj = { + 'a': 1, + 'b': 2, + 'c': 3, + 'd': 4 +}; + +forOwn( obj, log ); +// e.g., => a: 1 +``` + +To set the function execution context, provide a `thisArg`. + +```javascript +function sum( value ) { + this.sum += value; + this.count += 1; +} + +var obj = { + 'a': 1, + 'b': 2, + 'c': 3, + 'd': 4 +}; + +var context = { + 'sum': 0, + 'count': 0 +}; + +forOwn( obj, sum, context ); + +var mean = context.sum / context.count; +// returns 2.5 +``` + +
+ + + + + +
+ +## Notes + +- The function returns the input `object`. +- The function determines the list of own enumerable properties **before** invoking the provided function. Hence, any modifications made to the input `object` **after** calling this function (such as adding and removing properties) will **not** affect the list of visited properties. +- Property iteration order is **not** guaranteed. + +
+ + + + + +
+ +## Examples + + + +```javascript +var fromCodePoint = require( '@stdlib/string/from-code-point' ); +var forOwn = require( '@stdlib/object/for-own' ); + +function update( value, key, obj ) { + console.log( '%s: %d', key, value ); + obj[ key ] *= value; +} + +var obj; +var key; +var i; + +obj = {}; +for ( i = 0; i < 26; i++ ) { + key = fromCodePoint( 97 + i ); + obj[ key ] = i; +} + +forOwn( obj, update ); +console.log( obj ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/object/for-own/benchmark/benchmark.js b/lib/node_modules/@stdlib/object/for-own/benchmark/benchmark.js new file mode 100644 index 000000000000..fbf56d66d395 --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/benchmark/benchmark.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var forOwn = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var obj; + var i; + + function onKey( v ) { + if ( isnan( v ) ) { + b.fail( 'should not be NaN' ); + } + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = { + 'a': i, + 'b': i+1, + 'c': i+2, + 'd': i+3, + 'e': i+4 + }; + forOwn( obj, onKey ); + if ( isnan( obj.a ) ) { + b.fail( 'should not be NaN' ); + } + } + b.toc(); + if ( isnan( obj.a ) ) { + b.fail( 'should not be NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::loop', function benchmark( b ) { + 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 ); + for ( j = 0; j < keys.length; j++ ) { + if ( isnan( obj[ keys[ j ] ] ) ) { + b.fail( 'should not be NaN' ); + } + } + } + b.toc(); + if ( isnan( obj.a ) ) { + b.fail( 'should not be NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/object/for-own/docs/repl.txt b/lib/node_modules/@stdlib/object/for-own/docs/repl.txt new file mode 100644 index 000000000000..c0267f76720b --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/docs/repl.txt @@ -0,0 +1,49 @@ + +{{alias}}( obj, fcn[, thisArg] ) + Invokes a function for each own enumerable property of an object. + + When invoked, the function is provided three arguments: + + - value: object property value. + - key: object property. + - obj: the input object. + + To terminate iteration before visiting all properties, the provided function + must explicitly return `false`. + + The function determines the list of own enumerable properties *before* + invoking the provided function. Hence, any modifications made to the input + object *after* calling this function (such as adding and removing + properties) will *not* affect the list of visited properties. + + Property iteration order is *not* guaranteed. + + Parameters + ---------- + obj: Object + Input object, including arrays, typed arrays, and other collections. + + fcn: Function + The function to invoke for each own enumerable property. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Object + Input object. + + Examples + -------- + > function logger( v, k ) { console.log( '%s: %d', k, v ); }; + > var obj = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }; + > {{alias}}( obj, logger ) + a: 1 + b: 2 + c: 3 + d: 4 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/object/for-own/docs/types/index.d.ts b/lib/node_modules/@stdlib/object/for-own/docs/types/index.d.ts new file mode 100644 index 000000000000..aeb8a7aabf2c --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/docs/types/index.d.ts @@ -0,0 +1,63 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Invokes a function once for each own enumerable property of an object. +* +* ## Notes +* +* - When invoked, the function is provided three arguments: +* +* - `value`: object property value +* - `key`: object property +* - `obj`: the input object +* +* - To terminate iteration before visiting all properties, the provided function must explicitly return `false`. +* +* - The function determines the list of own enumerable properties *before* invoking the provided function. Hence, any modifications made to the input object *after* calling this function (such as adding and removing properties) will *not* affect the list of visited properties. +* +* - Iteration order is **not** guaranteed. +* +* +* @param obj - input object +* @param fcn - function to invoke +* @param thisArg - execution context +* @returns obj - input object +* +* @example +* function log( v, key ) { +* console.log( '%s: %d', key, v ); +* } +* +* var obj = { +* 'a': 1, +* 'b': 2, +* 'c': 3, +* 'd': 4 +* }; +* +* forOwn( obj, log ); +*/ +declare function forOwn( obj: any, fcn: Function, thisArg?: any ): any; + + +// EXPORTS // + +export = forOwn; diff --git a/lib/node_modules/@stdlib/object/for-own/docs/types/test.ts b/lib/node_modules/@stdlib/object/for-own/docs/types/test.ts new file mode 100644 index 000000000000..bf6de7772023 --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/docs/types/test.ts @@ -0,0 +1,50 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable no-new-wrappers */ + +import forOwn = require( './index' ); + +const log = ( v: any, key: string ): string => { + return `${key}: ${v}`; +}; + +// TESTS // + +// The function returns an object... +{ + forOwn( new String( 'abc' ), log ); // $ExpectType any + forOwn( new String( 'abc' ), log, {} ); // $ExpectType any +} + +// The compiler throws an error if the function is provided a second argument which is not a function... +{ + forOwn( new String( 'abc' ), 2 ); // $ExpectError + forOwn( new String( 'abc' ), false ); // $ExpectError + forOwn( new String( 'abc' ), true ); // $ExpectError + forOwn( new String( 'abc' ), 'abc' ); // $ExpectError + forOwn( new String( 'abc' ), {} ); // $ExpectError + forOwn( new String( 'abc' ), [] ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid number of arguments... +{ + forOwn(); // $ExpectError + forOwn( new String( 'abc' ) ); // $ExpectError + forOwn( new String( 'abc' ), log, {}, 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/object/for-own/examples/index.js b/lib/node_modules/@stdlib/object/for-own/examples/index.js new file mode 100644 index 000000000000..2247d7c1d033 --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/examples/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var fromCodePoint = require( '@stdlib/string/from-code-point' ); +var forOwn = require( './../lib' ); + +function update( value, key, obj ) { + console.log( '%s: %d', key, value ); + obj[ key ] *= value; +} + +var obj; +var key; +var i; + +obj = {}; +for ( i = 0; i < 26; i++ ) { + key = fromCodePoint( 97 + i ); + obj[ key ] = i; +} + +forOwn( obj, update ); +console.log( obj ); diff --git a/lib/node_modules/@stdlib/object/for-own/lib/index.js b/lib/node_modules/@stdlib/object/for-own/lib/index.js new file mode 100644 index 000000000000..1d559399fe2d --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/lib/index.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Invoke a function once for each own enumerable property of an object. +* +* @module @stdlib/object/for-own +* +* @example +* var forOwn = require( '@stdlib/object/for-own' ); +* +* function log( v, key ) { +* console.log( '%s: %d', key, v ); +* } +* +* var obj = { +* 'a': 1, +* 'b': 2, +* 'c': 3, +* 'd': 4 +* }; +* +* forOwn( obj, log ); +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/object/for-own/lib/main.js b/lib/node_modules/@stdlib/object/for-own/lib/main.js new file mode 100644 index 000000000000..f889d7630469 --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/lib/main.js @@ -0,0 +1,85 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var objectKeys = require( '@stdlib/utils/keys' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Invokes a function once for each own enumerable property of an object. +* +* ## Notes +* +* - Iteration order is **not** guaranteed. +* +* @param {Object} obj - input object +* @param {Function} fcn - function to invoke +* @param {*} [thisArg] - execution context +* @throws {TypeError} first argument must be an object +* @throws {TypeError} second argument must be a function +* @returns {Object} obj - input object +* +* @example +* function log( v, key ) { +* console.log( '%s: %d', key, v ); +* } +* +* var obj = { +* 'a': 1, +* 'b': 2, +* 'c': 3, +* 'd': 4 +* }; +* +* forOwn( obj, log ); +*/ +function forOwn( obj, fcn, thisArg ) { + var keys; + var bool; + var len; + var k; + var i; + if ( typeof obj !== 'object' || obj === null ) { + throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); + } + if ( !isFunction( fcn ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); + } + keys = objectKeys( obj ); + len = keys.length; + for ( i = 0; i < len; i++ ) { + k = keys[ i ]; + bool = fcn.call( thisArg, obj[ k ], k, obj ); + if ( bool === false ) { + return obj; + } + } + return obj; +} + + +// EXPORTS // + +module.exports = forOwn; diff --git a/lib/node_modules/@stdlib/object/for-own/package.json b/lib/node_modules/@stdlib/object/for-own/package.json new file mode 100644 index 000000000000..7e0d2a472479 --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/object/for-own", + "version": "0.0.0", + "description": "Invoke a function for each own enumerable property of an object.", + "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", + "for", + "own", + "forown", + "object.keys", + "keys", + "properties", + "props", + "enumerable", + "iterate", + "object", + "obj" + ] +} diff --git a/lib/node_modules/@stdlib/object/for-own/test/test.js b/lib/node_modules/@stdlib/object/for-own/test/test.js new file mode 100644 index 000000000000..f9b5d10c5335 --- /dev/null +++ b/lib/node_modules/@stdlib/object/for-own/test/test.js @@ -0,0 +1,224 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var defineProperty = require( '@stdlib/utils/define-property' ); +var objectKeys = require( '@stdlib/utils/keys' ); +var noop = require( '@stdlib/utils/noop' ); +var forOwn = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof forOwn, '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 + ]; + + 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() { + forOwn( value, noop ); + }; + } +}); + +tape( 'the function throws an error if not provided a function to invoke', 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() { + forOwn( {}, value ); + }; + } +}); + +tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { + var obj = {}; + + function foo() { + t.fail( 'should not be invoked' ); + } + + forOwn( obj, foo ); + + t.deepEqual( obj, {}, 'expected result' ); + t.end(); +}); + +tape( 'the function returns the input object', function test( t ) { + var obj; + var out; + + function foo() { + t.pass( 'invoked provided function' ); + } + + obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + + out = forOwn( obj, foo ); + + t.strictEqual( out, obj, 'returns input object' ); + t.end(); +}); + +tape( 'the function invokes a provided function for each own enumerable property in an object', function test( t ) { + var expected; + var obj; + var out; + + function copy( value, key ) { + out[ key ] = value; + } + + function Obj() { + if ( !(this instanceof Obj) ) { + return new Obj(); + } + this.a = 1; + this.b = 2; + this.c = 3; + + defineProperty( this, 'nonenum', { + 'configurable': false, + 'writable': false, + 'enumerable': false, + 'value': 'beep' + }); + + return this; + } + + Obj.prototype.d = 4; + Obj.prototype.e = 5; + + out = {}; + + obj = new Obj(); + forOwn( obj, copy ); + + expected = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + t.deepEqual( out, expected, 'expected result' ); + t.end(); +}); + +tape( 'the function supports early termination', function test( t ) { + var keys; + var obj; + var out; + + function copy( value, key ) { + out[ key ] = value; + + // Explicitly return `false`: + return false; + } + + obj = { + 'a': 1, + 'b': 2, + 'c': 3 + }; + out = {}; + + forOwn( obj, copy ); + + keys = objectKeys( out ); + t.strictEqual( keys.length, 1, 'object contains only one property' ); + t.strictEqual( out[ keys[0] ], obj[ keys[0] ], 'copies property value' ); + + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var ctx; + var obj; + + function sum( value ) { + /* eslint-disable no-invalid-this */ + this.sum += value; + this.count += 1; + } + + ctx = { + 'sum': 0.0, + 'count': 0.0 + }; + obj = { + 'a': 1.0, + 'b': 2.0, + 'c': 3.0 + }; + + forOwn( obj, sum, ctx ); + + t.strictEqual( ctx.sum/ctx.count, 2.0, 'expected result' ); + + t.end(); +}); From f6c0d3953546ca333f5111143b34b0618323797a Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Thu, 25 Dec 2025 19:47:28 +0530 Subject: [PATCH 2/4] remove: remove `forOwn` from namespace This commit removes the `forOwn` symbol from the `@stdlib/utils` namespace due to a package migration. BREAKING CHANGE: remove `forOwn` To migrate, users should access the same symbol via the `@stdlib/object` namespace. Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/utils/docs/types/index.d.ts | 40 ------------------- lib/node_modules/@stdlib/utils/lib/index.js | 9 ----- 2 files changed, 49 deletions(-) diff --git a/lib/node_modules/@stdlib/utils/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/docs/types/index.d.ts index 92b9bc4e4c15..812f91489e65 100644 --- a/lib/node_modules/@stdlib/utils/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/docs/types/index.d.ts @@ -88,7 +88,6 @@ import flattenArray = require( '@stdlib/utils/flatten-array' ); import flattenObject = require( '@stdlib/utils/flatten-object' ); import forEach = require( '@stdlib/utils/for-each' ); import forEachRight = require( '@stdlib/utils/for-each-right' ); -import forOwn = require( '@stdlib/utils/for-own' ); import objectFromEntries = require( '@stdlib/utils/from-entries' ); import functionName = require( '@stdlib/utils/function-name' ); import functionSequence = require( '@stdlib/utils/function-sequence' ); @@ -2189,45 +2188,6 @@ interface Namespace { */ forEachRight: typeof forEachRight; - /** - * Invokes a function once for each own enumerable property of an object. - * - * ## Notes - * - * - When invoked, the function is provided three arguments: - * - * - `value`: object property value - * - `key`: object property - * - `obj`: the input object - * - * - To terminate iteration before visiting all properties, the provided function must explicitly return `false`. - * - * - The function determines the list of own enumerable properties *before* invoking the provided function. Hence, any modifications made to the input object *after* calling this function (such as adding and removing properties) will *not* affect the list of visited properties. - * - * - Iteration order is **not** guaranteed. - * - * - * @param obj - input object - * @param fcn - function to invoke - * @param thisArg - execution context - * @returns obj - input object - * - * @example - * function log( v, key ) { - * console.log( '%s: %d', key, v ); - * } - * - * var obj = { - * 'a': 1, - * 'b': 2, - * 'c': 3, - * 'd': 4 - * }; - * - * ns.forOwn( obj, log ); - */ - forOwn: typeof forOwn; - /** * Creates an object from an array of key-value pairs. * diff --git a/lib/node_modules/@stdlib/utils/lib/index.js b/lib/node_modules/@stdlib/utils/lib/index.js index b3d1f76b98c3..95f531d3e821 100644 --- a/lib/node_modules/@stdlib/utils/lib/index.js +++ b/lib/node_modules/@stdlib/utils/lib/index.js @@ -652,15 +652,6 @@ setReadOnly( utils, 'forEach', require( '@stdlib/utils/for-each' ) ); */ setReadOnly( utils, 'forEachRight', require( '@stdlib/utils/for-each-right' ) ); -/** -* @name forOwn -* @memberof utils -* @readonly -* @type {Function} -* @see {@link module:@stdlib/utils/for-own} -*/ -setReadOnly( utils, 'forOwn', require( '@stdlib/utils/for-own' ) ); - /** * @name objectFromEntries * @memberof utils From 6f6bc7281cfe657f77401b79e257c06da8d36b02 Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Thu, 25 Dec 2025 19:50:36 +0530 Subject: [PATCH 3/4] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv | 2 +- lib/node_modules/@stdlib/namespace/lib/namespace/f.js | 6 +++--- lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv | 2 +- .../@stdlib/namespace/pkg2related/data/data.csv | 6 +++--- .../@stdlib/namespace/pkg2standalone/data/data.csv | 2 +- .../@stdlib/namespace/standalone2pkg/data/data.csv | 2 +- lib/node_modules/@stdlib/object/for-in/README.md | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv index c5d8b07983af..18e92fe2c7e9 100644 --- a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv @@ -1752,7 +1752,7 @@ forEachRight,"@stdlib/utils/for-each-right" forEachRightAsync,"@stdlib/utils/async/for-each-right" forIn,"@stdlib/object/for-in" format,"@stdlib/string/format" -forOwn,"@stdlib/utils/for-own" +forOwn,"@stdlib/object/for-own" FOURTH_PI,"@stdlib/constants/float64/fourth-pi" FOURTH_ROOT_EPS,"@stdlib/constants/float64/fourth-root-eps" FRB_SF_WAGE_RIGIDITY,"@stdlib/datasets/frb-sf-wage-rigidity" diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/f.js b/lib/node_modules/@stdlib/namespace/lib/namespace/f.js index 3ad47f5e1a8c..cdf068ad41aa 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/f.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/f.js @@ -1396,7 +1396,7 @@ ns.push({ 'type': 'Function', 'related': [ '@stdlib/utils/for-each', - '@stdlib/utils/for-own' + '@stdlib/object/for-own' ] }); @@ -1410,8 +1410,8 @@ ns.push({ ns.push({ 'alias': 'forOwn', - 'path': '@stdlib/utils/for-own', - 'value': require( '@stdlib/utils/for-own' ), + 'path': '@stdlib/object/for-own', + 'value': require( '@stdlib/object/for-own' ), 'type': 'Function', 'related': [ '@stdlib/utils/for-each', diff --git a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv index 8c5f3fa4c415..07b711008587 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv @@ -1752,7 +1752,7 @@ "@stdlib/utils/async/for-each-right",forEachRightAsync "@stdlib/object/for-in",forIn "@stdlib/string/format",format -"@stdlib/utils/for-own",forOwn +"@stdlib/object/for-own",forOwn "@stdlib/constants/float64/fourth-pi",FOURTH_PI "@stdlib/constants/float64/fourth-root-eps",FOURTH_ROOT_EPS "@stdlib/datasets/frb-sf-wage-rigidity",FRB_SF_WAGE_RIGIDITY diff --git a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv index 6a82421a2513..4face3a87044 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv @@ -1750,9 +1750,9 @@ "@stdlib/string/for-each","@stdlib/utils/for-each" "@stdlib/utils/for-each-right","@stdlib/utils/for-each,@stdlib/utils/async/for-each-right" "@stdlib/utils/async/for-each-right","@stdlib/utils/async/for-each,@stdlib/utils/for-each-right" -"@stdlib/object/for-in","@stdlib/utils/for-each,@stdlib/utils/for-own" +"@stdlib/object/for-in","@stdlib/utils/for-each,@stdlib/object/for-own" "@stdlib/string/format","" -"@stdlib/utils/for-own","@stdlib/utils/for-each,@stdlib/object/for-in" +"@stdlib/object/for-own","@stdlib/utils/for-each,@stdlib/object/for-in" "@stdlib/constants/float64/fourth-pi","@stdlib/constants/float64/pi" "@stdlib/constants/float64/fourth-root-eps","@stdlib/constants/float64/eps" "@stdlib/datasets/frb-sf-wage-rigidity","" @@ -2648,7 +2648,7 @@ "@stdlib/utils/nonenumerable-property-names-in","@stdlib/utils/keys-in,@stdlib/utils/inherited-nonenumerable-property-names,@stdlib/utils/nonenumerable-property-names,@stdlib/utils/property-names-in" "@stdlib/utils/nonenumerable-property-symbols","@stdlib/utils/enumerable-property-symbols,@stdlib/utils/inherited-nonenumerable-property-symbols,@stdlib/utils/nonenumerable-property-names,@stdlib/utils/nonenumerable-property-symbols-in,@stdlib/utils/property-symbols" "@stdlib/utils/nonenumerable-property-symbols-in","@stdlib/utils/enumerable-property-symbols-in,@stdlib/utils/inherited-nonenumerable-property-symbols,@stdlib/utils/nonenumerable-property-names-in,@stdlib/utils/nonenumerable-property-symbols,@stdlib/utils/property-symbols-in" -"@stdlib/object/none-own-by","@stdlib/object/any-own-by,@stdlib/object/every-own-by,@stdlib/utils/for-own,@stdlib/utils/none-by,@stdlib/object/some-own-by" +"@stdlib/object/none-own-by","@stdlib/object/any-own-by,@stdlib/object/every-own-by,@stdlib/object/for-own,@stdlib/utils/none-by,@stdlib/object/some-own-by" "@stdlib/utils/nonindex-keys","@stdlib/utils/entries,@stdlib/utils/keys,@stdlib/utils/values" "@stdlib/utils/noop","" "@stdlib/time/now","" diff --git a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv index 578006acfbb3..24307e4b482d 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv @@ -1752,7 +1752,7 @@ "@stdlib/utils/async/for-each-right","@stdlib/utils-async-for-each-right" "@stdlib/object/for-in","@stdlib/object-for-in" "@stdlib/string/format","@stdlib/string-format" -"@stdlib/utils/for-own","@stdlib/utils-for-own" +"@stdlib/object/for-own","@stdlib/object-for-own" "@stdlib/constants/float64/fourth-pi","@stdlib/constants-float64-fourth-pi" "@stdlib/constants/float64/fourth-root-eps","@stdlib/constants-float64-fourth-root-eps" "@stdlib/datasets/frb-sf-wage-rigidity","@stdlib/datasets-frb-sf-wage-rigidity" diff --git a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv index 3366e7598e2c..c550fac98ef0 100644 --- a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv @@ -1752,7 +1752,7 @@ "@stdlib/utils-async-for-each-right","@stdlib/utils/async/for-each-right" "@stdlib/object-for-in","@stdlib/object/for-in" "@stdlib/string-format","@stdlib/string/format" -"@stdlib/utils-for-own","@stdlib/utils/for-own" +"@stdlib/object-for-own","@stdlib/object/for-own" "@stdlib/constants-float64-fourth-pi","@stdlib/constants/float64/fourth-pi" "@stdlib/constants-float64-fourth-root-eps","@stdlib/constants/float64/fourth-root-eps" "@stdlib/datasets-frb-sf-wage-rigidity","@stdlib/datasets/frb-sf-wage-rigidity" diff --git a/lib/node_modules/@stdlib/object/for-in/README.md b/lib/node_modules/@stdlib/object/for-in/README.md index 2412bf16e8a2..263c18a3b881 100644 --- a/lib/node_modules/@stdlib/object/for-in/README.md +++ b/lib/node_modules/@stdlib/object/for-in/README.md @@ -195,7 +195,7 @@ console.log( obj ); ## See Also - [`@stdlib/utils/for-each`][@stdlib/utils/for-each]: invoke a function for each element in a collection. -- [`@stdlib/utils/for-own`][@stdlib/utils/for-own]: invoke a function for each own enumerable property of an object. +- [`@stdlib/object/for-own`][@stdlib/object/for-own]: invoke a function for each own enumerable property of an object. @@ -209,7 +209,7 @@ console.log( obj ); [@stdlib/utils/for-each]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/for-each -[@stdlib/utils/for-own]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/for-own +[@stdlib/object/for-own]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/for-own From 0b54671e16a2b49c94a31c74d3c3fffa22d8e35e Mon Sep 17 00:00:00 2001 From: NEERAJ Date: Thu, 25 Dec 2025 19:51:54 +0530 Subject: [PATCH 4/4] remove: remove `utils/for-own` This commit removes `@stdlib/utils/for-own` in favor of `@stdlib/object/for-own`. BREAKING CHANGE: remove `utils/for-own` To migrate, users should update their require/import paths to use `@stdlib/object/for-own` which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/utils/for-own/README.md | 209 ---------------- .../utils/for-own/benchmark/benchmark.js | 91 ------- .../@stdlib/utils/for-own/docs/repl.txt | 49 ---- .../utils/for-own/docs/types/index.d.ts | 63 ----- .../@stdlib/utils/for-own/docs/types/test.ts | 50 ---- .../@stdlib/utils/for-own/examples/index.js | 40 ---- .../@stdlib/utils/for-own/lib/index.js | 50 ---- .../@stdlib/utils/for-own/lib/main.js | 85 ------- .../@stdlib/utils/for-own/package.json | 71 ------ .../@stdlib/utils/for-own/test/test.js | 224 ------------------ 10 files changed, 932 deletions(-) delete mode 100644 lib/node_modules/@stdlib/utils/for-own/README.md delete mode 100644 lib/node_modules/@stdlib/utils/for-own/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/utils/for-own/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/utils/for-own/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/utils/for-own/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/utils/for-own/examples/index.js delete mode 100644 lib/node_modules/@stdlib/utils/for-own/lib/index.js delete mode 100644 lib/node_modules/@stdlib/utils/for-own/lib/main.js delete mode 100644 lib/node_modules/@stdlib/utils/for-own/package.json delete mode 100644 lib/node_modules/@stdlib/utils/for-own/test/test.js diff --git a/lib/node_modules/@stdlib/utils/for-own/README.md b/lib/node_modules/@stdlib/utils/for-own/README.md deleted file mode 100644 index bba6cc18e5b3..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/README.md +++ /dev/null @@ -1,209 +0,0 @@ - - -# forOwn - -> Invoke a function for each own enumerable property of an object. - - - -
- -
- - - - - -
- -## Usage - -```javascript -var forOwn = require( '@stdlib/utils/for-own' ); -``` - -#### forOwn( obj, fcn\[, thisArg ] ) - -Invokes a `function` for each own enumerable property of an `object`. - -```javascript -function log( value, key ) { - console.log( '%s: %d', key, value ); -} - -var obj = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4 -}; - -forOwn( obj, log ); -/* e.g., => - a: 1 - b: 2 - c: 3 - d: 4 -*/ -``` - -The invoked `function` is provided three arguments: - -- **value**: object property value. -- **key**: object property. -- **obj**: the input object. - -To terminate iteration before visiting all properties, the provided function must explicitly return `false`. - -```javascript -function log( value, key ) { - console.log( '%s: %d', key, value ); - return false; -} - -var obj = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4 -}; - -forOwn( obj, log ); -// e.g., => a: 1 -``` - -To set the function execution context, provide a `thisArg`. - -```javascript -function sum( value ) { - this.sum += value; - this.count += 1; -} - -var obj = { - 'a': 1, - 'b': 2, - 'c': 3, - 'd': 4 -}; - -var context = { - 'sum': 0, - 'count': 0 -}; - -forOwn( obj, sum, context ); - -var mean = context.sum / context.count; -// returns 2.5 -``` - -
- - - - - -
- -## Notes - -- The function returns the input `object`. -- The function determines the list of own enumerable properties **before** invoking the provided function. Hence, any modifications made to the input `object` **after** calling this function (such as adding and removing properties) will **not** affect the list of visited properties. -- Property iteration order is **not** guaranteed. - -
- - - - - -
- -## Examples - - - -```javascript -var fromCodePoint = require( '@stdlib/string/from-code-point' ); -var forOwn = require( '@stdlib/utils/for-own' ); - -function update( value, key, obj ) { - console.log( '%s: %d', key, value ); - obj[ key ] *= value; -} - -var obj; -var key; -var i; - -obj = {}; -for ( i = 0; i < 26; i++ ) { - key = fromCodePoint( 97 + i ); - obj[ key ] = i; -} - -forOwn( obj, update ); -console.log( obj ); -``` - -
- - - - - -
- -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/utils/for-own/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/for-own/benchmark/benchmark.js deleted file mode 100644 index fbf56d66d395..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/benchmark/benchmark.js +++ /dev/null @@ -1,91 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var pkg = require( './../package.json' ).name; -var forOwn = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var obj; - var i; - - function onKey( v ) { - if ( isnan( v ) ) { - b.fail( 'should not be NaN' ); - } - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - obj = { - 'a': i, - 'b': i+1, - 'c': i+2, - 'd': i+3, - 'e': i+4 - }; - forOwn( obj, onKey ); - if ( isnan( obj.a ) ) { - b.fail( 'should not be NaN' ); - } - } - b.toc(); - if ( isnan( obj.a ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::loop', function benchmark( b ) { - 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 ); - for ( j = 0; j < keys.length; j++ ) { - if ( isnan( obj[ keys[ j ] ] ) ) { - b.fail( 'should not be NaN' ); - } - } - } - b.toc(); - if ( isnan( obj.a ) ) { - b.fail( 'should not be NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/for-own/docs/repl.txt b/lib/node_modules/@stdlib/utils/for-own/docs/repl.txt deleted file mode 100644 index c0267f76720b..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/docs/repl.txt +++ /dev/null @@ -1,49 +0,0 @@ - -{{alias}}( obj, fcn[, thisArg] ) - Invokes a function for each own enumerable property of an object. - - When invoked, the function is provided three arguments: - - - value: object property value. - - key: object property. - - obj: the input object. - - To terminate iteration before visiting all properties, the provided function - must explicitly return `false`. - - The function determines the list of own enumerable properties *before* - invoking the provided function. Hence, any modifications made to the input - object *after* calling this function (such as adding and removing - properties) will *not* affect the list of visited properties. - - Property iteration order is *not* guaranteed. - - Parameters - ---------- - obj: Object - Input object, including arrays, typed arrays, and other collections. - - fcn: Function - The function to invoke for each own enumerable property. - - thisArg: any (optional) - Execution context. - - Returns - ------- - out: Object - Input object. - - Examples - -------- - > function logger( v, k ) { console.log( '%s: %d', k, v ); }; - > var obj = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }; - > {{alias}}( obj, logger ) - a: 1 - b: 2 - c: 3 - d: 4 - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/utils/for-own/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/for-own/docs/types/index.d.ts deleted file mode 100644 index aeb8a7aabf2c..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/docs/types/index.d.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/** -* Invokes a function once for each own enumerable property of an object. -* -* ## Notes -* -* - When invoked, the function is provided three arguments: -* -* - `value`: object property value -* - `key`: object property -* - `obj`: the input object -* -* - To terminate iteration before visiting all properties, the provided function must explicitly return `false`. -* -* - The function determines the list of own enumerable properties *before* invoking the provided function. Hence, any modifications made to the input object *after* calling this function (such as adding and removing properties) will *not* affect the list of visited properties. -* -* - Iteration order is **not** guaranteed. -* -* -* @param obj - input object -* @param fcn - function to invoke -* @param thisArg - execution context -* @returns obj - input object -* -* @example -* function log( v, key ) { -* console.log( '%s: %d', key, v ); -* } -* -* var obj = { -* 'a': 1, -* 'b': 2, -* 'c': 3, -* 'd': 4 -* }; -* -* forOwn( obj, log ); -*/ -declare function forOwn( obj: any, fcn: Function, thisArg?: any ): any; - - -// EXPORTS // - -export = forOwn; diff --git a/lib/node_modules/@stdlib/utils/for-own/docs/types/test.ts b/lib/node_modules/@stdlib/utils/for-own/docs/types/test.ts deleted file mode 100644 index bf6de7772023..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/docs/types/test.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-new-wrappers */ - -import forOwn = require( './index' ); - -const log = ( v: any, key: string ): string => { - return `${key}: ${v}`; -}; - -// TESTS // - -// The function returns an object... -{ - forOwn( new String( 'abc' ), log ); // $ExpectType any - forOwn( new String( 'abc' ), log, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a second argument which is not a function... -{ - forOwn( new String( 'abc' ), 2 ); // $ExpectError - forOwn( new String( 'abc' ), false ); // $ExpectError - forOwn( new String( 'abc' ), true ); // $ExpectError - forOwn( new String( 'abc' ), 'abc' ); // $ExpectError - forOwn( new String( 'abc' ), {} ); // $ExpectError - forOwn( new String( 'abc' ), [] ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - forOwn(); // $ExpectError - forOwn( new String( 'abc' ) ); // $ExpectError - forOwn( new String( 'abc' ), log, {}, 3 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/utils/for-own/examples/index.js b/lib/node_modules/@stdlib/utils/for-own/examples/index.js deleted file mode 100644 index 2247d7c1d033..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/examples/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var fromCodePoint = require( '@stdlib/string/from-code-point' ); -var forOwn = require( './../lib' ); - -function update( value, key, obj ) { - console.log( '%s: %d', key, value ); - obj[ key ] *= value; -} - -var obj; -var key; -var i; - -obj = {}; -for ( i = 0; i < 26; i++ ) { - key = fromCodePoint( 97 + i ); - obj[ key ] = i; -} - -forOwn( obj, update ); -console.log( obj ); diff --git a/lib/node_modules/@stdlib/utils/for-own/lib/index.js b/lib/node_modules/@stdlib/utils/for-own/lib/index.js deleted file mode 100644 index 34ec17d5276f..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Invoke a function once for each own enumerable property of an object. -* -* @module @stdlib/utils/for-own -* -* @example -* var forOwn = require( '@stdlib/utils/for-own' ); -* -* function log( v, key ) { -* console.log( '%s: %d', key, v ); -* } -* -* var obj = { -* 'a': 1, -* 'b': 2, -* 'c': 3, -* 'd': 4 -* }; -* -* forOwn( obj, log ); -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/for-own/lib/main.js b/lib/node_modules/@stdlib/utils/for-own/lib/main.js deleted file mode 100644 index f889d7630469..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/lib/main.js +++ /dev/null @@ -1,85 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var objectKeys = require( '@stdlib/utils/keys' ); -var isFunction = require( '@stdlib/assert/is-function' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Invokes a function once for each own enumerable property of an object. -* -* ## Notes -* -* - Iteration order is **not** guaranteed. -* -* @param {Object} obj - input object -* @param {Function} fcn - function to invoke -* @param {*} [thisArg] - execution context -* @throws {TypeError} first argument must be an object -* @throws {TypeError} second argument must be a function -* @returns {Object} obj - input object -* -* @example -* function log( v, key ) { -* console.log( '%s: %d', key, v ); -* } -* -* var obj = { -* 'a': 1, -* 'b': 2, -* 'c': 3, -* 'd': 4 -* }; -* -* forOwn( obj, log ); -*/ -function forOwn( obj, fcn, thisArg ) { - var keys; - var bool; - var len; - var k; - var i; - if ( typeof obj !== 'object' || obj === null ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', obj ) ); - } - if ( !isFunction( fcn ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', fcn ) ); - } - keys = objectKeys( obj ); - len = keys.length; - for ( i = 0; i < len; i++ ) { - k = keys[ i ]; - bool = fcn.call( thisArg, obj[ k ], k, obj ); - if ( bool === false ) { - return obj; - } - } - return obj; -} - - -// EXPORTS // - -module.exports = forOwn; diff --git a/lib/node_modules/@stdlib/utils/for-own/package.json b/lib/node_modules/@stdlib/utils/for-own/package.json deleted file mode 100644 index 1d6cfba7cc2b..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/package.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "name": "@stdlib/utils/for-own", - "version": "0.0.0", - "description": "Invoke a function for each own enumerable property of an object.", - "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", - "for", - "own", - "forown", - "object.keys", - "keys", - "properties", - "props", - "enumerable", - "iterate", - "object", - "obj" - ] -} diff --git a/lib/node_modules/@stdlib/utils/for-own/test/test.js b/lib/node_modules/@stdlib/utils/for-own/test/test.js deleted file mode 100644 index f9b5d10c5335..000000000000 --- a/lib/node_modules/@stdlib/utils/for-own/test/test.js +++ /dev/null @@ -1,224 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var defineProperty = require( '@stdlib/utils/define-property' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var noop = require( '@stdlib/utils/noop' ); -var forOwn = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof forOwn, '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 - ]; - - 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() { - forOwn( value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a function to invoke', 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() { - forOwn( {}, value ); - }; - } -}); - -tape( 'if provided an empty object, the function never invokes a provided function', function test( t ) { - var obj = {}; - - function foo() { - t.fail( 'should not be invoked' ); - } - - forOwn( obj, foo ); - - t.deepEqual( obj, {}, 'expected result' ); - t.end(); -}); - -tape( 'the function returns the input object', function test( t ) { - var obj; - var out; - - function foo() { - t.pass( 'invoked provided function' ); - } - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - - out = forOwn( obj, foo ); - - t.strictEqual( out, obj, 'returns input object' ); - t.end(); -}); - -tape( 'the function invokes a provided function for each own enumerable property in an object', function test( t ) { - var expected; - var obj; - var out; - - function copy( value, key ) { - out[ key ] = value; - } - - function Obj() { - if ( !(this instanceof Obj) ) { - return new Obj(); - } - this.a = 1; - this.b = 2; - this.c = 3; - - defineProperty( this, 'nonenum', { - 'configurable': false, - 'writable': false, - 'enumerable': false, - 'value': 'beep' - }); - - return this; - } - - Obj.prototype.d = 4; - Obj.prototype.e = 5; - - out = {}; - - obj = new Obj(); - forOwn( obj, copy ); - - expected = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - t.deepEqual( out, expected, 'expected result' ); - t.end(); -}); - -tape( 'the function supports early termination', function test( t ) { - var keys; - var obj; - var out; - - function copy( value, key ) { - out[ key ] = value; - - // Explicitly return `false`: - return false; - } - - obj = { - 'a': 1, - 'b': 2, - 'c': 3 - }; - out = {}; - - forOwn( obj, copy ); - - keys = objectKeys( out ); - t.strictEqual( keys.length, 1, 'object contains only one property' ); - t.strictEqual( out[ keys[0] ], obj[ keys[0] ], 'copies property value' ); - - t.end(); -}); - -tape( 'the function supports providing an execution context', function test( t ) { - var ctx; - var obj; - - function sum( value ) { - /* eslint-disable no-invalid-this */ - this.sum += value; - this.count += 1; - } - - ctx = { - 'sum': 0.0, - 'count': 0.0 - }; - obj = { - 'a': 1.0, - 'b': 2.0, - 'c': 3.0 - }; - - forOwn( obj, sum, ctx ); - - t.strictEqual( ctx.sum/ctx.count, 2.0, 'expected result' ); - - t.end(); -});