safeDel.js 373 B

12345678910111213141516
  1. var isUndef = require('./isUndef');
  2. var castPath = require('./castPath');
  3. exports = function(obj, path) {
  4. path = castPath(path, obj);
  5. var prop, ret;
  6. while ((prop = path.shift())) {
  7. ret = obj[prop];
  8. if (path.length === 0) delete obj[prop];
  9. obj = ret;
  10. if (isUndef(obj)) return;
  11. }
  12. return ret;
  13. };
  14. module.exports = exports;