PHP 8.2.30
Preview: set.js Size: 1.36 KB
//opt/alt/alt-nodejs9/root/lib/node_modules/npm/node_modules/cli-table2/node_modules/lodash/object/set.js

var isIndex = require('../internal/isIndex'),
    isKey = require('../internal/isKey'),
    isObject = require('../lang/isObject'),
    toPath = require('../internal/toPath');

/**
 * Sets the property value of `path` on `object`. If a portion of `path`
 * does not exist it's created.
 *
 * @static
 * @memberOf _
 * @category Object
 * @param {Object} object The object to augment.
 * @param {Array|string} path The path of the property to set.
 * @param {*} value The value to set.
 * @returns {Object} Returns `object`.
 * @example
 *
 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
 *
 * _.set(object, 'a[0].b.c', 4);
 * console.log(object.a[0].b.c);
 * // => 4
 *
 * _.set(object, 'x[0].y.z', 5);
 * console.log(object.x[0].y.z);
 * // => 5
 */
function set(object, path, value) {
  if (object == null) {
    return object;
  }
  var pathKey = (path + '');
  path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);

  var index = -1,
      length = path.length,
      lastIndex = length - 1,
      nested = object;

  while (nested != null && ++index < length) {
    var key = path[index];
    if (isObject(nested)) {
      if (index == lastIndex) {
        nested[key] = value;
      } else if (nested[key] == null) {
        nested[key] = isIndex(path[index + 1]) ? [] : {};
      }
    }
    nested = nested[key];
  }
  return object;
}

module.exports = set;

Directory Contents

Dirs: 0 × Files: 29

Name Size Perms Modified Actions
1.58 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.24 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
835 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
745 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
38 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.78 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.79 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
980 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
840 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
975 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
844 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
575 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
951 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.56 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.54 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.27 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.62 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
781 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.57 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.67 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
41 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.56 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
800 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.47 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.54 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
1.36 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
2.10 KB lrw-r--r-- 2021-09-28 11:28:33
Edit Download
691 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download
681 B lrw-r--r-- 2021-09-28 11:28:33
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).