@lhncbc/ucum-lhc 4.2.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.
- package/README.md +50 -12
- package/browser-dist/ucum-lhc.js +841 -1325
- package/data/ucumDefs.min.json +1 -1
- package/package.json +1 -1
- package/source/ucumLhcUtils.js +100 -66
- package/source/ucumXmlDocument.js +5 -2
- package/source/unit.js +2 -1
- package/source/unitString.js +159 -140
- package/source-cjs/config.js +1 -12
- package/source-cjs/config.js.map +1 -1
- package/source-cjs/dimension.js +20 -63
- package/source-cjs/dimension.js.map +1 -1
- package/source-cjs/jsonArrayPack.js +7 -25
- package/source-cjs/jsonArrayPack.js.map +1 -1
- package/source-cjs/prefix.js +12 -26
- package/source-cjs/prefix.js.map +1 -1
- package/source-cjs/prefixTables.js +10 -24
- package/source-cjs/prefixTables.js.map +1 -1
- package/source-cjs/ucumFunctions.js +35 -32
- package/source-cjs/ucumFunctions.js.map +1 -1
- package/source-cjs/ucumInternalUtils.js +5 -13
- package/source-cjs/ucumInternalUtils.js.map +1 -1
- package/source-cjs/ucumJsonDefs.js +1 -16
- package/source-cjs/ucumJsonDefs.js.map +1 -1
- package/source-cjs/ucumLhcUtils.js +117 -138
- package/source-cjs/ucumLhcUtils.js.map +1 -1
- package/source-cjs/ucumPkg.js +1 -6
- package/source-cjs/ucumPkg.js.map +1 -1
- package/source-cjs/ucumXmlDocument.js +162 -184
- package/source-cjs/ucumXmlDocument.js.map +1 -1
- package/source-cjs/unit.js +97 -181
- package/source-cjs/unit.js.map +1 -1
- package/source-cjs/unitString.js +537 -618
- package/source-cjs/unitString.js.map +1 -1
- package/source-cjs/unitTables.js +33 -139
- package/source-cjs/unitTables.js.map +1 -1
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.isNumericString = isNumericString;
|
|
7
7
|
exports.isIntegerUnit = isIntegerUnit;
|
|
8
8
|
exports.getSynonyms = getSynonyms;
|
|
9
|
-
|
|
10
9
|
/**
|
|
11
10
|
* Internal utilities used by multiple UCUM classes. For example,
|
|
12
11
|
* isNumericString is used by both the UnitString and UcumLhcUtils
|
|
@@ -25,7 +24,9 @@ exports.getSynonyms = getSynonyms;
|
|
|
25
24
|
* @author Lee Mericle, based on java version by Gunther Schadow
|
|
26
25
|
*
|
|
27
26
|
*/
|
|
27
|
+
|
|
28
28
|
var UnitTables = require('./unitTables.js').UnitTables;
|
|
29
|
+
|
|
29
30
|
/**
|
|
30
31
|
* This function tests a string to see if it contains only numbers (digits,
|
|
31
32
|
* a period, leading - or +). This code was taken from a stackoverflow
|
|
@@ -35,11 +36,8 @@ var UnitTables = require('./unitTables.js').UnitTables;
|
|
|
35
36
|
* @params theString
|
|
36
37
|
* @returns true if the string contains only numbers; false otherwise
|
|
37
38
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
39
|
function isNumericString(theString) {
|
|
41
40
|
let num = "" + theString; //coerce num to be a string
|
|
42
|
-
|
|
43
41
|
return !isNaN(num) && !isNaN(parseFloat(num));
|
|
44
42
|
} // end isNumericString
|
|
45
43
|
|
|
@@ -52,11 +50,10 @@ function isNumericString(theString) {
|
|
|
52
50
|
* it is positive, but you can't measure anything in units of zero.
|
|
53
51
|
* @param str the string to check
|
|
54
52
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
53
|
function isIntegerUnit(str) {
|
|
58
54
|
return /^\d+$/.test(str);
|
|
59
55
|
}
|
|
56
|
+
|
|
60
57
|
/**
|
|
61
58
|
* This method accepts a term and looks for units that include it as
|
|
62
59
|
* a synonym - or that include the term in its name.
|
|
@@ -72,14 +69,13 @@ function isIntegerUnit(str) {
|
|
|
72
69
|
* the unit's csCode_, the unit's name_, and the unit's guidance_
|
|
73
70
|
*
|
|
74
71
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
72
|
function getSynonyms(theSyn) {
|
|
78
73
|
let retObj = {};
|
|
79
74
|
let utab = UnitTables.getInstance();
|
|
80
75
|
let resp = {};
|
|
81
|
-
resp = utab.getUnitBySynonym(theSyn);
|
|
76
|
+
resp = utab.getUnitBySynonym(theSyn);
|
|
82
77
|
|
|
78
|
+
// If we didn't get any units, transfer the status and message
|
|
83
79
|
if (!resp['units']) {
|
|
84
80
|
retObj['status'] = resp['status'];
|
|
85
81
|
retObj['msg'] = resp['msg'];
|
|
@@ -87,7 +83,6 @@ function getSynonyms(theSyn) {
|
|
|
87
83
|
retObj['status'] = 'succeeded';
|
|
88
84
|
let aLen = resp['units'].length;
|
|
89
85
|
retObj['units'] = [];
|
|
90
|
-
|
|
91
86
|
for (let a = 0; a < aLen; a++) {
|
|
92
87
|
let theUnit = resp['units'][a];
|
|
93
88
|
retObj['units'][a] = {
|
|
@@ -96,10 +91,7 @@ function getSynonyms(theSyn) {
|
|
|
96
91
|
'guidance': theUnit.guidance_
|
|
97
92
|
};
|
|
98
93
|
} // end do for all units returned
|
|
99
|
-
|
|
100
94
|
} // end if we got a units list
|
|
101
|
-
|
|
102
|
-
|
|
103
95
|
return retObj;
|
|
104
96
|
} // end getSynonyms
|
|
105
97
|
//# sourceMappingURL=ucumInternalUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,"
|
|
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,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