From d5b46a556be1f39fbe594d66fe428e4b1ddabd9b Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sat, 10 Jan 2026 16:42:30 +0530 Subject: [PATCH 1/4] feat: add `object/deep-get` Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/object/deep-get/README.md | 181 +++++++++++++++++ .../object/deep-get/benchmark/benchmark.js | 130 ++++++++++++ .../@stdlib/object/deep-get/docs/repl.txt | 63 ++++++ .../object/deep-get/docs/types/index.d.ts | 125 ++++++++++++ .../object/deep-get/docs/types/test.ts | 109 ++++++++++ .../@stdlib/object/deep-get/examples/index.js | 42 ++++ .../@stdlib/object/deep-get/lib/defaults.js | 38 ++++ .../@stdlib/object/deep-get/lib/dget.js | 57 ++++++ .../@stdlib/object/deep-get/lib/factory.js | 94 +++++++++ .../@stdlib/object/deep-get/lib/index.js | 58 ++++++ .../@stdlib/object/deep-get/lib/main.js | 101 ++++++++++ .../@stdlib/object/deep-get/lib/validate.js | 66 +++++++ .../@stdlib/object/deep-get/package.json | 68 +++++++ .../@stdlib/object/deep-get/test/test.dget.js | 126 ++++++++++++ .../object/deep-get/test/test.factory.js | 167 ++++++++++++++++ .../@stdlib/object/deep-get/test/test.js | 187 ++++++++++++++++++ .../object/deep-get/test/test.validate.js | 103 ++++++++++ 17 files changed, 1715 insertions(+) create mode 100644 lib/node_modules/@stdlib/object/deep-get/README.md create mode 100644 lib/node_modules/@stdlib/object/deep-get/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/object/deep-get/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/object/deep-get/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/object/deep-get/examples/index.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/lib/defaults.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/lib/dget.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/lib/factory.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/lib/index.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/lib/main.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/lib/validate.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/package.json create mode 100644 lib/node_modules/@stdlib/object/deep-get/test/test.dget.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/test/test.factory.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/test/test.js create mode 100644 lib/node_modules/@stdlib/object/deep-get/test/test.validate.js diff --git a/lib/node_modules/@stdlib/object/deep-get/README.md b/lib/node_modules/@stdlib/object/deep-get/README.md new file mode 100644 index 000000000000..4e7664819ebb --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/README.md @@ -0,0 +1,181 @@ + + +# Deep Get + +> Get a nested property value. + +
+ +## Usage + +```javascript +var deepGet = require( '@stdlib/object/deep-get' ); +``` + +#### deepGet( obj, path\[, options] ) + +Returns a nested property value. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var val = deepGet( obj, 'a.b.c' ); +// returns 'd' +``` + +For `paths` including `arrays`, specify the numeric index. + + + +```javascript +var arr = [ + { 'a': [ {'x': 5} ] }, + { 'a': [ {'x': 10} ] } +]; + +var val = deepGet( arr, '1.a.0.x' ); +// returns 10 +``` + +The key `path` may be specified as either a delimited `string` or a key `array`. + + + +```javascript +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var val = deepGet( obj, [ 'a', 'b', 'c' ] ); +// returns 'd' +``` + +The function accepts the following `options`: + +- **sep**: key path separator. Default: `'.'`. + +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 val = deepGet( obj, 'a/b/c', { + 'sep': '/' +}); +// returns 'd' +``` + +#### deepGet.factory( path\[, options] ) + +Creates a reusable deep get function. The factory method ensures a `deepGet` function is configured identically by using the same set of provided `options`. + +```javascript +var dget = deepGet.factory( 'a/b/c', { + 'sep': '/' +}); +``` + +#### dget( obj ) + +Returns a nested property value. + + + +```javascript +var dget = deepGet.factory( 'a.b.c' ); + +var obj = { 'a': { 'b': { 'c': 'd' } } }; + +var val = dget( obj ); +// returns 'd' +``` + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var deepGet = require( '@stdlib/object/deep-get' ); + +var data; +var keys; +var val; +var i; + +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; + val = deepGet( data, keys ); + console.log( val ); +} +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/object/deep-get/benchmark/benchmark.js b/lib/node_modules/@stdlib/object/deep-get/benchmark/benchmark.js new file mode 100644 index 000000000000..7d1cd7e558dc --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/benchmark/benchmark.js @@ -0,0 +1,130 @@ +/** +* @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 isArray = require( '@stdlib/assert/is-array' ); +var randu = require( '@stdlib/random/base/randu' ); +var pkg = require( './../package.json' ).name; +var deepGet = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var arr; + var obj; + var out; + var i; + + obj = { + 'a': { + 'b': { + 'c': { + 'd': [ 0.0, 0.5, 1.0 ] + } + } + } + }; + arr = obj.a.b.c.d; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 1 ] = randu(); + out = deepGet( obj, 'a.b.c.d' ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::paths_array', function benchmark( b ) { + var paths; + var arr; + var obj; + var out; + var i; + + obj = { + 'a': { + 'b': { + 'c': { + 'd': [ 0.0, 0.5, 1.0 ] + } + } + } + }; + paths = [ 'a', 'b', 'c', 'd' ]; + arr = obj.a.b.c.d; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 1 ] = randu(); + out = deepGet( obj, paths ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':factory', function benchmark( b ) { + var dget; + var arr; + var obj; + var out; + var i; + + obj = { + 'a': { + 'b': { + 'c': { + 'd': [ 0.0, 0.5, 1.0 ] + } + } + } + }; + dget = deepGet.factory( 'a.b.c.d' ); + arr = obj.a.b.c.d; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + arr[ 1 ] = randu(); + out = dget( obj ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/object/deep-get/docs/repl.txt b/lib/node_modules/@stdlib/object/deep-get/docs/repl.txt new file mode 100644 index 000000000000..0bc1c3d8491f --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/docs/repl.txt @@ -0,0 +1,63 @@ + +{{alias}}( obj, path[, options] ) + Returns a nested property value. + + Parameters + ---------- + obj: ObjectLike + Input object. + + path: string|Array + Key path. + + options: Object (optional) + Options. + + options.sep: string (optional) + Key path separator. Default: '.'. + + Returns + ------- + out: any + Nested property value. + + Examples + -------- + > var obj = { 'a': { 'b': { 'c': 'd' } } }; + > var val = {{alias}}( obj, 'a.b.c' ) + 'd' + + // Specify a custom separator via the `sep` option: + > var obj = { 'a': { 'b': { 'c': 'd' } } }; + > var val = {{alias}}( obj, 'a/b/c', { 'sep': '/' } ) + 'd' + +{{alias}}.factory( path[, options] ) + Creates a reusable deep get function. + + Parameters + ---------- + path: string|Array + Key path. + + options: Object (optional) + Options. + + options.sep: string (optional) + Key path separator. Default: '.'. + + Returns + ------- + out: Function + Deep get factory. + + Examples + -------- + > var dget = {{alias}}.factory( 'a/b/c', { 'sep': '/' } ); + > var obj = { 'a': { 'b': { 'c': 'd' } } }; + > var val = dget( obj ) + 'd' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/object/deep-get/docs/types/index.d.ts b/lib/node_modules/@stdlib/object/deep-get/docs/types/index.d.ts new file mode 100644 index 000000000000..285b1d02fe99 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/docs/types/index.d.ts @@ -0,0 +1,125 @@ +/* +* @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 { + /** + * Key path separator. + */ + sep?: string; +} + +/** +* Returns a nested property value. +* +* @param obj - input object +* @returns nested property value +*/ +type Unary = ( obj: any ) => any; + +/** +* Interface for retrieving nested property values. +*/ +interface DeepGet { + /** + * Returns a nested property value. + * + * @param obj - input object + * @param path - key path + * @param options - function options + * @param options.sep - key path separator (default: '.') + * @returns nested property value + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var val = deepGet( obj, 'a.b.c' ); + * // returns 'd' + * + * @example + * var arr = [ + * { 'a': [ {'x': 5} ] }, + * { 'a': [ {'x': 10} ] } + * ]; + * var val = deepGet( arr, '1.a.0.x' ); + * // returns 10 + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var val = deepGet( obj, ['a','b','c'] ); + * // returns 'd' + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var val = deepGet( obj, 'a/b/c', { + * 'sep': '/' + * }); + * // returns 'd' + */ + ( obj: any, path: string | Array, options?: Options ): any; + + /** + * Returns a function for retrieving a nested property value. + * + * @param path - key path + * @param options - function options + * @param options.sep - key path separator (default: '.') + * @returns deep get factory + * + * @example + * var dget = deepGet.factory( 'a/b/c', { + * 'sep': '/' + * }); + */ + factory( path: string | Array, options?: Options ): Unary; +} + +/** +* Returns a nested property value. +* +* @param obj - input object +* @param path - key path +* @param options - function options +* @param options.sep - key path separator (default: '.') +* @returns nested property value +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* +* var val = deepGet( obj, 'a.b.c' ); +* // returns 'd' +* +* @example +* var dget = deepGet.factory( 'a/b/c', { +* 'sep': '/' +* }); +* +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* +* var val = dget( obj ); +* // returns 'd' +*/ +declare var deepGet: DeepGet; + + +// EXPORTS // + +export = deepGet; diff --git a/lib/node_modules/@stdlib/object/deep-get/docs/types/test.ts b/lib/node_modules/@stdlib/object/deep-get/docs/types/test.ts new file mode 100644 index 000000000000..e047b1e31b00 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/docs/types/test.ts @@ -0,0 +1,109 @@ +/* +* @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 deepGet = require( './index' ); + + +// TESTS // + +// The function returns an object... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + deepGet( obj, 'a.b.c' ); // $ExpectType any + deepGet( obj, [ 'a', 'b', 'c' ] ); // $ExpectType any + deepGet( obj, 'a-b-c', { 'sep': '-' } ); // $ExpectType any +} + +// 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' } } }; + deepGet( obj, true ); // $ExpectError + deepGet( obj, false ); // $ExpectError + deepGet( obj, 2.12 ); // $ExpectError + deepGet( obj, {} ); // $ExpectError + deepGet( obj, [ 1, 2, 3 ] ); // $ExpectError + deepGet( obj, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not an object... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + deepGet( obj, 'a.b.c', null ); // $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' } } }; + deepGet( obj, 'a.b.c', { 'sep': true } ); // $ExpectError + deepGet( obj, 'a.b.c', { 'sep': false } ); // $ExpectError + deepGet( obj, 'a.b.c', { 'sep': 123 } ); // $ExpectError + deepGet( obj, 'a.b.c', { 'sep': null } ); // $ExpectError + deepGet( obj, 'a.b.c', { 'sep': [] } ); // $ExpectError + deepGet( obj, 'a.b.c', { 'sep': {} } ); // $ExpectError + deepGet( obj, 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided no arguments... +{ + deepGet(); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + deepGet.factory( 'a.b.c' ); // $ExpectType Unary +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + deepGet.factory(); // $ExpectError + deepGet.factory( 'a.b.c', {}, 21 ); // $ExpectError +} + +// The `factory` method returns a function which returns an object... +{ + const obj = { 'a': { 'b': { 'c': 'd' } } }; + let fcn = deepGet.factory( 'a.b.c' ); + fcn( obj ); // $ExpectType any + + fcn = deepGet.factory( 'a-b-c', { 'sep': '-' } ); + fcn( obj ); // $ExpectType any +} + +// The compiler throws an error if the `factory` method is provided a second argument which is not an object... +{ + deepGet.factory( 'a.b.c', null ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... +{ + deepGet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError + deepGet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError + deepGet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError + deepGet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError + deepGet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError + deepGet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError + deepGet.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 = deepGet.factory( 'a.b.c' ); + fcn(); // $ExpectError + fcn( obj, 2 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/object/deep-get/examples/index.js b/lib/node_modules/@stdlib/object/deep-get/examples/index.js new file mode 100644 index 000000000000..c1bde24a5743 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/examples/index.js @@ -0,0 +1,42 @@ +/** +* @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 deepGet = require( './../lib' ); + +var data; +var keys; +var val; +var i; + +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; + val = deepGet( data, keys ); + console.log( val ); +} diff --git a/lib/node_modules/@stdlib/object/deep-get/lib/defaults.js b/lib/node_modules/@stdlib/object/deep-get/lib/defaults.js new file mode 100644 index 000000000000..061281e04982 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/lib/defaults.js @@ -0,0 +1,38 @@ +/** +* @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 { + 'sep': '.' + }; +} + + +// EXPORTS // + +module.exports = defaults; diff --git a/lib/node_modules/@stdlib/object/deep-get/lib/dget.js b/lib/node_modules/@stdlib/object/deep-get/lib/dget.js new file mode 100644 index 000000000000..7ca1b86017eb --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/lib/dget.js @@ -0,0 +1,57 @@ +/** +* @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' ); + + +// MAIN // + +/** +* Returns a nested property value. +* +* @private +* @param {ObjectLike} obj - input object +* @param {Array} props - list of properties defining a key path +* @returns {*} nested property value +*/ +function deepGet( obj, props ) { + var len = props.length; + var v = obj; + var i; + for ( i = 0; i < len; i++ ) { + if ( + isObjectLike( v ) && + hasOwnProp( v, props[ i ] ) + ) { + v = v[ props[ i ] ]; + } else { + return; + } + } + return v; +} + + +// EXPORTS // + +module.exports = deepGet; diff --git a/lib/node_modules/@stdlib/object/deep-get/lib/factory.js b/lib/node_modules/@stdlib/object/deep-get/lib/factory.js new file mode 100644 index 000000000000..ab3d1af4a31d --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/lib/factory.js @@ -0,0 +1,94 @@ +/** +* @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 dget = require( './dget.js' ); + + +// MAIN // + +/** +* Returns a function for retrieving a nested property value. +* +* @param {(string|Array)} path - key path +* @param {Options} [options] - function options +* @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 get function +* +* @example +* var dget = factory( 'a/b/c', { +* '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 deepGet; + + /** + * Returns a nested property value. + * + * @private + * @param {ObjectLike} obj - input object + * @returns {*} nested property value + * + * @example + * var obj = { 'a': { 'b': { 'c': 'd' } } }; + * var val = deepGet( obj ); + */ + function deepGet( obj ) { + if ( isObjectLike( obj ) ) { + return dget( obj, props ); + } + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/object/deep-get/lib/index.js b/lib/node_modules/@stdlib/object/deep-get/lib/index.js new file mode 100644 index 000000000000..eeeddbf0e561 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/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'; + +/** +* Get a nested property value. +* +* @module @stdlib/object/deep-get +* +* @example +* var deepGet = require( '@stdlib/object/deep-get' ); +* +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* +* var val = deepGet( obj, 'a.b.c' ); +* // returns 'd' +* +* var dget = factory( 'a/b/c', { +* 'sep': '/' +* }); +* +* obj = { 'a': { 'b': { 'c': 'd' } } }; +* +* val = dget( obj ); +* // returns 'd' +*/ + +// 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-get/lib/main.js b/lib/node_modules/@stdlib/object/deep-get/lib/main.js new file mode 100644 index 000000000000..0c67dbf5b045 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/lib/main.js @@ -0,0 +1,101 @@ +/** +* @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 dget = require( './dget.js' ); + + +// MAIN // + +/** +* Returns a nested property value. +* +* @param {ObjectLike} obj - input object +* @param {(string|Array)} path - key path +* @param {Options} [options] - function options +* @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 {*} nested property value +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var val = deepGet( obj, 'a.b.c' ); +* // returns 'd' +* +* @example +* var arr = [ +* { 'a': [ {'x': 5} ] }, +* { 'a': [ {'x': 10} ] } +* ]; +* var val = deepGet( arr, '1.a.0.x' ); +* // returns 10 +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var val = deepGet( obj, ['a','b','c'] ); +* // returns 'd' +* +* @example +* var obj = { 'a': { 'b': { 'c': 'd' } } }; +* var val = deepGet( obj, 'a/b/c', { +* 'sep': '/' +* }); +* // returns 'd' +*/ +function deepGet( obj, path, options ) { + var isStr; + var props; + var opts; + var err; + if ( !isObjectLike( obj ) ) { + return; + } + 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 > 2 ) { + err = validate( opts, options ); + if ( err ) { + throw err; + } + } + if ( isStr ) { + props = path.split( opts.sep ); + } else { + props = path; + } + return dget( obj, props ); +} + + +// EXPORTS // + +module.exports = deepGet; diff --git a/lib/node_modules/@stdlib/object/deep-get/lib/validate.js b/lib/node_modules/@stdlib/object/deep-get/lib/validate.js new file mode 100644 index 000000000000..8c021620c767 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/lib/validate.js @@ -0,0 +1,66 @@ +/** +* @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 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 {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, '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-get/package.json b/lib/node_modules/@stdlib/object/deep-get/package.json new file mode 100644 index 000000000000..e187d35ae0b5 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/object/deep-get", + "version": "0.0.0", + "description": "Get 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", + "get", + "object", + "obj", + "array", + "nested", + "property", + "prop" + ] +} diff --git a/lib/node_modules/@stdlib/object/deep-get/test/test.dget.js b/lib/node_modules/@stdlib/object/deep-get/test/test.dget.js new file mode 100644 index 000000000000..db6389abeba0 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/test/test.dget.js @@ -0,0 +1,126 @@ +/** +* @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 dget = require( './../lib/dget.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dget, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function deep gets a nested property', function test( t ) { + var expected; + var actual; + var obj; + + obj = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + + actual = dget( obj, ['a', 'b', 'c'] ); + expected = 'd'; + + t.strictEqual( actual, expected, 'deep gets value' ); + t.end(); +}); + +tape( 'the function returns `undefined` if unable to successfully get', function test( t ) { + var actual; + var obj; + + obj = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + + actual = dget( obj, ['a', 'b', 'djfajdfaj'] ); + t.strictEqual( actual, void 0, 'returns undefined' ); + + actual = dget( obj, ['null', 'e'] ); + t.strictEqual( actual, void 0, 'returns undefined' ); + t.end(); +}); + +tape( 'the function deep gets into an array', function test( t ) { + var expected; + var actual; + var obj; + + obj = { + 'a': { + 'b': { + 'c': 'd' + } + }, + 'arr': [ + { + 'x': 1, + 'y': 2 + }, + { + 'x': 3, + 'y': 4 + } + ], + 'null': null + }; + + actual = dget( obj, ['arr', 0, 'y'] ); + expected = 2; + + t.strictEqual( actual, expected, 'deep gets value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/object/deep-get/test/test.factory.js b/lib/node_modules/@stdlib/object/deep-get/test/test.factory.js new file mode 100644 index 000000000000..39708973967e --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/test/test.factory.js @@ -0,0 +1,167 @@ +/** +* @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, + null, + true, + 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', { + 'sep': value + }); + }; + } +}); + +tape( 'the function returns a function', function test( t ) { + var dget = factory( 'a/b', { + 'sep': '/' + }); + t.strictEqual( typeof dget, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'the created function returns `undefined` if provided a non-object or null', function test( t ) { + var values; + var dget; + var i; + + values = [ + '5', + 5, + null, + void 0, + NaN, + true, + function noop() {} + ]; + + dget = factory( 'a/b', { + 'sep': '/' + }); + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( dget( values[ i ] ), void 0, 'returns undefined' ); + } + t.end(); +}); + +tape( 'the created function deep gets', function test( t ) { + var expected; + var actual; + var dget; + var obj; + + dget = factory( ['a', 'b'] ); + obj = { + 'a': { + 'b': 999 + } + }; + + actual = dget( obj ); + expected = 999; + + t.strictEqual( actual, expected, 'deep gets value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/object/deep-get/test/test.js b/lib/node_modules/@stdlib/object/deep-get/test/test.js new file mode 100644 index 000000000000..a26d4608e57f --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/test/test.js @@ -0,0 +1,187 @@ +/** +* @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 deepGet = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof deepGet, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function exports a factory function', function test( t ) { + t.strictEqual( typeof deepGet.factory, 'function', 'exports a factory function' ); + t.end(); +}); + +tape( 'the function returns `undefined` 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( deepGet( values[ i ], 'a.b.c' ), void 0, 'returns undefined' ); + } + t.end(); +}); + +tape( 'the function throws an error if provided a key path argument which is not either 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 + }; + deepGet( obj, 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() { + var obj = { + 'a': 5 + }; + deepGet( obj, 'a', value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid option', function test( t ) { + var values; + var i; + + values = [ + 5, + null, + true, + 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 + }; + deepGet( obj, 'a', { + 'sep': value + }); + }; + } +}); + +tape( 'the function deep gets', function test( t ) { + var expected; + var actual; + var obj; + + obj = { + 'a': { + 'b': 999 + } + }; + + // String path: + actual = deepGet( obj, 'a.b' ); + expected = 999; + + t.strictEqual( actual, expected, 'deep gets value' ); + + // String path with custom separator: + actual = deepGet( obj, 'a/b', { + 'sep': '/' + }); + expected = 999; + + t.strictEqual( actual, expected, 'deep gets value' ); + + // Array path: + actual = deepGet( obj, ['a', 'b'] ); + expected = 999; + + t.strictEqual( actual, expected, 'deep gets value' ); + + // Non-existent path: + actual = deepGet( obj, ['a', 'c'] ); + expected = undefined; + + t.strictEqual( actual, expected, 'deep gets value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/object/deep-get/test/test.validate.js b/lib/node_modules/@stdlib/object/deep-get/test/test.validate.js new file mode 100644 index 000000000000..0782e3df0358 --- /dev/null +++ b/lib/node_modules/@stdlib/object/deep-get/test/test.validate.js @@ -0,0 +1,103 @@ +/** +* @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 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 provided an options argument which is not an object', function test( t ) { + var values; + var err; + var i; + + values = [ + '5', + 5, + null, + NaN, + true, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + err = validate( {}, values[ i ] ); + t.strictEqual( err instanceof TypeError, true, 'returns a TypeError when provided '+values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns an error if provided a separator option which is not a string primitive', function test( t ) { + var values; + var err; + var i; + + values = [ + new String( '5' ), // eslint-disable-line no-new-wrappers + 5, + null, + 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 TypeError when provided '+values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns `null` if all options are valid', function test( t ) { + var opts; + var obj; + + opts = { + 'sep': '_' + }; + obj = {}; + t.strictEqual( validate( obj, opts ), null, 'returns expected value' ); + 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 017b893f96fc6adf21fefaae9c83b189166f3d5c Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sat, 10 Jan 2026 16:44:06 +0530 Subject: [PATCH 2/4] remove: remove `deepGet` from namespace This commit removes the `deepGet` symbol from the `@stdlib/utils` namespace due to a package migration. BREAKING CHANGE: remove `deepGet` 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 | 28 ------------------- lib/node_modules/@stdlib/utils/lib/index.js | 9 ------ 2 files changed, 37 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 4fccf7b25ab5..5edf048bf203 100644 --- a/lib/node_modules/@stdlib/utils/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/docs/types/index.d.ts @@ -37,7 +37,6 @@ import countBy = require( '@stdlib/utils/count-by' ); import curry = require( '@stdlib/utils/curry' ); import curryRight = require( '@stdlib/utils/curry-right' ); import decorateAfter = require( '@stdlib/utils/decorate-after' ); -import deepGet = require( '@stdlib/utils/deep-get' ); import deepPluck = require( '@stdlib/utils/deep-pluck' ); import deepSet = require( '@stdlib/utils/deep-set' ); import setConfigurableReadOnlyAccessor = require( '@stdlib/utils/define-configurable-read-only-accessor' ); @@ -707,33 +706,6 @@ interface Namespace { */ decorateAfter: typeof decorateAfter; - /** - * Returns a nested property value. - * - * @param obj - input object - * @param path - key path - * @param options - function options - * @param options.sep - key path separator (default: '.') - * @returns nested property value - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * - * var val = ns.deepGet( obj, 'a.b.c' ); - * // returns 'd' - * - * @example - * var dget = ns.deepGet.factory( 'a/b/c', { - * 'sep': '/' - * }); - * - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * - * var val = dget( obj ); - * // returns 'd' - */ - deepGet: typeof deepGet; - /** * Extracts a nested property value from each element of an object array. * diff --git a/lib/node_modules/@stdlib/utils/lib/index.js b/lib/node_modules/@stdlib/utils/lib/index.js index 61ddbdb49f21..6249769a8851 100644 --- a/lib/node_modules/@stdlib/utils/lib/index.js +++ b/lib/node_modules/@stdlib/utils/lib/index.js @@ -193,15 +193,6 @@ setReadOnly( utils, 'curryRight', require( '@stdlib/utils/curry-right' ) ); */ setReadOnly( utils, 'decorateAfter', require( '@stdlib/utils/decorate-after' ) ); -/** -* @name deepGet -* @memberof utils -* @readonly -* @type {Function} -* @see {@link module:@stdlib/utils/deep-get} -*/ -setReadOnly( utils, 'deepGet', require( '@stdlib/utils/deep-get' ) ); - /** * @name deepPluck * @memberof utils From 23482e07729e8c410d6dfa3cdd01755b5000e853 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sat, 10 Jan 2026 16:57:06 +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/utils/deep-pluck/README.md | 6 +++--- .../@stdlib/utils/deep-pluck/lib/main.js | 2 +- lib/node_modules/@stdlib/utils/deep-set/README.md | 4 ++-- 11 files changed, 25 insertions(+), 25 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 803dc9e2e887..a49f6f5dd28c 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 @@ -253,7 +253,7 @@ bool = has( { 'a': [ { 'b': { 'c': 'd' } } ] } ); - [`@stdlib/assert/deep-has-property`][@stdlib/assert/deep-has-property]: test whether an object contains a nested key path, either own or inherited. - [`@stdlib/assert/has-own-property`][@stdlib/assert/has-own-property]: test if an object has a specified property. -- [`@stdlib/utils/deep-get`][@stdlib/utils/deep-get]: get a nested property value. +- [`@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. @@ -271,7 +271,7 @@ bool = has( { 'a': [ { 'b': { 'c': 'd' } } ] } ); [@stdlib/assert/has-own-property]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/has-own-property -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-get +[@stdlib/object/deep-get]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/deep-get [@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-pluck 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 645dfa0ecdb8..45502f88f247 100644 --- a/lib/node_modules/@stdlib/assert/deep-has-property/README.md +++ b/lib/node_modules/@stdlib/assert/deep-has-property/README.md @@ -249,7 +249,7 @@ bool = has( { 'a': [ { 'b': { 'c': 'd' } } ] } ); - [`@stdlib/assert/deep-has-own-property`][@stdlib/assert/deep-has-own-property]: test whether an object contains a nested key path. - [`@stdlib/assert/has-own-property`][@stdlib/assert/has-own-property]: test if an object has a specified property. -- [`@stdlib/utils/deep-get`][@stdlib/utils/deep-get]: get a nested property value. +- [`@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. @@ -267,7 +267,7 @@ bool = has( { 'a': [ { 'b': { 'c': 'd' } } ] } ); [@stdlib/assert/has-own-property]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/has-own-property -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-get +[@stdlib/object/deep-get]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/deep-get [@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-pluck diff --git a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv index 4d19584d813b..0306d7705255 100644 --- a/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/alias2pkg/data/data.csv @@ -1581,7 +1581,7 @@ debugSinkStream,"@stdlib/streams/node/debug-sink" debugStream,"@stdlib/streams/node/debug" decorateAfter,"@stdlib/utils/decorate-after" deepEqual,"@stdlib/assert/deep-equal" -deepGet,"@stdlib/utils/deep-get" +deepGet,"@stdlib/object/deep-get" deepHasOwnProp,"@stdlib/assert/deep-has-own-property" deepHasProp,"@stdlib/assert/deep-has-property" deepPluck,"@stdlib/utils/deep-pluck" diff --git a/lib/node_modules/@stdlib/namespace/lib/namespace/d.js b/lib/node_modules/@stdlib/namespace/lib/namespace/d.js index dc82f11af114..e52149fe62ef 100644 --- a/lib/node_modules/@stdlib/namespace/lib/namespace/d.js +++ b/lib/node_modules/@stdlib/namespace/lib/namespace/d.js @@ -176,8 +176,8 @@ ns.push({ ns.push({ 'alias': 'deepGet', - 'path': '@stdlib/utils/deep-get', - 'value': require( '@stdlib/utils/deep-get' ), + 'path': '@stdlib/object/deep-get', + 'value': require( '@stdlib/object/deep-get' ), 'type': 'Function', 'related': [ '@stdlib/utils/deep-pluck', @@ -193,7 +193,7 @@ ns.push({ 'related': [ '@stdlib/assert/deep-has-property', '@stdlib/assert/has-own-property', - '@stdlib/utils/deep-get', + '@stdlib/object/deep-get', '@stdlib/utils/deep-pluck', '@stdlib/utils/deep-set' ] @@ -207,7 +207,7 @@ ns.push({ 'related': [ '@stdlib/assert/deep-has-own-property', '@stdlib/assert/has-own-property', - '@stdlib/utils/deep-get', + '@stdlib/object/deep-get', '@stdlib/utils/deep-pluck', '@stdlib/utils/deep-set' ] @@ -219,7 +219,7 @@ ns.push({ 'value': require( '@stdlib/utils/deep-pluck' ), 'type': 'Function', 'related': [ - '@stdlib/utils/deep-get', + '@stdlib/object/deep-get', '@stdlib/utils/deep-set' ] }); @@ -230,7 +230,7 @@ ns.push({ 'value': require( '@stdlib/utils/deep-set' ), 'type': 'Function', 'related': [ - '@stdlib/utils/deep-get', + '@stdlib/object/deep-get', '@stdlib/utils/deep-pluck' ] }); diff --git a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv index ecf0493a3d89..1e99b8e06cbf 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2alias/data/data.csv @@ -1581,7 +1581,7 @@ "@stdlib/streams/node/debug",debugStream "@stdlib/utils/decorate-after",decorateAfter "@stdlib/assert/deep-equal",deepEqual -"@stdlib/utils/deep-get",deepGet +"@stdlib/object/deep-get",deepGet "@stdlib/assert/deep-has-own-property",deepHasOwnProp "@stdlib/assert/deep-has-property",deepHasProp "@stdlib/utils/deep-pluck",deepPluck diff --git a/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv b/lib/node_modules/@stdlib/namespace/pkg2related/data/data.csv index 4267979b7217..a166967cd021 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/utils/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/utils/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/utils/deep-get,@stdlib/utils/deep-pluck,@stdlib/utils/deep-set" -"@stdlib/utils/deep-pluck","@stdlib/utils/deep-get,@stdlib/utils/deep-set" -"@stdlib/utils/deep-set","@stdlib/utils/deep-get,@stdlib/utils/deep-pluck" +"@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/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 d54d1926a880..a319af23b1ac 100644 --- a/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/pkg2standalone/data/data.csv @@ -1581,7 +1581,7 @@ "@stdlib/streams/node/debug","@stdlib/streams-node-debug" "@stdlib/utils/decorate-after","@stdlib/utils-decorate-after" "@stdlib/assert/deep-equal","@stdlib/assert-deep-equal" -"@stdlib/utils/deep-get","@stdlib/utils-deep-get" +"@stdlib/object/deep-get","@stdlib/object-deep-get" "@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" diff --git a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv index 13d826b5e006..28d6611d7007 100644 --- a/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv +++ b/lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv @@ -1581,7 +1581,7 @@ "@stdlib/streams-node-debug","@stdlib/streams/node/debug" "@stdlib/utils-decorate-after","@stdlib/utils/decorate-after" "@stdlib/assert-deep-equal","@stdlib/assert/deep-equal" -"@stdlib/utils-deep-get","@stdlib/utils/deep-get" +"@stdlib/object-deep-get","@stdlib/object/deep-get" "@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" diff --git a/lib/node_modules/@stdlib/utils/deep-pluck/README.md b/lib/node_modules/@stdlib/utils/deep-pluck/README.md index cdfe2b00b0ea..b1bffca03106 100644 --- a/lib/node_modules/@stdlib/utils/deep-pluck/README.md +++ b/lib/node_modules/@stdlib/utils/deep-pluck/README.md @@ -69,7 +69,7 @@ var out = deepPluck( arr, [ 'a', 1 ] ); The function accepts the following `options`: - **copy**: `boolean` indicating whether to return a new data structure. Default: `true`. -- **sep**: key path [separator][@stdlib/utils/deep-get]. Default: `'.'`. +- **sep**: key path [separator][@stdlib/object/deep-get]. Default: `'.'`. By default, the function returns a new data structure. To mutate the input data structure (e.g., when input values can be discarded or when optimizing memory usage), set the `copy` option to `false`. @@ -215,7 +215,7 @@ console.log( out ); ## See Also -- [`@stdlib/utils/deep-get`][@stdlib/utils/deep-get]: get a nested property value. +- [`@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. @@ -230,7 +230,7 @@ console.log( out ); -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-get +[@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 diff --git a/lib/node_modules/@stdlib/utils/deep-pluck/lib/main.js b/lib/node_modules/@stdlib/utils/deep-pluck/lib/main.js index f01ced624645..baf43c633c27 100644 --- a/lib/node_modules/@stdlib/utils/deep-pluck/lib/main.js +++ b/lib/node_modules/@stdlib/utils/deep-pluck/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var deepGet = require( '@stdlib/utils/deep-get' ).factory; +var deepGet = require( '@stdlib/object/deep-get' ).factory; var isArray = require( '@stdlib/assert/is-array' ); var format = require( '@stdlib/string/format' ); var defaults = require( './defaults.js' ); diff --git a/lib/node_modules/@stdlib/utils/deep-set/README.md b/lib/node_modules/@stdlib/utils/deep-set/README.md index e617d617c1de..9379f040c62d 100644 --- a/lib/node_modules/@stdlib/utils/deep-set/README.md +++ b/lib/node_modules/@stdlib/utils/deep-set/README.md @@ -249,7 +249,7 @@ console.log( data ); ## See Also -- [`@stdlib/utils/deep-get`][@stdlib/utils/deep-get]: get a nested property value. +- [`@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. @@ -262,7 +262,7 @@ console.log( data ); -[@stdlib/utils/deep-get]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-get +[@stdlib/object/deep-get]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/object/deep-get [@stdlib/utils/deep-pluck]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/deep-pluck From b42e433818da498774514d44885df0c54045682e Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Sat, 10 Jan 2026 16:58:46 +0530 Subject: [PATCH 4/4] remove: remove `utils/deep-get` This commit removes `@stdlib/utils/deep-get` in favor of `@stdlib/object/deep-get`. BREAKING CHANGE: remove `utils/deep-get` To migrate, users should update their require/import paths to use `@stdlib/object/deep-get` which provides the same API and implementation. Ref: https://github.com/stdlib-js/stdlib/issues/8755 --- .../@stdlib/utils/deep-get/README.md | 181 ----------------- .../utils/deep-get/benchmark/benchmark.js | 130 ------------ .../@stdlib/utils/deep-get/docs/repl.txt | 63 ------ .../utils/deep-get/docs/types/index.d.ts | 125 ------------ .../@stdlib/utils/deep-get/docs/types/test.ts | 109 ---------- .../@stdlib/utils/deep-get/examples/index.js | 42 ---- .../@stdlib/utils/deep-get/lib/defaults.js | 38 ---- .../@stdlib/utils/deep-get/lib/dget.js | 57 ------ .../@stdlib/utils/deep-get/lib/factory.js | 94 --------- .../@stdlib/utils/deep-get/lib/index.js | 58 ------ .../@stdlib/utils/deep-get/lib/main.js | 101 ---------- .../@stdlib/utils/deep-get/lib/validate.js | 66 ------- .../@stdlib/utils/deep-get/package.json | 68 ------- .../@stdlib/utils/deep-get/test/test.dget.js | 126 ------------ .../utils/deep-get/test/test.factory.js | 167 ---------------- .../@stdlib/utils/deep-get/test/test.js | 187 ------------------ .../utils/deep-get/test/test.validate.js | 103 ---------- 17 files changed, 1715 deletions(-) delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/README.md delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/benchmark/benchmark.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/docs/types/index.d.ts delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/docs/types/test.ts delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/examples/index.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/lib/defaults.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/lib/dget.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/lib/factory.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/lib/index.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/lib/main.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/lib/validate.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/package.json delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/test/test.dget.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/test/test.factory.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/test/test.js delete mode 100644 lib/node_modules/@stdlib/utils/deep-get/test/test.validate.js diff --git a/lib/node_modules/@stdlib/utils/deep-get/README.md b/lib/node_modules/@stdlib/utils/deep-get/README.md deleted file mode 100644 index 5fa92c902795..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/README.md +++ /dev/null @@ -1,181 +0,0 @@ - - -# Deep Get - -> Get a nested property value. - -
- -## Usage - -```javascript -var deepGet = require( '@stdlib/utils/deep-get' ); -``` - -#### deepGet( obj, path\[, options] ) - -Returns a nested property value. - - - -```javascript -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var val = deepGet( obj, 'a.b.c' ); -// returns 'd' -``` - -For `paths` including `arrays`, specify the numeric index. - - - -```javascript -var arr = [ - { 'a': [ {'x': 5} ] }, - { 'a': [ {'x': 10} ] } -]; - -var val = deepGet( arr, '1.a.0.x' ); -// returns 10 -``` - -The key `path` may be specified as either a delimited `string` or a key `array`. - - - -```javascript -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var val = deepGet( obj, [ 'a', 'b', 'c' ] ); -// returns 'd' -``` - -The function accepts the following `options`: - -- **sep**: key path separator. Default: `'.'`. - -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 val = deepGet( obj, 'a/b/c', { - 'sep': '/' -}); -// returns 'd' -``` - -#### deepGet.factory( path\[, options] ) - -Creates a reusable deep get function. The factory method ensures a `deepGet` function is configured identically by using the same set of provided `options`. - -```javascript -var dget = deepGet.factory( 'a/b/c', { - 'sep': '/' -}); -``` - -#### dget( obj ) - -Returns a nested property value. - - - -```javascript -var dget = deepGet.factory( 'a.b.c' ); - -var obj = { 'a': { 'b': { 'c': 'd' } } }; - -var val = dget( obj ); -// returns 'd' -``` - -
- - - -
- -## Examples - - - -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var deepGet = require( '@stdlib/utils/deep-get' ); - -var data; -var keys; -var val; -var i; - -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; - val = deepGet( data, keys ); - console.log( val ); -} -``` - -
- - - - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/utils/deep-get/benchmark/benchmark.js b/lib/node_modules/@stdlib/utils/deep-get/benchmark/benchmark.js deleted file mode 100644 index 7d1cd7e558dc..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/benchmark/benchmark.js +++ /dev/null @@ -1,130 +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 isArray = require( '@stdlib/assert/is-array' ); -var randu = require( '@stdlib/random/base/randu' ); -var pkg = require( './../package.json' ).name; -var deepGet = require( './../lib' ); - - -// MAIN // - -bench( pkg, function benchmark( b ) { - var arr; - var obj; - var out; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': [ 0.0, 0.5, 1.0 ] - } - } - } - }; - arr = obj.a.b.c.d; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 1 ] = randu(); - out = deepGet( obj, 'a.b.c.d' ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::paths_array', function benchmark( b ) { - var paths; - var arr; - var obj; - var out; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': [ 0.0, 0.5, 1.0 ] - } - } - } - }; - paths = [ 'a', 'b', 'c', 'd' ]; - arr = obj.a.b.c.d; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 1 ] = randu(); - out = deepGet( obj, paths ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+':factory', function benchmark( b ) { - var dget; - var arr; - var obj; - var out; - var i; - - obj = { - 'a': { - 'b': { - 'c': { - 'd': [ 0.0, 0.5, 1.0 ] - } - } - } - }; - dget = deepGet.factory( 'a.b.c.d' ); - arr = obj.a.b.c.d; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - arr[ 1 ] = randu(); - out = dget( obj ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( out ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/deep-get/docs/repl.txt b/lib/node_modules/@stdlib/utils/deep-get/docs/repl.txt deleted file mode 100644 index 0bc1c3d8491f..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/docs/repl.txt +++ /dev/null @@ -1,63 +0,0 @@ - -{{alias}}( obj, path[, options] ) - Returns a nested property value. - - Parameters - ---------- - obj: ObjectLike - Input object. - - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: any - Nested property value. - - Examples - -------- - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var val = {{alias}}( obj, 'a.b.c' ) - 'd' - - // Specify a custom separator via the `sep` option: - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var val = {{alias}}( obj, 'a/b/c', { 'sep': '/' } ) - 'd' - -{{alias}}.factory( path[, options] ) - Creates a reusable deep get function. - - Parameters - ---------- - path: string|Array - Key path. - - options: Object (optional) - Options. - - options.sep: string (optional) - Key path separator. Default: '.'. - - Returns - ------- - out: Function - Deep get factory. - - Examples - -------- - > var dget = {{alias}}.factory( 'a/b/c', { 'sep': '/' } ); - > var obj = { 'a': { 'b': { 'c': 'd' } } }; - > var val = dget( obj ) - 'd' - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/utils/deep-get/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/deep-get/docs/types/index.d.ts deleted file mode 100644 index 285b1d02fe99..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/docs/types/index.d.ts +++ /dev/null @@ -1,125 +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 { - /** - * Key path separator. - */ - sep?: string; -} - -/** -* Returns a nested property value. -* -* @param obj - input object -* @returns nested property value -*/ -type Unary = ( obj: any ) => any; - -/** -* Interface for retrieving nested property values. -*/ -interface DeepGet { - /** - * Returns a nested property value. - * - * @param obj - input object - * @param path - key path - * @param options - function options - * @param options.sep - key path separator (default: '.') - * @returns nested property value - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var val = deepGet( obj, 'a.b.c' ); - * // returns 'd' - * - * @example - * var arr = [ - * { 'a': [ {'x': 5} ] }, - * { 'a': [ {'x': 10} ] } - * ]; - * var val = deepGet( arr, '1.a.0.x' ); - * // returns 10 - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var val = deepGet( obj, ['a','b','c'] ); - * // returns 'd' - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var val = deepGet( obj, 'a/b/c', { - * 'sep': '/' - * }); - * // returns 'd' - */ - ( obj: any, path: string | Array, options?: Options ): any; - - /** - * Returns a function for retrieving a nested property value. - * - * @param path - key path - * @param options - function options - * @param options.sep - key path separator (default: '.') - * @returns deep get factory - * - * @example - * var dget = deepGet.factory( 'a/b/c', { - * 'sep': '/' - * }); - */ - factory( path: string | Array, options?: Options ): Unary; -} - -/** -* Returns a nested property value. -* -* @param obj - input object -* @param path - key path -* @param options - function options -* @param options.sep - key path separator (default: '.') -* @returns nested property value -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* var val = deepGet( obj, 'a.b.c' ); -* // returns 'd' -* -* @example -* var dget = deepGet.factory( 'a/b/c', { -* 'sep': '/' -* }); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* var val = dget( obj ); -* // returns 'd' -*/ -declare var deepGet: DeepGet; - - -// EXPORTS // - -export = deepGet; diff --git a/lib/node_modules/@stdlib/utils/deep-get/docs/types/test.ts b/lib/node_modules/@stdlib/utils/deep-get/docs/types/test.ts deleted file mode 100644 index e047b1e31b00..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/docs/types/test.ts +++ /dev/null @@ -1,109 +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 deepGet = require( './index' ); - - -// TESTS // - -// The function returns an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepGet( obj, 'a.b.c' ); // $ExpectType any - deepGet( obj, [ 'a', 'b', 'c' ] ); // $ExpectType any - deepGet( obj, 'a-b-c', { 'sep': '-' } ); // $ExpectType any -} - -// 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' } } }; - deepGet( obj, true ); // $ExpectError - deepGet( obj, false ); // $ExpectError - deepGet( obj, 2.12 ); // $ExpectError - deepGet( obj, {} ); // $ExpectError - deepGet( obj, [ 1, 2, 3 ] ); // $ExpectError - deepGet( obj, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - deepGet( obj, 'a.b.c', null ); // $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' } } }; - deepGet( obj, 'a.b.c', { 'sep': true } ); // $ExpectError - deepGet( obj, 'a.b.c', { 'sep': false } ); // $ExpectError - deepGet( obj, 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepGet( obj, 'a.b.c', { 'sep': null } ); // $ExpectError - deepGet( obj, 'a.b.c', { 'sep': [] } ); // $ExpectError - deepGet( obj, 'a.b.c', { 'sep': {} } ); // $ExpectError - deepGet( obj, 'a.b.c', { 'sep': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided no arguments... -{ - deepGet(); // $ExpectError -} - -// Attached to main export is a `factory` method which returns a function... -{ - deepGet.factory( 'a.b.c' ); // $ExpectType Unary -} - -// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... -{ - deepGet.factory(); // $ExpectError - deepGet.factory( 'a.b.c', {}, 21 ); // $ExpectError -} - -// The `factory` method returns a function which returns an object... -{ - const obj = { 'a': { 'b': { 'c': 'd' } } }; - let fcn = deepGet.factory( 'a.b.c' ); - fcn( obj ); // $ExpectType any - - fcn = deepGet.factory( 'a-b-c', { 'sep': '-' } ); - fcn( obj ); // $ExpectType any -} - -// The compiler throws an error if the `factory` method is provided a second argument which is not an object... -{ - deepGet.factory( 'a.b.c', null ); // $ExpectError -} - -// The compiler throws an error if the `factory` method is provided a `sep` option which is not a string... -{ - deepGet.factory( 'a.b.c', { 'sep': 123 } ); // $ExpectError - deepGet.factory( 'a.b.c', { 'sep': true } ); // $ExpectError - deepGet.factory( 'a.b.c', { 'sep': false } ); // $ExpectError - deepGet.factory( 'a.b.c', { 'sep': null } ); // $ExpectError - deepGet.factory( 'a.b.c', { 'sep': [] } ); // $ExpectError - deepGet.factory( 'a.b.c', { 'sep': {} } ); // $ExpectError - deepGet.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 = deepGet.factory( 'a.b.c' ); - fcn(); // $ExpectError - fcn( obj, 2 ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/utils/deep-get/examples/index.js b/lib/node_modules/@stdlib/utils/deep-get/examples/index.js deleted file mode 100644 index c1bde24a5743..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/examples/index.js +++ /dev/null @@ -1,42 +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 deepGet = require( './../lib' ); - -var data; -var keys; -var val; -var i; - -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; - val = deepGet( data, keys ); - console.log( val ); -} diff --git a/lib/node_modules/@stdlib/utils/deep-get/lib/defaults.js b/lib/node_modules/@stdlib/utils/deep-get/lib/defaults.js deleted file mode 100644 index 061281e04982..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/lib/defaults.js +++ /dev/null @@ -1,38 +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 { - 'sep': '.' - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/node_modules/@stdlib/utils/deep-get/lib/dget.js b/lib/node_modules/@stdlib/utils/deep-get/lib/dget.js deleted file mode 100644 index 7ca1b86017eb..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/lib/dget.js +++ /dev/null @@ -1,57 +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' ); - - -// MAIN // - -/** -* Returns a nested property value. -* -* @private -* @param {ObjectLike} obj - input object -* @param {Array} props - list of properties defining a key path -* @returns {*} nested property value -*/ -function deepGet( obj, props ) { - var len = props.length; - var v = obj; - var i; - for ( i = 0; i < len; i++ ) { - if ( - isObjectLike( v ) && - hasOwnProp( v, props[ i ] ) - ) { - v = v[ props[ i ] ]; - } else { - return; - } - } - return v; -} - - -// EXPORTS // - -module.exports = deepGet; diff --git a/lib/node_modules/@stdlib/utils/deep-get/lib/factory.js b/lib/node_modules/@stdlib/utils/deep-get/lib/factory.js deleted file mode 100644 index ab3d1af4a31d..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/lib/factory.js +++ /dev/null @@ -1,94 +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 dget = require( './dget.js' ); - - -// MAIN // - -/** -* Returns a function for retrieving a nested property value. -* -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @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 get function -* -* @example -* var dget = factory( 'a/b/c', { -* '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 deepGet; - - /** - * Returns a nested property value. - * - * @private - * @param {ObjectLike} obj - input object - * @returns {*} nested property value - * - * @example - * var obj = { 'a': { 'b': { 'c': 'd' } } }; - * var val = deepGet( obj ); - */ - function deepGet( obj ) { - if ( isObjectLike( obj ) ) { - return dget( obj, props ); - } - } -} - - -// EXPORTS // - -module.exports = factory; diff --git a/lib/node_modules/@stdlib/utils/deep-get/lib/index.js b/lib/node_modules/@stdlib/utils/deep-get/lib/index.js deleted file mode 100644 index 06b2f7b36ae1..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/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'; - -/** -* Get a nested property value. -* -* @module @stdlib/utils/deep-get -* -* @example -* var deepGet = require( '@stdlib/utils/deep-get' ); -* -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* var val = deepGet( obj, 'a.b.c' ); -* // returns 'd' -* -* var dget = factory( 'a/b/c', { -* 'sep': '/' -* }); -* -* obj = { 'a': { 'b': { 'c': 'd' } } }; -* -* val = dget( obj ); -* // returns 'd' -*/ - -// 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-get/lib/main.js b/lib/node_modules/@stdlib/utils/deep-get/lib/main.js deleted file mode 100644 index 0c67dbf5b045..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/lib/main.js +++ /dev/null @@ -1,101 +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 dget = require( './dget.js' ); - - -// MAIN // - -/** -* Returns a nested property value. -* -* @param {ObjectLike} obj - input object -* @param {(string|Array)} path - key path -* @param {Options} [options] - function options -* @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 {*} nested property value -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var val = deepGet( obj, 'a.b.c' ); -* // returns 'd' -* -* @example -* var arr = [ -* { 'a': [ {'x': 5} ] }, -* { 'a': [ {'x': 10} ] } -* ]; -* var val = deepGet( arr, '1.a.0.x' ); -* // returns 10 -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var val = deepGet( obj, ['a','b','c'] ); -* // returns 'd' -* -* @example -* var obj = { 'a': { 'b': { 'c': 'd' } } }; -* var val = deepGet( obj, 'a/b/c', { -* 'sep': '/' -* }); -* // returns 'd' -*/ -function deepGet( obj, path, options ) { - var isStr; - var props; - var opts; - var err; - if ( !isObjectLike( obj ) ) { - return; - } - 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 > 2 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - if ( isStr ) { - props = path.split( opts.sep ); - } else { - props = path; - } - return dget( obj, props ); -} - - -// EXPORTS // - -module.exports = deepGet; diff --git a/lib/node_modules/@stdlib/utils/deep-get/lib/validate.js b/lib/node_modules/@stdlib/utils/deep-get/lib/validate.js deleted file mode 100644 index 8c021620c767..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/lib/validate.js +++ /dev/null @@ -1,66 +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 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 {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, '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-get/package.json b/lib/node_modules/@stdlib/utils/deep-get/package.json deleted file mode 100644 index 4061c104843c..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/package.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "name": "@stdlib/utils/deep-get", - "version": "0.0.0", - "description": "Get 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", - "get", - "object", - "obj", - "array", - "nested", - "property", - "prop" - ] -} diff --git a/lib/node_modules/@stdlib/utils/deep-get/test/test.dget.js b/lib/node_modules/@stdlib/utils/deep-get/test/test.dget.js deleted file mode 100644 index db6389abeba0..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/test/test.dget.js +++ /dev/null @@ -1,126 +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 dget = require( './../lib/dget.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dget, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function deep gets a nested property', function test( t ) { - var expected; - var actual; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - actual = dget( obj, ['a', 'b', 'c'] ); - expected = 'd'; - - t.strictEqual( actual, expected, 'deep gets value' ); - t.end(); -}); - -tape( 'the function returns `undefined` if unable to successfully get', function test( t ) { - var actual; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - actual = dget( obj, ['a', 'b', 'djfajdfaj'] ); - t.strictEqual( actual, void 0, 'returns undefined' ); - - actual = dget( obj, ['null', 'e'] ); - t.strictEqual( actual, void 0, 'returns undefined' ); - t.end(); -}); - -tape( 'the function deep gets into an array', function test( t ) { - var expected; - var actual; - var obj; - - obj = { - 'a': { - 'b': { - 'c': 'd' - } - }, - 'arr': [ - { - 'x': 1, - 'y': 2 - }, - { - 'x': 3, - 'y': 4 - } - ], - 'null': null - }; - - actual = dget( obj, ['arr', 0, 'y'] ); - expected = 2; - - t.strictEqual( actual, expected, 'deep gets value' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/deep-get/test/test.factory.js b/lib/node_modules/@stdlib/utils/deep-get/test/test.factory.js deleted file mode 100644 index 39708973967e..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/test/test.factory.js +++ /dev/null @@ -1,167 +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, - null, - true, - 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', { - 'sep': value - }); - }; - } -}); - -tape( 'the function returns a function', function test( t ) { - var dget = factory( 'a/b', { - 'sep': '/' - }); - t.strictEqual( typeof dget, 'function', 'returns expected value' ); - t.end(); -}); - -tape( 'the created function returns `undefined` if provided a non-object or null', function test( t ) { - var values; - var dget; - var i; - - values = [ - '5', - 5, - null, - void 0, - NaN, - true, - function noop() {} - ]; - - dget = factory( 'a/b', { - 'sep': '/' - }); - - for ( i = 0; i < values.length; i++ ) { - t.strictEqual( dget( values[ i ] ), void 0, 'returns undefined' ); - } - t.end(); -}); - -tape( 'the created function deep gets', function test( t ) { - var expected; - var actual; - var dget; - var obj; - - dget = factory( ['a', 'b'] ); - obj = { - 'a': { - 'b': 999 - } - }; - - actual = dget( obj ); - expected = 999; - - t.strictEqual( actual, expected, 'deep gets value' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/deep-get/test/test.js b/lib/node_modules/@stdlib/utils/deep-get/test/test.js deleted file mode 100644 index a26d4608e57f..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/test/test.js +++ /dev/null @@ -1,187 +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 deepGet = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof deepGet, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function exports a factory function', function test( t ) { - t.strictEqual( typeof deepGet.factory, 'function', 'exports a factory function' ); - t.end(); -}); - -tape( 'the function returns `undefined` 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( deepGet( values[ i ], 'a.b.c' ), void 0, 'returns undefined' ); - } - t.end(); -}); - -tape( 'the function throws an error if provided a key path argument which is not either 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 - }; - deepGet( obj, 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() { - var obj = { - 'a': 5 - }; - deepGet( obj, 'a', value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - 5, - null, - true, - 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 - }; - deepGet( obj, 'a', { - 'sep': value - }); - }; - } -}); - -tape( 'the function deep gets', function test( t ) { - var expected; - var actual; - var obj; - - obj = { - 'a': { - 'b': 999 - } - }; - - // String path: - actual = deepGet( obj, 'a.b' ); - expected = 999; - - t.strictEqual( actual, expected, 'deep gets value' ); - - // String path with custom separator: - actual = deepGet( obj, 'a/b', { - 'sep': '/' - }); - expected = 999; - - t.strictEqual( actual, expected, 'deep gets value' ); - - // Array path: - actual = deepGet( obj, ['a', 'b'] ); - expected = 999; - - t.strictEqual( actual, expected, 'deep gets value' ); - - // Non-existent path: - actual = deepGet( obj, ['a', 'c'] ); - expected = undefined; - - t.strictEqual( actual, expected, 'deep gets value' ); - t.end(); -}); diff --git a/lib/node_modules/@stdlib/utils/deep-get/test/test.validate.js b/lib/node_modules/@stdlib/utils/deep-get/test/test.validate.js deleted file mode 100644 index 0782e3df0358..000000000000 --- a/lib/node_modules/@stdlib/utils/deep-get/test/test.validate.js +++ /dev/null @@ -1,103 +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 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 provided an options argument which is not an object', function test( t ) { - var values; - var err; - var i; - - values = [ - '5', - 5, - null, - NaN, - true, - void 0, - [], - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - err = validate( {}, values[ i ] ); - t.strictEqual( err instanceof TypeError, true, 'returns a TypeError when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function returns an error if provided a separator option which is not a string primitive', function test( t ) { - var values; - var err; - var i; - - values = [ - new String( '5' ), // eslint-disable-line no-new-wrappers - 5, - null, - 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 TypeError when provided '+values[ i ] ); - } - t.end(); -}); - -tape( 'the function returns `null` if all options are valid', function test( t ) { - var opts; - var obj; - - opts = { - 'sep': '_' - }; - obj = {}; - t.strictEqual( validate( obj, opts ), null, 'returns expected value' ); - 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(); -});