all files / lib/ unitNormaliser.js

94.44% Statements 34/36
77.78% Branches 14/18
100% Functions 8/8
100% Lines 17/17
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 37 38 39 40                        17× 16×   15×   15×         12× 11×          
'use strict';
 
Object.defineProperty(exports, "__esModule", {
  value: true
});
 
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (EprotoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
function _classCallCheck(instance, Constructor) { if (I!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
var UnitNormaliser = function () {
  function UnitNormaliser() {
    _classCallCheck(this, UnitNormaliser);
 
    this.namesVarients = {};
  }
 
  _createClass(UnitNormaliser, [{
    key: 'addAlias',
    value: function addAlias(unitName, alias) {
      if (!unitName) throw new Error('absent name!');
      if (!alias) throw new Error('absent alias!');
 
      if (!this.namesVarients[unitName]) {
        this.namesVarients[unitName] = unitName;
      }
      this.namesVarients[alias.toLowerCase()] = unitName;
    }
  }, {
    key: 'normalise',
    value: function normalise(alias) {
      if (!alias) return;
      return this.namesVarients[alias.toLowerCase()];
    }
  }]);
 
  return UnitNormaliser;
}();
 
exports.default = UnitNormaliser;