index.js 488 B

1234567891011
  1. export function get (object, path, def) {
  2. return (object = (path.split ? path.split('.') : path).reduce(function (obj, p) {
  3. return obj && obj[p]
  4. }, object)) === undefined ? def : object;
  5. };
  6. export function set (object, path, val, obj) {
  7. return !/^(__proto__|constructor|prototype)$/.test(path) && ((path = path.split ? path.split('.') : path.slice(0)).slice(0, -1).reduce(function (obj, p) {
  8. return obj[p] = obj[p] || {};
  9. }, obj = object)[path.pop()] = val), object;
  10. };