Code coverage report for sc/config/config.js

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

All files » sc/config/ » config.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 371     1   1   1 1   1   3 3 2       9 8 7   1         612 611   1            
(function(sc) {
  "use strict";
 
  require("../libs/");
 
  var strlib = sc.libs.strlib;
 
  var values = {};
  var setter = {};
 
  sc.config = {
    add: function(name, defaultValue, func) {
      values[name] = typeof defaultValue !== "undefined" ? defaultValue : null;
      if (typeof func === "function") {
        setter[name] = func;
      }
    },
    set: function(name, value) {
      if (values.hasOwnProperty(name)) {
        value = setter[name] ? setter[name](value) : value;
        return (values[name] = value);
      }
      throw new Error(
        strlib.format("Config '#{0}' is not found.", name)
      );
    },
    get: function(name) {
      if (values.hasOwnProperty(name)) {
        return values[name];
      }
      throw new Error(
        strlib.format("Config '#{0}' is not found.", name)
      );
    }
  };
})(sc);