This repository was archived by the owner on Oct 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (41 loc) · 2.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// UMD shim generated by Browserify
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.deepSet=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/**
* Sets a value of a property in an object tree.
* Missing objects will (optionally) be created.
*
* var deepSet = require('deep-set')
* var obj = { one: { two: { three: 'sad' } } }
* deepSet(obj, 'one.two.three', 'yay')
* // { one: { two: { three: 'yay' } } }
*
*
* @param {object} obj The object.
* @param {string} path The property path, separated by dots.
* @param {*} value The value to set.
* @param {boolean} create Whether to create missing objects along the way.
* @return {object} The manipulated object.
*/
module.exports = function deepSet (obj, path, value, create) {
var properties = path.split('.')
var currentObject = obj
var property
create = create === undefined ? true : create
while (properties.length) {
property = properties.shift()
if (!currentObject) break;
if (!isObject(currentObject[property]) && create) {
currentObject[property] = {}
}
if (!properties.length){
currentObject[property] = value
}
currentObject = currentObject[property]
}
return obj
}
function isObject(obj) {
return typeof obj === 'object' && obj !== null
}
},{}]},{},[1])(1)
});