source: trip-planner-front/node_modules/unset-value/index.js@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 756 bytes
Line 
1/*!
2 * unset-value <https://github.com/jonschlinkert/unset-value>
3 *
4 * Copyright (c) 2015, 2017, Jon Schlinkert.
5 * Released under the MIT License.
6 */
7
8'use strict';
9
10var isObject = require('isobject');
11var has = require('has-value');
12
13module.exports = function unset(obj, prop) {
14 if (!isObject(obj)) {
15 throw new TypeError('expected an object.');
16 }
17 if (obj.hasOwnProperty(prop)) {
18 delete obj[prop];
19 return true;
20 }
21
22 if (has(obj, prop)) {
23 var segs = prop.split('.');
24 var last = segs.pop();
25 while (segs.length && segs[segs.length - 1].slice(-1) === '\\') {
26 last = segs.pop().slice(0, -1) + '.' + last;
27 }
28 while (segs.length) obj = obj[prop = segs.shift()];
29 return (delete obj[last]);
30 }
31 return true;
32};
Note: See TracBrowser for help on using the repository browser.