UNPKG

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