From 2932f9658e5e618814b9b7cf9348c67815955936 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sun, 11 Jan 2026 11:33:44 +0530 Subject: [PATCH 1/4] feat: add `object/deep-set` Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/object/deep-set/README.md | 273 ++++++++++++++++ .../object/deep-set/benchmark/benchmark.js | 140 +++++++++ .../@stdlib/object/deep-set/docs/repl.txt | 86 ++++++ .../object/deep-set/docs/types/index.d.ts | 180 +++++++++++ .../object/deep-set/docs/types/test.ts | 134 ++++++++ .../@stdlib/object/deep-set/examples/index.js | 49 +++ .../@stdlib/object/deep-set/lib/defaults.js | 39 +++ .../@stdlib/object/deep-set/lib/dset.js | 80 +++++ .../@stdlib/object/deep-set/lib/factory.js | 99 ++++++ .../@stdlib/object/deep-set/lib/index.js | 58 ++++ .../@stdlib/object/deep-set/lib/main.js | 120 +++++++ .../@stdlib/object/deep-set/lib/validate.js | 74 +++++ .../@stdlib/object/deep-set/package.json | 69 +++++ .../@stdlib/object/deep-set/test/test.dset.js | 292 ++++++++++++++++++ .../object/deep-set/test/test.factory.js | 221 +++++++++++++ .../@stdlib/object/deep-set/test/test.js | 201 ++++++++++++ .../object/deep-set/test/test.validate.js | 132 ++++++++ 17 files changed, 2247 insertions(+) create mode 100644 lib/node_modules/@stdlib/object/deep-set/README.md create mode 100644 lib/node_modules/@stdlib/object/deep-set/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/object/deep-set/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/object/deep-set/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/object/deep-set/examples/index.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/lib/defaults.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/lib/dset.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/lib/factory.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/lib/index.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/lib/main.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/lib/validate.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/package.json create mode 100644 lib/node_modules/@stdlib/object/deep-set/test/test.dset.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/test/test.factory.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/test/test.js create mode 100644 lib/node_modules/@stdlib/object/deep-set/test/test.validate.js diff --git a/lib/node_modules/@stdlib/object/deep-set/README.md b/lib/node_modules/@stdlib/object/deep-set/README.md new file mode 100644 index 000000000000..9277862e68b1 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/README.md @@ -0,0 +1,273 @@ + + +# Deep Set + +> Set a nested property value. + +
+ +## Usage + +```javascript +var deepSet = require( '@stdlib/object/deep-set' ); +``` + +#### deepSet( obj, path, value\[, options] ) + +Sets a nested property value. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a.b.c', 'beep' ); +// returns true + +console.log( obj ); +// => { 'a': { 'b': { 'c': 'beep' } } } +``` + +If the function is able to deep set a nested property, the function returns `true`; otherwise, the function returns `false`. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a.b.c', 'woot' ); +// returns true + +bool = deepSet( obj, 'a.beep.c', 'boop' ); +// returns false + +bool = deepSet( null, 'a.beep.c', 'boop' ); +// returns false + +bool = deepSet( 'bap', 'a.beep.c', 'boop' ); +// returns false +``` + +For `paths` including `arrays`, specify the numeric index. + + + +```javascript +var arr = [ + { 'a': [ { 'x': 5 } ] }, + { 'a': [ { 'x': 10 } ] } +]; + +var bool = deepSet( arr, '1.a.0.x', 25 ); +// returns true + +console.log( arr ); +/* => + [ + { 'a': [ { 'x': 5 } ] }, + { 'a': [ { 'x': 25 } ] } + ] +*/ +``` + +The key `path` may be specified as either a delimited `string` or a key `array`. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, [ 'a', 'b', 'c' ], 'beep' ); // obj => { 'a': { 'b': { 'c': 'beep' } } } +// returns true +``` + +If `value` is a `function`, the argument is treated as a `callback` and should return a value to set. + + + +```javascript +function set( val ) { + var ch = val; + var i; + for ( i = 0; i < 4; i++ ) { + val += ch; + } + return val; +} +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a.b.c', set ); // obj => { 'a': { 'b': { 'c': 'ddddd' } } } +// returns true +``` + +The function accepts the following `options`: + +- **sep**: key path separator. Default: `'.'`. +- **create**: `boolean` indicating whether to create a path if the key path does not already exist. Default: `false`. + +By default, the function assumes `dot` separated key values. To specify an alternative separator, set the `sep` option. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a/b/c', 'beep', { + 'sep': '/' +}); +// returns true + +console.log( obj ); +// => { 'a': { 'b': { 'c': 'beep' } } } +``` + +To create a key path which does not already exist, set the `create` option to `true`. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = deepSet( obj, 'a.e.c', 'boop', { + 'create': true +}); +// returns true + +console.log( obj ); +/* => + { + 'a': { + 'b': { + 'c': 'beep' + }, + 'e': { + 'c': 'boop' + } + } + } +*/ +``` + +#### deepSet.factory( path\[, options] ) + +Creates a reusable deep set function. The factory method ensures a `deepSet` function is configured identically by using the same set of provided `options`. + +```javascript +var dset = deepSet.factory( 'a/b/c', { + 'create': true, + 'sep': '/' +}); +``` + +#### dset( obj, value ) + +Sets a nested property value. + + + +```javascript +var dset = deepSet.factory( 'a.b.c' ); + +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var bool = dset( obj, 'beep' ); +// returns true + +console.log( obj ); +// => { 'a': { 'b': { 'c': 'beep' } } } +``` + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var deepSet = require( '@stdlib/object/deep-set' ); + +var data; +var bool; +var keys; +var i; + +function set( val ) { + return val * 10.0; +} + +data = new Array( 100 ); +for ( i = 0; i < data.length; i++ ) { + data[ i ] = { + 'x': Date.now(), + 'y': [ randu(), randu(), i ] + }; +} + +keys = [ 0, 'y', 2 ]; +for ( i = 0; i < data.length; i++ ) { + keys[ 0 ] = i; + bool = deepSet( data, keys, set ); + if ( !bool ) { + console.error( 'Unable to deep set value.' ); + } +} +console.log( data ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/object/deep-set/benchmark/benchmark.js b/lib/node_modules/@stdlib/object/deep-set/benchmark/benchmark.js new file mode 100644 index 000000000000..9019c9896903 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/benchmark/benchmark.js @@ -0,0 +1,140 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var deepSet = require( './../lib' ); + + +// FUNCTIONS // + +function set1() { + return randu(); +} + +function set2( val ) { + return val * 1.5; +} + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var bool; + var obj; + var val; + var i; + + obj = { + 'a': { + 'b': { + 'c': { + 'd': 0.5 + } + } + } + }; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + val = randu(); + bool = deepSet( obj, 'a.b.c.d', val ); + if ( bool !== true ) { + b.fail( 'should return true' ); + } + } + b.toc(); + if ( bool !== true ) { + b.fail( 'should return true' ); + } + if ( val !== obj.a.b.c.d ) { + b.fail( 'should successfully set property value' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::setter', function benchmark( b ) { + var bool; + var obj; + var i; + + obj = { + 'a': { + 'b': { + 'c': { + 'd': 0.5 + } + } + } + }; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = deepSet( obj, 'a.b.c.d', set1 ); + if ( bool !== true ) { + b.fail( 'should return true' ); + } + } + b.toc(); + if ( bool !== true ) { + b.fail( 'should return true' ); + } + if ( obj.a.b.c.d !== obj.a.b.c.d ) { + b.fail( 'should successfully set property value' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':factory', function benchmark( b ) { + var bool; + var dset; + var obj; + var i; + + obj = { + 'a': { + 'b': { + 'c': { + 'd': 0.5 + } + } + } + }; + dset = deepSet.factory( 'a.b.c.d' ); + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = dset( obj, set2 ); + if ( bool !== true ) { + b.fail( 'should return true' ); + } + } + b.toc(); + if ( bool !== true ) { + b.fail( 'should return true' ); + } + if ( obj.a.b.c.d !== obj.a.b.c.d ) { + b.fail( 'should successfully set property value' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/object/deep-set/docs/repl.txt b/lib/node_modules/@stdlib/object/deep-set/docs/repl.txt new file mode 100644 index 000000000000..8f6adcb2badf --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/docs/repl.txt @@ -0,0 +1,86 @@ + +{{alias}}( obj, path, value[, options] ) + Sets a nested property value. + + Parameters + ---------- + obj: ObjectLike + Input object. + + path: string|Array + Key path. + + value: any + Value to set. + + options: Object (optional) + Options. + + options.create: boolean (optional) + Boolean indicating whether to create a path if the key path does not + already exist. Default: false. + + options.sep: string (optional) + Key path separator. Default: '.'. + + Returns + ------- + bool: boolean + Boolean indicating if the property was successfully set. + + Examples + -------- + > var obj = { 'a': { 'b': { 'c': 'd' } } }; + > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) + true + + // Specify an alternative separator via the sep option: + > obj = { 'a': { 'b': { 'c': 'd' } } }; + > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); + > obj + { 'a': { 'b': { 'c': 'beep' } } } + + // To create a key path which does not exist, set the create option to true: + > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); + > obj + { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } + + +{{alias}}.factory( path[, options] ) + Creates a reusable deep set function. + + Parameters + ---------- + path: string|Array + Key path. + + options: Object (optional) + Options. + + options.create: boolean (optional) + Boolean indicating whether to create a path if the key path does not + already exist. Default: false. + + options.sep: string (optional) + Key path separator. Default: '.'. + + Returns + ------- + out: Function + Deep get function. + + Examples + -------- + > var dset = {{alias}}.factory( 'a/b/c', { + ... 'create': true, + ... 'sep': '/' + ... }); + > var obj = { 'a': { 'b': { 'c': 'd' } } }; + > var bool = dset( obj, 'beep' ) + true + > obj + { 'a': { 'b': { 'c': 'beep' } } } + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/object/deep-set/docs/types/index.d.ts b/lib/node_modules/@stdlib/object/deep-set/docs/types/index.d.ts new file mode 100644 index 000000000000..4dda520f457c --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/docs/types/index.d.ts @@ -0,0 +1,180 @@ +/* +* @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 + +/** +* Interface defining function options. +*/ +interface Options { + /** + * Boolean indicating whether to create a path if the key path does not already exist. + */ + create?: boolean; + + /** + * Key path separator. + */ + sep?: string; +} + +/** +* Sets a nested property. +* +* @param obj - input object +* @param value - value to set +* @returns boolean indicating if the property was successfully set +*/ +type Unary = ( obj: any, value: any ) => boolean; + +/** +* Interface for setting nested property values. +*/ +interface DeepSet { + /** + * Sets a nested property value. + * + * @param obj - input object + * @param path - key path + * @param value - value to set + * @param options - function options + * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) + * @param options.sep - key path separator (default: '.') + * @returns boolean indicating if the property was successfully set + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( obj, 'a.b.c', 'woot' ); + * // returns true + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( obj, 'a.beep.c', 'boop' ); + * // returns false + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( null, 'a.beep.c', 'boop' ); + * // returns false + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); + * // returns false + * + * @example + * var arr = [ + * { 'a': [ {'x': 5} ] }, + * { 'a': [ {'x': 10} ] } + * ]; + * var bool = deepSet( arr, '1.a.0.x', 25 ); + * // returns true + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( obj, 'a/b/c', 'beep', { + * 'sep': '/' + * }); + * // returns true + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = deepSet( obj, 'a.e.c', 'boop', { + * 'create': true + * }); + * // returns true + */ + ( obj: any, path: string | Array, value: any, options?: Options ): boolean; + + /** + * Creates a reusable deep set function. + * + * @param path - key path + * @param options - function options + * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) + * @param options.sep - key path separator (default: '.') + * @returns deep set function + * + * @example + * var dset = deepSet.factory( 'a/b/c', { + * 'create': true, + * 'sep': '/' + * }); + */ + factory( path: string | Array, options?: Options ): Unary; +} + +/** +* Sets a nested property value. +* +* @param obj - input object +* @param path - key path +* @param value - value to set +* @param options - function options +* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) +* @param options.sep - key path separator (default: '.') +* @returns boolean indicating if the property was successfully set +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.b.c', 'woot' ); +* // returns true +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.beep.c', 'boop' ); +* // returns false +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( null, 'a.beep.c', 'boop' ); +* // returns false +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); +* // returns false +* +* @example +* var arr = [ +* { 'a': [ {'x': 5} ] }, +* { 'a': [ {'x': 10} ] } +* ]; +* var bool = deepSet( arr, '1.a.0.x', 25 ); +* // returns true +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a/b/c', 'beep', { +* 'sep': '/' +* }); +* // returns true +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.e.c', 'boop', { +* 'create': true +* }); +* // returns true +*/ +declare var deepSet: DeepSet; + + +// EXPORTS // + +export = deepSet; diff --git a/lib/node_modules/@stdlib/object/deep-set/docs/types/test.ts b/lib/node_modules/@stdlib/object/deep-set/docs/types/test.ts new file mode 100644 index 000000000000..ed1c84fcea85 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/docs/types/test.ts @@ -0,0 +1,134 @@ +/* +* @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. +*/ + +import deepSet = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean + deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean + deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + deepSet( obj, true, 'e' ); // $ExpectError + deepSet( obj, false, 'e' ); // $ExpectError + deepSet( obj, 2.12, 'e' ); // $ExpectError + deepSet( obj, {}, 'e' ); // $ExpectError + deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError + deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not an object... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `create` option which is not a boolean... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `sep` option which is not a string... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError + deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided fewer than three arguments... +{ + deepSet(); // $ExpectError + deepSet( {} ); // $ExpectError + deepSet( {}, 'a.b.c' ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + deepSet.factory( 'a.b.c' ); // $ExpectType Unary + deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + deepSet.factory(); // $ExpectError + deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError +} + +// The `factory` method returns a function which returns a boolean... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + let fcn = deepSet.factory( 'a.b.c' ); + fcn( obj, 'e' ); // $ExpectType boolean + + fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); + fcn( obj, 'e' ); // $ExpectType boolean +} + +// The compiler throws an error if the `factory` method is provided a second argument which is not an object... +{ + deepSet.factory( 'a.b.c', null ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... +{ + deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... +{ + deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError + deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + const fcn = deepSet.factory( 'a.b.c' ); + fcn(); // $ExpectError + fcn( obj ); // $ExpectError + fcn( obj, 'e', 2 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/object/deep-set/examples/index.js b/lib/node_modules/@stdlib/object/deep-set/examples/index.js new file mode 100644 index 000000000000..dd760170e445 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/examples/index.js @@ -0,0 +1,49 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var deepSet = require( './../lib' ); + +var data; +var bool; +var keys; +var i; + +function set( val ) { + return val * 10.0; +} + +data = new Array( 100 ); +for ( i = 0; i < data.length; i++ ) { + data[ i ] = { + 'x': Date.now(), + 'y': [ randu(), randu(), i ] + }; +} + +keys = [ 0, 'y', 2 ]; +for ( i = 0; i < data.length; i++ ) { + keys[ 0 ] = i; + bool = deepSet( data, keys, set ); + if ( !bool ) { + console.error( 'Unable to deep set value.' ); + } +} +console.log( data ); diff --git a/lib/node_modules/@stdlib/object/deep-set/lib/defaults.js b/lib/node_modules/@stdlib/object/deep-set/lib/defaults.js new file mode 100644 index 000000000000..b8b7c5f20d66 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/lib/defaults.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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'; + +// MAIN // + +/** +* Returns default options. +* +* @private +* @returns {Object} default options +*/ +function defaults() { + return { + 'create': false, + 'sep': '.' + }; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/object/deep-set/lib/dset.js b/lib/node_modules/@stdlib/object/deep-set/lib/dset.js new file mode 100644 index 000000000000..64410eec6602 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/lib/dset.js @@ -0,0 +1,80 @@ +/** +* @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 isObjectLike = require( '@stdlib/assert/is-object-like' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); + + +// MAIN // + +/** +* Sets a nested property. +* +* @private +* @param {ObjectLike} obj - input object +* @param {Array} props - list of properties defining a key path +* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist +* @param {*} val - value to set +* @returns {boolean} boolean indicating if the property was successfully set +*/ +function deepSet( obj, props, create, val ) { + var bool; + var len; + var v; + var p; + var i; + + len = props.length; + bool = false; + v = obj; + for ( i = 0; i < len; i++ ) { + p = props[ i ]; + if ( isObjectLike( v ) ) { + if ( !hasOwnProp( v, p ) ) { + if ( create ) { + v[ p ] = {}; + } else { + break; + } + } + if ( i === len-1 ) { + if ( isFunction( val ) ) { + v[ p ] = val( v[ p ] ); + } else { + v[ p ] = val; + } + bool = true; + } else { + v = v[ p ]; + } + } else { + break; + } + } + return bool; +} + + +// EXPORTS // + +module.exports = deepSet; diff --git a/lib/node_modules/@stdlib/object/deep-set/lib/factory.js b/lib/node_modules/@stdlib/object/deep-set/lib/factory.js new file mode 100644 index 000000000000..612dd75372e9 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/lib/factory.js @@ -0,0 +1,99 @@ +/** +* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isArray = require( '@stdlib/assert/is-array' ); +var isObjectLike = require( '@stdlib/assert/is-object-like' ); +var format = require( '@stdlib/string/format' ); +var validate = require( './validate.js' ); +var defaults = require( './defaults.js' ); +var dset = require( './dset.js' ); + + +// MAIN // + +/** +* Creates a reusable deep set function. +* +* @param {(string|Array)} path - key path +* @param {Options} [options] - function options +* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist +* @param {string} [options.sep='.'] - key path separator +* @throws {TypeError} first argument must be a string or key array +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {Function} deep set function +* +* @example +* var dset = factory( 'a/b/c', { +* 'create': true, +* 'sep': '/' +* }); +*/ +function factory( path, options ) { + var isStr; + var props; + var opts; + var err; + + isStr = isString( path ); + if ( !isStr && !isArray( path ) ) { + throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + } + opts = defaults(); + if ( arguments.length > 1 ) { + err = validate( opts, options ); + if ( err ) { + throw err; + } + } + if ( isStr ) { + props = path.split( opts.sep ); + } else { + props = path; + } + return deepSet; + + /** + * Sets a nested property. + * + * @private + * @param {ObjectLike} obj - input object + * @param {*} value - value to set + * @returns {boolean} boolean indicating if the property was successfully set + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var bool = dset( obj, 'beep' ); + */ + function deepSet( obj, value ) { + if ( isObjectLike( obj ) ) { + return dset( obj, props, opts.create, value ); + } + return false; + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/object/deep-set/lib/index.js b/lib/node_modules/@stdlib/object/deep-set/lib/index.js new file mode 100644 index 000000000000..dd1c6e8c766d --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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'; + +/** +* Set a nested property value. +* +* @module @stdlib/object/deep-set +* +* @example +* var deepSet = require( '@stdlib/object/deep-set' ); +* +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.b.c', 'beep' ); +* // returns true +* +* var dset = deepSet.factory( 'a/b/c', { +* 'create': true, +* 'sep': '/' +* }); +* +* obj = { 'a': { 'b': { 'c': 'd' } } }; +* +* bool = dset( obj, 'beep' ); +* // returns true +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var factory = require( './factory.js' ); + + +// MAIN // + +setReadOnly( main, 'factory', factory ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/object/deep-set/lib/main.js b/lib/node_modules/@stdlib/object/deep-set/lib/main.js new file mode 100644 index 000000000000..676c99c8a17b --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/lib/main.js @@ -0,0 +1,120 @@ +/** +* @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 isObjectLike = require( '@stdlib/assert/is-object-like' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isArray = require( '@stdlib/assert/is-array' ); +var format = require( '@stdlib/string/format' ); +var validate = require( './validate.js' ); +var defaults = require( './defaults.js' ); +var dset = require( './dset.js' ); + + +// MAIN // + +/** +* Sets a nested property value. +* +* @param {ObjectLike} obj - input object +* @param {(string|Array)} path - key path +* @param {*} value - value to set +* @param {Options} [options] - function options +* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist +* @param {string} [options.sep='.'] - key path separator +* @throws {TypeError} second argument must be a string or key array +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options +* @returns {boolean} boolean indicating if the property was successfully set +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.b.c', 'woot' ); +* // returns true +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.beep.c', 'boop' ); +* // returns false +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( null, 'a.beep.c', 'boop' ); +* // returns false +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); +* // returns false +* +* @example +* var arr = [ +* { 'a': [ {'x': 5} ] }, +* { 'a': [ {'x': 10} ] } +* ]; +* var bool = deepSet( arr, '1.a.0.x', 25 ); +* // returns true +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a/b/c', 'beep', { +* 'sep': '/' +* }); +* // returns true +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var bool = deepSet( obj, 'a.e.c', 'boop', { +* 'create': true +* }); +* // returns true +*/ +function deepSet( obj, path, value, options ) { + var isStr; + var props; + var opts; + var err; + if ( !isObjectLike( obj ) ) { + return false; + } + isStr = isString( path ); + if ( !isStr && !isArray( path ) ) { + throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); + } + opts = defaults(); + if ( arguments.length > 3 ) { + err = validate( opts, options ); + if ( err ) { + throw err; + } + } + if ( isStr ) { + props = path.split( opts.sep ); + } else { + props = path; + } + return dset( obj, props, opts.create, value ); +} + + +// EXPORTS // + +module.exports = deepSet; diff --git a/lib/node_modules/@stdlib/object/deep-set/lib/validate.js b/lib/node_modules/@stdlib/object/deep-set/lib/validate.js new file mode 100644 index 000000000000..c3519fdfb92a --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/lib/validate.js @@ -0,0 +1,74 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isObject = require( '@stdlib/assert/is-plain-object' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Validates function options. +* +* @private +* @param {Object} opts - destination for function options +* @param {Options} options - function options +* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist +* @param {string} [options.sep] - key path separator +* @returns {(Error|null)} error or null +* +* @example +* var opts = {}; +* var options = { +* 'sep': '/' +* }; +* var err = validate( opts, options ); +* if ( err ) { +* throw err; +* } +*/ +function validate( opts, options ) { + if ( !isObject( options ) ) { + return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'create' ) ) { + opts.create = options.create; + if ( !isBoolean( opts.create ) ) { + return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); + } + } + if ( hasOwnProp( options, 'sep' ) ) { + opts.sep = options.sep; + if ( !isString( opts.sep ) ) { + return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); + } + } + return null; +} + + +// EXPORTS // + +module.exports = validate; diff --git a/lib/node_modules/@stdlib/object/deep-set/package.json b/lib/node_modules/@stdlib/object/deep-set/package.json new file mode 100644 index 000000000000..586ae9ac4d04 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/object/deep-set", + "version": "0.0.0", + "description": "Set a nested property value.", + "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", + "deep", + "set", + "assign", + "object", + "obj", + "array", + "nested", + "property", + "prop" + ] +} diff --git a/lib/node_modules/@stdlib/object/deep-set/test/test.dset.js b/lib/node_modules/@stdlib/object/deep-set/test/test.dset.js new file mode 100644 index 000000000000..0530f3ee5e04 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/test/test.dset.js @@ -0,0 +1,292 @@ +/** +* @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 dset = require( './../lib/dset.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dset, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function deep sets a nested property value', function test( t ) { + var expected; + var bool; + var obj; + + obj = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + expected = { + 'a': { + 'b': { + 'c': 'beep' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + + bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); + t.deepEqual( obj, expected, 'deep sets object' ); + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `true` if able to successfully set', function test( t ) { + var bool; + var obj; + + obj = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + + bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns `false` if unable to successfully set', function test( t ) { + var bool; + var obj; + + obj = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + + bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); + t.strictEqual( bool, false, 'returns expected value' ); + + bool = dset( obj, ['null', 'e'], false, 'beep' ); + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); +}); + +tape( 'the function deep sets an array', function test( t ) { + var expected; + var bool; + var obj; + + obj = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + expected = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 200 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + + bool = dset( obj, ['arr', 0, 'y'], false, 200 ); + t.deepEqual( obj, expected, 'deep sets object' ); + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function creates properties which do not exist', function test( t ) { + var expected; + var bool; + var obj; + + obj = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + expected = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + }, + { + 'y': 200 + } + ], + 'null': null + }; + + bool = dset( obj, ['arr', 2, 'y'], true, 200 ); + t.deepEqual( obj, expected, 'deep sets object' ); + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function deep sets using a callback function', function test( t ) { + var expected; + var bool; + var obj; + + obj = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + + expected = { + 'a': { + 'b': { + 'c': 'dub-beat' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + + bool = dset( obj, ['a', 'b', 'c'], false, set ); + t.deepEqual( obj, expected, 'deep sets object' ); + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function set( val ) { + return val + 'ub-beat'; + } +}); diff --git a/lib/node_modules/@stdlib/object/deep-set/test/test.factory.js b/lib/node_modules/@stdlib/object/deep-set/test/test.factory.js new file mode 100644 index 000000000000..de6aba4531c2 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/test/test.factory.js @@ -0,0 +1,221 @@ +/** +* @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 factory = require( './../lib/factory.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { + var values; + var i; + + values = [ + 5, + null, + void 0, + NaN, + true, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + factory( value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + null, + NaN, + true, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + factory( 'a', value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid option', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + null, + NaN, + {}, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + factory( 'a', { + 'create': value + }); + }; + } +}); + +tape( 'the function returns a function', function test( t ) { + var dset = factory( 'a/b', { + 'create': true, + 'sep': '/' + }); + t.strictEqual( typeof dset, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { + var values; + var dset; + var i; + + values = [ + '5', + 5, + null, + void 0, + NaN, + true, + function noop() {} + ]; + + dset = factory( 'a/b', { + 'create': true, + 'sep': '/' + }); + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( dset( values[ i ], 5 ), false, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the returned function returns a boolean', function test( t ) { + var bool; + var dset; + var obj; + + dset = factory( 'a', { + 'create': false, + 'sep': '.' + }); + + obj = { + 'a': 5 + }; + bool = dset( obj, 4 ); + t.strictEqual( bool, true, 'returns expected value' ); + + obj = { + 'b': 5 + }; + bool = dset( obj, 4 ); + t.strictEqual( bool, false, 'returns expected value' ); + + dset = factory( 'a', { + 'create': true + }); + + obj = { + 'b': 5 + }; + bool = dset( obj, 4 ); + t.strictEqual( bool, true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the returned function deep sets', function test( t ) { + var expected; + var dset; + var bool; + var obj; + + dset = factory( ['a', 'b'] ); + + obj = { + 'a': { + 'b': 0 + } + }; + + bool = dset( obj, 4 ); + expected = { + 'a': { + 'b': 4 + } + }; + + t.strictEqual( bool, true, 'returns expected value' ); + t.deepEqual( obj, expected, 'deep sets object' ); + + bool = dset( obj, 40 ); + expected = { + 'a': { + 'b': 40 + } + }; + + t.strictEqual( bool, true, 'returns expected value' ); + t.deepEqual( obj, expected, 'deep sets object' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/object/deep-set/test/test.js b/lib/node_modules/@stdlib/object/deep-set/test/test.js new file mode 100644 index 000000000000..be3ca4522125 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/test/test.js @@ -0,0 +1,201 @@ +/** +* @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 deepSet = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function exports a factory function', function test( t ) { + t.strictEqual( typeof deepSet.factory, 'function', 'exports a factory function' ); + t.end(); +}); + +tape( 'the function returns `false` if provided a non-object or null', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + null, + void 0, + NaN, + true, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { + var values; + var i; + + values = [ + 5, + null, + void 0, + NaN, + true, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var obj = { + 'a': 5 + }; + deepSet( obj, value, 5 ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + null, + NaN, + true, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var obj = { + 'a': 5 + }; + deepSet( obj, 'a', 4, value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid option', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + null, + NaN, + {}, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var obj = { + 'a': 5 + }; + deepSet( obj, 'a', 4, { + 'create': value + }); + }; + } +}); + +tape( 'the function returns a boolean', function test( t ) { + var bool; + var obj; + + obj = { + 'a': 5 + }; + bool = deepSet( obj, 'a', 4 ); + t.strictEqual( bool, true, 'returns expected value' ); + + bool = deepSet( obj, 'b', 4, { + 'create': false + }); + t.strictEqual( bool, false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function deep sets', function test( t ) { + var expected; + var bool; + var obj; + + obj = { + 'a': { + 'b': 0 + } + }; + + bool = deepSet( obj, 'a.b', 4 ); + expected = { + 'a': { + 'b': 4 + } + }; + + t.strictEqual( bool, true, 'returns expected value' ); + t.deepEqual( obj, expected, 'deep sets object' ); + + bool = deepSet( obj, ['a', 'b'], 40 ); + expected = { + 'a': { + 'b': 40 + } + }; + + t.strictEqual( bool, true, 'returns expected value' ); + t.deepEqual( obj, expected, 'deep sets object' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/object/deep-set/test/test.validate.js b/lib/node_modules/@stdlib/object/deep-set/test/test.validate.js new file mode 100644 index 000000000000..49797b7574f3 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-set/test/test.validate.js @@ -0,0 +1,132 @@ +/** +* @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 Boolean = require( '@stdlib/boolean/ctor' ); +var validate = require( './../lib/validate.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof validate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an error if not provided an object', function test( t ) { + var values; + var err; + var i; + + values = [ + '5', + 5, + NaN, + true, + null, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, values[i] ); + t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { + var values; + var err; + var i; + + values = [ + '5', + 5, + null, + NaN, + new Boolean( true ), + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, { + 'create': values[i] + }); + t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { + var values; + var err; + var i; + + values = [ + new String( '5' ), + null, + 5, + NaN, + true, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, { + 'sep': values[i] + }); + t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); + } + t.end(); +}); + +tape( 'the function returns `null` if all options are valid', function test( t ) { + var opts; + var obj; + + opts = { + 'create': true, + 'sep': '_' + }; + obj = {}; + t.strictEqual( validate( obj, opts ), null, 'returns expected value' ); + t.strictEqual( obj.create, true, 'sets create option' ); + t.strictEqual( obj.sep, '_', 'sets sep option' ); + + opts = { + 'beep': true, + 'boop': false + }; + obj = {}; + t.strictEqual( validate( obj, opts ), null, 'returns expected value' ); + t.deepEqual( obj, {}, 'does not set any properties' ); + t.end(); +}); From bf123ae437f1088c1adbd3ab49bf1346a8c11ead Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sun, 11 Jan 2026 11:35:13 +0530 Subject: [PATCH 2/4] remove: remove `deepSet` from namespace This commit removes the `deepSet` symbol from the `@stdlib/utils` namespace due to a package migration. BREAKING CHANGE: remove `deepSet` 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 | 56 ------------------- lib/node_modules/@stdlib/utils/lib/index.js | 9 --- 2 files changed, 65 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 5edf048bf203..eba897b1b602 100644 --- a/lib/node_modules/@stdlib/utils/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/docs/types/index.d.ts @@ -38,7 +38,6 @@ import curry = require( '@stdlib/utils/curry' ); import curryRight = require( '@stdlib/utils/curry-right' ); import decorateAfter = require( '@stdlib/utils/decorate-after' ); import deepPluck = require( '@stdlib/utils/deep-pluck' ); -import deepSet = require( '@stdlib/utils/deep-set' ); import setConfigurableReadOnlyAccessor = require( '@stdlib/utils/define-configurable-read-only-accessor' ); import setConfigurableReadOnly = require( '@stdlib/utils/define-configurable-read-only-property' ); import setConfigurableReadWriteAccessor = require( '@stdlib/utils/define-configurable-read-write-accessor' ); @@ -762,61 +761,6 @@ interface Namespace { */ deepPluck: typeof deepPluck; - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = ns.deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = ns.deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = ns.deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = ns.deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = ns.deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = ns.deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = ns.deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - deepSet: typeof deepSet; - /** * Defines a configurable read-only accessor. * diff --git a/lib/node_modules/@stdlib/utils/lib/index.js b/lib/node_modules/@stdlib/utils/lib/index.js index 6249769a8851..57359b923586 100644 --- a/lib/node_modules/@stdlib/utils/lib/index.js +++ b/lib/node_modules/@stdlib/utils/lib/index.js @@ -202,15 +202,6 @@ setReadOnly( utils, 'decorateAfter', require( '@stdlib/utils/decorate-after' ) ) */ setReadOnly( utils, 'deepPluck', require( '@stdlib/utils/deep-pluck' ) ); -/** -* @name deepSet -* @memberof utils -* @readonly -* @type {Function} -* @see {@link module:@stdlib/utils/deep-set} -*/ -setReadOnly( utils, 'deepSet', require( '@stdlib/utils/deep-set' ) ); - /** * @name setConfigurableReadOnlyAccessor * @memberof utils From dbf7af8fda9e080fd4400430b3b587ad647a23be Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sun, 11 Jan 2026 11:42:45 +0530 Subject: [PATCH 3/4] refactor: update paths Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/assert/deep-has-own-property/README.md | 4 ++-- .../@stdlib/assert/deep-has-property/README.md | 4 ++-- .../@stdlib/namespace/alias2pkg/data/data.csv | 2 +- .../@stdlib/namespace/lib/namespace/d.js | 12 ++++++------ .../@stdlib/namespace/pkg2alias/data/data.csv | 2 +- .../@stdlib/namespace/pkg2related/data/data.csv | 10 +++++----- .../@stdlib/namespace/pkg2standalone/data/data.csv | 2 +- .../@stdlib/namespace/standalone2pkg/data/data.csv | 2 +- lib/node_modules/@stdlib/object/deep-get/README.md | 4 ++-- lib/node_modules/@stdlib/utils/deep-pluck/README.md | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/deep-has-own-property/README.md b/lib/node_modules/@stdlib/assert/deep-has-own-property/README.md index a49f6f5dd28c..f1f71a7ce738 100644 --- a/lib/node_modules/@stdlib/assert/deep-has-own-property/README.md +++ b/lib/node_modules/@stdlib/assert/deep-has-own-property/README.md @@ -255,7 +255,7 @@ bool = has( { 'a': [ { 'b': { 'c': 'd' } } ] } ); - [`@stdlib/assert/has-own-property`][@stdlib/assert/has-own-property]: test if an object has a specified property. - [`@stdlib/object/deep-get`][@stdlib/object/deep-get]: get a nested property value. - [`@stdlib/utils/deep-pluck`][@stdlib/utils/deep-pluck]: extract a nested property value from each element of an object array. -- [`@stdlib/utils/deep-set`][@stdlib/utils/deep-set]: set a nested property value. +- [`@stdlib/object/deep-set`][@stdlib/object/deep-set]: set a nested property value. @@ -275,7 +275,7 @@ bool = has( { 'a': [ { 'b': { 'c': 'd' } } ] } ); [@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-pluck -[@stdlib/utils/deep-set]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set +[@stdlib/object/deep-set]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/deep-set diff --git a/lib/node_modules/@stdlib/assert/deep-has-property/README.md b/lib/node_modules/@stdlib/assert/deep-has-property/README.md index 45502f88f247..bfbd95a2866c 100644 --- a/lib/node_modules/@stdlib/assert/deep-has-property/README.md +++ b/lib/node_modules/@stdlib/assert/deep-has-property/README.md @@ -251,7 +251,7 @@ bool = has( { 'a': [ { 'b': { 'c': 'd' } } ] } ); - [`@stdlib/assert/has-own-property`][@stdlib/assert/has-own-property]: test if an object has a specified property. - [`@stdlib/object/deep-get`][@stdlib/object/deep-get]: get a nested property value. - [`@stdlib/utils/deep-pluck`][@stdlib/utils/deep-pluck]: extract a nested property value from each element of an object array. -- [`@stdlib/utils/deep-set`][@stdlib/utils/deep-set]: set a nested property value. +- [`@stdlib/object/deep-set`][@stdlib/object/deep-set]: set a nested property value. @@ -271,7 +271,7 @@ bool = has( { 'a': [ { 'b': { 'c': 'd' } } ] } ); [@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-pluck -[@stdlib/utils/deep-set]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set +[@stdlib/object/deep-set]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/deep-set diff --git a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv index 0306d7705255..e13a5faf4f78 100644 --- a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv @@ -1585,7 +1585,7 @@ deepGet,"@stdlib/object/deep-get" deepHasOwnProp,"@stdlib/assert/deep-has-own-property" deepHasProp,"@stdlib/assert/deep-has-property" deepPluck,"@stdlib/utils/deep-pluck" -deepSet,"@stdlib/utils/deep-set" +deepSet,"@stdlib/object/deep-set" defineMemoizedProperty,"@stdlib/utils/define-memoized-property" defineProperties,"@stdlib/utils/define-properties" defineProperty,"@stdlib/utils/define-property" diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/d.js index e52149fe62ef..a59d623209af 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/d.js @@ -181,7 +181,7 @@ ns.push({ 'type': 'Function', 'related': [ '@stdlib/utils/deep-pluck', - '@stdlib/utils/deep-set' + '@stdlib/object/deep-set' ] }); @@ -195,7 +195,7 @@ ns.push({ '@stdlib/assert/has-own-property', '@stdlib/object/deep-get', '@stdlib/utils/deep-pluck', - '@stdlib/utils/deep-set' + '@stdlib/object/deep-set' ] }); @@ -209,7 +209,7 @@ ns.push({ '@stdlib/assert/has-own-property', '@stdlib/object/deep-get', '@stdlib/utils/deep-pluck', - '@stdlib/utils/deep-set' + '@stdlib/object/deep-set' ] }); @@ -220,14 +220,14 @@ ns.push({ 'type': 'Function', 'related': [ '@stdlib/object/deep-get', - '@stdlib/utils/deep-set' + '@stdlib/object/deep-set' ] }); ns.push({ 'alias': 'deepSet', - 'path': '@stdlib/utils/deep-set', - 'value': require( '@stdlib/utils/deep-set' ), + 'path': '@stdlib/object/deep-set', + 'value': require( '@stdlib/object/deep-set' ), 'type': 'Function', 'related': [ '@stdlib/object/deep-get', diff --git a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv index 1e99b8e06cbf..1d520fb37f1f 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv @@ -1585,7 +1585,7 @@ "@stdlib/assert/deep-has-own-property",deepHasOwnProp "@stdlib/assert/deep-has-property",deepHasProp "@stdlib/utils/deep-pluck",deepPluck -"@stdlib/utils/deep-set",deepSet +"@stdlib/object/deep-set",deepSet "@stdlib/utils/define-memoized-property",defineMemoizedProperty "@stdlib/utils/define-properties",defineProperties "@stdlib/utils/define-property",defineProperty diff --git a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv index a166967cd021..d4a1a58393d6 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv @@ -1581,11 +1581,11 @@ "@stdlib/streams/node/debug","@stdlib/streams/node/debug-sink,@stdlib/streams/node/inspect" "@stdlib/utils/decorate-after","" "@stdlib/assert/deep-equal","@stdlib/assert/is-strict-equal,@stdlib/assert/is-same-value" -"@stdlib/object/deep-get","@stdlib/utils/deep-pluck,@stdlib/utils/deep-set" -"@stdlib/assert/deep-has-own-property","@stdlib/assert/deep-has-property,@stdlib/assert/has-own-property,@stdlib/object/deep-get,@stdlib/utils/deep-pluck,@stdlib/utils/deep-set" -"@stdlib/assert/deep-has-property","@stdlib/assert/deep-has-own-property,@stdlib/assert/has-own-property,@stdlib/object/deep-get,@stdlib/utils/deep-pluck,@stdlib/utils/deep-set" -"@stdlib/utils/deep-pluck","@stdlib/object/deep-get,@stdlib/utils/deep-set" -"@stdlib/utils/deep-set","@stdlib/object/deep-get,@stdlib/utils/deep-pluck" +"@stdlib/object/deep-get","@stdlib/utils/deep-pluck,@stdlib/object/deep-set" +"@stdlib/assert/deep-has-own-property","@stdlib/assert/deep-has-property,@stdlib/assert/has-own-property,@stdlib/object/deep-get,@stdlib/utils/deep-pluck,@stdlib/object/deep-set" +"@stdlib/assert/deep-has-property","@stdlib/assert/deep-has-own-property,@stdlib/assert/has-own-property,@stdlib/object/deep-get,@stdlib/utils/deep-pluck,@stdlib/object/deep-set" +"@stdlib/utils/deep-pluck","@stdlib/object/deep-get,@stdlib/object/deep-set" +"@stdlib/object/deep-set","@stdlib/object/deep-get,@stdlib/utils/deep-pluck" "@stdlib/utils/define-memoized-property","@stdlib/utils/define-memoized-read-only-property,@stdlib/utils/define-property" "@stdlib/utils/define-properties","@stdlib/utils/define-property,@stdlib/utils/define-read-only-property" "@stdlib/utils/define-property","@stdlib/utils/define-properties,@stdlib/utils/define-read-only-property" diff --git a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv index a319af23b1ac..d2a3fc9a8b24 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv @@ -1585,7 +1585,7 @@ "@stdlib/assert/deep-has-own-property","@stdlib/assert-deep-has-own-property" "@stdlib/assert/deep-has-property","@stdlib/assert-deep-has-property" "@stdlib/utils/deep-pluck","@stdlib/utils-deep-pluck" -"@stdlib/utils/deep-set","@stdlib/utils-deep-set" +"@stdlib/object/deep-set","@stdlib/object-deep-set" "@stdlib/utils/define-memoized-property","@stdlib/utils-define-memoized-property" "@stdlib/utils/define-properties","@stdlib/utils-define-properties" "@stdlib/utils/define-property","@stdlib/utils-define-property" diff --git a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv index 28d6611d7007..2d07e48efd95 100644 --- a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv @@ -1585,7 +1585,7 @@ "@stdlib/assert-deep-has-own-property","@stdlib/assert/deep-has-own-property" "@stdlib/assert-deep-has-property","@stdlib/assert/deep-has-property" "@stdlib/utils-deep-pluck","@stdlib/utils/deep-pluck" -"@stdlib/utils-deep-set","@stdlib/utils/deep-set" +"@stdlib/object-deep-set","@stdlib/object/deep-set" "@stdlib/utils-define-memoized-property","@stdlib/utils/define-memoized-property" "@stdlib/utils-define-properties","@stdlib/utils/define-properties" "@stdlib/utils-define-property","@stdlib/utils/define-property" diff --git a/lib/node_modules/@stdlib/object/deep-get/README.md b/lib/node_modules/@stdlib/object/deep-get/README.md index 4e7664819ebb..ea20f608767f 100644 --- a/lib/node_modules/@stdlib/object/deep-get/README.md +++ b/lib/node_modules/@stdlib/object/deep-get/README.md @@ -158,7 +158,7 @@ for ( i = 0; i < data.length; i++ ) { ## See Also - [`@stdlib/utils/deep-pluck`][@stdlib/utils/deep-pluck]: extract a nested property value from each element of an object array. -- [`@stdlib/utils/deep-set`][@stdlib/utils/deep-set]: set a nested property value. +- [`@stdlib/object/deep-set`][@stdlib/object/deep-set]: set a nested property value. @@ -172,7 +172,7 @@ for ( i = 0; i < data.length; i++ ) { [@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-pluck -[@stdlib/utils/deep-set]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set +[@stdlib/object/deep-set]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/deep-set diff --git a/lib/node_modules/@stdlib/utils/deep-pluck/README.md b/lib/node_modules/@stdlib/utils/deep-pluck/README.md index b1bffca03106..942d0b40ddc0 100644 --- a/lib/node_modules/@stdlib/utils/deep-pluck/README.md +++ b/lib/node_modules/@stdlib/utils/deep-pluck/README.md @@ -216,7 +216,7 @@ console.log( out ); ## See Also - [`@stdlib/object/deep-get`][@stdlib/object/deep-get]: get a nested property value. -- [`@stdlib/utils/deep-set`][@stdlib/utils/deep-set]: set a nested property value. +- [`@stdlib/object/deep-set`][@stdlib/object/deep-set]: set a nested property value. @@ -232,7 +232,7 @@ console.log( out ); [@stdlib/object/deep-get]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/deep-get -[@stdlib/utils/deep-set]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-set +[@stdlib/object/deep-set]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/deep-set From 6d1492101e986c1abee0e23f363bad8f74714605 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sun, 11 Jan 2026 11:44:16 +0530 Subject: [PATCH 4/4] remove: remove `utils/deep-set` This commit removes `@stdlib/utils/deep-set` in favor of `@stdlib/object/deep-set`. BREAKING CHANGE: remove `utils/deep-set` To migrate, users should update their require/import paths to use `@stdlib/object/deep-set` which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/utils/deep-set/README.md | 273 ---------------- .../utils/deep-set/benchmark/benchmark.js | 140 --------- .../@stdlib/utils/deep-set/docs/repl.txt | 86 ------ .../utils/deep-set/docs/types/index.d.ts | 180 ----------- .../@stdlib/utils/deep-set/docs/types/test.ts | 134 -------- .../@stdlib/utils/deep-set/examples/index.js | 49 --- .../@stdlib/utils/deep-set/lib/defaults.js | 39 --- .../@stdlib/utils/deep-set/lib/dset.js | 80 ----- .../@stdlib/utils/deep-set/lib/factory.js | 99 ------ .../@stdlib/utils/deep-set/lib/index.js | 58 ---- .../@stdlib/utils/deep-set/lib/main.js | 120 ------- .../@stdlib/utils/deep-set/lib/validate.js | 74 ----- .../@stdlib/utils/deep-set/package.json | 69 ----- .../@stdlib/utils/deep-set/test/test.dset.js | 292 ------------------ .../utils/deep-set/test/test.factory.js | 221 ------------- .../@stdlib/utils/deep-set/test/test.js | 201 ------------ .../utils/deep-set/test/test.validate.js | 132 -------- 17 files changed, 2247 deletions(-) delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/README.md delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/examples/index.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/lib/defaults.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/lib/dset.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/lib/factory.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/lib/index.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/lib/main.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/lib/validate.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/package.json delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/test/test.dset.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/test/test.factory.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/test/test.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-set/test/test.validate.js diff --git a/lib/node_modules/@stdlib/utils/deep-set/README.md b/lib/node_modules/@stdlib/utils/deep-set/README.md deleted file mode 100644 index 9379f040c62d..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/README.md +++ /dev/null @@ -1,273 +0,0 @@ - - -# Deep Set - -> Set a nested property value. - -
- -## Usage - -```javascript -var deepSet = require( '@stdlib/utils/deep-set' ); -``` - -#### deepSet( obj, path, value\[, options] ) - -Sets a nested property value. - - - -```javascript -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var bool = deepSet( obj, 'a.b.c', 'beep' ); -// returns true - -console.log( obj ); -// => { 'a': { 'b': { 'c': 'beep' } } } -``` - -If the function is able to deep set a nested property, the function returns `true`; otherwise, the function returns `false`. - - - -```javascript -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var bool = deepSet( obj, 'a.b.c', 'woot' ); -// returns true - -bool = deepSet( obj, 'a.beep.c', 'boop' ); -// returns false - -bool = deepSet( null, 'a.beep.c', 'boop' ); -// returns false - -bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -// returns false -``` - -For `paths` including `arrays`, specify the numeric index. - - - -```javascript -var arr = [ - { 'a': [ { 'x': 5 } ] }, - { 'a': [ { 'x': 10 } ] } -]; - -var bool = deepSet( arr, '1.a.0.x', 25 ); -// returns true - -console.log( arr ); -/* => - [ - { 'a': [ { 'x': 5 } ] }, - { 'a': [ { 'x': 25 } ] } - ] -*/ -``` - -The key `path` may be specified as either a delimited `string` or a key `array`. - - - -```javascript -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var bool = deepSet( obj, [ 'a', 'b', 'c' ], 'beep' ); // obj => { 'a': { 'b': { 'c': 'beep' } } } -// returns true -``` - -If `value` is a `function`, the argument is treated as a `callback` and should return a value to set. - - - -```javascript -function set( val ) { - var ch = val; - var i; - for ( i = 0; i < 4; i++ ) { - val += ch; - } - return val; -} -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var bool = deepSet( obj, 'a.b.c', set ); // obj => { 'a': { 'b': { 'c': 'ddddd' } } } -// returns true -``` - -The function accepts the following `options`: - -- **sep**: key path separator. Default: `'.'`. -- **create**: `boolean` indicating whether to create a path if the key path does not already exist. Default: `false`. - -By default, the function assumes `dot` separated key values. To specify an alternative separator, set the `sep` option. - - - -```javascript -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var bool = deepSet( obj, 'a/b/c', 'beep', { - 'sep': '/' -}); -// returns true - -console.log( obj ); -// => { 'a': { 'b': { 'c': 'beep' } } } -``` - -To create a key path which does not already exist, set the `create` option to `true`. - - - -```javascript -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var bool = deepSet( obj, 'a.e.c', 'boop', { - 'create': true -}); -// returns true - -console.log( obj ); -/* => - { - 'a': { - 'b': { - 'c': 'beep' - }, - 'e': { - 'c': 'boop' - } - } - } -*/ -``` - -#### deepSet.factory( path\[, options] ) - -Creates a reusable deep set function. The factory method ensures a `deepSet` function is configured identically by using the same set of provided `options`. - -```javascript -var dset = deepSet.factory( 'a/b/c', { - 'create': true, - 'sep': '/' -}); -``` - -#### dset( obj, value ) - -Sets a nested property value. - - - -```javascript -var dset = deepSet.factory( 'a.b.c' ); - -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var bool = dset( obj, 'beep' ); -// returns true - -console.log( obj ); -// => { 'a': { 'b': { 'c': 'beep' } } } -``` - -
- - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var deepSet = require( '@stdlib/utils/deep-set' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); -``` - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/utils/deep-set/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/deep-set/benchmark/benchmark.js deleted file mode 100644 index 9019c9896903..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/benchmark/benchmark.js +++ /dev/null @@ -1,140 +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 randu = require( '@stdlib/random/base/randu' ); -var pkg = require( './../package.json' ).name; -var deepSet = require( './../lib' ); - - -// FUNCTIONS // - -function set1() { - return randu(); -} - -function set2( val ) { - return val * 1.5; -} - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var bool; - var obj; - var val; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - val = randu(); - bool = deepSet( obj, 'a.b.c.d', val ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( val !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::setter', function benchmark( b ) { - var bool; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = deepSet( obj, 'a.b.c.d', set1 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var bool; - var dset; - var obj; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': 0.5 - } - } - } - }; - dset = deepSet.factory( 'a.b.c.d' ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - bool = dset( obj, set2 ); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - } - b.toc(); - if ( bool !== true ) { - b.fail( 'should return true' ); - } - if ( obj.a.b.c.d !== obj.a.b.c.d ) { - b.fail( 'should successfully set property value' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/deep-set/docs/repl.txt b/lib/node_modules/@stdlib/utils/deep-set/docs/repl.txt deleted file mode 100644 index 8f6adcb2badf..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/docs/repl.txt +++ /dev/null @@ -1,86 +0,0 @@ - -{{alias}}( obj, path, value[, options] ) - Sets a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - value: any - Value to set. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - bool: boolean - Boolean indicating if the property was successfully set. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = {{alias}}( obj, 'a.b.c', 'beep' ) - true - - // Specify an alternative separator via the sep option: - > obj = { 'a': { 'b': { 'c': 'd' } } }; - > bool = {{alias}}( obj, 'a/b/c', 'beep', { 'sep': '/' } ); - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - // To create a key path which does not exist, set the create option to true: - > bool = {{alias}}( obj, 'a.e.c', 'boop', { 'create': true } ); - > obj - { 'a': { 'b': { 'c': 'beep' }, 'e': { 'c': 'boop' } } } - - -{{alias}}.factory( path[, options] ) - Creates a reusable deep set function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.create: boolean (optional) - Boolean indicating whether to create a path if the key path does not - already exist. Default: false. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get function. - - Examples - -------- - > var dset = {{alias}}.factory( 'a/b/c', { - ... 'create': true, - ... 'sep': '/' - ... }); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var bool = dset( obj, 'beep' ) - true - > obj - { 'a': { 'b': { 'c': 'beep' } } } - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/utils/deep-set/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/deep-set/docs/types/index.d.ts deleted file mode 100644 index 4dda520f457c..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/docs/types/index.d.ts +++ /dev/null @@ -1,180 +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 - -/** -* Interface defining function options. -*/ -interface Options { - /** - * Boolean indicating whether to create a path if the key path does not already exist. - */ - create?: boolean; - - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Sets a nested property. -* -* @param obj - input object -* @param value - value to set -* @returns boolean indicating if the property was successfully set -*/ -type Unary = ( obj: any, value: any ) => boolean; - -/** -* Interface for setting nested property values. -*/ -interface DeepSet { - /** - * Sets a nested property value. - * - * @param obj - input object - * @param path - key path - * @param value - value to set - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.b.c', 'woot' ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( null, 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * bool = deepSet( 'bap', 'a.beep.c', 'boop' ); - * // returns false - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var bool = deepSet( arr, '1.a.0.x', 25 ); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a/b/c', 'beep', { - * 'sep': '/' - * }); - * // returns true - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = deepSet( obj, 'a.e.c', 'boop', { - * 'create': true - * }); - * // returns true - */ - ( obj: any, path: string | Array, value: any, options?: Options ): boolean; - - /** - * Creates a reusable deep set function. - * - * @param path - key path - * @param options - function options - * @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) - * @param options.sep - key path separator (default: '.') - * @returns deep set function - * - * @example - * var dset = deepSet.factory( 'a/b/c', { - * 'create': true, - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Sets a nested property value. -* -* @param obj - input object -* @param path - key path -* @param value - value to set -* @param options - function options -* @param options.create - boolean indicating whether to create a path if the key path does not already exist (default: false) -* @param options.sep - key path separator (default: '.') -* @returns boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -declare var deepSet: DeepSet; - - -// EXPORTS // - -export = deepSet; diff --git a/lib/node_modules/@stdlib/utils/deep-set/docs/types/test.ts b/lib/node_modules/@stdlib/utils/deep-set/docs/types/test.ts deleted file mode 100644 index ed1c84fcea85..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/docs/types/test.ts +++ /dev/null @@ -1,134 +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. -*/ - -import deepSet = require( './index' ); - - -// TESTS // - -// The function returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e' ); // $ExpectType boolean - deepSet( obj, [ 'a', 'b', 'c' ], 'e' ); // $ExpectType boolean - deepSet( obj, 'a-b-c', 'e', { 'sep': '-' } ); // $ExpectType boolean -} - -// The compiler throws an error if the function is provided a second argument which is not a string or array of strings... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, true, 'e' ); // $ExpectError - deepSet( obj, false, 'e' ); // $ExpectError - deepSet( obj, 2.12, 'e' ); // $ExpectError - deepSet( obj, {}, 'e' ); // $ExpectError - deepSet( obj, [ 1, 2, 3 ], 'e' ); // $ExpectError - deepSet( obj, ( x: number ): number => x, 'e' ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `create` option which is not a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'create': 'abc' } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `sep` option which is not a string... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepSet( obj, 'a.b.c', 'e', { 'sep': true } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': false } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': 123 } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': null } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': [] } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': {} } ); // $ExpectError - deepSet( obj, 'a.b.c', 'e', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided fewer than three arguments... -{ - deepSet(); // $ExpectError - deepSet( {} ); // $ExpectError - deepSet( {}, 'a.b.c' ); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepSet.factory( 'a.b.c' ); // $ExpectType Unary - deepSet.factory( 'a.b.c', {} ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepSet.factory(); // $ExpectError - deepSet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns a boolean... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepSet.factory( 'a.b.c' ); - fcn( obj, 'e' ); // $ExpectType boolean - - fcn = deepSet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj, 'e' ); // $ExpectType boolean -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepSet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `create` option which is not a boolean... -{ - deepSet.factory( 'a.b.c', { 'create': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': 'abc' } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'create': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepSet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepSet.factory( 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - const fcn = deepSet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj ); // $ExpectError - fcn( obj, 'e', 2 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/utils/deep-set/examples/index.js b/lib/node_modules/@stdlib/utils/deep-set/examples/index.js deleted file mode 100644 index dd760170e445..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/examples/index.js +++ /dev/null @@ -1,49 +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 randu = require( '@stdlib/random/base/randu' ); -var deepSet = require( './../lib' ); - -var data; -var bool; -var keys; -var i; - -function set( val ) { - return val * 10.0; -} - -data = new Array( 100 ); -for ( i = 0; i < data.length; i++ ) { - data[ i ] = { - 'x': Date.now(), - 'y': [ randu(), randu(), i ] - }; -} - -keys = [ 0, 'y', 2 ]; -for ( i = 0; i < data.length; i++ ) { - keys[ 0 ] = i; - bool = deepSet( data, keys, set ); - if ( !bool ) { - console.error( 'Unable to deep set value.' ); - } -} -console.log( data ); diff --git a/lib/node_modules/@stdlib/utils/deep-set/lib/defaults.js b/lib/node_modules/@stdlib/utils/deep-set/lib/defaults.js deleted file mode 100644 index b8b7c5f20d66..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/lib/defaults.js +++ /dev/null @@ -1,39 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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'; - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -*/ -function defaults() { - return { - 'create': false, - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/node_modules/@stdlib/utils/deep-set/lib/dset.js b/lib/node_modules/@stdlib/utils/deep-set/lib/dset.js deleted file mode 100644 index 64410eec6602..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/lib/dset.js +++ /dev/null @@ -1,80 +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 isObjectLike = require( '@stdlib/assert/is-object-like' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isFunction = require( '@stdlib/assert/is-function' ); - - -// MAIN // - -/** -* Sets a nested property. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @param {boolean} create - boolean indicating whether to create a path if the key path does not already exist -* @param {*} val - value to set -* @returns {boolean} boolean indicating if the property was successfully set -*/ -function deepSet( obj, props, create, val ) { - var bool; - var len; - var v; - var p; - var i; - - len = props.length; - bool = false; - v = obj; - for ( i = 0; i < len; i++ ) { - p = props[ i ]; - if ( isObjectLike( v ) ) { - if ( !hasOwnProp( v, p ) ) { - if ( create ) { - v[ p ] = {}; - } else { - break; - } - } - if ( i === len-1 ) { - if ( isFunction( val ) ) { - v[ p ] = val( v[ p ] ); - } else { - v[ p ] = val; - } - bool = true; - } else { - v = v[ p ]; - } - } else { - break; - } - } - return bool; -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/node_modules/@stdlib/utils/deep-set/lib/factory.js b/lib/node_modules/@stdlib/utils/deep-set/lib/factory.js deleted file mode 100644 index 612dd75372e9..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/lib/factory.js +++ /dev/null @@ -1,99 +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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert/is-array' ); -var isObjectLike = require( '@stdlib/assert/is-object-like' ); -var format = require( '@stdlib/string/format' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Creates a reusable deep set function. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} first argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {Function} deep set function -* -* @example -* var dset = factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -*/ -function factory( path, options ) { - var isStr; - var props; - var opts; - var err; - - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); - } - opts = defaults(); - if ( arguments.length > 1 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return deepSet; - - /** - * Sets a nested property. - * - * @private - * @param {ObjectLike} obj - input object - * @param {*} value - value to set - * @returns {boolean} boolean indicating if the property was successfully set - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var bool = dset( obj, 'beep' ); - */ - function deepSet( obj, value ) { - if ( isObjectLike( obj ) ) { - return dset( obj, props, opts.create, value ); - } - return false; - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/node_modules/@stdlib/utils/deep-set/lib/index.js b/lib/node_modules/@stdlib/utils/deep-set/lib/index.js deleted file mode 100644 index d36354c7603c..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/lib/index.js +++ /dev/null @@ -1,58 +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'; - -/** -* Set a nested property value. -* -* @module @stdlib/utils/deep-set -* -* @example -* var deepSet = require( '@stdlib/utils/deep-set' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'beep' ); -* // returns true -* -* var dset = deepSet.factory( 'a/b/c', { -* 'create': true, -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* bool = dset( obj, 'beep' ); -* // returns true -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var main = require( './main.js' ); -var factory = require( './factory.js' ); - - -// MAIN // - -setReadOnly( main, 'factory', factory ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/utils/deep-set/lib/main.js b/lib/node_modules/@stdlib/utils/deep-set/lib/main.js deleted file mode 100644 index 676c99c8a17b..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/lib/main.js +++ /dev/null @@ -1,120 +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 isObjectLike = require( '@stdlib/assert/is-object-like' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isArray = require( '@stdlib/assert/is-array' ); -var format = require( '@stdlib/string/format' ); -var validate = require( './validate.js' ); -var defaults = require( './defaults.js' ); -var dset = require( './dset.js' ); - - -// MAIN // - -/** -* Sets a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {*} value - value to set -* @param {Options} [options] - function options -* @param {boolean} [options.create=false] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep='.'] - key path separator -* @throws {TypeError} second argument must be a string or key array -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {boolean} boolean indicating if the property was successfully set -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.b.c', 'woot' ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( null, 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* bool = deepSet( 'bap', 'a.beep.c', 'boop' ); -* // returns false -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var bool = deepSet( arr, '1.a.0.x', 25 ); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a/b/c', 'beep', { -* 'sep': '/' -* }); -* // returns true -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var bool = deepSet( obj, 'a.e.c', 'boop', { -* 'create': true -* }); -* // returns true -*/ -function deepSet( obj, path, value, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return false; - } - isStr = isString( path ); - if ( !isStr && !isArray( path ) ) { - throw new TypeError( format( 'invalid argument. Key path must be a string or a key array. Value: `%s`.', path ) ); - } - opts = defaults(); - if ( arguments.length > 3 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dset( obj, props, opts.create, value ); -} - - -// EXPORTS // - -module.exports = deepSet; diff --git a/lib/node_modules/@stdlib/utils/deep-set/lib/validate.js b/lib/node_modules/@stdlib/utils/deep-set/lib/validate.js deleted file mode 100644 index c3519fdfb92a..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/lib/validate.js +++ /dev/null @@ -1,74 +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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isObject = require( '@stdlib/assert/is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination for function options -* @param {Options} options - function options -* @param {boolean} [options.create] - boolean indicating whether to create a path if the key path does not already exist -* @param {string} [options.sep] - key path separator -* @returns {(Error|null)} error or null -* -* @example -* var opts = {}; -* var options = { -* 'sep': '/' -* }; -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'create' ) ) { - opts.create = options.create; - if ( !isBoolean( opts.create ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'create', opts.create ) ); - } - } - if ( hasOwnProp( options, 'sep' ) ) { - opts.sep = options.sep; - if ( !isString( opts.sep ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'sep', opts.sep ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; diff --git a/lib/node_modules/@stdlib/utils/deep-set/package.json b/lib/node_modules/@stdlib/utils/deep-set/package.json deleted file mode 100644 index 1123668b0413..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/package.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "name": "@stdlib/utils/deep-set", - "version": "0.0.0", - "description": "Set a nested property value.", - "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", - "deep", - "set", - "assign", - "object", - "obj", - "array", - "nested", - "property", - "prop" - ] -} diff --git a/lib/node_modules/@stdlib/utils/deep-set/test/test.dset.js b/lib/node_modules/@stdlib/utils/deep-set/test/test.dset.js deleted file mode 100644 index 0530f3ee5e04..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/test/test.dset.js +++ /dev/null @@ -1,292 +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 dset = require( './../lib/dset.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dset, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep sets a nested property value', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'beep' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `true` if able to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, 'beep' ); - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function returns `false` if unable to successfully set', function test( t ) { - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'djfajdfaj'], false, 'beep' ); - t.strictEqual( bool, false, 'returns expected value' ); - - bool = dset( obj, ['null', 'e'], false, 'beep' ); - t.strictEqual( bool, false, 'returns expected value' ); - t.end(); -}); - -tape( 'the function deep sets an array', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 200 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 0, 'y'], false, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function creates properties which do not exist', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - expected = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - }, - { - 'y': 200 - } - ], - 'null': null - }; - - bool = dset( obj, ['arr', 2, 'y'], true, 200 ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); -}); - -tape( 'the function deep sets using a callback function', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - expected = { - 'a': { - 'b': { - 'c': 'dub-beat' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - bool = dset( obj, ['a', 'b', 'c'], false, set ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.strictEqual( bool, true, 'returns expected value' ); - t.end(); - - function set( val ) { - return val + 'ub-beat'; - } -}); diff --git a/lib/node_modules/@stdlib/utils/deep-set/test/test.factory.js b/lib/node_modules/@stdlib/utils/deep-set/test/test.factory.js deleted file mode 100644 index de6aba4531c2..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/test/test.factory.js +++ /dev/null @@ -1,221 +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 factory = require( './../lib/factory.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof factory, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( value ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - factory( 'a', { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - t.strictEqual( typeof dset, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the returned function returns `false` if provided a non-object or null', function test( t ) { - var values; - var dset; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dset = factory( 'a/b', { - 'create': true, - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.strictEqual( dset( values[ i ], 5 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the returned function returns a boolean', function test( t ) { - var bool; - var dset; - var obj; - - dset = factory( 'a', { - 'create': false, - 'sep': '.' - }); - - obj = { - 'a': 5 - }; - bool = dset( obj, 4 ); - t.strictEqual( bool, true, 'returns expected value' ); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.strictEqual( bool, false, 'returns expected value' ); - - dset = factory( 'a', { - 'create': true - }); - - obj = { - 'b': 5 - }; - bool = dset( obj, 4 ); - t.strictEqual( bool, true, 'returns expected value' ); - - t.end(); -}); - -tape( 'the returned function deep sets', function test( t ) { - var expected; - var dset; - var bool; - var obj; - - dset = factory( ['a', 'b'] ); - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = dset( obj, 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.strictEqual( bool, true, 'returns expected value' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = dset( obj, 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.strictEqual( bool, true, 'returns expected value' ); - t.deepEqual( obj, expected, 'deep sets object' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/deep-set/test/test.js b/lib/node_modules/@stdlib/utils/deep-set/test/test.js deleted file mode 100644 index be3ca4522125..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/test/test.js +++ /dev/null @@ -1,201 +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 deepSet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepSet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.strictEqual( typeof deepSet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `false` if provided a non-object or null', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.strictEqual( deepSet( values[ i ], 'a.b.c', 5 ), false, 'returns expected value' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is neither a string primitive or a key array', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - void 0, - NaN, - true, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, value, 5 ); - }; - } -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - null, - NaN, - {}, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws when provided a ' + ( typeof values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var obj = { - 'a': 5 - }; - deepSet( obj, 'a', 4, { - 'create': value - }); - }; - } -}); - -tape( 'the function returns a boolean', function test( t ) { - var bool; - var obj; - - obj = { - 'a': 5 - }; - bool = deepSet( obj, 'a', 4 ); - t.strictEqual( bool, true, 'returns expected value' ); - - bool = deepSet( obj, 'b', 4, { - 'create': false - }); - t.strictEqual( bool, false, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function deep sets', function test( t ) { - var expected; - var bool; - var obj; - - obj = { - 'a': { - 'b': 0 - } - }; - - bool = deepSet( obj, 'a.b', 4 ); - expected = { - 'a': { - 'b': 4 - } - }; - - t.strictEqual( bool, true, 'returns expected value' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - bool = deepSet( obj, ['a', 'b'], 40 ); - expected = { - 'a': { - 'b': 40 - } - }; - - t.strictEqual( bool, true, 'returns expected value' ); - t.deepEqual( obj, expected, 'deep sets object' ); - - t.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/deep-set/test/test.validate.js b/lib/node_modules/@stdlib/utils/deep-set/test/test.validate.js deleted file mode 100644 index 49797b7574f3..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-set/test/test.validate.js +++ /dev/null @@ -1,132 +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 Boolean = require( '@stdlib/boolean/ctor' ); -var validate = require( './../lib/validate.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof validate, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns an error if not provided an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - NaN, - true, - null, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[i] ); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `create` option which is not a boolean primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - new Boolean( true ), - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'create': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a `sep` option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), - null, - 5, - NaN, - true, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, { - 'sep': values[i] - }); - t.strictEqual( err instanceof TypeError, true, 'returns a type error when provided '+values[i] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'create': true, - 'sep': '_' - }; - obj = {}; - t.strictEqual( validate( obj, opts ), null, 'returns expected value' ); - t.strictEqual( obj.create, true, 'sets create option' ); - t.strictEqual( obj.sep, '_', 'sets sep option' ); - - opts = { - 'beep': true, - 'boop': false - }; - obj = {}; - t.strictEqual( validate( obj, opts ), null, 'returns expected value' ); - t.deepEqual( obj, {}, 'does not set any properties' ); - t.end(); -});