@lhncbc/ucum-lhc 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../source/ucumInternalUtils.js"],"names":["UnitTables","require","isNumericString","theString","num","isNaN","parseFloat","isIntegerUnit","str","test","getSynonyms","theSyn","retObj","utab","getInstance","resp","getUnitBySynonym","aLen","length","a","theUnit","csCode_","name_","guidance_"],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;AAYA;;;;;;AAOA,IAAIA,UAAU,GAAGC,OAAO,CAAC,iBAAD,CAAP,CAA2BD,UAA5C;AAGA;;;;;;;;;;;AASO,SAASE,eAAT,CAAyBC,SAAzB,EAAoC;AACzC,MAAIC,GAAG,GAAG,KAAKD,SAAf,CADyC,CACf;;AAC1B,SAAO,CAACE,KAAK,CAACD,GAAD,CAAN,IAAe,CAACC,KAAK,CAACC,UAAU,CAACF,GAAD,CAAX,CAA5B;AACD,C,CAAC;;AAGF;;;;;;;;;;;AASO,SAASG,aAAT,CAAuBC,GAAvB,EAA4B;AACjC,SAAO,QAAQC,IAAR,CAAaD,GAAb,CAAP;AACD;AAGD;;;;;;;;;;;;;;;;;AAeO,SAASE,WAAT,CAAqBC,MAArB,EAA6B;AAElC,MAAIC,MAAM,GAAG,EAAb;AACA,MAAIC,IAAI,GAAGb,UAAU,CAACc,WAAX,EAAX;AACA,MAAIC,IAAI,GAAG,EAAX;AACAA,EAAAA,IAAI,GAAGF,IAAI,CAACG,gBAAL,CAAsBL,MAAtB,CAAP,CALkC,CAOlC;;AACA,MAAI,CAACI,IAAI,CAAC,OAAD,CAAT,EAAoB;AAClBH,IAAAA,MAAM,CAAC,QAAD,CAAN,GAAmBG,IAAI,CAAC,QAAD,CAAvB;AACAH,IAAAA,MAAM,CAAC,KAAD,CAAN,GAAgBG,IAAI,CAAC,KAAD,CAApB;AACD,GAHD,MAIK;AACHH,IAAAA,MAAM,CAAC,QAAD,CAAN,GAAmB,WAAnB;AACA,QAAIK,IAAI,GAAGF,IAAI,CAAC,OAAD,CAAJ,CAAcG,MAAzB;AACAN,IAAAA,MAAM,CAAC,OAAD,CAAN,GAAkB,EAAlB;;AACA,SAAK,IAAIO,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,IAApB,EAA0BE,CAAC,EAA3B,EAA+B;AAC7B,UAAIC,OAAO,GAAGL,IAAI,CAAC,OAAD,CAAJ,CAAcI,CAAd,CAAd;AACAP,MAAAA,MAAM,CAAC,OAAD,CAAN,CAAgBO,CAAhB,IAAqB;AACnB,gBAAQC,OAAO,CAACC,OADG;AAEnB,gBAAQD,OAAO,CAACE,KAFG;AAGnB,oBAAYF,OAAO,CAACG;AAHD,OAArB;AAID,KAVE,CAUD;;AACH,GAvBiC,CAuBhC;;;AACF,SAAOX,MAAP;AAED,C,CAAC","sourcesContent":["/**\n * Internal utilities used by multiple UCUM classes. For example,\n * isNumericString is used by both the UnitString and UcumLhcUtils\n * classes. If it's in the UnitString class the UcumLhcUtils class\n * needs to require the UnitString class. But the checkSynonyms\n * class is used by the UnitString class - but was in the UcumLhcUtils\n * class. Requiring the UcumLhcUtils class from the UnitString class\n * made everything break (cyclical requires).\n *\n * So now they're here.\n */\n\n/**\n * This module implements internal ucum utilities.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar UnitTables = require('./unitTables.js').UnitTables ;\n\n\n/**\n * This function tests a string to see if it contains only numbers (digits,\n * a period, leading - or +). This code was taken from a stackoverflow\n * solution:\n * https://stackoverflow.com/questions/175739/is-there-a-built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number/42356340#42356340\n *\n * @params theString\n * @returns true if the string contains only numbers; false otherwise\n */\nexport function isNumericString(theString) {\n let num = \"\" + theString; //coerce num to be a string\n return !isNaN(num) && !isNaN(parseFloat(num));\n} // end isNumericString\n\n\n/**\n * Checks whether a string qualifies as an integer unit. Section 2.2.8 (\"integer\n * numbers\", says, \"A positive integer number may appear in place of a simple\n * unit symbol. Only a pure string of decimal digits (‘0’–‘9’) is\n * interpreted as a number.\"\n * Note: This leaves open the question of whether \"0\" is a valid unit, since\n * it is positive, but you can't measure anything in units of zero.\n * @param str the string to check\n */\nexport function isIntegerUnit(str) {\n return /^\\d+$/.test(str);\n}\n\n\n/**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for. This is assumed to be\n * a string and not undefined. The calling method should do any\n * necessary checking before calling this.\n * @returns a hash with up to three elements:\n * 'status' contains the status of the request, which can be 'error',\n * 'failed' or succeeded';\n * 'msg' which contains a message for an error or if no units were found; and\n * 'units' which is an array that contains one array for each unit found:\n * the unit's csCode_, the unit's name_, and the unit's guidance_\n *\n */\nexport function getSynonyms(theSyn) {\n\n let retObj = {} ;\n let utab = UnitTables.getInstance();\n let resp = {} ;\n resp = utab.getUnitBySynonym(theSyn);\n\n // If we didn't get any units, transfer the status and message\n if (!resp['units']) {\n retObj['status'] = resp['status'];\n retObj['msg'] = resp['msg'];\n }\n else {\n retObj['status'] = 'succeeded';\n let aLen = resp['units'].length ;\n retObj['units'] = [];\n for (let a = 0; a < aLen; a++) {\n let theUnit = resp['units'][a];\n retObj['units'][a] = {\n 'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_};\n } // end do for all units returned\n } // end if we got a units list\n return retObj ;\n\n} // end getSynonyms\n\n"],"file":"ucumInternalUtils.js"}
1
+ {"version":3,"file":"ucumInternalUtils.js","names":["UnitTables","require","isNumericString","theString","num","isNaN","parseFloat","isIntegerUnit","str","test","getSynonyms","theSyn","retObj","utab","getInstance","resp","getUnitBySynonym","aLen","length","a","theUnit","csCode_","name_","guidance_"],"sources":["../source/ucumInternalUtils.js"],"sourcesContent":["/**\n * Internal utilities used by multiple UCUM classes. For example,\n * isNumericString is used by both the UnitString and UcumLhcUtils\n * classes. If it's in the UnitString class the UcumLhcUtils class\n * needs to require the UnitString class. But the checkSynonyms\n * class is used by the UnitString class - but was in the UcumLhcUtils\n * class. Requiring the UcumLhcUtils class from the UnitString class\n * made everything break (cyclical requires).\n *\n * So now they're here.\n */\n\n/**\n * This module implements internal ucum utilities.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar UnitTables = require('./unitTables.js').UnitTables ;\n\n\n/**\n * This function tests a string to see if it contains only numbers (digits,\n * a period, leading - or +). This code was taken from a stackoverflow\n * solution:\n * https://stackoverflow.com/questions/175739/is-there-a-built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number/42356340#42356340\n *\n * @params theString\n * @returns true if the string contains only numbers; false otherwise\n */\nexport function isNumericString(theString) {\n let num = \"\" + theString; //coerce num to be a string\n return !isNaN(num) && !isNaN(parseFloat(num));\n} // end isNumericString\n\n\n/**\n * Checks whether a string qualifies as an integer unit. Section 2.2.8 (\"integer\n * numbers\", says, \"A positive integer number may appear in place of a simple\n * unit symbol. Only a pure string of decimal digits (‘0’–‘9’) is\n * interpreted as a number.\"\n * Note: This leaves open the question of whether \"0\" is a valid unit, since\n * it is positive, but you can't measure anything in units of zero.\n * @param str the string to check\n */\nexport function isIntegerUnit(str) {\n return /^\\d+$/.test(str);\n}\n\n\n/**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for. This is assumed to be\n * a string and not undefined. The calling method should do any\n * necessary checking before calling this.\n * @returns a hash with up to three elements:\n * 'status' contains the status of the request, which can be 'error',\n * 'failed' or succeeded';\n * 'msg' which contains a message for an error or if no units were found; and\n * 'units' which is an array that contains one array for each unit found:\n * the unit's csCode_, the unit's name_, and the unit's guidance_\n *\n */\nexport function getSynonyms(theSyn) {\n\n let retObj = {} ;\n let utab = UnitTables.getInstance();\n let resp = {} ;\n resp = utab.getUnitBySynonym(theSyn);\n\n // If we didn't get any units, transfer the status and message\n if (!resp['units']) {\n retObj['status'] = resp['status'];\n retObj['msg'] = resp['msg'];\n }\n else {\n retObj['status'] = 'succeeded';\n let aLen = resp['units'].length ;\n retObj['units'] = [];\n for (let a = 0; a < aLen; a++) {\n let theUnit = resp['units'][a];\n retObj['units'][a] = {\n 'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_};\n } // end do for all units returned\n } // end if we got a units list\n return retObj ;\n\n} // end getSynonyms\n\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIA,UAAU,GAAGC,OAAO,CAAC,iBAAiB,CAAC,CAACD,UAAU;;AAGtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAACC,SAAS,EAAE;EACzC,IAAIC,GAAG,GAAG,EAAE,GAAGD,SAAS,CAAC,CAAC;EAC1B,OAAO,CAACE,KAAK,CAACD,GAAG,CAAC,IAAI,CAACC,KAAK,CAACC,UAAU,CAACF,GAAG,CAAC,CAAC;AAC/C,CAAC,CAAC;;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAACC,GAAG,EAAE;EACjC,OAAO,OAAO,CAACC,IAAI,CAACD,GAAG,CAAC;AAC1B;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,WAAWA,CAACC,MAAM,EAAE;EAElC,IAAIC,MAAM,GAAG,CAAC,CAAC;EACf,IAAIC,IAAI,GAAGb,UAAU,CAACc,WAAW,CAAC,CAAC;EACnC,IAAIC,IAAI,GAAG,CAAC,CAAC;EACbA,IAAI,GAAGF,IAAI,CAACG,gBAAgB,CAACL,MAAM,CAAC;;EAEpC;EACA,IAAI,CAACI,IAAI,CAAC,OAAO,CAAC,EAAE;IAClBH,MAAM,CAAC,QAAQ,CAAC,GAAGG,IAAI,CAAC,QAAQ,CAAC;IACjCH,MAAM,CAAC,KAAK,CAAC,GAAGG,IAAI,CAAC,KAAK,CAAC;EAC7B,CAAC,MACI;IACHH,MAAM,CAAC,QAAQ,CAAC,GAAG,WAAW;IAC9B,IAAIK,IAAI,GAAGF,IAAI,CAAC,OAAO,CAAC,CAACG,MAAM;IAC/BN,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE;IACpB,KAAK,IAAIO,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,IAAI,EAAEE,CAAC,EAAE,EAAE;MAC7B,IAAIC,OAAO,GAAGL,IAAI,CAAC,OAAO,CAAC,CAACI,CAAC,CAAC;MAC9BP,MAAM,CAAC,OAAO,CAAC,CAACO,CAAC,CAAC,GAAG;QACnB,MAAM,EAAEC,OAAO,CAACC,OAAO;QACvB,MAAM,EAAED,OAAO,CAACE,KAAK;QACrB,UAAU,EAAEF,OAAO,CAACG;MAAS,CAAC;IAClC,CAAC,CAAC;EACJ,CAAC,CAAC;EACF,OAAOX,MAAM;AAEf,CAAC,CAAC"}
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ucumJsonDefs = exports.UcumJsonDefs = void 0;
7
-
8
7
  /**
9
8
  * This class handles opening, reading and loading the JSON file of ucum
10
9
  * definitions (prefixes, base units, and unit atoms).
@@ -12,16 +11,12 @@ exports.ucumJsonDefs = exports.UcumJsonDefs = void 0;
12
11
  * @author Lee Mericle
13
12
  *
14
13
  */
15
- var Pfx = require("./prefix.js");
16
14
 
15
+ var Pfx = require("./prefix.js");
17
16
  var PfxT = require("./prefixTables.js");
18
-
19
17
  var Un = require("./unit.js");
20
-
21
18
  var Utab = require('./unitTables.js');
22
-
23
19
  var unpackArray = require('./jsonArrayPack.js').unpackArray;
24
-
25
20
  class UcumJsonDefs {
26
21
  /**
27
22
  * This method loads the JSON prefix and unit objects into the prefix and
@@ -32,36 +27,26 @@ class UcumJsonDefs {
32
27
  loadJsonDefs() {
33
28
  // requiring the file will take care of opening it for use
34
29
  const jsonDefs = require('../data/ucumDefs.min.json');
35
-
36
30
  jsonDefs.prefixes = unpackArray(jsonDefs.prefixes);
37
31
  jsonDefs.units = unpackArray(jsonDefs.units);
38
-
39
32
  if (Utab.UnitTables.getInstance().unitsCount() === 0) {
40
33
  let pTab = PfxT.PrefixTables.getInstance();
41
34
  let prefixes = jsonDefs["prefixes"];
42
35
  let plen = prefixes.length;
43
-
44
36
  for (let p = 0; p < plen; p++) {
45
37
  let newPref = new Pfx.Prefix(prefixes[p]);
46
38
  pTab.add(newPref);
47
39
  }
48
-
49
40
  let uTab = Utab.UnitTables.getInstance();
50
41
  let units = jsonDefs["units"];
51
42
  let ulen = units.length;
52
-
53
43
  for (let u = 0; u < ulen; u++) {
54
44
  let newUnit = new Un.Unit(units[u]);
55
45
  uTab.addUnit(newUnit);
56
46
  }
57
47
  } // end if the data has not already been loaded
58
-
59
48
  } // end loadJsonDefs
60
-
61
-
62
49
  } // end UcumJsonDefs class
63
-
64
-
65
50
  exports.UcumJsonDefs = UcumJsonDefs;
66
51
  var ucumJsonDefs = new UcumJsonDefs();
67
52
  exports.ucumJsonDefs = ucumJsonDefs;
@@ -1 +1 @@
1
- {"version":3,"sources":["../source/ucumJsonDefs.js"],"names":["Pfx","require","PfxT","Un","Utab","unpackArray","UcumJsonDefs","loadJsonDefs","jsonDefs","prefixes","units","UnitTables","getInstance","unitsCount","pTab","PrefixTables","plen","length","p","newPref","Prefix","add","uTab","ulen","u","newUnit","Unit","addUnit","ucumJsonDefs"],"mappings":";;;;;;;AAAA;;;;;;;AAQA,IAAIA,GAAG,GAAGC,OAAO,CAAC,aAAD,CAAjB;;AACA,IAAIC,IAAI,GAAGD,OAAO,CAAC,mBAAD,CAAlB;;AACA,IAAIE,EAAE,GAAGF,OAAO,CAAC,WAAD,CAAhB;;AACA,IAAIG,IAAI,GAAGH,OAAO,CAAC,iBAAD,CAAlB;;AACA,IAAII,WAAW,GAAGJ,OAAO,CAAC,oBAAD,CAAP,CAA8BI,WAAhD;;AAEO,MAAM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AEF,IAAIG,YAAY,GAAG,IAAItB,YAAJ,EAAnB","sourcesContent":["/**\n * This class handles opening, reading and loading the JSON file of ucum\n * definitions (prefixes, base units, and unit atoms).\n *\n * @author Lee Mericle\n *\n */\n\nvar Pfx = require(\"./prefix.js\");\nvar PfxT = require(\"./prefixTables.js\");\nvar Un = require(\"./unit.js\");\nvar Utab = require('./unitTables.js');\nvar unpackArray = require('./jsonArrayPack.js').unpackArray;\n\nexport class UcumJsonDefs {\n\n /**\n * This method loads the JSON prefix and unit objects into the prefix and\n * unit tables.\n *\n * @returns nothing\n */\n loadJsonDefs() {\n // requiring the file will take care of opening it for use\n const jsonDefs = require('../data/ucumDefs.min.json');\n jsonDefs.prefixes = unpackArray(jsonDefs.prefixes);\n jsonDefs.units = unpackArray(jsonDefs.units);\n\n if (Utab.UnitTables.getInstance().unitsCount() === 0) {\n\n let pTab = PfxT.PrefixTables.getInstance();\n let prefixes = jsonDefs[\"prefixes\"];\n let plen = prefixes.length;\n\n for (let p = 0; p < plen; p++) {\n let newPref = new Pfx.Prefix(prefixes[p]);\n pTab.add(newPref);\n }\n\n let uTab = Utab.UnitTables.getInstance();\n let units = jsonDefs[\"units\"];\n let ulen = units.length;\n\n for (let u = 0; u < ulen; u++) {\n let newUnit = new Un.Unit(units[u]);\n uTab.addUnit(newUnit);\n }\n } // end if the data has not already been loaded\n } // end loadJsonDefs\n\n} // end UcumJsonDefs class\n\nvar ucumJsonDefs = new UcumJsonDefs();\nexport {ucumJsonDefs};\n"],"file":"ucumJsonDefs.js"}
1
+ {"version":3,"file":"ucumJsonDefs.js","names":["Pfx","require","PfxT","Un","Utab","unpackArray","UcumJsonDefs","loadJsonDefs","jsonDefs","prefixes","units","UnitTables","getInstance","unitsCount","pTab","PrefixTables","plen","length","p","newPref","Prefix","add","uTab","ulen","u","newUnit","Unit","addUnit","exports","ucumJsonDefs"],"sources":["../source/ucumJsonDefs.js"],"sourcesContent":["/**\n * This class handles opening, reading and loading the JSON file of ucum\n * definitions (prefixes, base units, and unit atoms).\n *\n * @author Lee Mericle\n *\n */\n\nvar Pfx = require(\"./prefix.js\");\nvar PfxT = require(\"./prefixTables.js\");\nvar Un = require(\"./unit.js\");\nvar Utab = require('./unitTables.js');\nvar unpackArray = require('./jsonArrayPack.js').unpackArray;\n\nexport class UcumJsonDefs {\n\n /**\n * This method loads the JSON prefix and unit objects into the prefix and\n * unit tables.\n *\n * @returns nothing\n */\n loadJsonDefs() {\n // requiring the file will take care of opening it for use\n const jsonDefs = require('../data/ucumDefs.min.json');\n jsonDefs.prefixes = unpackArray(jsonDefs.prefixes);\n jsonDefs.units = unpackArray(jsonDefs.units);\n\n if (Utab.UnitTables.getInstance().unitsCount() === 0) {\n\n let pTab = PfxT.PrefixTables.getInstance();\n let prefixes = jsonDefs[\"prefixes\"];\n let plen = prefixes.length;\n\n for (let p = 0; p < plen; p++) {\n let newPref = new Pfx.Prefix(prefixes[p]);\n pTab.add(newPref);\n }\n\n let uTab = Utab.UnitTables.getInstance();\n let units = jsonDefs[\"units\"];\n let ulen = units.length;\n\n for (let u = 0; u < ulen; u++) {\n let newUnit = new Un.Unit(units[u]);\n uTab.addUnit(newUnit);\n }\n } // end if the data has not already been loaded\n } // end loadJsonDefs\n\n} // end UcumJsonDefs class\n\nvar ucumJsonDefs = new UcumJsonDefs();\nexport {ucumJsonDefs};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIA,GAAG,GAAGC,OAAO,CAAC,aAAa,CAAC;AAChC,IAAIC,IAAI,GAAGD,OAAO,CAAC,mBAAmB,CAAC;AACvC,IAAIE,EAAE,GAAGF,OAAO,CAAC,WAAW,CAAC;AAC7B,IAAIG,IAAI,GAAGH,OAAO,CAAC,iBAAiB,CAAC;AACrC,IAAII,WAAW,GAAGJ,OAAO,CAAC,oBAAoB,CAAC,CAACI,WAAW;AAEpD,MAAMC,YAAY,CAAC;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,YAAYA,C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AG,IAAIvB,YAAY,CAAC,CAAC;AAACsB,OAAA,CAAAC,YAAA,GAAAA,YAAA"}
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.UcumLhcUtils = void 0;
7
-
8
7
  var _ucumJsonDefs = require("./ucumJsonDefs.js");
9
-
10
8
  var intUtils_ = _interopRequireWildcard(require("./ucumInternalUtils.js"));
11
-
12
9
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
13
-
14
10
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
11
  /**
17
12
  * This class provides a single point of access to the LHC UCUM utilities
18
13
  *
@@ -20,11 +15,8 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
20
15
  *
21
16
  */
22
17
  var Ucum = require('./config.js').Ucum;
23
-
24
18
  var UnitTables = require('./unitTables.js').UnitTables;
25
-
26
19
  var UnitString = require('./unitString.js').UnitString;
27
-
28
20
  /**
29
21
  * UCUM external utilities class
30
22
  */
@@ -38,10 +30,10 @@ class UcumLhcUtils {
38
30
  if (UnitTables.getInstance().unitsCount() === 0) {
39
31
  // Load the prefix and unit objects
40
32
  _ucumJsonDefs.ucumJsonDefs.loadJsonDefs();
41
- } // Get the UnitString parser that will be used with this instance
42
- // of the LHC Utilities
43
-
33
+ }
44
34
 
35
+ // Get the UnitString parser that will be used with this instance
36
+ // of the LHC Utilities
45
37
  this.uStrParser_ = UnitString.getInstance();
46
38
  } // end constructor
47
39
 
@@ -53,12 +45,11 @@ class UcumLhcUtils {
53
45
  * @param use flag indicating whether or not to use the braces message;
54
46
  * defaults to true
55
47
  */
56
-
57
-
58
48
  useHTMLInMessages(use) {
59
49
  if (use === undefined) use = true;
60
50
  this.uStrParser_.useHTMLInMessages(use);
61
51
  }
52
+
62
53
  /**
63
54
  * This method calls the useBraceMsgForEachString method on the UnitString
64
55
  * object. It should be called by web applications where unit
@@ -68,12 +59,11 @@ class UcumLhcUtils {
68
59
  * @param use flag indicating whether or not to use the braces message;
69
60
  * defaults to true
70
61
  */
71
-
72
-
73
62
  useBraceMsgForEachString(use) {
74
63
  if (use === undefined) use = true;
75
64
  this.uStrParser_.useBraceMsgForEachString(use);
76
65
  }
66
+
77
67
  /**
78
68
  * This method validates a unit string. It first checks to see if the
79
69
  * string passed in is a unit code that is found in the unit codes table.
@@ -127,8 +117,6 @@ class UcumLhcUtils {
127
117
  * If no suggestions were requested and found, this property is not
128
118
  * returned.
129
119
  */
130
-
131
-
132
120
  validateUnitString(uStr, suggest, valConv) {
133
121
  if (suggest === undefined) suggest = false;
134
122
  if (valConv === undefined) valConv = 'validate';
@@ -145,11 +133,9 @@ class UcumLhcUtils {
145
133
  }
146
134
  };
147
135
  retObj.status = resp.status;
148
-
149
136
  if (resp['suggestions']) {
150
137
  retObj['suggestions'] = resp['suggestions'];
151
138
  }
152
-
153
139
  retObj['msg'] = resp['retMsg'];
154
140
  return retObj;
155
141
  } // end validateUnitString
@@ -212,8 +198,6 @@ class UcumLhcUtils {
212
198
  * 'toUnit' the unit object for the toUnitCode passed in; returned
213
199
  * in case it's needed for additional data from the object.
214
200
  */
215
-
216
-
217
201
  convertUnitTo(fromUnitCode, fromVal, toUnitCode, suggest, molecularWeight) {
218
202
  if (suggest === undefined) suggest = false;
219
203
  if (molecularWeight === undefined) molecularWeight = null;
@@ -222,57 +206,45 @@ class UcumLhcUtils {
222
206
  'toVal': null,
223
207
  'msg': []
224
208
  };
225
-
226
209
  if (fromUnitCode) {
227
210
  fromUnitCode = fromUnitCode.trim();
228
211
  }
229
-
230
212
  if (!fromUnitCode || fromUnitCode == '') {
231
213
  returnObj['status'] = 'error';
232
214
  returnObj['msg'].push('No "from" unit expression specified.');
233
215
  }
234
-
235
216
  this._checkFromVal(fromVal, returnObj);
236
-
237
217
  if (toUnitCode) {
238
218
  toUnitCode = toUnitCode.trim();
239
219
  }
240
-
241
220
  if (!toUnitCode || toUnitCode == '') {
242
221
  returnObj['status'] = 'error';
243
222
  returnObj['msg'].push('No "to" unit expression specified.');
244
223
  }
245
-
246
224
  if (returnObj['status'] !== 'error') {
247
225
  try {
248
226
  let fromUnit = null;
249
227
  let parseResp = this.getSpecifiedUnit(fromUnitCode, 'convert', suggest);
250
228
  fromUnit = parseResp['unit'];
251
229
  if (parseResp['retMsg']) returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);
252
-
253
230
  if (parseResp['suggestions']) {
254
231
  returnObj['suggestions'] = {};
255
232
  returnObj['suggestions']['from'] = parseResp['suggestions'];
256
233
  }
257
-
258
234
  if (!fromUnit) {
259
235
  returnObj['msg'].push(`Unable to find a unit for ${fromUnitCode}, ` + `so no conversion could be performed.`);
260
236
  }
261
-
262
237
  let toUnit = null;
263
238
  parseResp = this.getSpecifiedUnit(toUnitCode, 'convert', suggest);
264
239
  toUnit = parseResp['unit'];
265
240
  if (parseResp['retMsg']) returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);
266
-
267
241
  if (parseResp['suggestions']) {
268
242
  if (!returnObj['suggestions']) returnObj['suggestions'] = {};
269
243
  returnObj['suggestions']['to'] = parseResp['suggestions'];
270
244
  }
271
-
272
245
  if (!toUnit) {
273
246
  returnObj['msg'].push(`Unable to find a unit for ${toUnitCode}, ` + `so no conversion could be performed.`);
274
247
  }
275
-
276
248
  if (fromUnit && toUnit) {
277
249
  try {
278
250
  // if no molecular weight was specified perform a normal conversion
@@ -282,29 +254,27 @@ class UcumLhcUtils {
282
254
  if (fromUnit.moleExp_ !== 0 && toUnit.moleExp_ !== 0) {
283
255
  throw new Error('A molecular weight was specified ' + 'but a mass <-> mole conversion cannot be executed for two ' + 'mole-based units. No conversion was attempted.');
284
256
  }
285
-
286
257
  if (fromUnit.moleExp_ === 0 && toUnit.moleExp_ === 0) {
287
258
  throw new Error('A molecular weight was specified ' + 'but a mass <-> mole conversion cannot be executed when ' + 'neither unit is mole-based. No conversion was attempted.');
288
259
  }
289
-
290
260
  if (!fromUnit.isMoleMassCommensurable(toUnit)) {
291
261
  throw new Error(`Sorry. ${fromUnitCode} cannot be ` + `converted to ${toUnitCode}.`);
292
- } // if the "from" unit is a mole-based unit, assume a mole to mass
293
- // request
294
-
262
+ }
295
263
 
264
+ // if the "from" unit is a mole-based unit, assume a mole to mass
265
+ // request
296
266
  if (fromUnit.moleExp_ !== 0) {
297
267
  returnObj['toVal'] = fromUnit.convertMolToMass(fromVal, toUnit, molecularWeight);
298
- } // else the "to" unit must be the mole-based unit, so assume a
268
+ }
269
+ // else the "to" unit must be the mole-based unit, so assume a
299
270
  // mass to mole request
300
271
  else {
301
- returnObj['toVal'] = fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight);
302
- }
272
+ returnObj['toVal'] = fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight);
273
+ }
303
274
  } // end if a molecular weight was specified
275
+
304
276
  // if an error hasn't been thrown - either from convertFrom or here,
305
277
  // set the return object to show success
306
-
307
-
308
278
  returnObj['status'] = 'succeeded';
309
279
  returnObj['fromUnit'] = fromUnit;
310
280
  returnObj['toUnit'] = toUnit;
@@ -313,13 +283,11 @@ class UcumLhcUtils {
313
283
  returnObj['msg'].push(err.message);
314
284
  }
315
285
  } // end if we have the from and to units
316
-
317
286
  } catch (err) {
318
287
  if (err.message == Ucum.needMoleWeightMsg_) returnObj['status'] = 'failed';else returnObj['status'] = 'error';
319
288
  returnObj['msg'].push(err.message);
320
289
  }
321
290
  }
322
-
323
291
  return returnObj;
324
292
  } // end convertUnitTo
325
293
 
@@ -335,7 +303,7 @@ class UcumLhcUtils {
335
303
  * 'invalid': fromUnit is not a valid UCUM code;
336
304
  * 'failed': the conversion could not be made (e.g., if it is an "arbitrary" unit);
337
305
  * 'error': if an error occurred (an input or programming error)
338
- * 'msg': an array of one or more messages, if the string is invalid or
306
+ * 'msg': an array of messages (possibly empty) if the string is invalid or
339
307
  * an error occurred, indicating the problem, or a suggestion of a
340
308
  * substitution such as the substitution of 'G' for 'Gauss', or
341
309
  * an empty array if no messages were generated. There can also be a
@@ -346,15 +314,11 @@ class UcumLhcUtils {
346
314
  * between fromUnit and the base units, so the returned magnitude is likely not
347
315
  * useful as a scale factor for other conversions (i.e., it only has validity
348
316
  * and usefulness for the input values that produced it).
349
- * 'unitToExp': a map of base units in uStr to their exponent
317
+ * 'unitToExp': a map of base units in fromUnit to their exponent
350
318
  */
351
-
352
-
353
319
  convertToBaseUnits(fromUnit, fromVal) {
354
320
  let retObj = {};
355
-
356
321
  this._checkFromVal(fromVal, retObj);
357
-
358
322
  if (!retObj.status) {
359
323
  // could be set to 'error' by _checkFromVal
360
324
  let inputUnitLookup = this.getSpecifiedUnit(fromUnit, 'validate');
@@ -363,7 +327,6 @@ class UcumLhcUtils {
363
327
  };
364
328
  let unit = inputUnitLookup.unit;
365
329
  retObj.msg = inputUnitLookup.retMsg || [];
366
-
367
330
  if (!unit) {
368
331
  if (inputUnitLookup.retMsg?.length == 0) retObj.msg.push('Could not find unit information for ' + fromUnit);
369
332
  } else if (unit.isArbitrary_) {
@@ -373,26 +336,22 @@ class UcumLhcUtils {
373
336
  let unitToExp = {};
374
337
  let dimVec = unit.dim_?.dimVec_;
375
338
  let baseUnitString = '1';
376
-
377
339
  if (dimVec) {
378
340
  let dimVecIndexToBaseUnit = UnitTables.getInstance().dimVecIndexToBaseUnit_;
379
-
380
341
  for (let i = 0, len = dimVec.length; i < len; ++i) {
381
342
  let exp = dimVec[i];
382
-
383
343
  if (exp) {
384
344
  unitToExp[dimVecIndexToBaseUnit[i]] = exp;
385
345
  baseUnitString += '.' + dimVecIndexToBaseUnit[i] + exp;
386
346
  }
387
347
  }
388
- } // The unit might have a conversion function, which has to be applied; we
389
- // cannot just assume unit_.magnitude_ is the magnitude in base units.
390
-
391
-
392
- let retUnitLookup = this.getSpecifiedUnit(baseUnitString, 'validate'); // There should not be any error in retUnitLookup, unless there is a bug.
348
+ }
393
349
 
350
+ // The unit might have a conversion function, which has to be applied; we
351
+ // cannot just assume unit_.magnitude_ is the magnitude in base units.
352
+ let retUnitLookup = this.getSpecifiedUnit(baseUnitString, 'validate');
353
+ // There should not be any error in retUnitLookup, unless there is a bug.
394
354
  let retUnit = retUnitLookup.unit;
395
-
396
355
  if (retUnitLookup.status !== 'valid') {
397
356
  retObj.msg.push('Unable construct base unit string; tried ' + baseUnitString);
398
357
  retObj.status = 'error';
@@ -403,7 +362,6 @@ class UcumLhcUtils {
403
362
  retObj.msg.push(e.toString());
404
363
  retObj.status = 'error';
405
364
  }
406
-
407
365
  if (retObj.status == 'succeeded') {
408
366
  retObj.unitToExp = unitToExp;
409
367
  retObj.fromUnitIsSpecial = unit.isSpecial_;
@@ -411,9 +369,9 @@ class UcumLhcUtils {
411
369
  }
412
370
  }
413
371
  }
414
-
415
372
  return retObj;
416
373
  }
374
+
417
375
  /**
418
376
  * Checks the given value as to whether it is suitable as a "from" value in a
419
377
  * unit conversion. If it is not, the responseObj will have its status set
@@ -422,8 +380,6 @@ class UcumLhcUtils {
422
380
  * @param responseObj the object that will be updated if the value is not
423
381
  * usable.
424
382
  */
425
-
426
-
427
383
  _checkFromVal(fromVal, responseObj) {
428
384
  if (fromVal === null || isNaN(fromVal) || typeof fromVal !== 'number' && !intUtils_.isNumericString(fromVal)) {
429
385
  responseObj.status = 'error';
@@ -431,6 +387,7 @@ class UcumLhcUtils {
431
387
  responseObj.msg.push('No "from" value, or an invalid "from" value, ' + 'was specified.');
432
388
  }
433
389
  }
390
+
434
391
  /**
435
392
  * This method accepts a term and looks for units that include it as
436
393
  * a synonym - or that include the term in its name.
@@ -446,11 +403,8 @@ class UcumLhcUtils {
446
403
  * 'guidance' is the unit's guidance_
447
404
  *
448
405
  */
449
-
450
-
451
406
  checkSynonyms(theSyn) {
452
407
  let retObj = {};
453
-
454
408
  if (theSyn === undefined || theSyn === null) {
455
409
  retObj['status'] = 'error';
456
410
  retObj['msg'] = 'No term specified for synonym search.';
@@ -458,7 +412,6 @@ class UcumLhcUtils {
458
412
  retObj = intUtils_.getSynonyms(theSyn);
459
413
  } // end if a search synonym was supplied
460
414
 
461
-
462
415
  return retObj;
463
416
  } // end checkSynonyms
464
417
 
@@ -498,23 +451,22 @@ class UcumLhcUtils {
498
451
  * The return hash will not contain a suggestions array if a valid unit
499
452
  * was found or if suggestions were not requested and found.
500
453
  */
501
-
502
-
503
454
  getSpecifiedUnit(uName, valConv, suggest) {
504
455
  if (suggest === undefined) suggest = false;
505
456
  let retObj = {};
506
457
  retObj['retMsg'] = [];
507
-
508
458
  if (!uName) {
509
459
  retObj['retMsg'].push('No unit string specified.');
510
460
  } else {
511
461
  let utab = UnitTables.getInstance();
512
- uName = uName.trim(); // go ahead and just try using the name as the code. This may or may not
462
+ uName = uName.trim();
463
+
464
+ // go ahead and just try using the name as the code. This may or may not
513
465
  // work, but if it does, it cuts out a lot of parsing.
466
+ let theUnit = utab.getUnitByCode(uName);
514
467
 
515
- let theUnit = utab.getUnitByCode(uName); // If we found it, set the returned unit string to what was passed in;
468
+ // If we found it, set the returned unit string to what was passed in;
516
469
  // otherwise try parsing as a unit string
517
-
518
470
  if (theUnit) {
519
471
  retObj['unit'] = theUnit;
520
472
  retObj['origString'] = uName;
@@ -530,11 +482,9 @@ class UcumLhcUtils {
530
482
  retObj['retMsg'].unshift(`${uName} is not a valid unit. ` + `${err.message}`);
531
483
  }
532
484
  } // end if the unit was not found as a unit name
533
-
534
485
  } // end if a unit expression was specified
535
- // Set the status field
536
-
537
486
 
487
+ // Set the status field
538
488
  if (!retObj.unit) {
539
489
  // No unit was found; check whether origString has a value
540
490
  retObj.status = !retObj.origString ? 'error' : 'invalid';
@@ -543,7 +493,6 @@ class UcumLhcUtils {
543
493
  // find the unit
544
494
  retObj.status = retObj.origString === uName ? 'valid' : 'invalid';
545
495
  }
546
-
547
496
  return retObj;
548
497
  } // end getSpecifiedUnit
549
498
 
@@ -557,21 +506,17 @@ class UcumLhcUtils {
557
506
  * first element is the list of commensurable units if any were found
558
507
  * second element is an error message if the "from" unit is not found
559
508
  */
560
-
561
-
562
509
  commensurablesList(fromName) {
563
510
  let retMsg = [];
564
511
  let commUnits = null;
565
512
  let parseResp = this.getSpecifiedUnit(fromName, 'validate', false);
566
513
  let fromUnit = parseResp['unit'];
567
514
  if (parseResp['retMsg'].length > 0) retMsg = parseResp['retMsg'];
568
-
569
515
  if (!fromUnit) {
570
516
  retMsg.push(`Could not find unit ${fromName}.`);
571
517
  } else {
572
518
  let dimVec = null;
573
519
  let fromDim = fromUnit.getProperty('dim_');
574
-
575
520
  if (!fromDim) {
576
521
  retMsg.push('No commensurable units were found for ' + fromName);
577
522
  } else {
@@ -581,20 +526,14 @@ class UcumLhcUtils {
581
526
  retMsg.push(err.message);
582
527
  if (err.message === "Dimension does not have requested property(dimVec_)") dimVec = null;
583
528
  }
584
-
585
529
  if (dimVec) {
586
530
  let utab = UnitTables.getInstance();
587
531
  commUnits = utab.getUnitsByDimension(dimVec);
588
532
  }
589
533
  } // end if the from unit has a dimension vector
590
-
591
534
  } // end if we found a "from" unit
592
-
593
-
594
535
  return [commUnits, retMsg];
595
536
  } // end commensurablesList
596
-
597
-
598
537
  } // end UcumLhcUtils class
599
538
 
600
539
  /**
@@ -611,10 +550,7 @@ class UcumLhcUtils {
611
550
  *
612
551
  * @return the (formerly singleton) UcumLhcUtils object.
613
552
  */
614
-
615
-
616
553
  exports.UcumLhcUtils = UcumLhcUtils;
617
-
618
554
  UcumLhcUtils.getInstance = function () {
619
555
  return new UcumLhcUtils();
620
556
  };