Gathering detailed insights and metrics for selectn
Gathering detailed insights and metrics for selectn
Gathering detailed insights and metrics for selectn
Gathering detailed insights and metrics for selectn
Curried property accessor function that resolves deeply-nested object properties via dot/bracket-notation string path while mitigating TypeErrors via friendly and composable API.
npm install selectn
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
196 Stars
226 Commits
16 Forks
5 Watching
189 Branches
6 Contributors
Updated on 13 Jun 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-11.7%
17,642
Compared to previous day
Last week
9%
118,189
Compared to previous week
Last month
17.8%
534,786
Compared to previous month
Last year
10.1%
4,136,390
Compared to previous year
Curried property accessor function that resolves deeply-nested object properties via dot/bracket-notation string path while mitigating
TypeErrors
via friendly and composable API.
1yarn add selectn
or
1npm install selectn --save
or
1<script src="https://unpkg.com/selectn/selectn.min.js"></script>
The browsers listed in .zuul.yml are continuously tested; however,
selectn
is also known to work on older unlisted legacy browsers.
person && person.info && person.info.name && person.info.name.full
selectn('info.name.full', person)
contacts.map(function (contact) {
return contact && contact.addresses && contact.addresses[0]
})
contacts.map(selectn('addresses[0]')))
if (obj && obj.a && obj.a.b && obj.a.b.c)
.Cannot read property '...' of undefined
.'group[0].section.a.seat[3]'
.'stats.temperature-today'
.selectn
is auto-curried so partial application is automatic when you omit the second argument.selectn
uses Haskell style parameter order (AKA: data-last) which enables pointfree style programming.selectn
are higher-order property accessors which can be passed to other higher-order functions like map or filter.eval
in disguise).Avoid annoying Cannot read property '...' of undefined
TypeError
without writing boilerplate anonymous functions or guards.
1var selectn = require('selectn') 2var language = [ 3 { strings: { en: { name: 'english' } }}, 4 { strings: { es: { name: 'spanish' } }}, 5 { strings: { km: { name: 'khmer' } }}, 6 { strings: { es: { name: 'spanish' } }}, 7 { nodatas: {}} 8] 9 10var spanish = selectn('strings.es') 11//=> [Function] 12 13language.filter(spanish).length 14//=> 2
Access deeply nested properties (including dashed properties) using point-free style.
1var selectn = require('selectn') 2var data = { 3 client: { 4 message: { 'message-id': 'd50afb80-a6be-11e2-9e96-0800200c9a66' } 5 } 6} 7 8var getId = selectn('client.message.message-id') 9//=> [Function] 10 11Promise.resolve(data).then(getId) 12//=> 'd50afb80-a6be-11e2-9e96-0800200c9a66'
Avoid wrapping property accessors in anonymous functions.
1var selectn = require('selectn') 2var contacts = [ 3 { addresses: [ '123 Main St, Broomfield, CO 80020', '123 Main St, Denver, CO 80202' ] }, 4 { addresses: [ '123 Main St, Kirkland, IL 60146' ] }, 5 { phones: [] }, 6] 7 8var primaryAddress = selectn('addresses[0]') 9//=> [Function] 10 11contacts.map(primaryAddress) 12//=> [ '123 Main St, Broomfield, CO 80020', '123 Main St, Kirkland, IL 60146', undefined ]
.
Pass an array as path instead of a string.
1var selectn = require('selectn') 2var data = { 3 client: { 4 'message.id': 'd50afb80-a6be-11e2-9e96-0800200c9a66' 5 } 6} 7 8selectn(['client', 'message.id'], data) 9//=> 'd50afb80-a6be-11e2-9e96-0800200c9a66'
Avoid
var fn = data.may.be.a.fn; if (typeof fn === 'function') fn()
.
1var selectn = require('selectn') 2function hi () { return 'hi' } 3var data = { may: { be: { a: { fn: hi } } } } 4 5selectn('may.be.a.fn', data) 6//=> 'hi'
selectn(String|Array)
path (String|Array)
Dot/bracket-notation string path or array.(Function)
Unary function accepting the object to access.selectn(String|Array, Object)
path (String|Array)
Dot/bracket-notation string path or array.object (String|Array)
Object to access.(*|undefined)
Value at path if path exists or undefined
if path does not exist.selectn
has inspired ports to other languages:
Language | Project |
---|---|
Python | selectn |
Other JS packages whose friendly API is driven by selectn
:
JS packages that have inspired selectn
:
Alternative packages you might like instead of selectn
:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 6/15 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
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