pselect
Safely select arbitrarily nested nullable fields (with strong types).
; const foo = {}; const baz = ; // No Error!console; // undefined
How?
pselect uses the JavaScript Proxy
object and Reflect
ion to safely select the nullable field. If Proxy
support doesn't exist (ex: due to an old browser), if gracefully falls back to the less effiecient, but always available try-catch.
Installing
npm install pselect
API
select
select
takes in your subject and a selector function and returns the value or undefined
.
;
Example:
; const foo = {}; const baz = ; // No Error!console; // undefined
cselect
cselect
is the curried version of the select
function. It lets you write nice functional code that you can pipe and chain. (See example)
;
Examples:
; const foo = {}; const getBaz = pbarbaz; console; // undefined
; ; ; passportNumberfred; // NO_PASSPORT
Prior Art
Licence
MIT