Gathering detailed insights and metrics for @stdlib/utils-deep-pluck
Gathering detailed insights and metrics for @stdlib/utils-deep-pluck
Gathering detailed insights and metrics for @stdlib/utils-deep-pluck
Gathering detailed insights and metrics for @stdlib/utils-deep-pluck
npm install @stdlib/utils-deep-pluck
Typescript
Module System
Min. Node Version
Node Version
NPM Version
70.7
Supply Chain
88.1
Quality
82.3
Maintenance
100
Vulnerability
88
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
3,813
Last Day
3
Last Week
16
Last Month
84
Last Year
676
Apache-2.0 License
2 Stars
67 Commits
3 Watchers
5 Branches
11 Contributors
Updated on Feb 03, 2025
Latest Version
0.2.2
Package Id
@stdlib/utils-deep-pluck@0.2.2
Unpacked Size
40.36 kB
Size
10.53 kB
File Count
13
NPM Version
8.19.4
Node Version
16.20.2
Published on
Jul 27, 2024
Cumulative downloads
Total Downloads
Last Day
50%
3
Compared to previous day
Last Week
-11.1%
16
Compared to previous week
Last Month
20%
84
Compared to previous month
Last Year
-44.5%
676
Compared to previous year
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Extract a nested property value from each element of an object array.
1npm install @stdlib/utils-deep-pluck
1var deepPluck = require( '@stdlib/utils-deep-pluck' );
Extracts a nested property value from each element of an object array
based on a key path
.
1var arr = [ 2 { 'a': { 'b': { 'c': 1 } } }, 3 { 'a': { 'b': { 'c': 2 } } } 4]; 5 6var out = deepPluck( arr, 'a.b.c' ); 7// returns [ 1, 2 ]
A key path
may be specified as either a string
or as an array
.
1var arr = [ 2 { 'a': [ 0, 1, 2 ] }, 3 { 'a': [ 3, 4, 5 ] } 4]; 5 6var out = deepPluck( arr, [ 'a', 1 ] ); 7// returns [ 1, 4 ]
The function accepts the following options
:
boolean
indicating whether to return a new data structure. Default: true
.'.'
.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
.
1var arr = [ 2 { 'a': { 'b': { 'c': 1 } } }, 3 { 'a': { 'b': { 'c': 2 } } } 4]; 5 6var out = deepPluck( arr, 'a.b.c', { 'copy': false } ); 7// returns [ 1, 2 ] 8 9var bool = ( arr[ 0 ] === out[ 0 ] ); 10// returns true
The default key path
separator is .
. To specify an alternative separator, set the sep
option.
1var arr = [ 2 { 'a': { 'b': { 'c': 1 } } }, 3 { 'a': { 'b': { 'c': 2 } } } 4]; 5 6var out = deepPluck( arr, 'a|b|c', { 'sep': '|' } ); 7// returns [ 1, 2 ]
If a key path does not exist, the function sets the plucked value as undefined
.
1var arr = [ 2 { 'a': { 'b': { 'c': 1 } } }, 3 null, 4 void 0, 5 { 'a': { 'b': { 'c': 2 } } } 6]; 7 8var out = deepPluck( arr, 'a.b.c' ); 9// returns [ 1, undefined, undefined, 2 ]
Extracted values are not cloned.
1var arr = [ 2 { 'a': { 'b': { 'c': 2 } } }, 3 { 'a': { 'b': { 'c': 3 } } } 4]; 5 6var out = deepPluck( arr, 'a.b' ); 7// returns [ { 'c': 2 }, { 'c': 3 } ] 8 9var bool = ( arr[ 0 ].a.b === out[ 0 ] ); 10// returns true
To prevent subsequent unintended mutation, use copy.
1var copy = require( '@stdlib/utils-copy' ); 2 3var arr = [ 4 { 'a': { 'b': { 'c': 2 } } }, 5 { 'a': { 'b': { 'c': 3 } } } 6]; 7 8var out = deepPluck( arr, 'a.b' ); 9// returns [ { 'c': 2 }, { 'c': 3 } ] 10 11// Perform a deep copy: 12out = copy( out ); 13 14var bool = ( arr[ 0 ].a.b === out[ 0 ] ); 15// returns false
1var randu = require( '@stdlib/random-base-randu' ); 2var round = require( '@stdlib/math-base-special-round' ); 3var deepPluck = require( '@stdlib/utils-deep-pluck' ); 4 5var arr; 6var out; 7var tmp; 8var i; 9 10arr = new Array( 100 ); 11for ( i = 0; i < arr.length; i++ ) { 12 tmp = { 13 'a': { 14 'b': { 15 'c': { 16 'd': null 17 } 18 } 19 } 20 }; 21 tmp.a.b.c.d = round( randu()*100.0 ); 22 arr[ i ] = tmp; 23} 24 25// Pluck the deeply nested values: 26out = deepPluck( arr, 'a.b.c.d' ); 27console.log( out );
@stdlib/utils-deep-get
: get a nested property value.@stdlib/utils-deep-set
: set a nested property value.This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2024. The Stdlib Authors.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
no SAST tool detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More