UNPKG

839 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var is_object_1 = require("./is-object");
4var is_string_1 = require("./is-string");
5var is_number_1 = require("./is-number");
6/**
7 * https://github.com/developit/dlv/blob/master/index.js
8 * @param obj
9 * @param path
10 * @param value
11 */
12exports.default = (function (obj, path, value) {
13 var o = obj;
14 var keyArr = is_string_1.default(path) ? path.split('.') : path;
15 keyArr.forEach(function (key, idx) {
16 // 不是最后一个
17 if (idx < keyArr.length - 1) {
18 if (!is_object_1.default(o[key])) {
19 o[key] = is_number_1.default(keyArr[idx + 1]) ? [] : {};
20 }
21 o = o[key];
22 }
23 else {
24 o[key] = value;
25 }
26 });
27 return obj;
28});
29//# sourceMappingURL=set.js.map
\No newline at end of file