@lhncbc/ucum-lhc 4.1.2 → 4.1.5
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/CHANGELOG.md +14 -0
- package/README.md +0 -2
- package/browser-dist/ucum-lhc.js +28 -89
- package/package.json +7 -7
- package/source/dimension.js +4 -4
- package/source/ucumLhcUtils.js +0 -20
- package/source/ucumXmlDocument.js +1 -1
- package/source/unit.js +4 -5
- package/source/unitString.js +6 -6
- package/source/unitTables.js +0 -26
- package/source-cjs/dimension.js +3 -3
- package/source-cjs/dimension.js.map +1 -1
- package/source-cjs/ucumLhcUtils.js +0 -24
- package/source-cjs/ucumLhcUtils.js.map +1 -1
- package/source-cjs/ucumXmlDocument.js +1 -1
- package/source-cjs/ucumXmlDocument.js.map +1 -1
- package/source-cjs/unit.js +4 -4
- package/source-cjs/unit.js.map +1 -1
- package/source-cjs/unitString.js +6 -6
- package/source-cjs/unitString.js.map +1 -1
- package/source-cjs/unitTables.js +0 -33
- package/source-cjs/unitTables.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lhncbc/ucum-lhc",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.5",
|
|
4
4
|
"description": "Implements Unified Code for Units of Measure (UCUM) functions in a javascript library",
|
|
5
5
|
"main": "source-cjs/ucumPkg.js",
|
|
6
6
|
"homepage": "https://lhncbc.github.io/ucum-lhc/",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"data/ucumDefs.min.json"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
+
"coffeescript": "^2.7.0",
|
|
17
18
|
"csv-parse": "^4.4.6",
|
|
18
19
|
"csv-stringify": "^1.0.4",
|
|
19
20
|
"escape-html": "^1.0.3",
|
|
20
|
-
"grunt-extract-sourcemap": "^0.1.19",
|
|
21
21
|
"is-integer": "^1.0.6",
|
|
22
22
|
"jsonfile": "^2.2.3",
|
|
23
23
|
"stream": "0.0.2",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"xmldoc": "^0.4.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@babel/cli": "^7.
|
|
29
|
+
"@babel/cli": "^7.12.13",
|
|
30
30
|
"@babel/core": "^7.3.4",
|
|
31
31
|
"@babel/plugin-transform-modules-commonjs": "^7.8.3",
|
|
32
32
|
"@babel/preset-env": "^7.6.2",
|
|
@@ -36,8 +36,7 @@
|
|
|
36
36
|
"bootstrap": "^4.3.1",
|
|
37
37
|
"bower": "^1.8.8",
|
|
38
38
|
"browserify": "^16.2.3",
|
|
39
|
-
"
|
|
40
|
-
"grunt": "^1.0.4",
|
|
39
|
+
"grunt": "^1.5.3",
|
|
41
40
|
"grunt-babel": "^8.0.0",
|
|
42
41
|
"grunt-browserify": "^5.0.0",
|
|
43
42
|
"grunt-cli": "^1.2.0",
|
|
@@ -45,14 +44,15 @@
|
|
|
45
44
|
"grunt-contrib-connect": "^2.1.0",
|
|
46
45
|
"grunt-contrib-cssmin": "^3.0.0",
|
|
47
46
|
"grunt-contrib-uglify": "^2.0.0",
|
|
47
|
+
"grunt-extract-sourcemap": "^0.1.19",
|
|
48
48
|
"grunt-mocha-test": "^0.13.2",
|
|
49
49
|
"grunt-wiredep": "^3.0.1",
|
|
50
50
|
"jit-grunt": "^0.10.0",
|
|
51
|
-
"mocha": "^
|
|
51
|
+
"mocha": "^8.2.1",
|
|
52
52
|
"path": "^0.12.7",
|
|
53
53
|
"semver": "^5.5.1",
|
|
54
54
|
"time-grunt": "^1.4.0",
|
|
55
|
-
"webpack": "^
|
|
55
|
+
"webpack": "^5.20.2",
|
|
56
56
|
"webpack-cli": "^3.3.9"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
package/source/dimension.js
CHANGED
|
@@ -81,7 +81,7 @@ export class Dimension {
|
|
|
81
81
|
**/
|
|
82
82
|
setElementAt(indexPos, value) {
|
|
83
83
|
|
|
84
|
-
if (!
|
|
84
|
+
if (!isInteger(indexPos) ||
|
|
85
85
|
indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {
|
|
86
86
|
throw(new Error(`Dimension.setElementAt called with an invalid index ` +
|
|
87
87
|
`position (${indexPos})`));
|
|
@@ -107,7 +107,7 @@ export class Dimension {
|
|
|
107
107
|
* number or is less than 0 or greater than Ucum.dimLen_
|
|
108
108
|
**/
|
|
109
109
|
getElementAt(indexPos) {
|
|
110
|
-
if (!
|
|
110
|
+
if (!isInteger(indexPos) ||
|
|
111
111
|
indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {
|
|
112
112
|
throw(new Error(`Dimension.getElementAt called with an invalid index ` +
|
|
113
113
|
`position (${indexPos})`));
|
|
@@ -132,8 +132,8 @@ export class Dimension {
|
|
|
132
132
|
* @throws an error if the property is not found for this Dimension
|
|
133
133
|
*/
|
|
134
134
|
getProperty(propertyName) {
|
|
135
|
-
let uProp = (
|
|
136
|
-
|
|
135
|
+
let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName : propertyName + '_';
|
|
136
|
+
|
|
137
137
|
return this[uProp] ;
|
|
138
138
|
|
|
139
139
|
} // end getProperty
|
package/source/ucumLhcUtils.js
CHANGED
|
@@ -8,9 +8,6 @@ var Ucum = require('./config.js').Ucum;
|
|
|
8
8
|
import {ucumJsonDefs} from './ucumJsonDefs.js';
|
|
9
9
|
var UnitTables = require('./unitTables.js').UnitTables;
|
|
10
10
|
var UnitString = require('./unitString.js').UnitString;
|
|
11
|
-
var Unit = require('./unit.js').Unit;
|
|
12
|
-
var Prefix = require('./prefix.js').Prefix;
|
|
13
|
-
var fs = require('fs');
|
|
14
11
|
|
|
15
12
|
import * as intUtils_ from "./ucumInternalUtils.js";
|
|
16
13
|
|
|
@@ -495,23 +492,6 @@ export class UcumLhcUtils {
|
|
|
495
492
|
return [commUnits , retMsg];
|
|
496
493
|
} // end commensurablesList
|
|
497
494
|
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Creates a file containing a list of the units. The file is created
|
|
501
|
-
* in the current directory.
|
|
502
|
-
*/
|
|
503
|
-
printUnits() {
|
|
504
|
-
|
|
505
|
-
// for now, create a list of the units created and save it to a file
|
|
506
|
-
// for debugging. This is a temporary file.
|
|
507
|
-
let utab = UnitTables.getInstance();
|
|
508
|
-
let uct = utab.unitsCount();
|
|
509
|
-
let uList = utab.printUnits(true);
|
|
510
|
-
fs.writeFileSync('JsonUnitsList.txt', uList,
|
|
511
|
-
{encoding: 'utf8', mode: 0o666, flag: 'w'} );
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
|
|
515
495
|
} // end UcumLhcUtils class
|
|
516
496
|
|
|
517
497
|
|
|
@@ -228,7 +228,7 @@ export class UcumXmlDocument {
|
|
|
228
228
|
attrs['class_'] = curUA.attr.class;
|
|
229
229
|
}
|
|
230
230
|
let valNode = curUA.childNamed('value');
|
|
231
|
-
if (this.moleCodes_.
|
|
231
|
+
if (this.moleCodes_.indexOf(curUA.attr.Code) !== -1)
|
|
232
232
|
attrs['moleExp_'] = 1;
|
|
233
233
|
else
|
|
234
234
|
attrs['moleExp_'] = 0;
|
package/source/unit.js
CHANGED
|
@@ -872,8 +872,8 @@ export class Unit {
|
|
|
872
872
|
* concatenated string. Basically it checks to see if the string
|
|
873
873
|
* needs to be enclosed either in parentheses or square brackets.
|
|
874
874
|
*
|
|
875
|
-
* The string is enclosed if it is not a number,
|
|
876
|
-
*
|
|
875
|
+
* The string is enclosed if it is not a number, is not already enclosed in a pair of
|
|
876
|
+
* parentheses or square brackets, and includes a period, and asterisk,
|
|
877
877
|
* a slash or a blank space.
|
|
878
878
|
*
|
|
879
879
|
* @param str the string
|
|
@@ -887,11 +887,10 @@ export class Unit {
|
|
|
887
887
|
ret = str;
|
|
888
888
|
}
|
|
889
889
|
else {
|
|
890
|
-
if (str.charAt(0) === '(' || str.charAt(0) === '[') {
|
|
890
|
+
if (str.charAt(0) === '(' && str.endsWith(')') || str.charAt(0) === '[' && str.endsWith(']')) {
|
|
891
891
|
ret = str;
|
|
892
892
|
}
|
|
893
|
-
else if (
|
|
894
|
-
str.includes('*') || str.includes(' ')) {
|
|
893
|
+
else if (/[./* ]/.test(str)) {
|
|
895
894
|
ret = startChar + str + endChar ;
|
|
896
895
|
}
|
|
897
896
|
else {
|
package/source/unitString.js
CHANGED
|
@@ -188,7 +188,7 @@ export class UnitString {
|
|
|
188
188
|
// preceded by a prefix or followed by an operator and another unit.
|
|
189
189
|
let sUnit = null ;
|
|
190
190
|
for (sUnit in Ucum.specUnits_) {
|
|
191
|
-
while (uStr.
|
|
191
|
+
while (uStr.indexOf(sUnit) !== -1)
|
|
192
192
|
uStr = uStr.replace(sUnit, Ucum.specUnits_[sUnit]);
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -602,7 +602,7 @@ export class UnitString {
|
|
|
602
602
|
numRes[2] !== '' && numRes[2].indexOf(this.braceFlag_) !== 0) {
|
|
603
603
|
let dispVal = numRes[2] ;
|
|
604
604
|
|
|
605
|
-
if (!endProcessing && numRes[2].
|
|
605
|
+
if (!endProcessing && numRes[2].indexOf(this.parensFlag_) !== -1) {
|
|
606
606
|
let parensback = this._getParensUnit(numRes[2], origString);
|
|
607
607
|
numRes[2] = parensback[0]['csCode_'];
|
|
608
608
|
dispVal = `(${numRes[2]})`;
|
|
@@ -643,7 +643,7 @@ export class UnitString {
|
|
|
643
643
|
n = u1;
|
|
644
644
|
endProcessing = true;
|
|
645
645
|
}
|
|
646
|
-
else if (Ucum.validOps_.
|
|
646
|
+
else if (Ucum.validOps_.indexOf(uArray1[n]) !== -1) {
|
|
647
647
|
this.retMsg_.push(`${origString} is not a valid UCUM code. ` +
|
|
648
648
|
`A unit code is missing between${this.openEmph_}` +
|
|
649
649
|
`${theOp}${this.closeEmph_}and${this.openEmph_}` +
|
|
@@ -666,7 +666,7 @@ export class UnitString {
|
|
|
666
666
|
if (numRes2 && numRes2.length === 3 && numRes2[1] !== '' &&
|
|
667
667
|
numRes2[2] !== '' && numRes2[2].indexOf(this.braceFlag_) !== 0) {
|
|
668
668
|
let invalidString = numRes2[0];
|
|
669
|
-
if (!endProcessing && numRes2[2].
|
|
669
|
+
if (!endProcessing && numRes2[2].indexOf(this.parensFlag_) !== -1) {
|
|
670
670
|
let parensback = this._getParensUnit(numRes2[2], origString);
|
|
671
671
|
numRes2[2] = parensback[0]['csCode_'];
|
|
672
672
|
invalidString = `(${numRes2[2]})`;
|
|
@@ -1107,7 +1107,7 @@ export class UnitString {
|
|
|
1107
1107
|
// whatever text (probably a prefix) goes with the unit string.
|
|
1108
1108
|
let sUnit = null;
|
|
1109
1109
|
for (sUnit in Ucum.specUnits_) {
|
|
1110
|
-
if (uCode.
|
|
1110
|
+
if (uCode.indexOf(Ucum.specUnits_[sUnit]) !== -1)
|
|
1111
1111
|
uCode = uCode.replace(Ucum.specUnits_[sUnit], sUnit);
|
|
1112
1112
|
}
|
|
1113
1113
|
retUnit = this.utabs_.getUnitByCode(uCode);
|
|
@@ -1290,7 +1290,7 @@ export class UnitString {
|
|
|
1290
1290
|
|
|
1291
1291
|
// Add the warning about annotations - just once.
|
|
1292
1292
|
|
|
1293
|
-
if (
|
|
1293
|
+
if (this.bracesMsg_ && this.retMsg_.indexOf(this.bracesMsg_) === -1)
|
|
1294
1294
|
this.retMsg_.push(this.bracesMsg_);
|
|
1295
1295
|
|
|
1296
1296
|
// If there's no text before or after the annotation, it's probably
|
package/source/unitTables.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
var Ucum = require('./config.js').Ucum;
|
|
10
|
-
var fs = require('fs');
|
|
11
10
|
|
|
12
11
|
class UnitTablesFactory {
|
|
13
12
|
|
|
@@ -709,31 +708,6 @@ class UnitTablesFactory {
|
|
|
709
708
|
return codeList ;
|
|
710
709
|
}
|
|
711
710
|
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* This creates a list of the synonyms in the unitSynonyms hash. It writes
|
|
715
|
-
* it in synonym order and in csv format, and includes the synonym, the number
|
|
716
|
-
* of units for the synonym, and the list of unit codes for the synonym.
|
|
717
|
-
* It uses | as a separator rather than a comma, to keep from interfering
|
|
718
|
-
* with the JSON output for the unit code arrays kept for each synonym.
|
|
719
|
-
*
|
|
720
|
-
* @returns outputs to a file named "SynonymsList.txt'
|
|
721
|
-
*/
|
|
722
|
-
printSynonyms() {
|
|
723
|
-
let sList = 'synonym|unit count|unit codes\n';
|
|
724
|
-
let sKeys = Object.keys(this.unitSynonyms_).sort();
|
|
725
|
-
let sLen = sKeys.length ;
|
|
726
|
-
for (let s = 0; s < sLen; s++) {
|
|
727
|
-
let sKey = sKeys[s];
|
|
728
|
-
let kLen = this.unitSynonyms_[sKey].length;
|
|
729
|
-
let codes = JSON.stringify(this.unitSynonyms_[sKey]);
|
|
730
|
-
codes = codes.substring(1, codes.length - 2);
|
|
731
|
-
sList += sKey + '|' + kLen + '|' + codes + '\n';
|
|
732
|
-
}
|
|
733
|
-
fs.writeFileSync('SynonymsList.txt', sList,
|
|
734
|
-
{encoding: 'utf8', mode: 0o666, flag: 'w'} );
|
|
735
|
-
} // printSynonyms
|
|
736
|
-
|
|
737
711
|
} // end UnitTablesFactory
|
|
738
712
|
|
|
739
713
|
|
package/source-cjs/dimension.js
CHANGED
|
@@ -84,7 +84,7 @@ class Dimension {
|
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
setElementAt(indexPos, value) {
|
|
87
|
-
if (!
|
|
87
|
+
if (!isInteger(indexPos) || indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {
|
|
88
88
|
throw new Error(`Dimension.setElementAt called with an invalid index ` + `position (${indexPos})`);
|
|
89
89
|
}
|
|
90
90
|
|
|
@@ -107,7 +107,7 @@ class Dimension {
|
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
getElementAt(indexPos) {
|
|
110
|
-
if (!
|
|
110
|
+
if (!isInteger(indexPos) || indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {
|
|
111
111
|
throw new Error(`Dimension.getElementAt called with an invalid index ` + `position (${indexPos})`);
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -130,7 +130,7 @@ class Dimension {
|
|
|
130
130
|
|
|
131
131
|
|
|
132
132
|
getProperty(propertyName) {
|
|
133
|
-
let uProp =
|
|
133
|
+
let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName : propertyName + '_';
|
|
134
134
|
return this[uProp];
|
|
135
135
|
} // end getProperty
|
|
136
136
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/dimension.js"],"names":["UC","require","isInteger","Dimension","constructor","dimSetting","Ucum","dimLen_","Error","undefined","assignZero","Array","length","JSON","stringify","dimVec_","d","push","setElementAt","indexPos","value","Number","getElementAt","ret","getProperty","propertyName","uProp","endsWith","toString","join","add","dim2","i","sub","minus","mul","s","equals","isEqual","dimVec2","assignDim","isZero","allZero","isNull","clone","that"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;AAYA,IAAIA,EAAE,GAAGC,OAAO,CAAC,aAAD,CAAhB;;AACA,IAAIC,SAAS,GAAGD,OAAO,CAAC,YAAD,CAAvB;;AACO,MAAME,SAAN,CAAgB;AAErB;;;;;;;;;;;;;;;;;;;;AAqBAC,EAAAA,WAAW,CAACC,UAAD,EAAa;AAEtB,QAAIL,EAAE,CAACM,IAAH,CAAQC,OAAR,KAAoB,CAAxB,EAA2B;AACzB,YAAM,IAAIC,KAAJ,CAAU,qDAChB,uBADM,CAAN;AAED;;AACD,QAAIH,UAAU,KAAKI,SAAf,IAA4BJ,UAAU,KAAK,IAA/C,EAAqD;AACnD,WAAKK,UAAL;AACD,KAFD,MAGK,IAAIL,UAAU,YAAYM,KAA1B,EAAiC;AACpC,UAAIN,UAAU,CAACO,MAAX,KAAsBZ,EAAE,CAACM,IAAH,CAAQC,OAAlC,EAA2C;AACzC,cAAM,IAAIC,KAAJ,CAAU,2DACX,m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AAiBN,SAA9C,EACE,KAAKM,OAAL,GAAe,EAAf;;AAEF,SAAK,IAAIiB,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGhC,EAAE,CAACM,IAAH,CAAQC,OAA5B,EAAqCyB,CAAC,EAAtC,EAA0C;AACxC,WAAKjB,OAAL,CAAaE,IAAb,CAAkB,CAAlB;AACD;;AACD,WAAO,IAAP;AACD;AAGD;;;;;;;;;AAOAwB,EAAAA,MAAM,GAAG;AACP,QAAIC,OAAO,GAAG,KAAK3B,OAAL,KAAiB,IAA/B;;AACA,QAAI,KAAKA,OAAT,EAAkB;AAChB,WAAK,IAAIiB,CAAC,GAAG,CAAb,EAAgBU,OAAO,IAAIV,CAAC,GAAGhC,EAAE,CAACM,IAAH,CAAQC,OAAvC,EAAgDyB,CAAC,EAAjD,EACEU,OAAO,GAAG,KAAK3B,OAAL,CAAaiB,CAAb,MAAoB,CAA9B;AACH;;AACD,WAAOU,OAAP;AACD;AAGD;;;;;;;;AAMAC,EAAAA,MAAM,GAAG;AACP,WAAQ,KAAK5B,OAAL,KAAiB,IAAzB;AACD;AAGD;;;;;;;AAKA6B,EAAAA,KAAK,GAAG;AACN,QAAIC,IAAI,GAAG,IAAI1C,SAAJ,EAAX;AACA0C,IAAAA,IAAI,CAACL,SAAL,CAAe,IAAf;AACA,WAAOK,IAAP;AACD;;AAnVoB,C,CAqVrB","sourcesContent":["/**\n * This class implements an object containing the vector of exponents for\n * a unit and its operations for addition, subtraction, and multiplication\n * with a scalar.\n *\n * This object should exist for each unit that can be expressed as a\n * vector of numbers. This excludes arbitrary units, e.g., (10*23), and\n * units that are not numbers but are an expression based solely on numbers,\n * e.g., mol (mole) which is based on 10*23.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n */\nvar UC = require('./config.js');\nvar isInteger = require(\"is-integer\");\nexport class Dimension {\n\n /**\n * Constructor.\n *\n * @param dimSetting an optional parameter that may be:\n * null, which means that the dimVec_ attribute for this object will be null; or\n * an array, which must be the length defined by Ucum.dimLen_, and\n * whose contents will be copied to this new object's vector; or\n * an integer, which must be between 0 and 1 less than the vector length\n * defined by Ucum.dimLen_. This new object's vector will be\n * initialized to zero for all elements except the one whose index\n * matches the number passed in. That element will be set to one.\n\n * @throws an error if the dimSetting parameter does not meet the types\n * listed above.\n * An error will also be thrown if Ucum.dimLen_ has not been set yet,\n * i.e., is still zero. Currently that won't happen, because the\n * value is set in the config.js file. But further down the road\n * the setting will come from a definitions input file, so we check\n * here anyway.\n *\n */\n constructor(dimSetting) {\n\n if (UC.Ucum.dimLen_ === 0) {\n throw(new Error('Dimension.setDimensionLen must be called before ' +\n 'Dimension constructor'));\n }\n if (dimSetting === undefined || dimSetting === null) {\n this.assignZero() ;\n }\n else if (dimSetting instanceof Array) {\n if (dimSetting.length !== UC.Ucum.dimLen_) {\n throw(new Error('Parameter error, incorrect length of vector passed to ' +\n `Dimension constructor, vector = ${JSON.stringify(dimSetting)}`));\n }\n this.dimVec_ = [];\n for (let d = 0; d < UC.Ucum.dimLen_; d++)\n this.dimVec_.push(dimSetting[d]);\n }\n\n // In es6 this should be Number.isInteger(dimSetting). But Babel\n // doesn't transpile that correctly, so we need to use the isInteger\n // module. :0\n else if (isInteger(dimSetting)) {\n if (dimSetting < 0 || dimSetting >= UC.Ucum.dimLen_) {\n throw(new Error('Parameter error, invalid element number specified for ' +\n 'Dimension constructor'));\n }\n this.assignZero() ;\n this.dimVec_[dimSetting] = 1;\n }\n } // end constructor\n\n\n /**\n * Sets the element at the specified position to a specified value. The\n * default value is 1. If the dimension vector is null when this is called\n * a zero-filled vector is created and then the indicated position is set.\n *\n * @param indexPos the index of the element to be set\n * @param value the value to assign to the specified element; optional,\n * default value is 1\n * @throws an exception if the specified position is invalid, i.e., not a\n * number or is less than 0 or greater than Ucum.dimLen_\n **/\n setElementAt(indexPos, value) {\n\n if (!Number.isInteger(indexPos) ||\n indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {\n throw(new Error(`Dimension.setElementAt called with an invalid index ` +\n `position (${indexPos})`));\n }\n\n if (!this.dimVec_) {\n this.assignZero();\n }\n if (value === undefined || value === null)\n value = 1 ;\n\n this.dimVec_[indexPos] = value;\n }\n\n\n /**\n * Gets the value of the element at the specified position\n *\n * @param indexPos the index of the element whose value is to be returned\n * @return the value of the element at indexPos, or null if the dimension\n * vector is null\n * @throws an exception if the specified position is invalid, i.e., not a\n * number or is less than 0 or greater than Ucum.dimLen_\n **/\n getElementAt(indexPos) {\n if (!Number.isInteger(indexPos) ||\n indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {\n throw(new Error(`Dimension.getElementAt called with an invalid index ` +\n `position (${indexPos})`));\n }\n let ret = null;\n if (this.dimVec_)\n ret = this.dimVec_[indexPos];\n return ret;\n }\n\n\n /**\n * This returns the value of the property named by the parameter\n * passed in. Although we currently only have one property, dimVec_,\n * that this will get, it's possible that we'll have additional\n * properties. If we don't this could just be replaced by a\n * getVector function.\n *\n * @param propertyName name of the property to be returned, with\n * or without the trailing underscore.\n * @return the requested property, if found for this Dimension\n * @throws an error if the property is not found for this Dimension\n */\n getProperty(propertyName) {\n let uProp = (!(propertyName.endsWith('_'))) ? propertyName + '_' :\n propertyName ;\n return this[uProp] ;\n\n } // end getProperty\n\n\n /**\n * Return a string that represents the dimension vector. Returns null if\n * the dimension vector is null.\n *\n * @return the string that represents the dimension vector. The\n * values are enclosed in square brackets, each separated\n * by a comma and a space\n **/\n toString() {\n let ret = null ;\n if (this.dimVec_)\n ret = '[' + this.dimVec_.join(', ') + ']';\n return ret ;\n }\n\n\n /**\n * Adds the vector of the dimension object passed in to this\n * dimension object's vector. This object's vector is changed.\n * If either dimension vector is null, no changes are made to this object.\n *\n *\n * @param dim2 the dimension whose vector is to be added to this one\n * @return this object\n * @throws an exception if dim2 is not a Dimension object\n **/\n add(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.add called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (this.dimVec_ && dim2.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] += dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Subtracts the vector of the dimension object passed in from this\n * dimension object's vector. This object's vector is changed.\n * If either dimension vector is null, no changes are made to this object.\n *\n * @param dim2 the dimension whose vector is to be subtracted from this one\n * @return this object\n * @throws an exception if dim2 is not a Dimension object\n **/\n sub(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.sub called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (this.dimVec_ && dim2.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] -= dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Inverts this dimension object's vector (by multiplying each element\n * by negative 1). This object's vector is changed - unless it is null,\n * in which case it stays that way.\n *\n * @return this object\n **/\n minus() {\n if (this.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] = -this.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Multiplies this dimension object's vector with a scalar. This is used\n * when a unit is raised to a power. This object's vector is changed unless\n * the vector is null, in which case it stays that way.\n *\n * @param s the scalar to use\n * @return this object\n * @throws an exception if s is not a number\n */\n mul(s) {\n if (!isInteger(s)) {\n throw(new Error(`Dimension.sub called with an invalid parameter - ` +\n `${typeof dim2} instead of a number`));\n }\n if (this.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] *= s;\n }\n return this;\n }\n\n\n /**\n * Tests for equality of this dimension object's vector and that of\n * the dimension object passed in. If the dimension vector for one of\n * the objects is null, the dimension vector for the other object must\n * also be null for the two to be equal. (I know - duh. still)\n *\n * @param dim2 the dimension object whose vector is to be compared to this one\n * @return true if the two vectors are equal; false otherwise.\n * @throws an exception if dim2 is not a Dimension object\n */\n equals(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.equals called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n let isEqual = true ;\n let dimVec2 = dim2.dimVec_;\n if (this.dimVec_ && dimVec2) {\n for (let i = 0; isEqual && i < UC.Ucum.dimLen_; i++)\n isEqual = (this.dimVec_[i] === dimVec2[i]);\n }\n else {\n isEqual = (this.dimVec_ === null && dimVec2 === null);\n }\n return isEqual;\n }\n\n\n /**\n * Assigns the contents of the vector belonging to the dimension object\n * passed in to this dimension's vector. If this dimension vector is null\n * and the other is not, this one will get the contents of the other. If\n * this dimension vector is not null but the one passed in is null, this\n * one will be set to null.\n *\n * @param dim2 the dimension object with the vector whose contents are\n * to be assigned to this dimension's vector\n * @return this object (not sure why)\n * @throws an exception if dim2 is not a Dimension object\n */\n assignDim(dim2) {\n\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.assignDim called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (dim2.dimVec_ === null)\n this.dimVec_ = null;\n else {\n if (this.dimVec_ === null) {\n this.dimVec_ = [] ;\n }\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] = dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Sets all elements of this dimension object's vector to zero.\n * If this object's vector is null, it is created as a zero-filled vector.\n *\n * @return this object (not sure why)\n */\n assignZero() {\n if (this.dimVec_ === null || this.dimVec_ === undefined)\n this.dimVec_ = [];\n\n for (let i = 0; i < UC.Ucum.dimLen_; i++) {\n this.dimVec_.push(0);\n }\n return this;\n }\n\n\n /**\n * Tests for a dimension vector set to all zeroes.\n *\n * @return true if exponents (elements) of this dimension's vector are all\n * zero; false otherwise (including if the current vector is null).\n *\n */\n isZero() {\n let allZero = this.dimVec_ !== null ;\n if (this.dimVec_) {\n for (let i = 0; allZero && i < UC.Ucum.dimLen_; i++)\n allZero = this.dimVec_[i] === 0;\n }\n return allZero;\n }\n\n\n /**\n * Tests for a Dimension object with no dimension vector (dimVec_ is null).\n *\n * @return true the dimension vector is null; false if it is not\n *\n */\n isNull() {\n return (this.dimVec_ === null);\n }\n\n\n /**\n * Creates and returns a clone of this Dimension object\n *\n * @return the clone\n */\n clone() {\n let that = new Dimension();\n that.assignDim(this);\n return that;\n }\n\n} // end Dimension class\n"],"file":"dimension.js"}
|
|
1
|
+
{"version":3,"sources":["../source/dimension.js"],"names":["UC","require","isInteger","Dimension","constructor","dimSetting","Ucum","dimLen_","Error","undefined","assignZero","Array","length","JSON","stringify","dimVec_","d","push","setElementAt","indexPos","value","getElementAt","ret","getProperty","propertyName","uProp","charAt","toString","join","add","dim2","i","sub","minus","mul","s","equals","isEqual","dimVec2","assignDim","isZero","allZero","isNull","clone","that"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;AAYA,IAAIA,EAAE,GAAGC,OAAO,CAAC,aAAD,CAAhB;;AACA,IAAIC,SAAS,GAAGD,OAAO,CAAC,YAAD,CAAvB;;AACO,MAAME,SAAN,CAAgB;AAErB;;;;;;;;;;;;;;;;;;;;AAqBAC,EAAAA,WAAW,CAACC,UAAD,EAAa;AAEtB,QAAIL,EAAE,CAACM,IAAH,CAAQC,OAAR,KAAoB,CAAxB,EAA2B;AACzB,YAAM,IAAIC,KAAJ,CAAU,qDAChB,uBADM,CAAN;AAED;;AACD,QAAIH,UAAU,KAAKI,SAAf,IAA4BJ,UAAU,KAAK,IAA/C,EAAqD;AACnD,WAAKK,UAAL;AACD,KAFD,MAGK,IAAIL,UAAU,YAAYM,KAA1B,EAAiC;AACpC,UAAIN,UAAU,CAACO,MAAX,KAAsBZ,EAAE,CAACM,IAAH,CAAQC,OAAlC,EAA2C;AACzC,cAAM,IAAIC,KAAJ,CAAU,2DACX,mCAAkCK,IAAI,CAACC,SAAL,CAAeT,UAAf,CAA2B,EAD5D,CAAN;AAED;;AACD,WAAKU,OAAL,GAAe,EAAf;;AACA,WAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGhB,EAAE,CAACM,IAAH,CAAQC,OAA5B,EAA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;AACD;;AACD,WAAO,IAAP;AACD;AAGD;;;;;;;;;AAOAuB,EAAAA,MAAM,GAAG;AACP,QAAIC,OAAO,GAAG,KAAK1B,OAAL,KAAiB,IAA/B;;AACA,QAAI,KAAKA,OAAT,EAAkB;AAChB,WAAK,IAAIgB,CAAC,GAAG,CAAb,EAAgBU,OAAO,IAAIV,CAAC,GAAG/B,EAAE,CAACM,IAAH,CAAQC,OAAvC,EAAgDwB,CAAC,EAAjD,EACEU,OAAO,GAAG,KAAK1B,OAAL,CAAagB,CAAb,MAAoB,CAA9B;AACH;;AACD,WAAOU,OAAP;AACD;AAGD;;;;;;;;AAMAC,EAAAA,MAAM,GAAG;AACP,WAAQ,KAAK3B,OAAL,KAAiB,IAAzB;AACD;AAGD;;;;;;;AAKA4B,EAAAA,KAAK,GAAG;AACN,QAAIC,IAAI,GAAG,IAAIzC,SAAJ,EAAX;AACAyC,IAAAA,IAAI,CAACL,SAAL,CAAe,IAAf;AACA,WAAOK,IAAP;AACD;;AAnVoB,C,CAqVrB","sourcesContent":["/**\n * This class implements an object containing the vector of exponents for\n * a unit and its operations for addition, subtraction, and multiplication\n * with a scalar.\n *\n * This object should exist for each unit that can be expressed as a\n * vector of numbers. This excludes arbitrary units, e.g., (10*23), and\n * units that are not numbers but are an expression based solely on numbers,\n * e.g., mol (mole) which is based on 10*23.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n */\nvar UC = require('./config.js');\nvar isInteger = require(\"is-integer\");\nexport class Dimension {\n\n /**\n * Constructor.\n *\n * @param dimSetting an optional parameter that may be:\n * null, which means that the dimVec_ attribute for this object will be null; or\n * an array, which must be the length defined by Ucum.dimLen_, and\n * whose contents will be copied to this new object's vector; or\n * an integer, which must be between 0 and 1 less than the vector length\n * defined by Ucum.dimLen_. This new object's vector will be\n * initialized to zero for all elements except the one whose index\n * matches the number passed in. That element will be set to one.\n\n * @throws an error if the dimSetting parameter does not meet the types\n * listed above.\n * An error will also be thrown if Ucum.dimLen_ has not been set yet,\n * i.e., is still zero. Currently that won't happen, because the\n * value is set in the config.js file. But further down the road\n * the setting will come from a definitions input file, so we check\n * here anyway.\n *\n */\n constructor(dimSetting) {\n\n if (UC.Ucum.dimLen_ === 0) {\n throw(new Error('Dimension.setDimensionLen must be called before ' +\n 'Dimension constructor'));\n }\n if (dimSetting === undefined || dimSetting === null) {\n this.assignZero() ;\n }\n else if (dimSetting instanceof Array) {\n if (dimSetting.length !== UC.Ucum.dimLen_) {\n throw(new Error('Parameter error, incorrect length of vector passed to ' +\n `Dimension constructor, vector = ${JSON.stringify(dimSetting)}`));\n }\n this.dimVec_ = [];\n for (let d = 0; d < UC.Ucum.dimLen_; d++)\n this.dimVec_.push(dimSetting[d]);\n }\n\n // In es6 this should be Number.isInteger(dimSetting). But Babel\n // doesn't transpile that correctly, so we need to use the isInteger\n // module. :0\n else if (isInteger(dimSetting)) {\n if (dimSetting < 0 || dimSetting >= UC.Ucum.dimLen_) {\n throw(new Error('Parameter error, invalid element number specified for ' +\n 'Dimension constructor'));\n }\n this.assignZero() ;\n this.dimVec_[dimSetting] = 1;\n }\n } // end constructor\n\n\n /**\n * Sets the element at the specified position to a specified value. The\n * default value is 1. If the dimension vector is null when this is called\n * a zero-filled vector is created and then the indicated position is set.\n *\n * @param indexPos the index of the element to be set\n * @param value the value to assign to the specified element; optional,\n * default value is 1\n * @throws an exception if the specified position is invalid, i.e., not a\n * number or is less than 0 or greater than Ucum.dimLen_\n **/\n setElementAt(indexPos, value) {\n\n if (!isInteger(indexPos) ||\n indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {\n throw(new Error(`Dimension.setElementAt called with an invalid index ` +\n `position (${indexPos})`));\n }\n\n if (!this.dimVec_) {\n this.assignZero();\n }\n if (value === undefined || value === null)\n value = 1 ;\n\n this.dimVec_[indexPos] = value;\n }\n\n\n /**\n * Gets the value of the element at the specified position\n *\n * @param indexPos the index of the element whose value is to be returned\n * @return the value of the element at indexPos, or null if the dimension\n * vector is null\n * @throws an exception if the specified position is invalid, i.e., not a\n * number or is less than 0 or greater than Ucum.dimLen_\n **/\n getElementAt(indexPos) {\n if (!isInteger(indexPos) ||\n indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {\n throw(new Error(`Dimension.getElementAt called with an invalid index ` +\n `position (${indexPos})`));\n }\n let ret = null;\n if (this.dimVec_)\n ret = this.dimVec_[indexPos];\n return ret;\n }\n\n\n /**\n * This returns the value of the property named by the parameter\n * passed in. Although we currently only have one property, dimVec_,\n * that this will get, it's possible that we'll have additional\n * properties. If we don't this could just be replaced by a\n * getVector function.\n *\n * @param propertyName name of the property to be returned, with\n * or without the trailing underscore.\n * @return the requested property, if found for this Dimension\n * @throws an error if the property is not found for this Dimension\n */\n getProperty(propertyName) {\n let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName : propertyName + '_';\n\n return this[uProp] ;\n\n } // end getProperty\n\n\n /**\n * Return a string that represents the dimension vector. Returns null if\n * the dimension vector is null.\n *\n * @return the string that represents the dimension vector. The\n * values are enclosed in square brackets, each separated\n * by a comma and a space\n **/\n toString() {\n let ret = null ;\n if (this.dimVec_)\n ret = '[' + this.dimVec_.join(', ') + ']';\n return ret ;\n }\n\n\n /**\n * Adds the vector of the dimension object passed in to this\n * dimension object's vector. This object's vector is changed.\n * If either dimension vector is null, no changes are made to this object.\n *\n *\n * @param dim2 the dimension whose vector is to be added to this one\n * @return this object\n * @throws an exception if dim2 is not a Dimension object\n **/\n add(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.add called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (this.dimVec_ && dim2.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] += dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Subtracts the vector of the dimension object passed in from this\n * dimension object's vector. This object's vector is changed.\n * If either dimension vector is null, no changes are made to this object.\n *\n * @param dim2 the dimension whose vector is to be subtracted from this one\n * @return this object\n * @throws an exception if dim2 is not a Dimension object\n **/\n sub(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.sub called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (this.dimVec_ && dim2.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] -= dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Inverts this dimension object's vector (by multiplying each element\n * by negative 1). This object's vector is changed - unless it is null,\n * in which case it stays that way.\n *\n * @return this object\n **/\n minus() {\n if (this.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] = -this.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Multiplies this dimension object's vector with a scalar. This is used\n * when a unit is raised to a power. This object's vector is changed unless\n * the vector is null, in which case it stays that way.\n *\n * @param s the scalar to use\n * @return this object\n * @throws an exception if s is not a number\n */\n mul(s) {\n if (!isInteger(s)) {\n throw(new Error(`Dimension.sub called with an invalid parameter - ` +\n `${typeof dim2} instead of a number`));\n }\n if (this.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] *= s;\n }\n return this;\n }\n\n\n /**\n * Tests for equality of this dimension object's vector and that of\n * the dimension object passed in. If the dimension vector for one of\n * the objects is null, the dimension vector for the other object must\n * also be null for the two to be equal. (I know - duh. still)\n *\n * @param dim2 the dimension object whose vector is to be compared to this one\n * @return true if the two vectors are equal; false otherwise.\n * @throws an exception if dim2 is not a Dimension object\n */\n equals(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.equals called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n let isEqual = true ;\n let dimVec2 = dim2.dimVec_;\n if (this.dimVec_ && dimVec2) {\n for (let i = 0; isEqual && i < UC.Ucum.dimLen_; i++)\n isEqual = (this.dimVec_[i] === dimVec2[i]);\n }\n else {\n isEqual = (this.dimVec_ === null && dimVec2 === null);\n }\n return isEqual;\n }\n\n\n /**\n * Assigns the contents of the vector belonging to the dimension object\n * passed in to this dimension's vector. If this dimension vector is null\n * and the other is not, this one will get the contents of the other. If\n * this dimension vector is not null but the one passed in is null, this\n * one will be set to null.\n *\n * @param dim2 the dimension object with the vector whose contents are\n * to be assigned to this dimension's vector\n * @return this object (not sure why)\n * @throws an exception if dim2 is not a Dimension object\n */\n assignDim(dim2) {\n\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.assignDim called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (dim2.dimVec_ === null)\n this.dimVec_ = null;\n else {\n if (this.dimVec_ === null) {\n this.dimVec_ = [] ;\n }\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] = dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Sets all elements of this dimension object's vector to zero.\n * If this object's vector is null, it is created as a zero-filled vector.\n *\n * @return this object (not sure why)\n */\n assignZero() {\n if (this.dimVec_ === null || this.dimVec_ === undefined)\n this.dimVec_ = [];\n\n for (let i = 0; i < UC.Ucum.dimLen_; i++) {\n this.dimVec_.push(0);\n }\n return this;\n }\n\n\n /**\n * Tests for a dimension vector set to all zeroes.\n *\n * @return true if exponents (elements) of this dimension's vector are all\n * zero; false otherwise (including if the current vector is null).\n *\n */\n isZero() {\n let allZero = this.dimVec_ !== null ;\n if (this.dimVec_) {\n for (let i = 0; allZero && i < UC.Ucum.dimLen_; i++)\n allZero = this.dimVec_[i] === 0;\n }\n return allZero;\n }\n\n\n /**\n * Tests for a Dimension object with no dimension vector (dimVec_ is null).\n *\n * @return true the dimension vector is null; false if it is not\n *\n */\n isNull() {\n return (this.dimVec_ === null);\n }\n\n\n /**\n * Creates and returns a clone of this Dimension object\n *\n * @return the clone\n */\n clone() {\n let that = new Dimension();\n that.assignDim(this);\n return that;\n }\n\n} // end Dimension class\n"],"file":"dimension.js"}
|
|
@@ -25,12 +25,6 @@ var UnitTables = require('./unitTables.js').UnitTables;
|
|
|
25
25
|
|
|
26
26
|
var UnitString = require('./unitString.js').UnitString;
|
|
27
27
|
|
|
28
|
-
var Unit = require('./unit.js').Unit;
|
|
29
|
-
|
|
30
|
-
var Prefix = require('./prefix.js').Prefix;
|
|
31
|
-
|
|
32
|
-
var fs = require('fs');
|
|
33
|
-
|
|
34
28
|
/**
|
|
35
29
|
* UCUM external utilities class
|
|
36
30
|
*/
|
|
@@ -487,24 +481,6 @@ class UcumLhcUtils {
|
|
|
487
481
|
return [commUnits, retMsg];
|
|
488
482
|
} // end commensurablesList
|
|
489
483
|
|
|
490
|
-
/**
|
|
491
|
-
* Creates a file containing a list of the units. The file is created
|
|
492
|
-
* in the current directory.
|
|
493
|
-
*/
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
printUnits() {
|
|
497
|
-
// for now, create a list of the units created and save it to a file
|
|
498
|
-
// for debugging. This is a temporary file.
|
|
499
|
-
let utab = UnitTables.getInstance();
|
|
500
|
-
let uct = utab.unitsCount();
|
|
501
|
-
let uList = utab.printUnits(true);
|
|
502
|
-
fs.writeFileSync('JsonUnitsList.txt', uList, {
|
|
503
|
-
encoding: 'utf8',
|
|
504
|
-
mode: 0o666,
|
|
505
|
-
flag: 'w'
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
484
|
|
|
509
485
|
} // end UcumLhcUtils class
|
|
510
486
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/ucumLhcUtils.js"],"names":["Ucum","require","UnitTables","UnitString","Unit","Prefix","fs","UcumLhcUtils","constructor","getInstance","unitsCount","ucumJsonDefs","loadJsonDefs","uStrParser_","useHTMLInMessages","use","undefined","useBraceMsgForEachString","validateUnitString","uStr","suggest","valConv","resp","getSpecifiedUnit","theUnit","retObj","csCode_","name_","guidance_","convertUnitTo","fromUnitCode","fromVal","toUnitCode","molecularWeight","returnObj","trim","push","isNaN","intUtils_","isNumericString","fromUnit","parseResp","concat","toUnit","convertFrom","moleExp_","Error","isMoleMassCommensurable","convertMolToMass","convertMassToMol","err","message","needMoleWeightMsg_","checkSynonyms","theSyn","getSynonyms","uName","utab","getUnitByCode","parseString","console","log","unshift","commensurablesList","fromName","retMsg","commUnits","length","dimVec","fromDim","getProperty","getUnitsByDimension","printUnits","uct","uList","writeFileSync","encoding","mode","flag"],"mappings":";;;;;;;AAOA;;AAOA;;;;;;AAdA;;;;;;AAMA,IAAIA,IAAI,GAAGC,OAAO,CAAC,aAAD,CAAP,CAAuBD,IAAlC;;AAEA,IAAIE,UAAU,GAAGD,OAAO,CAAC,iBAAD,CAAP,CAA2BC,UAA5C;;AACA,IAAIC,UAAU,GAAGF,OAAO,CAAC,iBAAD,CAAP,CAA2BE,UAA5C;;AACA,IAAIC,IAAI,GAAGH,OAAO,CAAC,WAAD,CAAP,CAAqBG,IAAhC;;AACA,IAAIC,MAAM,GAAGJ,OAAO,CAAC,aAAD,CAAP,CAAuBI,MAApC;;AACA,IAAIC,EAAE,GAAGL,OAAO,CAAC,IAAD,CAAhB;;AAIA;;;AAGO,MAAMM,YAAN,CAAmB;AAExB;;;;;AAKAC,EAAAA,WAAW,GAAG;AAEV,QAAIN,UAAU,CAACO,WAAX,GAAyBC,UAAzB,OAA0C,CAA9C,EAAiD;AAE/C;AACAC,iCAAaC,YAAb;AACD,KANS,CAQV;AACA;;;AACA,SAAKC,WAAL,GAAmBV,UAAU,CAACM,WAAX,EAAnB;AAEH,GAnBuB,CAmBtB;;AAGF;;;;;;;;;;AAQAK,EAAAA,iBAAiB,CAACC,GAAD,EAAM;AACrB,QAAIA,GAAG,KAAKC,SAAZ,EACED,GAAG,GAAG,IAAN;AACF,SAAKF,WAAL,CAAiBC,iBAAjB,CAAmCC,GAAnC;AACD;AAGD;;;;;;;;;;;AASAE,EAAAA,wBAAwB,CAACF,GAAD,EAAM;AAC5B,QAAIA,GAAG,KAAKC,SAAZ,EACED,GAAG,GAAG,IAAN;AACF,SAAKF,WAAL,CAAiBI,wBAAjB,CAA0CF,GAA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AhC0B,CAgCzB;;;AACF,WAAO,CAACF,SAAD,EAAaD,MAAb,CAAP;AACD,GA5duB,CA4dtB;;AAGF;;;;;;AAIAO,EAAAA,UAAU,GAAG;AAEX;AACA;AACA,QAAIf,IAAI,GAAGvD,UAAU,CAACO,WAAX,EAAX;AACA,QAAIgE,GAAG,GAAGhB,IAAI,CAAC/C,UAAL,EAAV;AACA,QAAIgE,KAAK,GAAGjB,IAAI,CAACe,UAAL,CAAgB,IAAhB,CAAZ;AACAlE,IAAAA,EAAE,CAACqE,aAAH,CAAiB,mBAAjB,EAAsCD,KAAtC,EACI;AAACE,MAAAA,QAAQ,EAAE,MAAX;AAAmBC,MAAAA,IAAI,EAAE,KAAzB;AAAgCC,MAAAA,IAAI,EAAE;AAAtC,KADJ;AAED;;AA5euB,C,CA+exB;;AAGF;;;;;;;;;;;;;;;;;;AAcAvE,YAAY,CAACE,WAAb,GAA2B,YAAU;AACnC,SAAO,IAAIF,YAAJ,EAAP;AACD,CAFD","sourcesContent":["/**\n * This class provides a single point of access to the LHC UCUM utilities\n *\n * @author Lee Mericle\n *\n */\nvar Ucum = require('./config.js').Ucum;\nimport {ucumJsonDefs} from './ucumJsonDefs.js';\nvar UnitTables = require('./unitTables.js').UnitTables;\nvar UnitString = require('./unitString.js').UnitString;\nvar Unit = require('./unit.js').Unit;\nvar Prefix = require('./prefix.js').Prefix;\nvar fs = require('fs');\n\nimport * as intUtils_ from \"./ucumInternalUtils.js\";\n\n/**\n * UCUM external utilities class\n */\nexport class UcumLhcUtils {\n\n /**\n * Constructor. This loads the json prefix and unit definitions if\n * they haven't been loaded already and creates itself as a singleton object.\n *\n */\n constructor() {\n\n if (UnitTables.getInstance().unitsCount() === 0) {\n\n // Load the prefix and unit objects\n ucumJsonDefs.loadJsonDefs();\n }\n\n // Get the UnitString parser that will be used with this instance\n // of the LHC Utilities\n this.uStrParser_ = UnitString.getInstance();\n\n } // end constructor\n\n\n /**\n * This method calls the useHTMLInMessages method on the UnitString\n * object. It should be called by web applications that use\n * these utilities.\n *\n * @param use flag indicating whether or not to use the braces message;\n * defaults to true\n */\n useHTMLInMessages(use) {\n if (use === undefined)\n use = true ;\n this.uStrParser_.useHTMLInMessages(use);\n }\n\n\n /**\n * This method calls the useBraceMsgForEachString method on the UnitString\n * object. It should be called by web applications where unit\n * strings are validated individually (as opposed to validating a whole\n * file of unit strings).\n *\n * @param use flag indicating whether or not to use the braces message;\n * defaults to true\n */\n useBraceMsgForEachString(use) {\n if (use === undefined)\n use = true ;\n this.uStrParser_.useBraceMsgForEachString(use);\n }\n\n\n /**\n * This method validates a unit string. It first checks to see if the\n * string passed in is a unit code that is found in the unit codes table.\n * If it is not found it parses the string to see if it resolves to a\n * valid unit string.\n *\n * If a valid unit cannot be found, the string is tested for some common\n * errors, such as missing brackets or a missing multiplication operator.\n * If found, the error is reported in the messages array that is returned.\n *\n * If a valid unit cannot be found and an error cannot be discerned, this\n * may return, if requested, a list of suggested units in the messages\n * array that is returned. Suggestions are based on matching the expression\n * with unit names and synonyms.\n *\n * @param uStr the string to be validated\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @param valConv a string indicating if this validation request was initiated\n * by a validation task ('validate') or a conversion task ('convert'),\n * used only for the demo code, and the default is 'Validator' if the\n * parameter is not specified;\n * @returns an object with five properties:\n * 'status' will be 'valid' (the uStr is a valid UCUM code), 'invalid'\n * (the uStr is not a valid UCUM code, and substitutions or\n * suggestions may or may not be returned, depending on what was\n * requested and found); or 'error' (an input or programming error\n * occurred);\n * 'ucumCode' the valid ucum code, which may differ from what was passed\n * in (e.g., if 'Gauss' is passed in, this will contain 'G') OR null if\n * the string was flagged as invalid or an error occurred;\n * 'msg' is an array of one or more messages, if the string is invalid or\n * an error occurred, indicating the problem, or an explanation of a\n * substitution such as the substitution of 'G' for 'Gauss', or\n * an empty array if no messages were generated;\n * 'unit' which is null if no unit is found, or a hash for a unit found:\n * 'code' is the unit's ucum code (G in the above example;\n * 'name' is the unit's name (Gauss in the above example); and\n * 'guidance' is the unit's guidance/description data; and\n * 'suggestions' if suggestions were requested and found, this is an array\n * of one or more hash objects. Each hash contains three elements:\n * 'msg' which is a message indicating what part of the uStr input\n * parameter the suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions are\n * for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were requested and found, this property is not\n * returned.\n */\n validateUnitString(uStr, suggest, valConv) {\n\n if (suggest === undefined)\n suggest = false ;\n\n if (valConv === undefined)\n valConv = 'validate' ;\n\n let resp = this.getSpecifiedUnit(uStr, valConv, suggest);\n let theUnit = resp['unit'];\n let retObj = {};\n if (!theUnit) {\n retObj = {'status': (!resp['origString'] || resp['origString'] === null) ?\n 'error' : 'invalid',\n 'ucumCode': null};\n }\n else {\n retObj = {'status': resp['origString'] === uStr ? 'valid': 'invalid',\n 'ucumCode': resp['origString'],\n 'unit': {'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_ }};\n }\n if (resp['suggestions']) {\n retObj['suggestions'] = resp['suggestions'];\n }\n retObj['msg'] = resp['retMsg'];\n return retObj;\n\n } // end validateUnitString\n\n\n /**\n * This method converts one unit to another\n *\n * @param fromUnitCode the unit code/expression/string of the unit to be converted\n * @param fromVal the number of \"from\" units to be converted to \"to\" units\n * @param toUnitCode the unit code/expression/string of the unit that the from\n * field is to be converted to\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @param molecularWeight the molecular weight of the substance in question\n * when a conversion is being requested from mass to moles and vice versa.\n * This is required when one of the units represents a value in moles. It is\n * ignored if neither unit includes a measurement in moles.\n * @returns a hash with six elements:\n * 'status' that will be: 'succeeded' if the conversion was successfully\n * calculated; 'failed' if the conversion could not be made, e.g., if\n * the units are not commensurable; or 'error' if an error occurred;\n * 'toVal' the numeric value indicating the conversion amount, or null\n * if the conversion failed (e.g., if the units are not commensurable);\n * 'msg' is an array message, if the string is invalid or an error occurred,\n * indicating the problem, or an explanation of a substitution such as\n * the substitution of 'G' for 'Gauss', or an empty array if no\n * messages were generated;\n * 'suggestions' if suggestions were requested and found, this is a hash\n * that contains at most two elements:\n * 'from' which, if the fromUnitCode input parameter or one or more of\n * its components could not be found, is an array one or more hash\n * objects. Each hash contains three elements:\n * 'msg' which is a message indicating what unit expression the\n * suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions\n * are for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were found for the fromUnitCode this element\n * will not be included.\n * 'to' which, if the \"to\" unit expression or one or more of its\n * components could not be found, is an array one or more hash objects. Each hash\n * contains three elements:\n * 'msg' which is a message indicating what toUnitCode input\n * parameter the suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions\n * are for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were found for the toUnitCode this element\n * will not be included.\n * No 'suggestions' element will be included in the returned hash\n * object if none were found, whether or not they were requested.\n * 'fromUnit' the unit object for the fromUnitCode passed in; returned\n * in case it's needed for additional data from the object; and\n * 'toUnit' the unit object for the toUnitCode passed in; returned\n * in case it's needed for additional data from the object.\n */\n convertUnitTo(fromUnitCode, fromVal, toUnitCode, suggest, molecularWeight) {\n if (suggest === undefined)\n suggest = false ;\n\n if (molecularWeight === undefined)\n molecularWeight = null ;\n\n let returnObj = {'status' : 'failed',\n 'toVal' : null,\n 'msg' : []} ;\n\n if (fromUnitCode) {\n fromUnitCode = fromUnitCode.trim();\n }\n if (!fromUnitCode || fromUnitCode == '') {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"from\" unit expression specified.');\n }\n if (fromVal === null || isNaN(fromVal) || (typeof fromVal !== 'number' &&\n !intUtils_.isNumericString(fromVal))) {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"from\" value, or an invalid \"from\" value, ' +\n 'was specified.');\n }\n if (toUnitCode) {\n toUnitCode = toUnitCode.trim();\n }\n if (!toUnitCode || toUnitCode == '') {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"to\" unit expression specified.');\n }\n if (returnObj['status'] !== 'error') {\n try {\n let fromUnit = null;\n\n let parseResp = this.getSpecifiedUnit(fromUnitCode, 'convert', suggest);\n fromUnit = parseResp['unit'];\n if (parseResp['retMsg'])\n returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);\n if (parseResp['suggestions']) {\n returnObj['suggestions'] = {};\n returnObj['suggestions']['from'] = parseResp['suggestions'];\n }\n if (!fromUnit) {\n returnObj['msg'].push(`Unable to find a unit for ${fromUnitCode}, ` +\n `so no conversion could be performed.`);\n }\n\n let toUnit = null;\n parseResp = this.getSpecifiedUnit(toUnitCode, 'convert', suggest);\n toUnit = parseResp['unit'];\n if (parseResp['retMsg'])\n returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);\n if (parseResp['suggestions']) {\n if (!returnObj['suggestions'])\n returnObj['suggestions'] = {} ;\n returnObj['suggestions']['to'] = parseResp['suggestions'];\n }\n if (!toUnit) {\n returnObj['msg'].push(`Unable to find a unit for ${toUnitCode}, ` +\n `so no conversion could be performed.`);\n }\n\n if (fromUnit && toUnit) {\n try {\n // if no molecular weight was specified perform a normal conversion\n if (!molecularWeight) {\n returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);\n }\n else {\n if (fromUnit.moleExp_ !== 0 && toUnit.moleExp_ !== 0) {\n throw(new Error('A molecular weight was specified ' +\n 'but a mass <-> mole conversion cannot be executed for two ' +\n 'mole-based units. No conversion was attempted.'));\n }\n if (fromUnit.moleExp_ === 0 && toUnit.moleExp_ === 0) {\n throw(new Error('A molecular weight was specified ' +\n 'but a mass <-> mole conversion cannot be executed when ' +\n 'neither unit is mole-based. No conversion was attempted.'));\n }\n if (!fromUnit.isMoleMassCommensurable(toUnit)) {\n throw(new Error(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`));\n }\n\n // if the \"from\" unit is a mole-based unit, assume a mole to mass\n // request\n if (fromUnit.moleExp_ !== 0) {\n returnObj['toVal'] =\n fromUnit.convertMolToMass(fromVal, toUnit, molecularWeight);\n }\n // else the \"to\" unit must be the mole-based unit, so assume a\n // mass to mole request\n else {\n returnObj['toVal'] =\n fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight);\n }\n } // end if a molecular weight was specified\n\n // if an error hasn't been thrown - either from convertFrom or here,\n // set the return object to show success\n returnObj['status'] = 'succeeded';\n returnObj['fromUnit'] = fromUnit;\n returnObj['toUnit'] = toUnit;\n }\n catch (err) {\n returnObj['status'] = 'failed';\n returnObj['msg'].push(err.message);\n }\n\n\n } // end if we have the from and to units\n }\n catch (err) {\n if (err.message == Ucum.needMoleWeightMsg_)\n returnObj['status'] = 'failed';\n else\n returnObj['status'] = 'error';\n returnObj['msg'].push(err.message);\n }\n }\n\n return returnObj ;\n\n } // end convertUnitTo\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\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 hash for each unit found:\n * 'code' is the unit's csCode_\n * 'name' is the unit's name_\n * 'guidance' is the unit's guidance_\n *\n */\n checkSynonyms(theSyn) {\n let retObj = {} ;\n if (theSyn === undefined || theSyn === null) {\n retObj['status'] = 'error';\n retObj['msg'] = 'No term specified for synonym search.'\n }\n else {\n retObj = intUtils_.getSynonyms(theSyn);\n } // end if a search synonym was supplied\n\n return retObj ;\n\n } // end checkSynonyms\n\n\n /**\n * This method parses a unit string to get (or try to get) the unit\n * represented by the string. It returns an error message if no string was specified\n * or if any errors were encountered trying to get the unit.\n *\n * @param uName the expression/string representing the unit\n * @param valConv indicates what type of request this is for - a request to\n * validate (pass in 'validate') or a request to convert (pass in 'convert')\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @returns a hash containing:\n * 'unit' the unit object (or null if there were problems creating the\n * unit);\n * 'origString' the possibly updated unit string passed in;\n * 'retMsg' an array of user messages (informational, error or warning) if\n * any were generated (IF any were generated, otherwise will be an\n * empty array); and\n * 'suggestions' is an array of 1 or more hash objects. Each hash\n * contains three elements:\n * 'msg' which is a message indicating what unit expression the\n * suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions are\n * for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * The return hash will not contain a suggestions array if a valid unit\n * was found or if suggestions were not requested and found.\n */\n getSpecifiedUnit(uName, valConv, suggest) {\n\n if (suggest === undefined)\n suggest = false ;\n\n let retObj = {};\n retObj['retMsg'] = [];\n\n if (!uName) {\n retObj['retMsg'].push('No unit string specified.');\n }\n else {\n let utab = UnitTables.getInstance();\n uName = uName.trim();\n\n // go ahead and just try using the name as the code. This may or may not\n // work, but if it does, it cuts out a lot of parsing.\n let theUnit = utab.getUnitByCode(uName);\n\n // If we found it, set the returned unit string to what was passed in;\n // otherwise try parsing as a unit string\n if (theUnit) {\n retObj['unit'] = theUnit ;\n retObj['origString'] = uName;\n }\n else {\n try {\n let resp = this.uStrParser_.parseString(uName, valConv, suggest);\n retObj['unit'] = resp[0];\n retObj['origString'] = resp[1];\n if (resp[2])\n retObj['retMsg'] = resp[2];\n retObj['suggestions'] = resp[3];\n }\n catch (err) {\n console.log(`Unit requested for unit string ${uName}.` +\n 'request unsuccessful; error thrown = ' + err.message);\n retObj['retMsg'].unshift(`${uName} is not a valid unit. ` +\n `${err.message}`);\n }\n } // end if the unit was not found as a unit name\n } // end if a unit expression was specified\n\n return retObj;\n\n } // end getSpecifiedUnit\n\n\n /**\n * This method retrieves a list of units commensurable, i.e., that can be\n * converted from and to, a specified unit. Returns an error if the \"from\"\n * unit cannot be found.\n *\n * @param fromName the name/unit string of the \"from\" unit\n * @returns an array containing two elements;\n * first element is the list of commensurable units if any were found\n * second element is an error message if the \"from\" unit is not found\n */\n commensurablesList(fromName) {\n\n let retMsg = [];\n let commUnits = null ;\n let parseResp = this.getSpecifiedUnit(fromName, 'validate', false);\n let fromUnit = parseResp['unit'];\n if (parseResp['retMsg'].length > 0)\n retMsg = parseResp['retMsg'] ;\n if (!fromUnit) {\n retMsg.push(`Could not find unit ${fromName}.`);\n }\n else {\n let dimVec = null ;\n let fromDim = fromUnit.getProperty('dim_');\n if (!fromDim) {\n retMsg.push('No commensurable units were found for ' + fromName) ;\n }\n else {\n try {\n dimVec = fromDim.getProperty('dimVec_');\n }\n catch (err) {\n retMsg.push(err.message);\n if (err.message ===\n \"Dimension does not have requested property(dimVec_)\")\n dimVec = null;\n }\n if (dimVec) {\n let utab = UnitTables.getInstance();\n commUnits = utab.getUnitsByDimension(dimVec);\n }\n } // end if the from unit has a dimension vector\n } // end if we found a \"from\" unit\n return [commUnits , retMsg];\n } // end commensurablesList\n\n\n /**\n * Creates a file containing a list of the units. The file is created\n * in the current directory.\n */\n printUnits() {\n\n // for now, create a list of the units created and save it to a file\n // for debugging. This is a temporary file.\n let utab = UnitTables.getInstance();\n let uct = utab.unitsCount();\n let uList = utab.printUnits(true);\n fs.writeFileSync('JsonUnitsList.txt', uList,\n {encoding: 'utf8', mode: 0o666, flag: 'w'} );\n }\n\n\n} // end UcumLhcUtils class\n\n\n/**\n * This function exists ONLY until the original UcumLhcUtils constructor\n * is called for the first time. It's defined here in case getInstance\n * is called before the constructor. This calls the constructor.\n *\n * The constructor redefines the getInstance function to return the\n * singleton UcumLhcUtils object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * NO LONGER TRUE - not implemented as a singleton. This method retained to\n * avoid problems with calls to it that exist throughout the code.\n *\n * @return the (formerly singleton) UcumLhcUtils object.\n */\nUcumLhcUtils.getInstance = function(){\n return new UcumLhcUtils();\n} ;\n\n\n\n\n"],"file":"ucumLhcUtils.js"}
|
|
1
|
+
{"version":3,"sources":["../source/ucumLhcUtils.js"],"names":["Ucum","require","UnitTables","UnitString","UcumLhcUtils","constructor","getInstance","unitsCount","ucumJsonDefs","loadJsonDefs","uStrParser_","useHTMLInMessages","use","undefined","useBraceMsgForEachString","validateUnitString","uStr","suggest","valConv","resp","getSpecifiedUnit","theUnit","retObj","csCode_","name_","guidance_","convertUnitTo","fromUnitCode","fromVal","toUnitCode","molecularWeight","returnObj","trim","push","isNaN","intUtils_","isNumericString","fromUnit","parseResp","concat","toUnit","convertFrom","moleExp_","Error","isMoleMassCommensurable","convertMolToMass","convertMassToMol","err","message","needMoleWeightMsg_","checkSynonyms","theSyn","getSynonyms","uName","utab","getUnitByCode","parseString","console","log","unshift","commensurablesList","fromName","retMsg","commUnits","length","dimVec","fromDim","getProperty","getUnitsByDimension"],"mappings":";;;;;;;AAOA;;AAIA;;;;;;AAXA;;;;;;AAMA,IAAIA,IAAI,GAAGC,OAAO,CAAC,aAAD,CAAP,CAAuBD,IAAlC;;AAEA,IAAIE,UAAU,GAAGD,OAAO,CAAC,iBAAD,CAAP,CAA2BC,UAA5C;;AACA,IAAIC,UAAU,GAAGF,OAAO,CAAC,iBAAD,CAAP,CAA2BE,UAA5C;;AAIA;;;AAGO,MAAMC,YAAN,CAAmB;AAExB;;;;;AAKAC,EAAAA,WAAW,GAAG;AAEV,QAAIH,UAAU,CAACI,WAAX,GAAyBC,UAAzB,OAA0C,CAA9C,EAAiD;AAE/C;AACAC,iCAAaC,YAAb;AACD,KANS,CAQV;AACA;;;AACA,SAAKC,WAAL,GAAmBP,UAAU,CAACG,WAAX,EAAnB;AAEH,GAnBuB,CAmBtB;;AAGF;;;;;;;;;;AAQAK,EAAAA,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AAA,MAAM,CAAC7B,IAAP,CAAYc,GAAG,CAACC,OAAhB;AACA,cAAID,GAAG,CAACC,OAAJ,KACF,qDADF,EAEEiB,MAAM,GAAG,IAAT;AACH;;AACD,YAAIA,MAAJ,EAAY;AACV,cAAIX,IAAI,GAAGpD,UAAU,CAACI,WAAX,EAAX;AACAyD,UAAAA,SAAS,GAAGT,IAAI,CAACc,mBAAL,CAAyBH,MAAzB,CAAZ;AACD;AACF,OApBE,CAoBD;;AACH,KAhC0B,CAgCzB;;;AACF,WAAO,CAACF,SAAD,EAAaD,MAAb,CAAP;AACD,GA5duB,CA4dtB;;;AA5dsB,C,CA8dxB;;AAGF;;;;;;;;;;;;;;;;;;AAcA1D,YAAY,CAACE,WAAb,GAA2B,YAAU;AACnC,SAAO,IAAIF,YAAJ,EAAP;AACD,CAFD","sourcesContent":["/**\n * This class provides a single point of access to the LHC UCUM utilities\n *\n * @author Lee Mericle\n *\n */\nvar Ucum = require('./config.js').Ucum;\nimport {ucumJsonDefs} from './ucumJsonDefs.js';\nvar UnitTables = require('./unitTables.js').UnitTables;\nvar UnitString = require('./unitString.js').UnitString;\n\nimport * as intUtils_ from \"./ucumInternalUtils.js\";\n\n/**\n * UCUM external utilities class\n */\nexport class UcumLhcUtils {\n\n /**\n * Constructor. This loads the json prefix and unit definitions if\n * they haven't been loaded already and creates itself as a singleton object.\n *\n */\n constructor() {\n\n if (UnitTables.getInstance().unitsCount() === 0) {\n\n // Load the prefix and unit objects\n ucumJsonDefs.loadJsonDefs();\n }\n\n // Get the UnitString parser that will be used with this instance\n // of the LHC Utilities\n this.uStrParser_ = UnitString.getInstance();\n\n } // end constructor\n\n\n /**\n * This method calls the useHTMLInMessages method on the UnitString\n * object. It should be called by web applications that use\n * these utilities.\n *\n * @param use flag indicating whether or not to use the braces message;\n * defaults to true\n */\n useHTMLInMessages(use) {\n if (use === undefined)\n use = true ;\n this.uStrParser_.useHTMLInMessages(use);\n }\n\n\n /**\n * This method calls the useBraceMsgForEachString method on the UnitString\n * object. It should be called by web applications where unit\n * strings are validated individually (as opposed to validating a whole\n * file of unit strings).\n *\n * @param use flag indicating whether or not to use the braces message;\n * defaults to true\n */\n useBraceMsgForEachString(use) {\n if (use === undefined)\n use = true ;\n this.uStrParser_.useBraceMsgForEachString(use);\n }\n\n\n /**\n * This method validates a unit string. It first checks to see if the\n * string passed in is a unit code that is found in the unit codes table.\n * If it is not found it parses the string to see if it resolves to a\n * valid unit string.\n *\n * If a valid unit cannot be found, the string is tested for some common\n * errors, such as missing brackets or a missing multiplication operator.\n * If found, the error is reported in the messages array that is returned.\n *\n * If a valid unit cannot be found and an error cannot be discerned, this\n * may return, if requested, a list of suggested units in the messages\n * array that is returned. Suggestions are based on matching the expression\n * with unit names and synonyms.\n *\n * @param uStr the string to be validated\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @param valConv a string indicating if this validation request was initiated\n * by a validation task ('validate') or a conversion task ('convert'),\n * used only for the demo code, and the default is 'Validator' if the\n * parameter is not specified;\n * @returns an object with five properties:\n * 'status' will be 'valid' (the uStr is a valid UCUM code), 'invalid'\n * (the uStr is not a valid UCUM code, and substitutions or\n * suggestions may or may not be returned, depending on what was\n * requested and found); or 'error' (an input or programming error\n * occurred);\n * 'ucumCode' the valid ucum code, which may differ from what was passed\n * in (e.g., if 'Gauss' is passed in, this will contain 'G') OR null if\n * the string was flagged as invalid or an error occurred;\n * 'msg' is an array of one or more messages, if the string is invalid or\n * an error occurred, indicating the problem, or an explanation of a\n * substitution such as the substitution of 'G' for 'Gauss', or\n * an empty array if no messages were generated;\n * 'unit' which is null if no unit is found, or a hash for a unit found:\n * 'code' is the unit's ucum code (G in the above example;\n * 'name' is the unit's name (Gauss in the above example); and\n * 'guidance' is the unit's guidance/description data; and\n * 'suggestions' if suggestions were requested and found, this is an array\n * of one or more hash objects. Each hash contains three elements:\n * 'msg' which is a message indicating what part of the uStr input\n * parameter the suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions are\n * for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were requested and found, this property is not\n * returned.\n */\n validateUnitString(uStr, suggest, valConv) {\n\n if (suggest === undefined)\n suggest = false ;\n\n if (valConv === undefined)\n valConv = 'validate' ;\n\n let resp = this.getSpecifiedUnit(uStr, valConv, suggest);\n let theUnit = resp['unit'];\n let retObj = {};\n if (!theUnit) {\n retObj = {'status': (!resp['origString'] || resp['origString'] === null) ?\n 'error' : 'invalid',\n 'ucumCode': null};\n }\n else {\n retObj = {'status': resp['origString'] === uStr ? 'valid': 'invalid',\n 'ucumCode': resp['origString'],\n 'unit': {'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_ }};\n }\n if (resp['suggestions']) {\n retObj['suggestions'] = resp['suggestions'];\n }\n retObj['msg'] = resp['retMsg'];\n return retObj;\n\n } // end validateUnitString\n\n\n /**\n * This method converts one unit to another\n *\n * @param fromUnitCode the unit code/expression/string of the unit to be converted\n * @param fromVal the number of \"from\" units to be converted to \"to\" units\n * @param toUnitCode the unit code/expression/string of the unit that the from\n * field is to be converted to\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @param molecularWeight the molecular weight of the substance in question\n * when a conversion is being requested from mass to moles and vice versa.\n * This is required when one of the units represents a value in moles. It is\n * ignored if neither unit includes a measurement in moles.\n * @returns a hash with six elements:\n * 'status' that will be: 'succeeded' if the conversion was successfully\n * calculated; 'failed' if the conversion could not be made, e.g., if\n * the units are not commensurable; or 'error' if an error occurred;\n * 'toVal' the numeric value indicating the conversion amount, or null\n * if the conversion failed (e.g., if the units are not commensurable);\n * 'msg' is an array message, if the string is invalid or an error occurred,\n * indicating the problem, or an explanation of a substitution such as\n * the substitution of 'G' for 'Gauss', or an empty array if no\n * messages were generated;\n * 'suggestions' if suggestions were requested and found, this is a hash\n * that contains at most two elements:\n * 'from' which, if the fromUnitCode input parameter or one or more of\n * its components could not be found, is an array one or more hash\n * objects. Each hash contains three elements:\n * 'msg' which is a message indicating what unit expression the\n * suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions\n * are for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were found for the fromUnitCode this element\n * will not be included.\n * 'to' which, if the \"to\" unit expression or one or more of its\n * components could not be found, is an array one or more hash objects. Each hash\n * contains three elements:\n * 'msg' which is a message indicating what toUnitCode input\n * parameter the suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions\n * are for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were found for the toUnitCode this element\n * will not be included.\n * No 'suggestions' element will be included in the returned hash\n * object if none were found, whether or not they were requested.\n * 'fromUnit' the unit object for the fromUnitCode passed in; returned\n * in case it's needed for additional data from the object; and\n * 'toUnit' the unit object for the toUnitCode passed in; returned\n * in case it's needed for additional data from the object.\n */\n convertUnitTo(fromUnitCode, fromVal, toUnitCode, suggest, molecularWeight) {\n if (suggest === undefined)\n suggest = false ;\n\n if (molecularWeight === undefined)\n molecularWeight = null ;\n\n let returnObj = {'status' : 'failed',\n 'toVal' : null,\n 'msg' : []} ;\n\n if (fromUnitCode) {\n fromUnitCode = fromUnitCode.trim();\n }\n if (!fromUnitCode || fromUnitCode == '') {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"from\" unit expression specified.');\n }\n if (fromVal === null || isNaN(fromVal) || (typeof fromVal !== 'number' &&\n !intUtils_.isNumericString(fromVal))) {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"from\" value, or an invalid \"from\" value, ' +\n 'was specified.');\n }\n if (toUnitCode) {\n toUnitCode = toUnitCode.trim();\n }\n if (!toUnitCode || toUnitCode == '') {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"to\" unit expression specified.');\n }\n if (returnObj['status'] !== 'error') {\n try {\n let fromUnit = null;\n\n let parseResp = this.getSpecifiedUnit(fromUnitCode, 'convert', suggest);\n fromUnit = parseResp['unit'];\n if (parseResp['retMsg'])\n returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);\n if (parseResp['suggestions']) {\n returnObj['suggestions'] = {};\n returnObj['suggestions']['from'] = parseResp['suggestions'];\n }\n if (!fromUnit) {\n returnObj['msg'].push(`Unable to find a unit for ${fromUnitCode}, ` +\n `so no conversion could be performed.`);\n }\n\n let toUnit = null;\n parseResp = this.getSpecifiedUnit(toUnitCode, 'convert', suggest);\n toUnit = parseResp['unit'];\n if (parseResp['retMsg'])\n returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);\n if (parseResp['suggestions']) {\n if (!returnObj['suggestions'])\n returnObj['suggestions'] = {} ;\n returnObj['suggestions']['to'] = parseResp['suggestions'];\n }\n if (!toUnit) {\n returnObj['msg'].push(`Unable to find a unit for ${toUnitCode}, ` +\n `so no conversion could be performed.`);\n }\n\n if (fromUnit && toUnit) {\n try {\n // if no molecular weight was specified perform a normal conversion\n if (!molecularWeight) {\n returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);\n }\n else {\n if (fromUnit.moleExp_ !== 0 && toUnit.moleExp_ !== 0) {\n throw(new Error('A molecular weight was specified ' +\n 'but a mass <-> mole conversion cannot be executed for two ' +\n 'mole-based units. No conversion was attempted.'));\n }\n if (fromUnit.moleExp_ === 0 && toUnit.moleExp_ === 0) {\n throw(new Error('A molecular weight was specified ' +\n 'but a mass <-> mole conversion cannot be executed when ' +\n 'neither unit is mole-based. No conversion was attempted.'));\n }\n if (!fromUnit.isMoleMassCommensurable(toUnit)) {\n throw(new Error(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`));\n }\n\n // if the \"from\" unit is a mole-based unit, assume a mole to mass\n // request\n if (fromUnit.moleExp_ !== 0) {\n returnObj['toVal'] =\n fromUnit.convertMolToMass(fromVal, toUnit, molecularWeight);\n }\n // else the \"to\" unit must be the mole-based unit, so assume a\n // mass to mole request\n else {\n returnObj['toVal'] =\n fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight);\n }\n } // end if a molecular weight was specified\n\n // if an error hasn't been thrown - either from convertFrom or here,\n // set the return object to show success\n returnObj['status'] = 'succeeded';\n returnObj['fromUnit'] = fromUnit;\n returnObj['toUnit'] = toUnit;\n }\n catch (err) {\n returnObj['status'] = 'failed';\n returnObj['msg'].push(err.message);\n }\n\n\n } // end if we have the from and to units\n }\n catch (err) {\n if (err.message == Ucum.needMoleWeightMsg_)\n returnObj['status'] = 'failed';\n else\n returnObj['status'] = 'error';\n returnObj['msg'].push(err.message);\n }\n }\n\n return returnObj ;\n\n } // end convertUnitTo\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\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 hash for each unit found:\n * 'code' is the unit's csCode_\n * 'name' is the unit's name_\n * 'guidance' is the unit's guidance_\n *\n */\n checkSynonyms(theSyn) {\n let retObj = {} ;\n if (theSyn === undefined || theSyn === null) {\n retObj['status'] = 'error';\n retObj['msg'] = 'No term specified for synonym search.'\n }\n else {\n retObj = intUtils_.getSynonyms(theSyn);\n } // end if a search synonym was supplied\n\n return retObj ;\n\n } // end checkSynonyms\n\n\n /**\n * This method parses a unit string to get (or try to get) the unit\n * represented by the string. It returns an error message if no string was specified\n * or if any errors were encountered trying to get the unit.\n *\n * @param uName the expression/string representing the unit\n * @param valConv indicates what type of request this is for - a request to\n * validate (pass in 'validate') or a request to convert (pass in 'convert')\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @returns a hash containing:\n * 'unit' the unit object (or null if there were problems creating the\n * unit);\n * 'origString' the possibly updated unit string passed in;\n * 'retMsg' an array of user messages (informational, error or warning) if\n * any were generated (IF any were generated, otherwise will be an\n * empty array); and\n * 'suggestions' is an array of 1 or more hash objects. Each hash\n * contains three elements:\n * 'msg' which is a message indicating what unit expression the\n * suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions are\n * for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * The return hash will not contain a suggestions array if a valid unit\n * was found or if suggestions were not requested and found.\n */\n getSpecifiedUnit(uName, valConv, suggest) {\n\n if (suggest === undefined)\n suggest = false ;\n\n let retObj = {};\n retObj['retMsg'] = [];\n\n if (!uName) {\n retObj['retMsg'].push('No unit string specified.');\n }\n else {\n let utab = UnitTables.getInstance();\n uName = uName.trim();\n\n // go ahead and just try using the name as the code. This may or may not\n // work, but if it does, it cuts out a lot of parsing.\n let theUnit = utab.getUnitByCode(uName);\n\n // If we found it, set the returned unit string to what was passed in;\n // otherwise try parsing as a unit string\n if (theUnit) {\n retObj['unit'] = theUnit ;\n retObj['origString'] = uName;\n }\n else {\n try {\n let resp = this.uStrParser_.parseString(uName, valConv, suggest);\n retObj['unit'] = resp[0];\n retObj['origString'] = resp[1];\n if (resp[2])\n retObj['retMsg'] = resp[2];\n retObj['suggestions'] = resp[3];\n }\n catch (err) {\n console.log(`Unit requested for unit string ${uName}.` +\n 'request unsuccessful; error thrown = ' + err.message);\n retObj['retMsg'].unshift(`${uName} is not a valid unit. ` +\n `${err.message}`);\n }\n } // end if the unit was not found as a unit name\n } // end if a unit expression was specified\n\n return retObj;\n\n } // end getSpecifiedUnit\n\n\n /**\n * This method retrieves a list of units commensurable, i.e., that can be\n * converted from and to, a specified unit. Returns an error if the \"from\"\n * unit cannot be found.\n *\n * @param fromName the name/unit string of the \"from\" unit\n * @returns an array containing two elements;\n * first element is the list of commensurable units if any were found\n * second element is an error message if the \"from\" unit is not found\n */\n commensurablesList(fromName) {\n\n let retMsg = [];\n let commUnits = null ;\n let parseResp = this.getSpecifiedUnit(fromName, 'validate', false);\n let fromUnit = parseResp['unit'];\n if (parseResp['retMsg'].length > 0)\n retMsg = parseResp['retMsg'] ;\n if (!fromUnit) {\n retMsg.push(`Could not find unit ${fromName}.`);\n }\n else {\n let dimVec = null ;\n let fromDim = fromUnit.getProperty('dim_');\n if (!fromDim) {\n retMsg.push('No commensurable units were found for ' + fromName) ;\n }\n else {\n try {\n dimVec = fromDim.getProperty('dimVec_');\n }\n catch (err) {\n retMsg.push(err.message);\n if (err.message ===\n \"Dimension does not have requested property(dimVec_)\")\n dimVec = null;\n }\n if (dimVec) {\n let utab = UnitTables.getInstance();\n commUnits = utab.getUnitsByDimension(dimVec);\n }\n } // end if the from unit has a dimension vector\n } // end if we found a \"from\" unit\n return [commUnits , retMsg];\n } // end commensurablesList\n\n} // end UcumLhcUtils class\n\n\n/**\n * This function exists ONLY until the original UcumLhcUtils constructor\n * is called for the first time. It's defined here in case getInstance\n * is called before the constructor. This calls the constructor.\n *\n * The constructor redefines the getInstance function to return the\n * singleton UcumLhcUtils object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * NO LONGER TRUE - not implemented as a singleton. This method retained to\n * avoid problems with calls to it that exist throughout the code.\n *\n * @return the (formerly singleton) UcumLhcUtils object.\n */\nUcumLhcUtils.getInstance = function(){\n return new UcumLhcUtils();\n} ;\n\n\n\n\n"],"file":"ucumLhcUtils.js"}
|
|
@@ -231,7 +231,7 @@ class UcumXmlDocument {
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
let valNode = curUA.childNamed('value');
|
|
234
|
-
if (this.moleCodes_.
|
|
234
|
+
if (this.moleCodes_.indexOf(curUA.attr.Code) !== -1) attrs['moleExp_'] = 1;else attrs['moleExp_'] = 0; // Process special units
|
|
235
235
|
|
|
236
236
|
if (curUA.attr.isSpecial) {
|
|
237
237
|
attrs['isSpecial_'] = curUA.attr.isSpecial === "yes";
|