2 * set-value <https://github.com/jonschlinkert/set-value>
4 * Copyright (c) 2014-2015, 2017, Jon Schlinkert.
5 * Released under the MIT License.
10 var split = require('split-string');
11 var extend = require('extend-shallow');
12 var isPlainObject = require('is-plain-object');
13 var isObject = require('is-extendable');
15 module.exports = function(obj, prop, val) {
20 if (Array.isArray(prop)) {
21 prop = [].concat.apply([], prop).join('.');
24 if (typeof prop !== 'string') {
28 var keys = split(prop, {sep: '.', brackets: true}).filter(isValidKey);
29 var len = keys.length;
35 if (idx !== len - 1) {
36 if (!isObject(current[key])) {
39 current = current[key];
43 if (isPlainObject(current[key]) && isPlainObject(val)) {
44 current[key] = extend({}, current[key], val);
53 function isValidKey(key) {
54 return key !== '__proto__' && key !== 'constructor' && key !== 'prototype';