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
Typescript
Module System
Node Version
NPM Version
98.6
Supply Chain
100
Quality
76.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
197 Stars
243 Commits
16 Forks
4 Watchers
194 Branches
6 Contributors
Updated on Mar 02, 2025
Minified
Minified + Gzipped
Latest Version
1.3.0
Package Id
selectn@1.3.0
Unpacked Size
22.69 kB
Size
6.95 kB
File Count
8
NPM Version
10.9.2
Node Version
23.9.0
Published on
Mar 02, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
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>
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
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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
Reason
73 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
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