p3ol/junipero

[utils] .get is trying to get value inside the default value

dackmin opened this issue · 1 comments

export const get = (obj = {}, path = '', defaultValue = null) => path
.split('.')
.reduce((a, c) => exists(a?.[c]) ? a[c] : defaultValue, obj);

get({}, 'foo.bold', 'Default value');

Capture d’écran 2021-08-02 à 10 27 44

fix:

export const get = (obj = {}, path = '', defaultValue = null) => path
  .split('.')
  .reduce((a, c) => exists(a?.[c]) ? a[c] : undefined, obj) ?? defaultValue;