You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

property.js 377B

1234567891011121314151617181920
  1. const shallowProperty = require('./shallow-property');
  2. const deepGet = (obj, path) => {
  3. const { length } = path;
  4. for (let i = 0; i < length; i++) {
  5. if (obj == null) return void 0;
  6. obj = obj[path[i]];
  7. }
  8. return length ? obj : void 0;
  9. };
  10. module.exports = path => {
  11. if (!Array.isArray(path)) {
  12. return shallowProperty(path);
  13. }
  14. return obj => deepGet(obj, path);
  15. };