# Code coverage report for lib/utils/set.js

## Statements: 9.09% (1 / 11) Branches: 0% (0 / 4) Functions: 0% (0 / 1) Lines: 9.09% (1 / 11) Ignored: none

All files » lib/utils/ » set.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    181

     module.exports = function(target, keypath, value) {

      var keys = typeof keypath === "string" ? keypath.split(".") : keypath;
      var ct   = target;
      var key;

      for (var i = 0, n = keys.length - 1; i < n; i++) {
        key = keys[i];
        if (!ct[key]) {
          ct[key] = {};
        }
        ct = ct[key];
      }

      ct[keys[keys.length - 1]] = value;
      return value;
    };