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

## Statements: 100% (10 / 10) Branches: 100% (4 / 4) Functions: 100% (1 / 1) Lines: 100% (10 / 10) Ignored: none

All files » lib/utils/ » set.js

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

    194

    194
    19
    19
    11

    19

    194
    194

     module.exports = function (target, keypath, value) {
      var keys = typeof keypath === "string" ? keypath.split(".") : keypath;

      var ct = target;

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

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