@lhncbc/ucum-lhc 7.1.6 → 7.1.9
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 +109 -121
- package/browser-dist/ucum-lhc.min.js +1 -1
- package/browser-dist/ucum-lhc.min.js.map +1 -1
- package/package.json +6 -8
- package/source/dimension.js +8 -8
- package/source/unit.js +1 -1
- package/source/unitString.js +165 -99
- package/source-cjs/config.js +1 -2
- package/source-cjs/config.js.map +1 -1
- package/source-cjs/dimension.js +7 -7
- package/source-cjs/dimension.js.map +1 -1
- package/source-cjs/prefixTables.js +2 -3
- package/source-cjs/prefixTables.js.map +1 -1
- package/source-cjs/ucumFunctions.js +1 -2
- package/source-cjs/ucumFunctions.js.map +1 -1
- package/source-cjs/ucumInternalUtils.js +2 -2
- package/source-cjs/ucumJsonDefs.js +1 -2
- package/source-cjs/ucumJsonDefs.js.map +1 -1
- package/source-cjs/ucumLhcUtils.js.map +1 -1
- package/source-cjs/ucumPkg.js +3 -6
- package/source-cjs/ucumPkg.js.map +1 -1
- package/source-cjs/ucumXmlDocument.js.map +1 -1
- package/source-cjs/unit.js +1 -1
- package/source-cjs/unit.js.map +1 -1
- package/source-cjs/unitString.js +150 -92
- package/source-cjs/unitString.js.map +1 -1
- package/source-cjs/unitTables.js +1 -2
- 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": "7.1.
|
|
3
|
+
"version": "7.1.9",
|
|
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/",
|
|
@@ -32,19 +32,16 @@
|
|
|
32
32
|
"@babel/preset-env": "^7.6.2",
|
|
33
33
|
"@babel/register": "^7.6.2",
|
|
34
34
|
"babel-loader": "^8.0.6",
|
|
35
|
-
"babelify": "^10.0.0",
|
|
36
35
|
"bower": "^1.8.8",
|
|
36
|
+
"fast-xml-parser": "^5.5.2",
|
|
37
37
|
"grunt": "^1.5.3",
|
|
38
38
|
"grunt-babel": "^8.0.0",
|
|
39
|
-
"grunt-browserify": "^6.0.0",
|
|
40
39
|
"grunt-cli": "^1.4.3",
|
|
41
40
|
"grunt-contrib-clean": "^1.0.0",
|
|
42
41
|
"grunt-contrib-cssmin": "^3.0.0",
|
|
43
|
-
"grunt-contrib-uglify": "^5.2.2",
|
|
44
|
-
"grunt-extract-sourcemap": "^0.1.19",
|
|
45
42
|
"grunt-mocha-test": "^0.13.2",
|
|
46
43
|
"jit-grunt": "^0.10.0",
|
|
47
|
-
"mocha": "^
|
|
44
|
+
"mocha": "^11.7.5",
|
|
48
45
|
"path": "^0.12.7",
|
|
49
46
|
"semver": "^5.5.1",
|
|
50
47
|
"time-grunt": "^1.4.0",
|
|
@@ -52,8 +49,9 @@
|
|
|
52
49
|
"webpack-cli": "^5.0.1"
|
|
53
50
|
},
|
|
54
51
|
"scripts": {
|
|
55
|
-
"build": "grunt build
|
|
56
|
-
"test": "grunt test"
|
|
52
|
+
"build": "grunt build",
|
|
53
|
+
"test": "grunt test",
|
|
54
|
+
"scan": "rm source.zip; zip -r source source"
|
|
57
55
|
},
|
|
58
56
|
"repository": {
|
|
59
57
|
"type": "git",
|
package/source/dimension.js
CHANGED
|
@@ -166,7 +166,7 @@ export class Dimension {
|
|
|
166
166
|
* @throws an exception if dim2 is not a Dimension object
|
|
167
167
|
**/
|
|
168
168
|
add(dim2) {
|
|
169
|
-
if (!dim2 instanceof Dimension) {
|
|
169
|
+
if (!(dim2 instanceof Dimension)) {
|
|
170
170
|
throw(new Error(`Dimension.add called with an invalid parameter - ` +
|
|
171
171
|
`${typeof dim2} instead of a Dimension object`));
|
|
172
172
|
}
|
|
@@ -188,7 +188,7 @@ export class Dimension {
|
|
|
188
188
|
* @throws an exception if dim2 is not a Dimension object
|
|
189
189
|
**/
|
|
190
190
|
sub(dim2) {
|
|
191
|
-
if (!dim2 instanceof Dimension) {
|
|
191
|
+
if (!(dim2 instanceof Dimension)) {
|
|
192
192
|
throw(new Error(`Dimension.sub called with an invalid parameter - ` +
|
|
193
193
|
`${typeof dim2} instead of a Dimension object`));
|
|
194
194
|
}
|
|
@@ -221,14 +221,14 @@ export class Dimension {
|
|
|
221
221
|
* when a unit is raised to a power. This object's vector is changed unless
|
|
222
222
|
* the vector is null, in which case it stays that way.
|
|
223
223
|
*
|
|
224
|
-
* @param s the scalar to use
|
|
224
|
+
* @param s the integer scalar to use
|
|
225
225
|
* @return this object
|
|
226
|
-
* @throws an exception if s is not
|
|
226
|
+
* @throws an exception if s is not an integer
|
|
227
227
|
*/
|
|
228
228
|
mul(s) {
|
|
229
229
|
if (!isInteger(s)) {
|
|
230
|
-
throw(new Error(`Dimension.
|
|
231
|
-
`${typeof
|
|
230
|
+
throw(new Error(`Dimension.mul called with an invalid parameter - ` +
|
|
231
|
+
`${typeof s} instead of an integer`));
|
|
232
232
|
}
|
|
233
233
|
if (this.dimVec_) {
|
|
234
234
|
for (let i = 0; i < UC.Ucum.dimLen_; i++)
|
|
@@ -249,7 +249,7 @@ export class Dimension {
|
|
|
249
249
|
* @throws an exception if dim2 is not a Dimension object
|
|
250
250
|
*/
|
|
251
251
|
equals(dim2) {
|
|
252
|
-
if (!dim2 instanceof Dimension) {
|
|
252
|
+
if (!(dim2 instanceof Dimension)) {
|
|
253
253
|
throw(new Error(`Dimension.equals called with an invalid parameter - ` +
|
|
254
254
|
`${typeof dim2} instead of a Dimension object`));
|
|
255
255
|
}
|
|
@@ -280,7 +280,7 @@ export class Dimension {
|
|
|
280
280
|
*/
|
|
281
281
|
assignDim(dim2) {
|
|
282
282
|
|
|
283
|
-
if (!dim2 instanceof Dimension) {
|
|
283
|
+
if (!(dim2 instanceof Dimension)) {
|
|
284
284
|
throw(new Error(`Dimension.assignDim called with an invalid parameter - ` +
|
|
285
285
|
`${typeof dim2} instead of a Dimension object`));
|
|
286
286
|
}
|
package/source/unit.js
CHANGED
|
@@ -243,7 +243,7 @@ export class Unit {
|
|
|
243
243
|
*/
|
|
244
244
|
assignVals(vals) {
|
|
245
245
|
for (let key in vals) {
|
|
246
|
-
let uKey =
|
|
246
|
+
let uKey = key.charAt(key.length - 1) !== '_' ? key + '_' : key ;
|
|
247
247
|
if (this.hasOwnProperty(uKey))
|
|
248
248
|
this[uKey] = vals[key];
|
|
249
249
|
else
|
package/source/unitString.js
CHANGED
|
@@ -1076,40 +1076,6 @@ export class UnitString {
|
|
|
1076
1076
|
retUnit.ciCode_ = retUnit.ciCode_.replace('*', '^');
|
|
1077
1077
|
}
|
|
1078
1078
|
}
|
|
1079
|
-
// If that didn't work, check to see if it should have brackets
|
|
1080
|
-
// around it (uCode = degF when it should be [degF]
|
|
1081
|
-
if (!retUnit) {
|
|
1082
|
-
let addBrackets = '[' + uCode + ']' ;
|
|
1083
|
-
retUnit = this.utabs_.getUnitByCode(addBrackets);
|
|
1084
|
-
if (retUnit) {
|
|
1085
|
-
retUnit = retUnit.clone();
|
|
1086
|
-
origString = origString.replace(uCode, addBrackets);
|
|
1087
|
-
this.retMsg_.push(`${uCode} is not a valid unit expression, but ` +
|
|
1088
|
-
`${addBrackets} is.\n` + this.vcMsgStart_ +
|
|
1089
|
-
`${addBrackets} (${retUnit.name_})${this.vcMsgEnd_}`);
|
|
1090
|
-
} // end if we found the unit after adding brackets
|
|
1091
|
-
} // end trying to add brackets
|
|
1092
|
-
|
|
1093
|
-
// If we didn't find it, try it as a name
|
|
1094
|
-
if (!retUnit) {
|
|
1095
|
-
let retUnitAry = this.utabs_.getUnitByName(uCode);
|
|
1096
|
-
if (retUnitAry && retUnitAry.length > 0) {
|
|
1097
|
-
retUnit = retUnitAry[0].clone();
|
|
1098
|
-
let mString = 'The UCUM code for ' + uCode + ' is ' +
|
|
1099
|
-
retUnit.csCode_ + '.\n' + this.vcMsgStart_ +
|
|
1100
|
-
retUnit.csCode_ + this.vcMsgEnd_;
|
|
1101
|
-
let dupMsg = false;
|
|
1102
|
-
for (let r = 0; r < this.retMsg_.length && !dupMsg; r++)
|
|
1103
|
-
dupMsg = this.retMsg_[r] === mString;
|
|
1104
|
-
if (!dupMsg)
|
|
1105
|
-
this.retMsg_.push(mString);
|
|
1106
|
-
let rStr = new RegExp('(^|[.\/({])(' + uCode + ')($|[.\/)}])');
|
|
1107
|
-
let res = origString.match(rStr);
|
|
1108
|
-
origString = origString.replace(rStr, res[1] + retUnit.csCode_ + res[3]);
|
|
1109
|
-
uCode = retUnit.csCode_;
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
1079
|
// If we still don't have a unit, try assuming a modifier (prefix and/or
|
|
1114
1080
|
// exponent) and look for a unit without the modifier
|
|
1115
1081
|
if (!retUnit) {
|
|
@@ -1189,13 +1155,22 @@ export class UnitString {
|
|
|
1189
1155
|
// without the exponent, the unit string without a prefix,
|
|
1190
1156
|
// common errors, etc. That's all we can try).
|
|
1191
1157
|
if (!origUnit) {
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1158
|
+
let bracketRet = this._getUnitAfterAddingBrackets(origCode, origString);
|
|
1159
|
+
retUnit = bracketRet[0];
|
|
1160
|
+
origString = bracketRet[1];
|
|
1161
|
+
if (!retUnit) {
|
|
1162
|
+
let nameRet = this._getUnitByName(origCode, origString);
|
|
1163
|
+
retUnit = nameRet[0];
|
|
1164
|
+
origString = nameRet[1];
|
|
1165
|
+
if (!retUnit) {
|
|
1166
|
+
// BUT if the user asked for suggestions, at least look for them
|
|
1167
|
+
if (this.suggestions_) {
|
|
1168
|
+
let suggestStat = this._getSuggestions(origCode);
|
|
1169
|
+
}
|
|
1170
|
+
else {
|
|
1171
|
+
this.retMsg_.push(`${origCode} is not a valid UCUM code.`);
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1199
1174
|
}
|
|
1200
1175
|
}
|
|
1201
1176
|
else {
|
|
@@ -1214,72 +1189,81 @@ export class UnitString {
|
|
|
1214
1189
|
// If there is an exponent for the unit, apply it to the dimension
|
|
1215
1190
|
// and magnitude now
|
|
1216
1191
|
if (exp) {
|
|
1217
|
-
|
|
1218
|
-
if (
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1192
|
+
// Special units cannot be raised to a power
|
|
1193
|
+
if (retUnit.isSpecial_) {
|
|
1194
|
+
this.retMsg_.push(`Special units like ${retUnit.name_} cannot be raised to a power.`);
|
|
1195
|
+
retUnit = null;
|
|
1196
|
+
}
|
|
1197
|
+
else {
|
|
1198
|
+
exp = parseInt(exp);
|
|
1199
|
+
if (theDim)
|
|
1200
|
+
theDim = theDim.mul(exp);
|
|
1201
|
+
retUnit.equivalentExp_ *= exp;
|
|
1202
|
+
retUnit.moleExp_ *= exp;
|
|
1203
|
+
theMag = Math.pow(theMag, exp);
|
|
1204
|
+
retUnit.assignVals({'magnitude_': theMag});
|
|
1205
|
+
|
|
1206
|
+
// If there is also a prefix, apply the exponent to the prefix.
|
|
1207
|
+
if (pfxObj) {
|
|
1208
|
+
// We don't need to consider pfxObj.getExp(), because when
|
|
1209
|
+
// present that is reflected in the pfxVal. However, in some
|
|
1210
|
+
// cases one can avoid floating-point math inaccuracies by using
|
|
1211
|
+
// that exponent instead of relying on pfxVal. For example:
|
|
1212
|
+
// 1e-66 = Math.pow(10, -3*22) = Math.pow(0.001, 22) = 1.0000000000000005e-66
|
|
1213
|
+
// (This is the from the test case of the unit mg% raised to the 22nd power (mg%22).)
|
|
1214
|
+
// This does not help in all cases, but it does help the above
|
|
1215
|
+
// test case (which is in our web API service test code).
|
|
1216
|
+
let pfxExp = pfxObj.getExp();
|
|
1217
|
+
if (pfxExp) {
|
|
1218
|
+
// This is relying on the fact that pfxExp is null when
|
|
1219
|
+
// the prefix base is not 10.
|
|
1220
|
+
pfxVal = Math.pow(10, exp * pfxExp);
|
|
1221
|
+
}
|
|
1222
|
+
else {
|
|
1223
|
+
pfxVal = Math.pow(pfxVal, exp);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
} // end else - prefix and exponent handling for non-special units
|
|
1227
|
+
} // end if there's an exponent
|
|
1228
|
+
|
|
1229
|
+
if (retUnit) {
|
|
1230
|
+
// Now apply the prefix, if there is one, to the conversion
|
|
1231
|
+
// prefix or the magnitude
|
|
1226
1232
|
if (pfxObj) {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
// cases one can avoid floating-point math inaccuracies by using
|
|
1230
|
-
// that exponent instead of relying on pfxVal. For example:
|
|
1231
|
-
// 1e-66 = Math.pow(10, -3*22) = Math.pow(0.001, 22) = 1.0000000000000005e-66
|
|
1232
|
-
// (This is the from the test case of the unit mg% raised to the 22nd power (mg%22).)
|
|
1233
|
-
// This does not help in all cases, but it does help the above
|
|
1234
|
-
// test case (which is in our web API service test code).
|
|
1235
|
-
let pfxExp = pfxObj.getExp();
|
|
1236
|
-
if (pfxExp) {
|
|
1237
|
-
// This is relying on the fact that pfxExp is null when
|
|
1238
|
-
// the prefix base is not 10.
|
|
1239
|
-
pfxVal = Math.pow(10, exp * pfxExp);
|
|
1233
|
+
if (retUnit.cnv_) {
|
|
1234
|
+
retUnit.assignVals({'cnvPfx_': pfxVal});
|
|
1240
1235
|
}
|
|
1241
1236
|
else {
|
|
1242
|
-
|
|
1237
|
+
theMag *= pfxVal;
|
|
1238
|
+
retUnit.assignVals({'magnitude_': theMag})
|
|
1243
1239
|
}
|
|
1244
1240
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1241
|
+
// if we have a prefix and/or an exponent, add them to the unit
|
|
1242
|
+
// attributes - name, csCode, ciCode and print symbol
|
|
1243
|
+
let theCode = retUnit.csCode_;
|
|
1244
|
+
if (pfxObj) {
|
|
1245
|
+
theName = pfxObj.getName() + theName;
|
|
1246
|
+
theCode = pfxCode + theCode;
|
|
1247
|
+
theCiCode = pfxObj.getCiCode() + theCiCode;
|
|
1248
|
+
thePrintSymbol = pfxObj.getPrintSymbol() + thePrintSymbol;
|
|
1249
|
+
retUnit.assignVals({
|
|
1250
|
+
'name_': theName,
|
|
1251
|
+
'csCode_': theCode,
|
|
1252
|
+
'ciCode_': theCiCode,
|
|
1253
|
+
'printSymbol_': thePrintSymbol
|
|
1254
|
+
});
|
|
1252
1255
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
+
if (exp) {
|
|
1257
|
+
let expStr = exp.toString();
|
|
1258
|
+
const intergerUnitExpSign = isIntegerUnitWithExp && exp > 0 ? '+' : '';
|
|
1259
|
+
retUnit.assignVals({
|
|
1260
|
+
'name_': theName + '<sup>' + expStr + '</sup>',
|
|
1261
|
+
'csCode_': theCode + intergerUnitExpSign + expStr,
|
|
1262
|
+
'ciCode_': theCiCode + intergerUnitExpSign + expStr,
|
|
1263
|
+
'printSymbol_': thePrintSymbol + '<sup>' + expStr + '</sup>'
|
|
1264
|
+
});
|
|
1256
1265
|
}
|
|
1257
1266
|
}
|
|
1258
|
-
// if we have a prefix and/or an exponent, add them to the unit
|
|
1259
|
-
// attributes - name, csCode, ciCode and print symbol
|
|
1260
|
-
let theCode = retUnit.csCode_;
|
|
1261
|
-
if (pfxObj) {
|
|
1262
|
-
theName = pfxObj.getName() + theName;
|
|
1263
|
-
theCode = pfxCode + theCode;
|
|
1264
|
-
theCiCode = pfxObj.getCiCode() + theCiCode;
|
|
1265
|
-
thePrintSymbol = pfxObj.getPrintSymbol() + thePrintSymbol;
|
|
1266
|
-
retUnit.assignVals({
|
|
1267
|
-
'name_': theName,
|
|
1268
|
-
'csCode_': theCode,
|
|
1269
|
-
'ciCode_': theCiCode,
|
|
1270
|
-
'printSymbol_': thePrintSymbol
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
if (exp) {
|
|
1274
|
-
let expStr = exp.toString();
|
|
1275
|
-
const intergerUnitExpSign = isIntegerUnitWithExp && exp > 0 ? '+' : '';
|
|
1276
|
-
retUnit.assignVals({
|
|
1277
|
-
'name_': theName + '<sup>' + expStr + '</sup>',
|
|
1278
|
-
'csCode_': theCode + intergerUnitExpSign + expStr,
|
|
1279
|
-
'ciCode_': theCiCode + intergerUnitExpSign + expStr,
|
|
1280
|
-
'printSymbol_': thePrintSymbol + '<sup>' + expStr + '</sup>'
|
|
1281
|
-
});
|
|
1282
|
-
}
|
|
1283
1267
|
} // end if an original unit was found (without prefix and/or exponent)
|
|
1284
1268
|
} // end if an invalid exponent wasn't found
|
|
1285
1269
|
} // end if we didn't get a unit for the full unit code (w/out modifiers)
|
|
@@ -1288,6 +1272,88 @@ export class UnitString {
|
|
|
1288
1272
|
} // end _makeUnit
|
|
1289
1273
|
|
|
1290
1274
|
|
|
1275
|
+
/**
|
|
1276
|
+
* Checks whether an otherwise unresolved unit code matches a unit name.
|
|
1277
|
+
*
|
|
1278
|
+
* @param uCode the unit code or name to check
|
|
1279
|
+
* @param origString the original full string submitted to parseString
|
|
1280
|
+
* @returns an array containing the unit object found, or null, and origString
|
|
1281
|
+
*/
|
|
1282
|
+
_getUnitByName(uCode, origString) {
|
|
1283
|
+
|
|
1284
|
+
let retUnit = null;
|
|
1285
|
+
let retUnitAry = this.utabs_.getUnitByName(uCode);
|
|
1286
|
+
if (retUnitAry && retUnitAry.length > 0) {
|
|
1287
|
+
retUnit = retUnitAry[0].clone();
|
|
1288
|
+
let mString = 'The UCUM code for ' + uCode + ' is ' +
|
|
1289
|
+
retUnit.csCode_ + '.\n' + this.vcMsgStart_ +
|
|
1290
|
+
retUnit.csCode_ + this.vcMsgEnd_;
|
|
1291
|
+
let dupMsg = false;
|
|
1292
|
+
for (let r = 0; r < this.retMsg_.length && !dupMsg; r++)
|
|
1293
|
+
dupMsg = this.retMsg_[r] === mString;
|
|
1294
|
+
if (!dupMsg)
|
|
1295
|
+
this.retMsg_.push(mString);
|
|
1296
|
+
const escapedCode = uCode.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1297
|
+
let rStr = new RegExp('(^|[./(])(' + escapedCode + ')($|[./)\\-\\d{])');
|
|
1298
|
+
const updatedOrigString = origString.replace(rStr, '$1' + retUnit.csCode_ + '$3');
|
|
1299
|
+
if (updatedOrigString == origString) {
|
|
1300
|
+
// This should not happen, if the processing has been correct. However, if it does happen, we
|
|
1301
|
+
// still have to change origString to signal that the input unit is invalid.
|
|
1302
|
+
// There is a test present to make sure this message does not appear from the top-level APIs in
|
|
1303
|
+
// ucumLhcUtils.js.
|
|
1304
|
+
// Ideally, this problem would be signalled some other way, but that would be a bigger change.
|
|
1305
|
+
origString += ' (Unable to update the unit expression with a suggested replacement.)';
|
|
1306
|
+
}
|
|
1307
|
+
else {
|
|
1308
|
+
origString = updatedOrigString;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
return [retUnit, origString];
|
|
1312
|
+
} // end _getUnitByName
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
/**
|
|
1316
|
+
* Checks whether an otherwise unresolved unit code can be found after adding
|
|
1317
|
+
* square brackets, e.g., degF -> [degF]. If a bracketed unit is found,
|
|
1318
|
+
* origString is modified to include the suggested replacement.
|
|
1319
|
+
*
|
|
1320
|
+
* @param uCode the unit code to check
|
|
1321
|
+
* @param origString the original full string submitted to parseString
|
|
1322
|
+
* @returns an array containing the unit object found, or null, and the possibly
|
|
1323
|
+
* modified origString
|
|
1324
|
+
*/
|
|
1325
|
+
_getUnitAfterAddingBrackets(uCode, origString) {
|
|
1326
|
+
|
|
1327
|
+
let retUnit = null;
|
|
1328
|
+
const addBrackets = '[' + uCode + ']' ;
|
|
1329
|
+
const bracketUnit = this.utabs_.getUnitByCode(addBrackets);
|
|
1330
|
+
if (bracketUnit) {
|
|
1331
|
+
retUnit = bracketUnit.clone();
|
|
1332
|
+
const escapedCode = uCode.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1333
|
+
const leadingUnitBoundary = '(^|[./(])';
|
|
1334
|
+
const trailingUnitBoundary = '($|[./)\\-\\d{])';
|
|
1335
|
+
const rStr = new RegExp(leadingUnitBoundary + '(' + escapedCode + ')' +
|
|
1336
|
+
trailingUnitBoundary);
|
|
1337
|
+
const updatedOrigString = origString.replace(rStr, '$1' + addBrackets + '$3');
|
|
1338
|
+
if (updatedOrigString == origString) {
|
|
1339
|
+
// This should not happen, if the processing has been correct. However, if it does happen, we
|
|
1340
|
+
// still have to change origString to signal that the input unit is invalid.
|
|
1341
|
+
// There is a test present to make sure this message does not appear from the top-level APIs in
|
|
1342
|
+
// ucumLhcUtils.js.
|
|
1343
|
+
// Ideally, this problem would be signalled some other way, but that would be a bigger change.
|
|
1344
|
+
origString += ' (Unable to update the unit expression with a suggested replacement.)';
|
|
1345
|
+
}
|
|
1346
|
+
else {
|
|
1347
|
+
origString = updatedOrigString;
|
|
1348
|
+
}
|
|
1349
|
+
this.retMsg_.push(`${uCode} is not a valid unit expression, but ` +
|
|
1350
|
+
`${addBrackets} is.\n` + this.vcMsgStart_ +
|
|
1351
|
+
`${addBrackets} (${retUnit.name_})${this.vcMsgEnd_}`);
|
|
1352
|
+
}
|
|
1353
|
+
return [retUnit, origString];
|
|
1354
|
+
} // end _getUnitAfterAddingBrackets
|
|
1355
|
+
|
|
1356
|
+
|
|
1291
1357
|
/**
|
|
1292
1358
|
* This method handles unit creation when an annotation is included
|
|
1293
1359
|
* in the unit string. This basically isolates and retrieves the
|
package/source-cjs/config.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.Ucum = void 0;
|
|
|
12
12
|
* defined by the ECMAScript 6 standard
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
var Ucum = {
|
|
15
|
+
var Ucum = exports.Ucum = {
|
|
16
16
|
/**
|
|
17
17
|
* Flag indicating whether or not we're using case sensitive labels
|
|
18
18
|
* I don't think we need this. I think we're just going with
|
|
@@ -119,5 +119,4 @@ var Ucum = {
|
|
|
119
119
|
'[m/s2/Hz^(1/2)]': 'specialUnitTwo'
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
-
exports.Ucum = Ucum;
|
|
123
122
|
//# sourceMappingURL=config.js.map
|
package/source-cjs/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","names":["Ucum","dimLen_","validOps_","codeSep_","valMsgStart_","valMsgEnd_","cnvMsgStart_","cnvMsgEnd_","openEmph_","closeEmph_","openEmphHTML_","closeEmphHTML_","bracesMsg_","needMoleWeightMsg_","needEqWeightMsg_","needEqChargeMsg_","csvCols_","inputKey_","specUnits_"
|
|
1
|
+
{"version":3,"file":"config.js","names":["Ucum","exports","dimLen_","validOps_","codeSep_","valMsgStart_","valMsgEnd_","cnvMsgStart_","cnvMsgEnd_","openEmph_","closeEmph_","openEmphHTML_","closeEmphHTML_","bracesMsg_","needMoleWeightMsg_","needEqWeightMsg_","needEqChargeMsg_","csvCols_","inputKey_","specUnits_"],"sources":["../source/config.js"],"sourcesContent":["/*\n * This defines the namespace for the UCUM classes and provides\n * a place for the definition of global variables and constants.\n *\n * The javascript for this UCUM implementation uses syntax as\n * defined by the ECMAScript 6 standard\n */\n\nexport var Ucum = {\n\n /**\n * Flag indicating whether or not we're using case sensitive labels\n * I don't think we need this. I think we're just going with\n * case sensitive, per Clem. Gunther's code has this flag, but I\n * am removing it, at least for now. lm, 6/2016\n */\n //caseSensitive_: true ,\n\n /**\n * The number of elements in a Dimension array. Currently this\n * is set as a configuration variable, but when we get to the point\n * of loading the unit definitions from a file, this value will be\n * set from that.\n */\n dimLen_: 7,\n\n\n /**\n * The characters used as valid operators in a UCUM unit expression,\n * where '.' is for multiplication and '/' is for division.\n */\n validOps_: ['.', '/'],\n\n\n /**\n * The string used to separate a unit code and unit name when they\n * are displayed together\n */\n codeSep_ : ': ',\n\n // Message text variations for validation methods and conversion methods\n valMsgStart_ : 'Did you mean ',\n valMsgEnd_ : '?' ,\n cnvMsgStart_ : 'We assumed you meant ',\n cnvMsgEnd_ : '.',\n\n\n/**\n * Default opening string used to emphasize portions of error messages.\n * Used when NOT displaying messages on a web site, i.e., for output\n * from the library methods or to a file.\n */\n openEmph_ : ' ->',\n\n /**\n * Default closing string used to emphasize portions of error messages.\n * Used when NOT displaying messages on a web site, i.e., for output\n * from the library methods or to a file.\n */\n closeEmph_ : '<- ' ,\n\n /**\n * Opening HTML used to emphasize portions of error messages. Used when\n * displaying messages on a web site; should be blank when output is\n * to a file.\n */\n openEmphHTML_ : ' <span class=\"emphSpan\">',\n\n /**\n * Closing HTML used to emphasize portions of error messages. Used when\n * displaying messages on a web site; should be blank when output is\n * to a file.\n */\n closeEmphHTML_ : '</span> ' ,\n\n /**\n * Message that is displayed when annotations are included in a unit\n * string, to let the user know how they are interpreted.\n */\n bracesMsg_ : 'FYI - annotations (text in curly braces {}) are ignored, ' +\n 'except that an annotation without a leading symbol implies ' +\n 'the default unit 1 (the unity).',\n\n /**\n * Message that is displayed or returned when a conversion is requested\n * for two units where (only) a mass<->moles conversion is appropriate\n * but no molecular weight was specified.\n */\n needMoleWeightMsg_ : 'Did you wish to convert between mass and moles? The ' +\n 'molecular weight of the substance represented by the ' +\n 'units is required to perform the conversion.',\n\n /**\n * Message that is returned when a mass<->eq conversion is requested \n * (which requires a molecular weight to calculate), but no molecular \n * weight was provided by the user.\n */ \n needEqWeightMsg_ : 'Did you wish to convert with equivalents? The ' +\n 'molecular weight of the substance is required to perform ' + \n 'the conversion.', \n\n /**\n * Message that is returned when a mass<->eq or a mol<->eq conversion \n * is requested (which requires a charge to calculate), but no charge\n * was provided by the user.\n */\n needEqChargeMsg_ : 'Did you wish to convert with equivalents? The ' +\n 'charge of the substance is required to perform ' + \n 'the conversion.', \n\n /**\n * Hash that matches unit column names to names used in the csv file\n * that is submitted to the data updater.\n */\n csvCols_ : {\n 'case-sensitive code' : 'csCode_',\n 'LOINC property' : 'loincProperty_',\n 'name (display)' : 'name_',\n 'synonyms' : 'synonyms_',\n 'source' : 'source_',\n 'category' : 'category_',\n 'Guidance' : 'guidance_'\n } ,\n\n /**\n * Name of the column in the csv file that serves as the key\n */\n inputKey_ : 'case-sensitive code' ,\n\n /**\n * Special codes that contain operators within brackets. The operator\n * within these codes causes them to parse incorrectly if they are preceded\n * by a prefix, because the parsing algorithm splits them up on the operator.\n * So we use this object to identify them and substitute placeholders to\n * avoid that.\n */\n specUnits_ : { 'B[10.nV]' : 'specialUnitOne',\n '[m/s2/Hz^(1/2)]' : 'specialUnitTwo'}\n} ;\n\n\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,IAAIA,IAAI,GAAAC,OAAA,CAAAD,IAAA,GAAG;EAEhB;AACF;AACA;AACA;AACA;AACA;EACE;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEE,OAAO,EAAE,CAAC;EAGV;AACF;AACA;AACA;EACEC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;EAGrB;AACF;AACA;AACA;EACEC,QAAQ,EAAG,IAAI;EAEf;EACAC,YAAY,EAAG,eAAe;EAC9BC,UAAU,EAAG,GAAG;EAChBC,YAAY,EAAG,uBAAuB;EACtCC,UAAU,EAAG,GAAG;EAGlB;AACA;AACA;AACA;AACA;EACEC,SAAS,EAAG,KAAK;EAEjB;AACF;AACA;AACA;AACA;EACEC,UAAU,EAAG,KAAK;EAElB;AACF;AACA;AACA;AACA;EACEC,aAAa,EAAG,0BAA0B;EAE1C;AACF;AACA;AACA;AACA;EACEC,cAAc,EAAG,UAAU;EAE3B;AACF;AACA;AACA;EACEC,UAAU,EAAG,2DAA2D,GAC3D,6DAA6D,GAC7D,iCAAiC;EAE9C;AACF;AACA;AACA;AACA;EACEC,kBAAkB,EAAG,uDAAuD,GACvD,uDAAuD,GACvD,8CAA8C;EAEnE;AACF;AACA;AACA;AACA;EACEC,gBAAgB,EAAG,iDAAiD,GAChD,2DAA2D,GAC3D,iBAAiB;EAErC;AACF;AACA;AACA;AACA;EACEC,gBAAgB,EAAG,iDAAiD,GAChD,iDAAiD,GACjD,iBAAiB;EAErC;AACF;AACA;AACA;EACEC,QAAQ,EAAG;IACT,qBAAqB,EAAG,SAAS;IACjC,gBAAgB,EAAG,gBAAgB;IACnC,gBAAgB,EAAG,OAAO;IAC1B,UAAU,EAAG,WAAW;IACxB,QAAQ,EAAG,SAAS;IACpB,UAAU,EAAG,WAAW;IACxB,UAAU,EAAG;EACf,CAAC;EAED;AACF;AACA;EACEC,SAAS,EAAG,qBAAqB;EAEjC;AACF;AACA;AACA;AACA;AACA;AACA;EACGC,UAAU,EAAG;IAAE,UAAU,EAAG,gBAAgB;IAC7B,iBAAiB,EAAG;EAAgB;AACtD,CAAC","ignoreList":[]}
|
package/source-cjs/dimension.js
CHANGED
|
@@ -147,7 +147,7 @@ class Dimension {
|
|
|
147
147
|
* @throws an exception if dim2 is not a Dimension object
|
|
148
148
|
**/
|
|
149
149
|
add(dim2) {
|
|
150
|
-
if (!dim2 instanceof Dimension) {
|
|
150
|
+
if (!(dim2 instanceof Dimension)) {
|
|
151
151
|
throw new Error(`Dimension.add called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`);
|
|
152
152
|
}
|
|
153
153
|
if (this.dimVec_ && dim2.dimVec_) {
|
|
@@ -166,7 +166,7 @@ class Dimension {
|
|
|
166
166
|
* @throws an exception if dim2 is not a Dimension object
|
|
167
167
|
**/
|
|
168
168
|
sub(dim2) {
|
|
169
|
-
if (!dim2 instanceof Dimension) {
|
|
169
|
+
if (!(dim2 instanceof Dimension)) {
|
|
170
170
|
throw new Error(`Dimension.sub called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`);
|
|
171
171
|
}
|
|
172
172
|
if (this.dimVec_ && dim2.dimVec_) {
|
|
@@ -194,13 +194,13 @@ class Dimension {
|
|
|
194
194
|
* when a unit is raised to a power. This object's vector is changed unless
|
|
195
195
|
* the vector is null, in which case it stays that way.
|
|
196
196
|
*
|
|
197
|
-
* @param s the scalar to use
|
|
197
|
+
* @param s the integer scalar to use
|
|
198
198
|
* @return this object
|
|
199
|
-
* @throws an exception if s is not
|
|
199
|
+
* @throws an exception if s is not an integer
|
|
200
200
|
*/
|
|
201
201
|
mul(s) {
|
|
202
202
|
if (!isInteger(s)) {
|
|
203
|
-
throw new Error(`Dimension.
|
|
203
|
+
throw new Error(`Dimension.mul called with an invalid parameter - ` + `${typeof s} instead of an integer`);
|
|
204
204
|
}
|
|
205
205
|
if (this.dimVec_) {
|
|
206
206
|
for (let i = 0; i < UC.Ucum.dimLen_; i++) this.dimVec_[i] *= s;
|
|
@@ -219,7 +219,7 @@ class Dimension {
|
|
|
219
219
|
* @throws an exception if dim2 is not a Dimension object
|
|
220
220
|
*/
|
|
221
221
|
equals(dim2) {
|
|
222
|
-
if (!dim2 instanceof Dimension) {
|
|
222
|
+
if (!(dim2 instanceof Dimension)) {
|
|
223
223
|
throw new Error(`Dimension.equals called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`);
|
|
224
224
|
}
|
|
225
225
|
let isEqual = true;
|
|
@@ -245,7 +245,7 @@ class Dimension {
|
|
|
245
245
|
* @throws an exception if dim2 is not a Dimension object
|
|
246
246
|
*/
|
|
247
247
|
assignDim(dim2) {
|
|
248
|
-
if (!dim2 instanceof Dimension) {
|
|
248
|
+
if (!(dim2 instanceof Dimension)) {
|
|
249
249
|
throw new Error(`Dimension.assignDim called with an invalid parameter - ` + `${typeof dim2} instead of a Dimension object`);
|
|
250
250
|
}
|
|
251
251
|
if (dim2.dimVec_ === null) this.dimVec_ = null;else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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","exports"],"sources":["../source/dimension.js"],"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"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIA,EAAE,GAAGC,OAAO,CAAC,aAAa,CAAC;AAC/B,IAAIC,SAAS,GAAGD,OAAO,CAAC,YAAY,CAAC;AAC9B,MAAME,SAAS,CAAC;EAErB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EAEEC,WAAWA,CAACC,UAAU,EAAE;IAEtB,IAAIL,EAAE,CAACM,IAAI,CAACC,OAAO,KAAK,CAAC,EAAE;MACzB,MAAM,IAAIC,KAAK,CAAC,kDAAkD,GAClE,uBAAuB,CAAC;IAC1B;IACA,IAAIH,UAAU,KAAKI,SAAS,IAAIJ,UAAU,KAAK,IAAI,EAAE;MACnD,IAAI,CAACK,UAAU,CAAC,CAAC;IACnB,CAAC,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OAAQ,IAAI,CAAC3B,OAAO,KAAK,IAAI;EAC/B;;EAGA;AACF;AACA;AACA;AACA;EACE4B,KAAKA,CAAA,EAAG;IACN,IAAIC,IAAI,GAAG,IAAIzC,SAAS,CAAC,CAAC;IAC1ByC,IAAI,CAACL,SAAS,CAAC,IAAI,CAAC;IACpB,OAAOK,IAAI;EACb;AAEF,CAAC,CAAC;AAAAC,OAAA,CAAA1C,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"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","exports"],"sources":["../source/dimension.js"],"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 integer scalar to use\n * @return this object\n * @throws an exception if s is not an integer\n */\n mul(s) {\n if (!isInteger(s)) {\n throw(new Error(`Dimension.mul called with an invalid parameter - ` +\n `${typeof s} instead of an integer`));\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"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIA,EAAE,GAAGC,OAAO,CAAC,aAAa,CAAC;AAC/B,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IACtB;IACA,OAAO,IAAI;EACb;;EAGA;AACF;AACA;AACA;AACA;AACA;AACA;EACEuB,MAAMA,CAAA,EAAG;IACP,IAAIC,OAAO,GAAG,IAAI,CAAC1B,OAAO,KAAK,IAAI;IACnC,IAAI,IAAI,CAACA,OAAO,EAAE;MAChB,KAAK,IAAIgB,CAAC,GAAG,CAAC,EAAEU,OAAO,IAAIV,CAAC,GAAG/B,EAAE,CAACM,IAAI,CAACC,OAAO,EAAEwB,CAAC,EAAE,EACjDU,OAAO,GAAG,IAAI,CAAC1B,OAAO,CAACgB,CAAC,CAAC,KAAK,CAAC;IACnC;IACA,OAAOU,OAAO;EAChB;;EAGA;AACF;AACA;AACA;AACA;AACA;EACEC,MAAMA,CAAA,EAAG;IACP,OAAQ,IAAI,CAAC3B,OAAO,KAAK,IAAI;EAC/B;;EAGA;AACF;AACA;AACA;AACA;EACE4B,KAAKA,CAAA,EAAG;IACN,IAAIC,IAAI,GAAG,IAAIzC,SAAS,CAAC,CAAC;IAC1ByC,IAAI,CAACL,SAAS,CAAC,IAAI,CAAC;IACpB,OAAOK,IAAI;EACb;AAEF,CAAC,CAAC;AAAAC,OAAA,CAAA1C,SAAA,GAAAA,SAAA","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.PrefixTablesFactory = exports.PrefixTables = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* The tables of defined prefixes is defined in this file.
|
|
9
9
|
*/
|
|
@@ -120,10 +120,9 @@ class PrefixTablesFactory {
|
|
|
120
120
|
// provides that instance via getInstance().
|
|
121
121
|
exports.PrefixTablesFactory = PrefixTablesFactory;
|
|
122
122
|
var prefixTablesInstance = new PrefixTablesFactory();
|
|
123
|
-
const PrefixTables = {
|
|
123
|
+
const PrefixTables = exports.PrefixTables = {
|
|
124
124
|
getInstance: function () {
|
|
125
125
|
return prefixTablesInstance;
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
|
-
exports.PrefixTables = PrefixTables;
|
|
129
128
|
//# sourceMappingURL=prefixTables.js.map
|