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

## Statements: 100% (11 / 11) Branches: 100% (4 / 4) Functions: 100% (1 / 1) Lines: 100% (11 / 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

    289
    289
    289

    289
    20
    20
    12

    20

    289
    289

     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;
    };