@lhncbc/ucum-lhc 5.0.4 → 6.0.1
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 +15 -10
- package/browser-dist/ucum-lhc.js +326 -77
- package/data/ucumDefs.min.json +1 -1
- package/package.json +1 -1
- package/source/config.js +18 -0
- package/source/ucumLhcUtils.js +166 -83
- package/source/ucumXmlDocument.js +15 -1
- package/source/unit.js +140 -3
- package/source/unitString.js +11 -3
- package/source-cjs/config.js +12 -0
- package/source-cjs/config.js.map +1 -1
- package/source-cjs/ucumLhcUtils.js +155 -69
- package/source-cjs/ucumLhcUtils.js.map +1 -1
- package/source-cjs/ucumXmlDocument.js +15 -1
- package/source-cjs/ucumXmlDocument.js.map +1 -1
- package/source-cjs/unit.js +139 -3
- package/source-cjs/unit.js.map +1 -1
- package/source-cjs/unitString.js +12 -4
- package/source-cjs/unitString.js.map +1 -1
|
@@ -140,67 +140,141 @@ class UcumLhcUtils {
|
|
|
140
140
|
return retObj;
|
|
141
141
|
} // end validateUnitString
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* @typedef {
|
|
145
|
+
* 'normal',
|
|
146
|
+
* 'mol->mass',
|
|
147
|
+
* 'mass->mol',
|
|
148
|
+
* 'eq->mass',
|
|
149
|
+
* 'mass->eq',
|
|
150
|
+
* 'eq->mol',
|
|
151
|
+
* 'mol->eq',
|
|
152
|
+
* } ConversionType
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Detects the type of conversion between two units.
|
|
157
|
+
*
|
|
158
|
+
* @param {Object} fromUnit - The unit to convert from.
|
|
159
|
+
* @param {Object} toUnit - The unit to convert to.
|
|
160
|
+
* @returns {ConversionType} conversionType - The type of conversion as a string.
|
|
161
|
+
*/
|
|
162
|
+
detectConversionType(fromUnit, toUnit) {
|
|
163
|
+
/** @type {ConversionType} */
|
|
164
|
+
let conversionType = 'normal';
|
|
165
|
+
|
|
166
|
+
// detect mol <-> mass conversions and eq <-> eq conversions,
|
|
167
|
+
// and non-mol <-> eq <-> mass conversions
|
|
168
|
+
if (fromUnit.isMolarUnit() && toUnit.isMolarUnit() || fromUnit.isEquivalentUnit() && toUnit.isEquivalentUnit() || !(fromUnit.isMolarUnit() || toUnit.isMolarUnit()) && !(fromUnit.isEquivalentUnit() || toUnit.isEquivalentUnit())) {
|
|
169
|
+
conversionType = 'normal';
|
|
170
|
+
}
|
|
171
|
+
// handle eq <-> mol/mass conversions
|
|
172
|
+
else if (fromUnit.isEquivalentUnit()) {
|
|
173
|
+
conversionType = toUnit.isMolarUnit() ? 'eq->mol' : 'eq->mass';
|
|
174
|
+
} else if (toUnit.isEquivalentUnit()) {
|
|
175
|
+
conversionType = fromUnit.isMolarUnit() ? 'mol->eq' : 'mass->eq';
|
|
176
|
+
}
|
|
177
|
+
// handle mol <-> mass conversions
|
|
178
|
+
else if (fromUnit.isMolarUnit()) {
|
|
179
|
+
conversionType = 'mol->mass';
|
|
180
|
+
} else if (toUnit.isMolarUnit()) {
|
|
181
|
+
conversionType = 'mass->mol';
|
|
182
|
+
}
|
|
183
|
+
return conversionType;
|
|
184
|
+
} // end detectConversionType
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @typedef {{
|
|
188
|
+
* status: 'succeeded' | 'failed' | 'error',
|
|
189
|
+
* toVal: number | null,
|
|
190
|
+
* msg: string[],
|
|
191
|
+
* suggestions: {
|
|
192
|
+
* from: {
|
|
193
|
+
* msg: string,
|
|
194
|
+
* invalidUnit: string,
|
|
195
|
+
* units: string[]
|
|
196
|
+
* },
|
|
197
|
+
* to: {
|
|
198
|
+
* msg: string,
|
|
199
|
+
* invalidUnit: string,
|
|
200
|
+
* units: string[]
|
|
201
|
+
* }
|
|
202
|
+
* },
|
|
203
|
+
* fromUnit: string,
|
|
204
|
+
* toUnit: string
|
|
205
|
+
* }} ConvertUnitResult
|
|
206
|
+
*/
|
|
207
|
+
|
|
143
208
|
/**
|
|
144
209
|
* This method converts one unit to another
|
|
145
210
|
*
|
|
146
|
-
* @param fromUnitCode the unit code/expression/string of the unit to be converted
|
|
147
|
-
* @param fromVal the number of "from" units to be converted to "to" units
|
|
148
|
-
* @param toUnitCode the unit code/expression/string of the unit that the from
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* ignored if neither unit includes a measurement in moles.
|
|
158
|
-
*
|
|
159
|
-
*
|
|
211
|
+
* @param {string} fromUnitCode - the unit code/expression/string of the unit to be converted
|
|
212
|
+
* @param {number | string} fromVal - the number of "from" units to be converted to "to" units
|
|
213
|
+
* @param {string} toUnitCode - the unit code/expression/string of the unit that the from field is to be converted to
|
|
214
|
+
* @param {{
|
|
215
|
+
* suggest?: boolean,
|
|
216
|
+
* molecularWeight?: number
|
|
217
|
+
* charge?: number
|
|
218
|
+
* }} options
|
|
219
|
+
* - suggest: a boolean to indicate whether or not suggestions are requested for a string that cannot be resolved to a valid unit;
|
|
220
|
+
* true indicates suggestions are wanted; false indicates they are not, and is the default if the parameter is not specified;
|
|
221
|
+
* - molecularWeight: the molecular weight of the substance in question when a conversion is being requested from mass to moles and vice versa.
|
|
222
|
+
* This is required when one of the units represents a value in moles. It is ignored if neither unit includes a measurement in moles.
|
|
223
|
+
* - charge: the absolute value of the charge of the substance in question when a conversion is being requested from mass/moles to
|
|
224
|
+
* equivalents and vice versa. It is required when one of the units represents a value in equivalents and the other in mass or moles.
|
|
225
|
+
* It is ignored if neither unit includes an equivalent unit.
|
|
226
|
+
* @returns {ConvertUnitResult}
|
|
227
|
+
* - a hash with six elements:
|
|
228
|
+
* - 'status' that will be: 'succeeded' if the conversion was successfully
|
|
160
229
|
* calculated; 'failed' if the conversion could not be made, e.g., if
|
|
161
230
|
* the units are not commensurable; or 'error' if an error occurred;
|
|
162
|
-
*
|
|
231
|
+
* - 'toVal' the numeric value indicating the conversion amount, or null
|
|
163
232
|
* if the conversion failed (e.g., if the units are not commensurable);
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
233
|
+
* - 'msg' is an array message, if the string is invalid or an error occurred,
|
|
234
|
+
* indicating the problem, or an explanation of a substitution such as
|
|
235
|
+
* the substitution of 'G' for 'Gauss', or an empty array if no
|
|
236
|
+
* messages were generated;
|
|
237
|
+
* - 'suggestions' if suggestions were requested and found, this is a hash
|
|
169
238
|
* that contains at most two elements:
|
|
170
|
-
* 'from' which, if the fromUnitCode input parameter or one or more of
|
|
239
|
+
* - 'from' which, if the fromUnitCode input parameter or one or more of
|
|
171
240
|
* its components could not be found, is an array one or more hash
|
|
172
241
|
* objects. Each hash contains three elements:
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
242
|
+
* - 'msg' which is a message indicating what unit expression the
|
|
243
|
+
* suggestions are for;
|
|
244
|
+
* - 'invalidUnit' which is the unit expression the suggestions
|
|
245
|
+
* are for; and
|
|
246
|
+
* - 'units' which is an array of data for each suggested unit found.
|
|
247
|
+
* Each array will contain the unit code, the unit name and the
|
|
248
|
+
* unit guidance (if any).
|
|
180
249
|
* If no suggestions were found for the fromUnitCode this element
|
|
181
250
|
* will not be included.
|
|
182
|
-
* 'to' which, if the "to" unit expression or one or more of its
|
|
251
|
+
* - 'to' which, if the "to" unit expression or one or more of its
|
|
183
252
|
* components could not be found, is an array one or more hash objects. Each hash
|
|
184
253
|
* contains three elements:
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
254
|
+
* - 'msg' which is a message indicating what toUnitCode input
|
|
255
|
+
* parameter the suggestions are for;
|
|
256
|
+
* - 'invalidUnit' which is the unit expression the suggestions
|
|
257
|
+
* are for; and
|
|
258
|
+
* - 'units' which is an array of data for each suggested unit found.
|
|
259
|
+
* Each array will contain the unit code, the unit name and the
|
|
260
|
+
* unit guidance (if any).
|
|
192
261
|
* If no suggestions were found for the toUnitCode this element
|
|
193
262
|
* will not be included.
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
263
|
+
* No 'suggestions' element will be included in the returned hash
|
|
264
|
+
* object if none were found, whether or not they were requested.
|
|
265
|
+
* - 'fromUnit' the unit object for the fromUnitCode passed in; returned
|
|
197
266
|
* in case it's needed for additional data from the object; and
|
|
198
|
-
*
|
|
267
|
+
* - 'toUnit' the unit object for the toUnitCode passed in; returned
|
|
199
268
|
* in case it's needed for additional data from the object.
|
|
200
269
|
*/
|
|
201
|
-
convertUnitTo(fromUnitCode, fromVal, toUnitCode,
|
|
202
|
-
|
|
203
|
-
|
|
270
|
+
convertUnitTo(fromUnitCode, fromVal, toUnitCode, options = {}) {
|
|
271
|
+
let {
|
|
272
|
+
suggest = false,
|
|
273
|
+
molecularWeight = null,
|
|
274
|
+
charge = null
|
|
275
|
+
} = options;
|
|
276
|
+
|
|
277
|
+
/** @type {ConvertUnitResult} */
|
|
204
278
|
let returnObj = {
|
|
205
279
|
'status': 'failed',
|
|
206
280
|
'toVal': null,
|
|
@@ -247,32 +321,44 @@ class UcumLhcUtils {
|
|
|
247
321
|
}
|
|
248
322
|
if (fromUnit && toUnit) {
|
|
249
323
|
try {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
324
|
+
const convertType = this.detectConversionType(fromUnit, toUnit);
|
|
325
|
+
switch (convertType) {
|
|
326
|
+
case 'normal':
|
|
327
|
+
returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);
|
|
328
|
+
break;
|
|
329
|
+
case 'mol->mass':
|
|
330
|
+
case 'mass->mol':
|
|
331
|
+
if (!molecularWeight) {
|
|
332
|
+
throw new Error(Ucum.needMoleWeightMsg_);
|
|
333
|
+
}
|
|
334
|
+
if (!fromUnit.isMoleMassCommensurable(toUnit)) {
|
|
335
|
+
throw new Error(`Sorry. ${fromUnitCode} cannot be ` + `converted to ${toUnitCode}.`);
|
|
336
|
+
}
|
|
337
|
+
returnObj['toVal'] = convertType === "mol->mass" ? fromUnit.convertMolToMass(fromVal, toUnit, molecularWeight) : fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight);
|
|
338
|
+
break;
|
|
339
|
+
case 'eq->mass':
|
|
340
|
+
case 'mass->eq':
|
|
341
|
+
if (!molecularWeight) {
|
|
342
|
+
throw new Error(Ucum.needEqWeightMsg_);
|
|
343
|
+
}
|
|
344
|
+
if (!charge) {
|
|
345
|
+
throw new Error(Ucum.needEqChargeMsg_);
|
|
346
|
+
}
|
|
347
|
+
if (!fromUnit.isEqMassCommensurable(toUnit)) {
|
|
348
|
+
throw new Error(`Sorry. ${fromUnitCode} cannot be ` + `converted to ${toUnitCode}.`);
|
|
349
|
+
}
|
|
350
|
+
returnObj['toVal'] = convertType === "eq->mass" ? fromUnit.convertEqToMass(fromVal, toUnit, molecularWeight, charge) : fromUnit.convertMassToEq(fromVal, toUnit, molecularWeight, charge);
|
|
351
|
+
break;
|
|
352
|
+
case 'eq->mol':
|
|
353
|
+
case 'mol->eq':
|
|
354
|
+
if (!charge) {
|
|
355
|
+
throw new Error(Ucum.needEqChargeMsg_);
|
|
356
|
+
}
|
|
357
|
+
returnObj['toVal'] = convertType === "eq->mol" ? fromUnit.convertEqToMol(fromVal, toUnit, charge) : fromUnit.convertMolToEq(fromVal, toUnit, charge);
|
|
358
|
+
break;
|
|
359
|
+
default:
|
|
360
|
+
throw new Error("Unknown conversion type. No conversion was attempted.");
|
|
361
|
+
}
|
|
276
362
|
// if an error hasn't been thrown - either from convertFrom or here,
|
|
277
363
|
// set the return object to show success
|
|
278
364
|
returnObj['status'] = 'succeeded';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ucumLhcUtils.js","names":["_ucumJsonDefs","require","intUtils_","_interopRequireWildcard","_getRequireWildcardCache","WeakMap","cache","obj","__esModule","default","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","Ucum","UnitTables","UnitString","UcumLhcUtils","constructor","getInstance","unitsCount","ucumJsonDefs","loadJsonDefs","uStrParser_","useHTMLInMessages","use","undefined","useBraceMsgForEachString","validateUnitString","uStr","suggest","valConv","resp","getSpecifiedUnit","theUnit","retObj","csCode_","name_","guidance_","status","convertUnitTo","fromUnitCode","fromVal","toUnitCode","molecularWeight","returnObj","trim","push","_checkFromVal","fromUnit","parseResp","concat","toUnit","convertFrom","moleExp_","Error","isMoleMassCommensurable","convertMolToMass","convertMassToMol","err","message","needMoleWeightMsg_","convertToBaseUnits","inputUnitLookup","unit","msg","retMsg","length","isArbitrary_","unitToExp","dimVec","dim_","dimVec_","baseUnitString","dimVecIndexToBaseUnit","dimVecIndexToBaseUnit_","i","len","exp","retUnitLookup","retUnit","magnitude","e","toString","fromUnitIsSpecial","isSpecial_","responseObj","isNaN","isNumericString","checkSynonyms","theSyn","getSynonyms","uName","utab","getUnitByCode","parseString","console","log","unshift","origString","commensurablesList","fromName","commUnits","fromDim","getProperty","getUnitsByDimension","exports"],"sources":["../source/ucumLhcUtils.js"],"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 = !theUnit ? {'ucumCode': null} :\n {'ucumCode': resp['origString'],\n 'unit': {'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_ }};\n retObj.status = resp.status;\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 this._checkFromVal(fromVal, returnObj);\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 * Converts the given unit string into its base units, their exponents, and\n * a magnitude, and returns that data.\n * @param fromUnit the unit string to be converted to base units information\n * @param fromVal the number of \"from\" units to be converted\n * @returns an object with the properties:\n * 'status' indicates whether the result succeeded. The value will be one of:\n * 'succeeded': the conversion was successfully calculated (which can be\n * true even if it was already in base units);\n * 'invalid': fromUnit is not a valid UCUM code;\n * 'failed': the conversion could not be made (e.g., if it is an \"arbitrary\" unit);\n * 'error': if an error occurred (an input or programming error)\n * 'msg': an array of messages (possibly empty) if the string is invalid or\n * an error occurred, indicating the problem, or a suggestion of a\n * substitution such as the substitution of 'G' for 'Gauss', or\n * an empty array if no messages were generated. There can also be a\n * message that is just informational or warning.\n * 'magnitude': the new value when fromVal units of fromUnits is expressed in the base units.\n * 'fromUnitIsSpecial': whether the input unit fromUnit is a \"special unit\"\n * as defined in UCUM. This means there is some function applied to convert\n * between fromUnit and the base units, so the returned magnitude is likely not\n * useful as a scale factor for other conversions (i.e., it only has validity\n * and usefulness for the input values that produced it).\n * 'unitToExp': a map of base units in fromUnit to their exponent\n */\n convertToBaseUnits(fromUnit, fromVal) {\n let retObj = {};\n this._checkFromVal(fromVal, retObj);\n if (!retObj.status) { // could be set to 'error' by _checkFromVal\n let inputUnitLookup = this.getSpecifiedUnit(fromUnit, 'validate');\n retObj = {status: inputUnitLookup.status == 'valid' ? 'succeeded' : inputUnitLookup.status};\n let unit = inputUnitLookup.unit;\n retObj.msg = inputUnitLookup.retMsg || [];\n if (!unit) {\n if (inputUnitLookup.retMsg?.length == 0)\n retObj.msg.push('Could not find unit information for '+fromUnit);\n }\n else if (unit.isArbitrary_) {\n retObj.msg.push('Arbitrary units cannot be converted to base units or other units.');\n retObj.status = 'failed';\n }\n else if (retObj.status == 'succeeded') {\n let unitToExp = {};\n let dimVec = unit.dim_?.dimVec_\n let baseUnitString = '1';\n if (dimVec) {\n let dimVecIndexToBaseUnit = UnitTables.getInstance().dimVecIndexToBaseUnit_;\n for (let i=0, len=dimVec.length; i<len; ++i) {\n let exp = dimVec[i];\n if (exp) {\n unitToExp[dimVecIndexToBaseUnit[i]] = exp;\n baseUnitString += '.' + dimVecIndexToBaseUnit[i] + exp;\n }\n }\n }\n\n // The unit might have a conversion function, which has to be applied; we\n // cannot just assume unit_.magnitude_ is the magnitude in base units.\n let retUnitLookup = this.getSpecifiedUnit(baseUnitString, 'validate');\n // There should not be any error in retUnitLookup, unless there is a bug.\n let retUnit = retUnitLookup.unit;\n if (retUnitLookup.status !== 'valid') {\n retObj.msg.push('Unable construct base unit string; tried '+baseUnitString);\n retObj.status = 'error';\n }\n else {\n try {\n retObj.magnitude = retUnit.convertFrom(fromVal, unit);\n }\n catch (e) {\n retObj.msg.push(e.toString());\n retObj.status = 'error';\n }\n if (retObj.status == 'succeeded') {\n retObj.unitToExp = unitToExp;\n retObj.fromUnitIsSpecial = unit.isSpecial_;\n }\n }\n }\n }\n return retObj;\n }\n\n\n /**\n * Checks the given value as to whether it is suitable as a \"from\" value in a\n * unit conversion. If it is not, the responseObj will have its status set\n * to 'error' and a message added.\n * @param fromVal The value to check\n * @param responseObj the object that will be updated if the value is not\n * usable.\n */\n _checkFromVal(fromVal, responseObj) {\n if (fromVal === null || isNaN(fromVal) || (typeof fromVal !== 'number' &&\n !intUtils_.isNumericString(fromVal))) {\n responseObj.status = 'error';\n if (!responseObj.msg)\n responseObj.msg = [];\n responseObj.msg.push('No \"from\" value, or an invalid \"from\" value, ' +\n 'was specified.');\n }\n }\n\n\n /**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for\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 * 'status' will be 'valid' (uName 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 * '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 // Set the status field\n if (!retObj.unit) {\n // No unit was found; check whether origString has a value\n retObj.status = !retObj.origString ? 'error' : 'invalid';\n }\n else {\n // Check whether substitutions were made to the unit string in order to\n // find the unit\n retObj.status = retObj.origString === uName ? 'valid': 'invalid';\n }\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 */\nUcumLh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AC,iBAAiB,CAAC,CAACuB,UAAU;AACtD,IAAIC,UAAU,GAAGxB,OAAO,CAAC,iBAAiB,CAAC,CAACwB,UAAU;AAItD;AACA;AACA;AACO,MAAMC,YAAY,CAAC;EAExB;AACF;AACA;AACA;AACA;EACEC,WAAWA,CAAA,EAAG;IAEV,IAAIH,UAAU,CAACI,WAAW,CAAC,CAAC,CAACC,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE;MAE/C;MACAC,0BAAY,CAACC,YAAY,CAAC,CAAC;IAC7B;;IAEA;IACA;IACA,IAAI,CAACC,WAAW,GAAGP,UAAU,CAACG,WAAW,CAAC,CAAC;EAE/C,CAAC,CAAC;;EAGF;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEK,iBAAiBA,CAACC,GAAG,EAAE;IACrB,IAAIA,GAAG,KAAKC,SAAS,EACnBD,GAAG,GAAG,IAAI;IACZ,IAAI,CAACF,WAAW,CAACC,iBAAiB,CAACC,GAAG,CAAC;EACzC;;EAGA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEE,wBAAwBA,CAACF,GAAG,EAAE;IAC5B,IAAIA,GAAG,KAAKC,SAAS,EACnBD,GAAG,GAAG,IAAI;IACZ,IAAI,CAACF,WAAW,CAACI,wBAAwB,CAACF,GAAG,CAAC;EAChD;;EAGA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEG,kBAAkBA,CAACC,IAAI,EAAEC,OAAO,EAAEC,OAAO,EAAE;IAEzC,IAAID,OAAO,KAAKJ,SAAS,EACvBI,OAAO,GAAG,KAAK;IAEjB,IAAIC,OAAO,KAAKL,SAAS,EACvBK,O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;IACJ,CAAC,CAAC;IACF,OAAO,CAACgC,SAAS,EAAGpC,MAAM,CAAC;EAC7B,CAAC,CAAC;AAEJ,CAAC,CAAC;;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAbAwC,OAAA,CAAAzF,YAAA,GAAAA,YAAA;AAcAA,YAAY,CAACE,WAAW,GAAG,YAAU;EACnC,OAAO,IAAIF,YAAY,CAAC,CAAC;AAC3B,CAAC"}
|
|
1
|
+
{"version":3,"file":"ucumLhcUtils.js","names":["_ucumJsonDefs","require","intUtils_","_interopRequireWildcard","_getRequireWildcardCache","WeakMap","cache","obj","__esModule","default","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","Ucum","UnitTables","UnitString","UcumLhcUtils","constructor","getInstance","unitsCount","ucumJsonDefs","loadJsonDefs","uStrParser_","useHTMLInMessages","use","undefined","useBraceMsgForEachString","validateUnitString","uStr","suggest","valConv","resp","getSpecifiedUnit","theUnit","retObj","csCode_","name_","guidance_","status","detectConversionType","fromUnit","toUnit","conversionType","isMolarUnit","isEquivalentUnit","convertUnitTo","fromUnitCode","fromVal","toUnitCode","options","molecularWeight","charge","returnObj","trim","push","_checkFromVal","parseResp","concat","convertType","convertFrom","Error","needMoleWeightMsg_","isMoleMassCommensurable","convertMolToMass","convertMassToMol","needEqWeightMsg_","needEqChargeMsg_","isEqMassCommensurable","convertEqToMass","convertMassToEq","convertEqToMol","convertMolToEq","err","message","convertToBaseUnits","inputUnitLookup","unit","msg","retMsg","length","isArbitrary_","unitToExp","dimVec","dim_","dimVec_","baseUnitString","dimVecIndexToBaseUnit","dimVecIndexToBaseUnit_","i","len","exp","retUnitLookup","retUnit","magnitude","e","toString","fromUnitIsSpecial","isSpecial_","responseObj","isNaN","isNumericString","checkSynonyms","theSyn","getSynonyms","uName","utab","getUnitByCode","parseString","console","log","unshift","origString","commensurablesList","fromName","commUnits","fromDim","getProperty","getUnitsByDimension","exports"],"sources":["../source/ucumLhcUtils.js"],"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 = !theUnit ? {'ucumCode': null} :\n {'ucumCode': resp['origString'],\n 'unit': {'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_ }};\n retObj.status = resp.status;\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/**\n * @typedef {\n * 'normal', \n * 'mol->mass',\n * 'mass->mol',\n * 'eq->mass',\n * 'mass->eq',\n * 'eq->mol',\n * 'mol->eq',\n * } ConversionType\n */\n\n /**\n * Detects the type of conversion between two units.\n *\n * @param {Object} fromUnit - The unit to convert from.\n * @param {Object} toUnit - The unit to convert to.\n * @returns {ConversionType} conversionType - The type of conversion as a string.\n */\n detectConversionType(fromUnit, toUnit) {\n /** @type {ConversionType} */\n let conversionType = 'normal';\n\n // detect mol <-> mass conversions and eq <-> eq conversions,\n // and non-mol <-> eq <-> mass conversions\n if ((fromUnit.isMolarUnit() && toUnit.isMolarUnit()) || \n (fromUnit.isEquivalentUnit() && toUnit.isEquivalentUnit()) ||\n (!(fromUnit.isMolarUnit() || toUnit.isMolarUnit()) && \n !(fromUnit.isEquivalentUnit() || toUnit.isEquivalentUnit()))) {\n conversionType = 'normal';\n }\n // handle eq <-> mol/mass conversions\n else if (fromUnit.isEquivalentUnit()) {\n conversionType = toUnit.isMolarUnit() ? 'eq->mol' : 'eq->mass';\n } else if (toUnit.isEquivalentUnit()) {\n conversionType = fromUnit.isMolarUnit() ? 'mol->eq' : 'mass->eq';\n }\n // handle mol <-> mass conversions\n else if (fromUnit.isMolarUnit()) {\n conversionType = 'mol->mass';\n } else if (toUnit.isMolarUnit()) {\n conversionType = 'mass->mol';\n }\n\n return conversionType;\n } // end detectConversionType\n\n /** \n * @typedef {{\n * status: 'succeeded' | 'failed' | 'error',\n * toVal: number | null,\n * msg: string[],\n * suggestions: {\n * from: {\n * msg: string,\n * invalidUnit: string,\n * units: string[]\n * },\n * to: {\n * msg: string,\n * invalidUnit: string,\n * units: string[]\n * }\n * },\n * fromUnit: string,\n * toUnit: string\n * }} ConvertUnitResult\n */\n\n \n /**\n * This method converts one unit to another\n *\n * @param {string} fromUnitCode - the unit code/expression/string of the unit to be converted\n * @param {number | string} fromVal - the number of \"from\" units to be converted to \"to\" units\n * @param {string} toUnitCode - the unit code/expression/string of the unit that the from field is to be converted to\n * @param {{\n * suggest?: boolean,\n * molecularWeight?: number\n * charge?: number\n * }} options\n * - suggest: a boolean to indicate whether or not suggestions are requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not, and is the default if the parameter is not specified;\n * - molecularWeight: the molecular weight of the substance in question 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 ignored if neither unit includes a measurement in moles.\n * - charge: the absolute value of the charge of the substance in question when a conversion is being requested from mass/moles to\n * equivalents and vice versa. It is required when one of the units represents a value in equivalents and the other in mass or moles. \n * It is ignored if neither unit includes an equivalent unit.\n * @returns {ConvertUnitResult}\n * - 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, options = {}) {\n let { suggest = false, molecularWeight = null, charge = null } = options;\n\n /** @type {ConvertUnitResult} */\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 this._checkFromVal(fromVal, returnObj);\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 const convertType = this.detectConversionType(fromUnit, toUnit); \n\n switch (convertType) {\n case 'normal':\n returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);\n break;\n case 'mol->mass':\n case 'mass->mol':\n if (!molecularWeight) {\n throw new Error(Ucum.needMoleWeightMsg_);\n }\n if (!fromUnit.isMoleMassCommensurable(toUnit)) {\n throw new Error(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n }\n returnObj['toVal'] = convertType === \"mol->mass\" ?\n fromUnit.convertMolToMass(fromVal, toUnit, molecularWeight) :\n fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight);\n break;\n case 'eq->mass':\n case 'mass->eq':\n if (!molecularWeight) {\n throw new Error(Ucum.needEqWeightMsg_);\n }\n if (!charge) {\n throw new Error(Ucum.needEqChargeMsg_);\n }\n if (!fromUnit.isEqMassCommensurable(toUnit)) {\n throw new Error(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n }\n returnObj['toVal'] = convertType === \"eq->mass\" ?\n fromUnit.convertEqToMass(fromVal, toUnit, molecularWeight, charge) :\n fromUnit.convertMassToEq(fromVal, toUnit, molecularWeight, charge);\n break;\n case 'eq->mol':\n case 'mol->eq':\n if (!charge) {\n throw new Error(Ucum.needEqChargeMsg_);\n }\n returnObj['toVal'] = convertType === \"eq->mol\" ?\n fromUnit.convertEqToMol(fromVal, toUnit, charge) :\n fromUnit.convertMolToEq(fromVal, toUnit, charge);\n break;\n default:\n throw new Error(\"Unknown conversion type. No conversion was attempted.\");\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 } // 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 * Converts the given unit string into its base units, their exponents, and\n * a magnitude, and returns that data.\n * @param fromUnit the unit string to be converted to base units information\n * @param fromVal the number of \"from\" units to be converted\n * @returns an object with the properties:\n * 'status' indicates whether the result succeeded. The value will be one of:\n * 'succeeded': the conversion was successfully calculated (which can be\n * true even if it was already in base units);\n * 'invalid': fromUnit is not a valid UCUM code;\n * 'failed': the conversion could not be made (e.g., if it is an \"arbitrary\" unit);\n * 'error': if an error occurred (an input or programming error)\n * 'msg': an array of messages (possibly empty) if the string is invalid or\n * an error occurred, indicating the problem, or a suggestion of a\n * substitution such as the substitution of 'G' for 'Gauss', or\n * an empty array if no messages were generated. There can also be a\n * message that is just informational or warning.\n * 'magnitude': the new value when fromVal units of fromUnits is expressed in the base units.\n * 'fromUnitIsSpecial': whether the input unit fromUnit is a \"special unit\"\n * as defined in UCUM. This means there is some function applied to convert\n * between fromUnit and the base units, so the returned magnitude is likely not\n * useful as a scale factor for other conversions (i.e., it only has validity\n * and usefulness for the input values that produced it).\n * 'unitToExp': a map of base units in fromUnit to their exponent\n */\n convertToBaseUnits(fromUnit, fromVal) {\n let retObj = {};\n this._checkFromVal(fromVal, retObj);\n if (!retObj.status) { // could be set to 'error' by _checkFromVal\n let inputUnitLookup = this.getSpecifiedUnit(fromUnit, 'validate');\n retObj = {status: inputUnitLookup.status == 'valid' ? 'succeeded' : inputUnitLookup.status};\n let unit = inputUnitLookup.unit;\n retObj.msg = inputUnitLookup.retMsg || [];\n if (!unit) {\n if (inputUnitLookup.retMsg?.length == 0)\n retObj.msg.push('Could not find unit information for '+fromUnit);\n }\n else if (unit.isArbitrary_) {\n retObj.msg.push('Arbitrary units cannot be converted to base units or other units.');\n retObj.status = 'failed';\n }\n else if (retObj.status == 'succeeded') {\n let unitToExp = {};\n let dimVec = unit.dim_?.dimVec_\n let baseUnitString = '1';\n if (dimVec) {\n let dimVecIndexToBaseUnit = UnitTables.getInstance().dimVecIndexToBaseUnit_;\n for (let i=0, len=dimVec.length; i<len; ++i) {\n let exp = dimVec[i];\n if (exp) {\n unitToExp[dimVecIndexToBaseUnit[i]] = exp;\n baseUnitString += '.' + dimVecIndexToBaseUnit[i] + exp;\n }\n }\n }\n\n // The unit might have a conversion function, which has to be applied; we\n // cannot just assume unit_.magnitude_ is the magnitude in base units.\n let retUnitLookup = this.getSpecifiedUnit(baseUnitString, 'validate');\n // There should not be any error in retUnitLookup, unless there is a bug.\n let retUnit = retUnitLookup.unit;\n if (retUnitLookup.status !== 'valid') {\n retObj.msg.push('Unable construct base unit string; tried '+baseUnitString);\n retObj.status = 'error';\n }\n else {\n try {\n retObj.magnitude = retUnit.convertFrom(fromVal, unit);\n }\n catch (e) {\n retObj.msg.push(e.toString());\n retObj.status = 'error';\n }\n if (retObj.status == 'succeeded') {\n retObj.unitToExp = unitToExp;\n retObj.fromUnitIsSpecial = unit.isSpecial_;\n }\n }\n }\n }\n return retObj;\n }\n\n\n /**\n * Checks the given value as to whether it is suitable as a \"from\" value in a\n * unit conversion. If it is not, the responseObj will have its status set\n * to 'error' and a message added.\n * @param fromVal The value to check\n * @param responseObj the object that will be updated if the value is not\n * usable.\n */\n _checkFromVal(fromVal, responseObj) {\n if (fromVal === null || isNaN(fromVal) || (typeof fromVal !== 'number' &&\n !intUtils_.isNumericString(fromVal))) {\n responseObj.status = 'error';\n if (!responseObj.msg)\n responseObj.msg = [];\n responseObj.msg.push('No \"from\" value, or an invalid \"from\" value, ' +\n 'was specified.');\n }\n }\n\n\n /**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for\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 * 'status' will be 'valid' (uName 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 * '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 // Set the status field\n if (!retObj.unit) {\n // No unit was found; check whether origString has a value\n retObj.status = !retObj.origString ? 'error' : 'invalid';\n }\n else {\n // Check whether substitutions were made to the unit string in order to\n // find the unit\n retObj.status = retObj.origString === uName ? 'valid': 'invalid';\n }\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"],"mappings":";;;;;;AAOA,IAAAA,aAAA,GAAAC,OAAA;AAIA,IAAAC,SAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAoD,SAAAG,yBAAA,eAAAC,OAAA,kCAAAC,KAAA,OAAAD,OAAA,IAAAD,wBAAA,YAAAA,CAAA,WAAAE,KAAA,YAAAA,KAAA;AAAA,SAAAH,wBAAAI,GAAA,QAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAD,KAAA,GAAAF,wBAAA,QAAAE,KAAA,IAAAA,KAAA,CAAAI,GAAA,CAAAH,GAAA,YAAAD,KAAA,CAAAK,GAAA,CAAAJ,GAAA,SAAAK,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAV,GAAA,QAAAO,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAb,GAAA,EAAAU,GAAA,SAAAI,I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ACnCgG,SAAS,GAAGT,IAAI,CAACY,mBAAmB,CAACnC,MAAM,CAAC;QAC9C;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,CAACgC,SAAS,EAAGpC,MAAM,CAAC;EAC7B,CAAC,CAAC;AAEJ,CAAC,CAAC;;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAbAwC,OAAA,CAAAtG,YAAA,GAAAA,YAAA;AAcAA,YAAY,CAACE,WAAW,GAAG,YAAU;EACnC,OAAO,IAAIF,YAAY,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -46,7 +46,11 @@ class UcumXmlDocument {
|
|
|
46
46
|
// Creation of unit objects after this file is processed will pick up
|
|
47
47
|
// the moleExp_ value from the base mole unit, but the ones defined in
|
|
48
48
|
// this file will not necessarily do that.
|
|
49
|
-
this.moleCodes_ = ['mol', '
|
|
49
|
+
this.moleCodes_ = ['mol', 'osm', 'kat', 'U'];
|
|
50
|
+
// Works similarly to the moleCodes_ array, but for units that represents
|
|
51
|
+
// equivalent units. For unit codes in the equivCodes_ array, an equivalentExp_
|
|
52
|
+
// attribute flag will be set to 1.
|
|
53
|
+
this.equivCodes_ = ['eq'];
|
|
50
54
|
|
|
51
55
|
// Make this a singleton. See UnitTables constructor for details.
|
|
52
56
|
|
|
@@ -211,7 +215,17 @@ class UcumXmlDocument {
|
|
|
211
215
|
attrs['class_'] = curUA.attr.class;
|
|
212
216
|
}
|
|
213
217
|
let valNode = curUA.childNamed('value');
|
|
218
|
+
// Note: This currently works as a boolean flag,
|
|
219
|
+
// but it should be used to represent the dimensionality
|
|
220
|
+
// of the unit as an integer instead.
|
|
214
221
|
if (this.moleCodes_.indexOf(curUA.attr.Code) !== -1) attrs['moleExp_'] = 1;else attrs['moleExp_'] = 0;
|
|
222
|
+
// Adds a flag similar to how moleExp_ works, but for units
|
|
223
|
+
// that are equivalent. Note that ideally this should also
|
|
224
|
+
// take values other than 1 or 0, but for now it is a boolean
|
|
225
|
+
// flag.
|
|
226
|
+
if (this.equivCodes_.indexOf(curUA.attr.Code) !== -1) {
|
|
227
|
+
attrs['equivalentExp_'] = 1;
|
|
228
|
+
}
|
|
215
229
|
|
|
216
230
|
// Process special units
|
|
217
231
|
if (curUA.attr.isSpecial) {
|