UNPKG
null-propagation
Version:
latest (1.0.1)
1.0.1
1.0.0
Emulate null propagation operator.
null-propagation
/
src
/
index.js
16 lines
(14 loc)
•
299 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function
nullPropagation
(
accessor, defaultValue
) {
try
{
return
accessor
() }
catch
(error) {
if
(error
instanceof
TypeError
) {
if
(
typeof
defaultValue !==
'undefined'
) {
return
defaultValue; }
return
; }
throw
error } }
export
default
nullPropagation