@lhncbc/ucum-lhc 7.1.8 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"ucum-lhc.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAiB,QAAID,IAErBD,EAAc,QAAIC,GACnB,CATD,CASGK,KAAM,I,iCCPTH,EAAOD,QAAUK,OAAOC,UAAY,SAAUC,GAC7C,QAA0B,iBAAVA,GAAsBA,GAAUA,GAASA,IAAUC,KAAYD,KAAU,IAC1F,C,aCFA,IAAID,EAAWG,EAAQ,KACvBR,EAAOD,QAAUK,OAAOK,WAAa,SAASC,GAC5C,MAAsB,iBAARA,GACZL,EAASK,IACTC,KAAKC,MAAMF,KAASA,CACxB,C,0ECCeX,EAAAA,KAAG,CAgBhBc,QAAS,EAOTC,UAAW,CAAC,IAAK,KAOjBC,SAAW,KAGXC,aAAe,gBACfC,WAAa,IACbC,aAAe,wBACfC,WAAa,IAQbC,UAAY,MAOZC,WAAa,MAObC,cAAgB,2BAOhBC,eAAiB,WAMjBC,WAAa,sJASbC,mBAAqB,yJASrBC,iBAAmB,0HASnBC,iBAAmB,gHAQnBC,SAAW,CACT,sBAAwB,UACxB,iBAAmB,iBACnB,iBAAmB,QACnB,SAAa,YACb,OAAW,UACX,SAAa,YACb,SAAa,aAMfC,UAAY,sBASXC,WAAa,CAAE,WAAa,iBACb,kBAAoB,kB,0rBC7HtC,IAAIC,EAAKvB,EAAQ,KACbC,EAAYD,EAAQ,KACFT,EAAAA,EAAA,WAuBpB,SAAAiC,EAAYC,GAEV,G,4FAFsBC,CAAA,KAAAF,GAEE,IAApBD,EAAGI,KAAKtB,QACV,MAAM,IAAIuB,MAAM,yEAGlB,GAAI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2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBnf,IAAjBof,EACH,OAAOA,EAAa/iB,QAGrB,IAAIC,EAAS2iB,EAAyBE,GAAY,CAGjD9iB,QAAS,CAAC,GAOX,OAHAgjB,EAAoBF,GAAU7iB,EAAQA,EAAOD,QAAS6iB,GAG/C5iB,EAAOD,OACf,C,wHCfeA,EAAAA,KAAAA,EAAAA,KAAAA,KACQA,EAAAA,aAAAA,EAAAA,KAAAA,aACFA,EAAAA,WAAAA,EAAAA,KAAAA,U","sources":["webpack://ucumPkg/webpack/universalModuleDefinition","webpack://ucumPkg/./node_modules/is-finite/index.js","webpack://ucumPkg/./node_modules/is-integer/index.js","webpack://ucumPkg/./source/config.js","webpack://ucumPkg/./source/dimension.js","webpack://ucumPkg/./source/jsonArrayPack.js","webpack://ucumPkg/./source/prefix.js","webpack://ucumPkg/./source/prefixTables.js","webpack://ucumPkg/./source/ucumFunctions.js","webpack://ucumPkg/./source/ucumInternalUtils.js","webpack://ucumPkg/./source/ucumJsonDefs.js","webpack://ucumPkg/./source/ucumLhcUtils.js","webpack://ucumPkg/./source/unit.js","webpack://ucumPkg/./source/unitString.js","webpack://ucumPkg/./source/unitTables.js","webpack://ucumPkg/webpack/bootstrap","webpack://ucumPkg/./source/ucumPkg.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ucumPkg\"] = factory();\n\telse\n\t\troot[\"ucumPkg\"] = factory();\n})(this, () => {\nreturn ","'use strict';\n\nmodule.exports = Number.isFinite || function (value) {\n\treturn !(typeof value !== 'number' || value !== value || value === Infinity || value === -Infinity);\n};\n","// https://github.com/paulmillr/es6-shim\n// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isinteger\nvar isFinite = require(\"is-finite\");\nmodule.exports = Number.isInteger || function(val) {\n return typeof val === \"number\" &&\n isFinite(val) &&\n Math.floor(val) === val;\n};\n","/*\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","/**\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","/**\n * This file provides functions to reduce the size of an array of objects of the same structure in JSON.\n */\nconst pushFn = Array.prototype.push;\n\nfunction isObject(value) {\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\n/**\n * Makes human readable config used to pack/unpack array of objects of the same structure to store with packed data.\n * @param {Object} refObj - reference item of array of objects of the same structure\n * @returns {Array}\n */\nfunction createConfig(refObj) {\n return Object.keys(refObj).reduce((config, key) => {\n if (isObject(refObj[key])) {\n pushFn.apply(config, createConfig(refObj[key]).map(keyTail => [key, ...[].concat(keyTail)]));\n } else {\n config.push(key);\n }\n return config;\n }, [])\n}\n\n/**\n * Prepares config created with createConfig function to use in packItem/unpackItem functions.\n * @param {Array} config\n * @returns {Array}\n */\nfunction prepareConfig(config) {\n return config.map(key => Array.isArray(key) ? key : [key]);\n}\n\n/**\n * Converts an object to an array of values in the order of keys from configuration array.\n * @param {Array} config - configuration array\n * @param {Object} item - input object\n * @returns {Array}\n */\nfunction packItem(config, item) {\n if (config.join() !== prepareConfig(createConfig(item)).join()) {\n throw new Error('Object of unusual structure')\n }\n\n return config.map(keyArr => {\n let place = item;\n keyArr.forEach(key => {\n place = place[key];\n if (place === undefined) {\n throw new Error('Object of unusual structure')\n }\n });\n return place;\n });\n}\n\n/**\n * Performs the reverse of packItem function.\n * @param {Array} config - configuration array\n * @param {Array} item - input object\n * @returns {Object}\n */\nfunction unpackItem(config, item) {\n let result = {};\n\n config.forEach((keyArr, i) => {\n let place = result;\n for (let i = 0; i < keyArr.length - 1; i++) {\n place = place[keyArr[i]] = place[keyArr[i]] || {};\n }\n place[keyArr[keyArr.length - 1]] = item[i];\n });\n\n return result;\n}\n\n/**\n * Reduces size of an array of objects of the same structure before serialize it to JSON\n * @param {Array} arr\n * @returns {Object}\n */\nexport function packArray(arr) {\n if (arr && arr.length) {\n const config = createConfig(arr[0]),\n _config = prepareConfig(config);\n\n if (config.length) {\n return {\n config: config,\n data: arr.map(packItem.bind(null, _config))\n };\n }\n }\n\n return {\n config: [],\n data: arr\n };\n}\n\n/**\n * Restores an array of objects of the same structure after deserializing this object from JSON\n * @param {Object} obj\n * @returns {Array}\n */\nexport function unpackArray(obj) {\n const config = obj && obj.config;\n\n if (config) {\n if (config.length && obj.data) {\n const _config = prepareConfig(config);\n\n return obj.data.map(unpackItem.bind(null, _config));\n } else {\n return obj.data;\n }\n }\n\n return obj;\n}","/**\n * Prefix objects are defined in this file.\n */\n\n/**\n * This class implements the prefix object. Prefixes are used as multipliers\n * for units, e.g., km for kilometers\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nvar Ucum = require('./config.js');\n\nexport class Prefix {\n\n /**\n * Creates a single prefix object.\n *\n * @param attrs a hash of the values to use in creating the prefix object.\n * They should be:\n * code_ - which is the case-sensitive code used for the prefix,\n * e.g., k for kilo\n * ciCode_ - which is the case-insensitive code used for the prefix,\n * e.g., K for kilo\n * name_ - which is the name of the prefix, e.g., kilo\n * printSymbol_ - which is the print symbol for the prefix, e.g., k for kilo\n * value_ - which is teh value to use in multiplying the magnitude of\n * a unit, e.g., for a prefix of c the value will be .01.\n * exp_ - which is the exponent used to get the value. For decimal based\n * prefixes the base is 10 and the exp_ is applied to 10, e.g., for a\n * prefix of c, the exponent will be -2. For prefixes that are not\n * decimal based, this will be null (but must not be undefined).\n *\n * @throws an error if the not all required parameters are provided\n */\n constructor(attrs) {\n\n if (attrs['code_'] === undefined || attrs['code_'] === null ||\n attrs['name_'] === undefined || attrs['name_'] === null ||\n attrs['value_'] === undefined || attrs['value_'] === null ||\n attrs['exp_'] === undefined) {\n throw(new Error('Prefix constructor called missing one or more parameters. ' +\n 'Prefix codes (cs or ci), name, value and exponent must all be specified ' +\n 'and all but the exponent must not be null.'));\n }\n\n /**\n * The prefix code, e.g., k for kilo. This should be the case-sensitive\n * code. Since there's no way to check to see if it's the case-sensitive\n * one as opposed to the case-insensitive one (because although\n * case-insensitive codes all seem to be uppercase, some case-sensitive\n * codes are also all uppercase), we'll just have to believe that the\n * right one was passed in.\n */\n this.code_ = attrs['code_'];\n\n /**\n * The case-insensitive code, e.g., K for kilo\n */\n this.ciCode_ = attrs['ciCode_'];\n\n /**\n * The prefix name, e.g., kilo\n */\n this.name_ = attrs['name_'];\n\n /**\n * The printSymbol for the prefix, e.g., k for kilo\n */\n this.printSymbol_ = attrs['printSymbol_'];\n\n /**\n * The value to use in multiplying the magnitude of a unit\n */\n if (typeof attrs['value_'] === 'string')\n this.value_ = parseFloat(attrs['value_']);\n else\n this.value_ = attrs['value_'] ;\n\n /**\n * The exponent used to create the value from 10. For prefixes that are\n * not based on 10, this will be null.\n */\n this.exp_ = attrs['exp_'] ;\n\n } // end constructor\n\n\n /**\n * Returns the value for the current prefix object\n * @return the value for the prefix object with the specified code\n * */\n getValue() {\n return this.value_;\n }\n\n\n /**\n * Returns the prefix code for the current prefix object\n * @return the code for the current prefix object\n */\n getCode() {\n return this.code_;\n }\n\n\n /**\n * Returns the case-insensitive code for the current prefix object\n * @return the case_insensitive code for the current prefix object\n */\n getCiCode() {\n return this.ciCode_;\n }\n\n\n /**\n * Returns the prefix name for the current prefix object\n * @return the name for the current prefix object\n */\n getName() {\n return this.name_;\n }\n\n\n /**\n * Returns the print symbol for the current prefix object\n * @return the print symbol for the current prefix object\n */\n getPrintSymbol() {\n return this.printSymbol_;\n }\n\n\n /**\n * Returns the exponent for the current prefix object\n * @return the exponent for the current prefix object\n */\n getExp() {\n return this.exp_;\n }\n\n\n /**\n * Provides way to tell if one prefix equals another. The second prefix\n * must match all attribute values.\n *\n * @param prefix2 prefix object to check for a match\n * @return true for a match; false if one or more attributes don't match\n */\n equals(prefix2) {\n return this.code_ === prefix2.code_ &&\n this.ciCode_ === prefix2.ciCode_ &&\n this.name_ === prefix2.name_ &&\n this.printSymbol_ === prefix2.printSymbol_ &&\n this.value_ === prefix2.value_ &&\n this.exp_ === prefix2.exp_ ;\n }\n} // end Prefix class\n","/**\n * The tables of defined prefixes is defined in this file.\n */\n\n/**\n * This class implements the table of multiplier prefixes.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nexport class PrefixTablesFactory {\n\n /**\n * Constructor. This creates the empty PrefixTable hashes once.\n * There is one hash whose key is the prefix code and one whose\n * key is the prefix value.\n *\n * Implementation of this as a singleton is based on the UnitTables\n * implementation. See that class for details.\n */\n constructor(){\n this.byCode_ = {} ;\n this.byValue_ = {};\n }\n\n\n /**\n * Provides the number of prefix objects in each table\n * @returns count of the number of prefix objects in each table\n */\n prefixCount() {\n return Object.keys(this.byCode_).length ;\n }\n\n\n /**\n * This is used to get all prefix objects by value. Currently it is used\n * to create a csv file with all prefixes and units.\n * @returns csv string containing all prefix objects, ordered by value.\n */\n allPrefixesByValue() {\n let prefixBuff = '';\n let pList = Object.keys(this.byValue_);\n //pList.sort() ;\n let pLen = pList.length;\n for (let p = 0; p < pLen; p++) {\n let pfx = this.getPrefixByValue(pList[p]) ;\n prefixBuff += pfx.code_ + ',' + pfx.name_ + ',,' + pfx.value_ + '\\r\\n';\n }\n return prefixBuff ;\n }\n\n /**\n * This is used to get all prefix objects. Currently it is used\n * to get the objects to write to the json ucum definitions file\n * that is used to provide prefix and unit definition objects for\n * conversions and validations.\n *\n * @returns an array containing all prefix objects, ordered by code.\n */\n allPrefixesByCode() {\n let prefixList = [];\n let pList = Object.keys(this.byCode_);\n pList.sort() ;\n let pLen = pList.length;\n for (let p = 0; p < pLen; p++) {\n prefixList.push(this.getPrefixByCode(pList[p])) ;\n }\n return prefixList ;\n }\n\n /**\n * Adds a prefix object to the tables\n *\n * @param prefixObj the object to be added to the tables\n */\n add(prefixObj){\n this.byCode_[prefixObj.getCode()] = prefixObj;\n this.byValue_[prefixObj.getValue()] = prefixObj;\n }\n\n\n /**\n * Tests whether a prefix object is found for a specified code. This\n * is used to determine whether or not a prefix object has been created\n * for the code.\n *\n * @param code the code to be used to find the prefix object\n * @return boolean indicating whether or not a prefix object was found\n * for the specified code\n */\n isDefined(code) {\n return this.byCode_[code] !== null && this.byCode_[code] !== undefined ;\n }\n\n\n /**\n * Obtains a prefix object for a specified code.\n *\n * @param code the code to be used to find the prefix object\n * @return the prefix object found, or null if nothing was found\n */\n getPrefixByCode(code) {\n return this.byCode_[code];\n }\n\n\n /**\n * Obtains a prefix object for a specified value.\n *\n * @param value the value to be used to find the prefix object\n * @return the prefix object found, or null if nothing was found\n */\n getPrefixByValue(value) {\n return this.byValue_[value];\n }\n\n} // end PrefixTablesFactory class\n\n\n// Create a singleton instance and (to preserve the existing API) an object that\n// provides that instance via getInstance().\nvar prefixTablesInstance = new PrefixTablesFactory();\nexport const PrefixTables = {\n getInstance: function() {\n return prefixTablesInstance;\n }\n}\n","/*\n * This class manages the special functions used by some units.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nclass UcumFunctions {\n\n /**\n * Constructor\n *\n * Creates the singleton object that contains the list of functions used\n * to convert special units.\n */\n constructor() {\n\n // Create the hash containing the function pairs\n this.funcs = {};\n\n // Celsius - convert to Celsius from kelvin and from Celsius to kelvin\n // where kelvin is the base unit for temperature\n this.funcs['cel'] = {cnvTo : function(x){return x - 273.15;},\n cnvFrom : function(x){return x + 273.15;}};\n\n // Fahrenheit - convert to Fahrenheit from kelvin and from Fahrenheit to\n // kelvin - which is the base unit for temperature\n this.funcs['degf'] = {cnvTo : function(x){return x - 459.67;},\n cnvFrom : function(x){return x + 459.67;}};\n\n // Reaumur - convert between Reaumur and Kelvin. Because of the way the\n // calling code in the Units class is set up (in the convertFrom method),\n // what is given here as the convertTo function is actually the convert\n // from method and vice versa.\n //this.funcs['degre'] = {cnvTo : function(x){return x + 273.15;},\n // cnvFrom : function(x){return x - 273.15;}};\n this.funcs['degre'] = {cnvTo : function(x){return x - 273.15;},\n cnvFrom : function(x){return x + 273.15;}};\n\n // pH - convert to pH from moles per liter and from moles per liter to pH\n // where a mole is an amount of a substance (a count of particles)\n this.funcs['ph'] = {cnvTo : function(x){return - Math.log(x) / Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, -x);}};\n\n // ln - natural logarithm (base e 2.71828) - apply (cnvTo) and invert (cnvFrom)\n // and 2ln - two times the natural logarithm\n this.funcs['ln'] = {cnvTo : function(x){return Math.log(x);},\n cnvFrom : function(x){return Math.exp(x);}};\n this.funcs['2ln'] = {cnvTo : function(x){return 2 * Math.log(x);},\n cnvFrom : function(x){return Math.exp(x / 2);}};\n\n // lg - the decadic logarithm (base 10)\n this.funcs['lg'] = {cnvTo : function(x){return Math.log(x) / Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x);}};\n this.funcs['10lg'] = {cnvTo : function(x){return 10 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 10);}};\n this.funcs['20lg'] = {cnvTo : function(x){return 20 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 20);}};\n // The plain text ucum units file uses '2lg'\n this.funcs['2lg'] = {cnvTo : function(x){return 2 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 2);}};\n // The xml essence ucum file uses lgTimes2\n this.funcs['lgtimes2'] = this.funcs['2lg'];\n\n // ld - dual logarithm (base 2)\n this.funcs['ld'] = {cnvTo : function(x){return Math.log(x)/Math.LN2;},\n cnvFrom : function(x){return Math.pow(2, x);}};\n\n // tan - tangent\n this.funcs['100tan'] = {cnvTo : function(x){return Math.tan(x) * 100;},\n cnvFrom : function(x){return Math.atan(x/100);}};\n // the xml essence ucum file uses both 100tan and tanTimes100\n this.funcs['tanTimes100'] = this.funcs['100tan'] ;\n\n // sqrt - square root\n this.funcs['sqrt'] = {cnvTo : function(x){return Math.sqrt(x);},\n cnvFrom : function(x){return x*x;}};\n\n // inv - inverse\n this.funcs['inv'] = {cnvTo : function(x){return 1.0 / x;},\n cnvFrom : function(x){return 1.0 / x;}};\n\n // homeopathic potency functions\n this.funcs['hpX'] = {cnvTo : function(x){return -(this.funcs['lg'](x));},\n cnvFrom : function(x){return Math.pow(10, -x);}};\n\n this.funcs['hpC'] = {cnvTo : function(x){\n return -(this.func['ln'](x))/this.funcs['ln'](100);},\n cnvFrom : function(x){return Math.pow(100, -x);}};\n\n this.funcs['hpM'] = {cnvTo : function(x){\n return -(this.funcs['ln'](x))/this.funcs['ln'](1000);},\n cnvFrom : function(x){return Math.pow(1000, -x);}};\n\n this.funcs['hpQ'] = {cnvTo : function(x){\n return -(this.funcs['ln'](x))/this.funcs['ln'](50000);},\n cnvFrom : function(x){return Math.pow(50000, -x);}};\n\n } // end of constructor\n\n\n /**\n * Returns the function with the name specified\n *\n * @param fname name of the function to be returned\n * @return the function with the specified name\n * @throws an error message if the function is not found\n */\n forName(fname) {\n fname = fname.toLowerCase();\n\n let f = this.funcs[fname] ;\n if (f === null)\n throw(new Error(`Requested function ${fname} is not defined`));\n return f;\n }\n\n\n /**\n * Returns a flag indicating whether or not the function has been\n * defined.\n *\n * @param fname name of the function in question\n * @return true if it has been defined; false if not\n */\n isDefined(fname) {\n fname = fname.toLowerCase();\n return this.funcs[fname] !== null;\n }\n\n} // end of UcumFunctions class\n\nexport default new UcumFunctions(); // one singleton instance\n","/**\n * Internal utilities used by multiple UCUM classes. For example,\n * isNumericString is used by both the UnitString and UcumLhcUtils\n * classes. If it's in the UnitString class the UcumLhcUtils class\n * needs to require the UnitString class. But the checkSynonyms\n * class is used by the UnitString class - but was in the UcumLhcUtils\n * class. Requiring the UcumLhcUtils class from the UnitString class\n * made everything break (cyclical requires).\n *\n * So now they're here.\n */\n\n/**\n * This module implements internal ucum utilities.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar UnitTables = require('./unitTables.js').UnitTables ;\n\n\n/**\n * This function tests a string to see if it contains only numbers (digits,\n * a period, leading - or +). This code was taken from a stackoverflow\n * solution:\n * https://stackoverflow.com/questions/175739/is-there-a-built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number/42356340#42356340\n *\n * @params theString\n * @returns true if the string contains only numbers; false otherwise\n */\nexport function isNumericString(theString) {\n let num = \"\" + theString; //coerce num to be a string\n return !isNaN(num) && !isNaN(parseFloat(num));\n} // end isNumericString\n\n\n/**\n * Checks whether a string qualifies as an integer unit. Section 2.2.8 (\"integer\n * numbers\", says, \"A positive integer number may appear in place of a simple\n * unit symbol. Only a pure string of decimal digits (‘0’–‘9’) is\n * interpreted as a number.\"\n * Note: This leaves open the question of whether \"0\" is a valid unit, since\n * it is positive, but you can't measure anything in units of zero.\n * @param str the string to check\n */\nexport function isIntegerUnit(str) {\n return /^\\d+$/.test(str);\n}\n\n\n/**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for. This is assumed to be\n * a string and not undefined. The calling method should do any\n * necessary checking before calling this.\n * @returns a hash with up to three elements:\n * 'status' contains the status of the request, which can be 'error',\n * 'failed' or succeeded';\n * 'msg' which contains a message for an error or if no units were found; and\n * 'units' which is an array that contains one array for each unit found:\n * the unit's csCode_, the unit's name_, and the unit's guidance_\n *\n */\nexport function getSynonyms(theSyn) {\n\n let retObj = {} ;\n let utab = UnitTables.getInstance();\n let resp = {} ;\n resp = utab.getUnitBySynonym(theSyn);\n\n // If we didn't get any units, transfer the status and message\n if (!resp['units']) {\n retObj['status'] = resp['status'];\n retObj['msg'] = resp['msg'];\n }\n else {\n retObj['status'] = 'succeeded';\n let aLen = resp['units'].length ;\n retObj['units'] = [];\n for (let a = 0; a < aLen; a++) {\n let theUnit = resp['units'][a];\n retObj['units'][a] = {\n 'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_};\n } // end do for all units returned\n } // end if we got a units list\n return retObj ;\n\n} // end getSynonyms\n\n","/**\n * This class handles opening, reading and loading the JSON file of ucum\n * definitions (prefixes, base units, and unit atoms).\n *\n * @author Lee Mericle\n *\n */\n\nvar Pfx = require(\"./prefix.js\");\nvar PfxT = require(\"./prefixTables.js\");\nvar Un = require(\"./unit.js\");\nvar Utab = require('./unitTables.js');\nvar unpackArray = require('./jsonArrayPack.js').unpackArray;\n\nexport class UcumJsonDefs {\n\n /**\n * This method loads the JSON prefix and unit objects into the prefix and\n * unit tables.\n *\n * @returns nothing\n */\n loadJsonDefs() {\n // requiring the file will take care of opening it for use\n const jsonDefs = require('../data/ucumDefs.min.json');\n jsonDefs.prefixes = unpackArray(jsonDefs.prefixes);\n jsonDefs.units = unpackArray(jsonDefs.units);\n\n if (Utab.UnitTables.getInstance().unitsCount() === 0) {\n\n let pTab = PfxT.PrefixTables.getInstance();\n let prefixes = jsonDefs[\"prefixes\"];\n let plen = prefixes.length;\n\n for (let p = 0; p < plen; p++) {\n let newPref = new Pfx.Prefix(prefixes[p]);\n pTab.add(newPref);\n }\n\n let uTab = Utab.UnitTables.getInstance();\n let units = jsonDefs[\"units\"];\n let ulen = units.length;\n\n for (let u = 0; u < ulen; u++) {\n let newUnit = new Un.Unit(units[u]);\n uTab.addUnit(newUnit);\n }\n } // end if the data has not already been loaded\n } // end loadJsonDefs\n\n} // end UcumJsonDefs class\n\nvar ucumJsonDefs = new UcumJsonDefs();\nexport {ucumJsonDefs};\n","/**\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 // Get a copy of the mass dimension index.\n this.massDimIndex_ = UnitTables.getInstance().getMassDimensionIndex();\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// Note that below when the value of ConversionType is mol|mass, it refers to\n// either a conversion from mol to mass or from mass to mol.\n/**\n * @typedef {\n * 'normal',\n * 'mol|mass',\n * 'eq|mass',\n * 'eq|mol',\n * 'eq|mol|mass'\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;\n if (fromUnit.moleExp_ == toUnit.moleExp_ &&\n fromUnit.equivalentExp_ == toUnit.equivalentExp_) {\n // Since the powers of the equivalents and mole in the units are the same in both\n // units, no conversion is going to happen between mass, mol, and eq.\n // There is the possibility that someone is trying to convert 'g' to 'g2',\n // but we will handle that as the \"normal\" case (and later find it invalid).\n conversionType = 'normal';\n }\n else if (fromUnit.equivalentExp_ == toUnit.equivalentExp_) {\n // In this case, the units have the same power of equivalents, so (because\n // it is not the first case) the units have different powers of mol and mass,\n // so this must be a conversion between mol and mass.\n conversionType = 'mol|mass';\n }\n else if (fromUnit.moleExp_ == toUnit.moleExp_) {\n // In this case, the units have the same power of mol, so (because\n // it is not the first case) the units have different powers of equivalents and mass,\n // so this must be a conversion between equivalents and mass.\n conversionType = 'eq|mass';\n }\n else if (fromUnit.dim_.getElementAt(this.massDimIndex_) ==\n toUnit.dim_.getElementAt(this.massDimIndex_)) {\n // In this case, the units have the same power of mass, so (because\n // it is not the first case) the units have different powers of equivalents and mol,\n // so this must be a conversion between equivalents and moles.\n conversionType = 'eq|mol';\n }\n else {\n // In this case, the units have different powers of mass, mol, and\n // equivalents, so there is a conversion between mass, mol, and\n // equivalents.\n conversionType = 'eq|mol|mass';\n }\n\n return conversionType;\n } // end detectConversionType\n\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 = {\n 'status': 'failed',\n 'toVal': null,\n 'msg': []\n };\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 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 const convertType = this.detectConversionType(fromUnit, toUnit);\n const msgCountBeforeConvert = returnObj['msg'].length;\n switch (convertType) {\n case 'normal':\n try {\n returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);\n } catch (err) {\n returnObj['msg'].push(err.message);\n }\n break;\n case 'mol|mass':\n if (!fromUnit.isMolMassCommensurable(toUnit)) {\n returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n break;\n }\n if (!molecularWeight) {\n returnObj['msg'].push(Ucum.needMoleWeightMsg_);\n break;\n }\n returnObj['toVal'] = fromUnit.convertMolMass(fromVal, toUnit, molecularWeight);\n break;\n case 'eq|mass':\n if (!fromUnit.isEqMassCommensurable(toUnit)) {\n returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n break;\n }\n if (!molecularWeight) {\n returnObj['msg'].push(Ucum.needEqWeightMsg_);\n }\n if (!charge) {\n returnObj['msg'].push(Ucum.needEqChargeMsg_);\n }\n if (!returnObj['msg'].length) {\n returnObj['toVal'] = fromUnit.convertEqMass(fromVal, toUnit, molecularWeight, charge);\n }\n break;\n case 'eq|mol':\n if (!fromUnit.isEqMolCommensurable(toUnit)) {\n returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n break;\n }\n if (!charge) {\n returnObj['msg'].push(Ucum.needEqChargeMsg_);\n break;\n }\n returnObj['toVal'] = fromUnit.convertEqMol(fromVal, toUnit, charge);\n break;\n case 'eq|mol|mass':\n if (!fromUnit.isEqMolMassCommensurable(toUnit)) {\n returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n break;\n }\n if (!molecularWeight) {\n returnObj['msg'].push(Ucum.needEqWeightMsg_);\n }\n if (!charge) {\n returnObj['msg'].push(Ucum.needEqChargeMsg_);\n }\n if (!returnObj['msg'].length) {\n returnObj['toVal'] = fromUnit.convertEqMolMass(fromVal, toUnit, molecularWeight, charge);\n }\n break;\n default:\n returnObj['msg'].push(\"Unknown conversion type. No conversion was attempted.\");\n }\n if (returnObj['msg'].length > msgCountBeforeConvert) {\n // If one or more failure messages are pushed into returnObj['msg']\n // in the switch statement, mark the status as 'failed'.\n returnObj['status'] = 'failed';\n } else {\n // Set the return object to show success.\n returnObj['status'] = 'succeeded';\n returnObj['fromUnit'] = fromUnit;\n returnObj['toUnit'] = toUnit;\n }\n } // end if we have the from and to units\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. If necessary, you can filter the list of units by\n * specifying a list of unit categories that should be in the resulting list.\n *\n * @param {string} fromName - the name/unit string of the \"from\" unit\n * @param {string[] | null} [categoryList] - the list of unit categories;\n * this parameter is optional, defaults to null if not specified;\n * possible list values: 'Clinical', 'Nonclinical', 'Obsolete', 'Constant'\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, categoryList = null) {\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 if (categoryList) {\n commUnits = commUnits.filter((item) => {\n return categoryList.indexOf(item.category_) !== -1;\n });\n }\n }\n } // end if the from unit has a dimension vector\n } // end if we found a \"from\" unit\n return [commUnits , retMsg];\n } // end commensurablesList\n\n} // end UcumLhcUtils class\n\n\n/**\n * This function exists ONLY until the original UcumLhcUtils constructor\n * is called for the first time. It's defined here in case getInstance\n * is called before the constructor. This calls the constructor.\n *\n * The constructor redefines the getInstance function to return the\n * singleton UcumLhcUtils object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * NO LONGER TRUE - not implemented as a singleton. This method retained to\n * avoid problems with calls to it that exist throughout the code.\n *\n * @return the (formerly singleton) UcumLhcUtils object.\n */\nUcumLhcUtils.getInstance = function(){\n return new UcumLhcUtils();\n} ;\n","\n/**\n * This class represents one unit of measure. It includes\n * functions to cover constructor, accessor, and assignment tasks as\n * well as operators to calculate multiplication, division and raising\n * to a power.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nvar Ucum = require('./config.js').Ucum;\nvar Dimension = require('./dimension.js').Dimension;\nimport funcs from \"./ucumFunctions.js\";\nvar UnitTables;\n\nvar isInteger = require(\"is-integer\");\nimport * as intUtils_ from \"./ucumInternalUtils.js\";\n\nexport class Unit {\n\n /**\n * Constructor.\n *\n * @param attrs an optional parameter that may be:\n * a string, which is parsed by the unit parser, which creates\n * the unit from the parsed string; or\n * a hash containing all or some values for the attributes of\n * the unit, where the keys are the attribute names, without a\n * trailing underscore, e.g., name instead of name_; or\n * null, in which case an empty hash is created and used to\n * set the values forthe attributes.\n * If a hash (empty or not) is used, attributes for which no value\n * is specified are assigned a default value.\n *\n */\n constructor(attrs = {}) {\n\n // Process the attrs hash passed in, which may be empty.\n // Create and assign values (from the attrs hash or defaults) to all\n // attributes. From Class Declarations in Understanding ECMAScript,\n // https://leanpub.com/understandinges6/read/#leanpub-auto-class-declarations,\n // \"Own properties, properties that occur on the instance rather than the\n // prototype, can only be created inside of a class constructor or method.\n // It's recommended to create all possible own properties inside of the\n // constructor function so there's a single place that's responsible for\n // all of them.\"\n\n /*\n * Flag indicating whether or not this is a base unit\n */\n this.isBase_ = attrs['isBase_'] || false ;\n\n /*\n * The unit name, e.g., meter\n */\n this.name_ = attrs['name_'] || '';\n\n /*\n * The unit's case-sensitive code, e.g., m\n */\n this.csCode_ = attrs['csCode_'] || '';\n\n /*\n * The unit's case-insensitive code, e.g., M\n */\n this.ciCode_ = attrs['ciCode_'] || '';\n\n /*\n * The unit's property, e.g., length\n */\n this.property_ = attrs['property_'] || '';\n\n /*\n * The magnitude of the unit, e.g., 3600/3937 for a yard,\n * where a yard - 3600/3973 * m(eter). The Dimension\n * property specifies the meter - which is the unit on which\n * a yard is based, and this magnitude specifies how to figure\n * this unit based on the base unit.\n */\n this.magnitude_ = attrs['magnitude_'] || 1;\n\n /*\n * The Dimension object of the unit\n */\n if (attrs['dim_'] === undefined || attrs['dim_'] === null) {\n this.dim_ = new Dimension();\n }\n // When the unit data stored in json format is reloaded, the dimension data\n // is recognized as a a hash, not as a Dimension object.\n else if (attrs['dim_']['dimVec_'] !== undefined) {\n this.dim_ = new Dimension(attrs['dim_']['dimVec_']) ;\n }\n else if (attrs['dim_'] instanceof Dimension) {\n this.dim_ = attrs['dim_'];\n }\n else if (attrs['dim_'] instanceof Array || isInteger(attrs['dim_'])) {\n this.dim_ = new Dimension(attrs['dim_']) ;\n }\n else {\n this.dim_ = new Dimension();\n }\n /*\n * The print symbol of the unit, e.g., m\n */\n this.printSymbol_ = attrs['printSymbol_'] || null;\n\n /*\n * The class of the unit, where given, e.g., dimless\n */\n this.class_ = attrs['class_'] || null;\n\n /*\n * A flag indicating whether or not the unit is metric\n */\n this.isMetric_ = attrs['isMetric_'] || false;\n\n /*\n * The \"variable\" - which I think is used only for base units\n * The symbol for the variable as used in equations, e.g., s for distance\n */\n this.variable_ = attrs['variable_'] || null ; // comes from 'dim' in XML\n\n /*\n * The conversion function\n */\n this.cnv_ = attrs['cnv_'] || null;\n\n /*\n * The conversion prefix\n */\n this.cnvPfx_ = attrs['cnvPfx_'] || 1;\n\n /*\n * Flag indicating whether or not this is a \"special\" unit, i.e., is\n * constructed using a function specific to the measurement, e.g.,\n * fahrenheit and celsius\n */\n this.isSpecial_ = attrs['isSpecial_'] || false ;\n\n /*\n * Flag indicating whether or not this is an arbitrary unit\n */\n this.isArbitrary_ = attrs['isArbitrary_'] || false;\n\n /*\n * Integer indicating what level of exponent applies to a mole-based portion\n * of the unit. So, for the unit \"mol\", this will be 1. For \"mol2\" this\n * will be 2. For \"1/mol\" this will be -1. Any unit that does not include\n * a mole will have a 0 in this field. This is used to determine\n * commensurability for mole<->mass conversions.\n */\n this.moleExp_ = attrs['moleExp_'] || 0;\n\n /**\n * Flag indicating whether or not this is a equivalent mole unit\n */\n this.equivalentExp_ = attrs['equivalentExp_'] || 0;\n\n /*\n * Added when added LOINC list of units\n * synonyms are used by the autocompleter to enhance lookup capabilities\n * while source says where the unit first shows up. Current sources are\n * UCUM - which are units from the https://ucum.org/ucum specification and LOINC -\n * which are units from the LOINC data.\n */\n this.synonyms_ = attrs['synonyms_'] || null ;\n this.source_ = attrs['source_'] || null ;\n this.loincProperty_ = attrs['loincProperty_'] || null;\n this.category_ = attrs['category_'] || null;\n this.guidance_ = attrs['guidance_'] || null;\n\n /*\n * Used to compute dimension; storing for now until I complete\n * unit definition parsing\n */\n /*\n * Case sensitive (cs) and case insensitive (ci) base unit strings,\n * includes exponent and prefix if applicable - specified in\n * <value Unit=x UNIT=X value=\"nnn\">nnn</value> -- the unit part --\n * in the ucum-essence.xml file, and may be specified by a user\n * when requesting conversion or validation of a unit string. The\n * magnitude (base factor) is used with this to determine the new unit.\n * For example, a Newton (unit code N) is created from the string\n * kg.m/s2, and the value of 1 (base factor defined below). An hour\n * (unit code h) is created from the unit min (minute) with a value\n * of 60.\n */\n this.csUnitString_ = attrs['csUnitString_'] || null ;\n this.ciUnitString_ = attrs['ciUnitString_'] || null ;\n\n /*\n * String and numeric versions of factor applied to unit specified in\n * <value Unit=x UNIT=X value=\"nnn\">nnn</value> -- the value part\n */\n this.baseFactorStr_ = attrs['baseFactorStr_'] || null;\n this.baseFactor_ = attrs['baseFactor_'] || null;\n\n /*\n * Flag used to indicate units where the definition process failed\n * when parsing units from the official units definitions file\n * (currently using the ucum-essence.xml file). We keep these\n * so that we can use them to at least validate them as valid\n * units, but we don't try to convert them. This is temporary\n * and only to account for instances where the code does not\n * take into account various special cases in the xml file.\n *\n * This is NOT used when trying to validate a unit string\n * submitted during a conversion or validation attempt.\n */\n this.defError_ = attrs['defError_'] || false ;\n\n\n } // end constructor\n\n\n /**\n * Assign the unity (= dimensionless unit 1) to this unit.\n *\n * @return this unit\n */\n assignUnity() {\n this.name_ = \"\" ;\n this.magnitude_ = 1 ;\n if (!this.dim_)\n this.dim_ = new Dimension();\n this.dim_.assignZero() ;\n this.cnv_ = null ;\n this.cnvPfx_ = 1 ;\n return this;\n\n } // end assignUnity\n\n\n /**\n * This assigns one or more values, as provided in the hash passed in,\n * to this unit.\n *\n * @param vals hash of values to be assigned to the attributes\n * specified by the key(s), which should be the attribute\n * name without the trailing underscore, e.g., name instead\n * of name_.\n * @return nothing\n */\n assignVals(vals) {\n for (let key in vals) {\n let uKey = !(key.charAt(key.length - 1)) === '_' ? key + '_' : key ;\n if (this.hasOwnProperty(uKey))\n this[uKey] = vals[key];\n else\n throw(new Error(`Parameter error; ${key} is not a property of a Unit`));\n }\n } // end assignVals\n\n\n /**\n * This creates a clone of this unit.\n *\n * @return the clone\n */\n clone() {\n let retUnit = new Unit() ;\n Object.getOwnPropertyNames(this).forEach(val => {\n if (val === 'dim_') {\n if (this['dim_'])\n retUnit['dim_'] = this['dim_'].clone();\n else\n retUnit['dim_'] = null;\n }\n else\n retUnit[val] = this[val];\n });\n return retUnit ;\n\n } // end clone\n\n\n /**\n * This assigns all properties of a unit passed to it to this unit.\n *\n * @param unit2 the unit whose properties are to be assigned to this one.\n * @return nothing; this unit is updated\n */\n assign(unit2) {\n Object.getOwnPropertyNames(unit2).forEach(val => {\n if (val === 'dim_') {\n if (unit2['dim_'])\n this['dim_'] = unit2['dim_'].clone();\n else\n this['dim_'] = null;\n }\n else {\n this[val] = unit2[val];\n }\n });\n } // end assign\n\n\n /**\n * This determines whether or not object properties of the unit\n * passed in are equal to the corresponding properties in this unit.\n * The following properties are the only ones checked:\n * magnitude_, dim_, cnv_ and cnvPfx_\n *\n * @param unit2 the unit whose properties are to be checked.\n * @return boolean indicating whether or not they match\n */\n equals(unit2) {\n\n return (this.magnitude_ === unit2.magnitude_ &&\n this.cnv_ === unit2.cnv_ &&\n this.cnvPfx_ === unit2.cnvPfx_ &&\n ((this.dim_ === null && unit2.dim_ === null) ||\n this.dim_.equals(unit2.dim_)));\n\n } // end equals\n\n\n /**\n * This method compares every attribute of two objects to determine\n * if they all match.\n *\n * @param unit2 the unit that is to be compared to this unit\n * @return boolean indicating whether or not every attribute matches\n */\n fullEquals(unit2) {\n\n let thisAttr = Object.keys(this).sort();\n let u2Attr = Object.keys(unit2).sort();\n\n let keyLen = thisAttr.length ;\n let match = (keyLen === u2Attr.length);\n\n // check each attribute. Dimension objects have to checked using\n // the equals function of the Dimension class.\n for (let k = 0; k < keyLen && match; k++) {\n if (thisAttr[k] === u2Attr[k]) {\n if (thisAttr[k] === 'dim_')\n match = this.dim_.equals(unit2.dim_);\n else\n match = this[thisAttr[k]] === unit2[thisAttr[k]];\n }\n else\n match = false ;\n } // end do for each key and attribute\n return match ;\n }// end of fullEquals\n\n\n /**\n * This returns the value of the property named by the parameter\n * passed in.\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 unit\n * @throws an error if the property is not found for this unit\n */\n getProperty(propertyName) {\n let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName :\n propertyName + '_' ;\n return this[uProp] ;\n\n } // end getProperty\n\n\n /**\n * Takes a measurement consisting of a number of units and a unit and returns\n * the equivalent number of this unit. So, 15 mL would translate\n * to 1 tablespoon if this object is a tablespoon.\n *\n * Note that the number returned may not be what is normally expected.\n * For example, converting 10 Celsius units to Fahrenheit would \"normally\"\n * return a value of 50. But in this case you'll get back something like\n * 49.99999999999994.\n *\n * If either unit is an arbitrary unit an exception is raised.\n *\n * @param num the magnitude for the unit to be translated (e.g. 15 for 15 mL)\n * @param fromUnit the unit to be translated to one of this type (e.g. a mL unit)\n *\n * @return the number of converted units (e.g. 1 for 1 tablespoon)\n * @throws an error if the dimension of the fromUnit differs from this unit's\n * dimension\n */\n convertFrom(num, fromUnit) {\n let newNum = 0.0 ;\n\n if (this.isArbitrary_)\n throw (new Error(`Attempt to convert to arbitrary unit \"${this.csCode_}\"`));\n if (fromUnit.isArbitrary_)\n throw (new Error(`Attempt to convert arbitrary unit \"${fromUnit.csCode_}\"`));\n\n // reject request if both units have dimensions that are not equal\n if (fromUnit.dim_ && this.dim_ && !(fromUnit.dim_.equals(this.dim_))) {\n // check first to see if a mole<->mass conversion is appropriate\n if (this.isMolMassCommensurable(fromUnit)) {\n throw(new Error(Ucum.needMoleWeightMsg_));\n }\n else {\n throw(new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` +\n `to ${this.csCode_}.`));\n }\n }\n // reject request if there is a \"from\" dimension but no \"to\" dimension\n if (fromUnit.dim_ && (!this.dim_ || this.dim_.isNull())) {\n throw(new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` +\n `to ${this.csCode_}.`));\n }\n\n // reject request if there is a \"to\" dimension but no \"from\" dimension\n if (this.dim_ && (!fromUnit.dim_ || fromUnit.dim_.isNull())) {\n throw(new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` +\n `to ${this.csCode_}.`));\n }\n\n let fromCnv = fromUnit.cnv_ ;\n let fromMag = fromUnit.magnitude_ ;\n\n let x;\n if (fromCnv != null) {\n // turn num * fromUnit.magnitude into its ratio scale equivalent,\n // e.g., convert Celsius to Kelvin\n let fromFunc = funcs.forName(fromCnv);\n x = fromFunc.cnvFrom(num * fromUnit.cnvPfx_) * fromMag;\n //x = fromFunc.cnvFrom(num * fromMag) * fromUnit.cnvPfx_;\n }\n else {\n x = num * fromMag;\n }\n\n if (this.cnv_ != null) {\n // turn mag * origUnit on ratio scale into a non-ratio unit,\n // e.g. convert Kelvin to Fahrenheit\n let toFunc = funcs.forName(this.cnv_);\n newNum = toFunc.cnvTo(x / this.magnitude_) / this.cnvPfx_;\n }\n else {\n newNum = x / this.magnitude_;\n }\n\n return newNum;\n\n } // end convertFrom\n\n\n /**\n * Takes a number and a target unit and returns the number for a measurement\n * of this unit that corresponds to the number of the target unit passed in.\n * So, 1 tablespoon (where this unit represents a tablespoon) would translate\n * to 15 mL.\n *\n * See the note on convertFrom about return values.\n *\n * @param mag the magnitude for this unit (e.g. 1 for 1 tablespoon)\n * @param toUnit the unit to which this unit is to be translated\n * (e.g. an mL unit)\n *\n * @return the converted number value (e.g. 15 mL)\n * @throws an error if the dimension of the toUnit differs from this unit's\n * dimension\n */\n convertTo(num, toUnit) {\n\n return toUnit.convertFrom(num, this) ;\n\n } // end convertTo\n\n\n /**\n * Takes a given number of this unit returns the number of this unit\n * if it is converted into a coherent unit. Does not change this unit.\n *\n * If this is a coherent unit already, just gives back the number\n * passed in.\n *\n * @param num the number for the coherent version of this unit\n * @return the number for the coherent version of this unit\n */\n convertCoherent(num) {\n\n // convert mag' * u' into canonical number * u on ratio scale\n if(this.cnv_ !== null)\n num = this.cnv_.f_from(num / this.cnvPfx_) * this.magnitude_;\n\n return num;\n\n } // end convertCoherent\n\n\n /**\n * Mutates this unit into a coherent unit and converts a given number of\n * units to the appropriate value for this unit as a coherent unit\n *\n * @param num the number for this unit before conversion\n * @return the number of this unit after conversion\n * @throws an error if the dimensions differ\n */\n mutateCoherent(num) {\n\n // convert mu' * u' into canonical mu * u on ratio scale\n num = this.convertCoherent(num) ;\n\n // mutate to coherent unit\n this.magnitude_ = 1;\n this.cnv_ = null;\n this.cnvPfx_ = 1;\n this.name_ = \"\";\n\n // build a name as a term of coherent base units\n // This is probably ALL WRONG and a HORRIBLE MISTAKE\n // but until we figure out what the heck the name being\n // built here really is, it will have to stay.\n for (let i = 0, max = Dimension.getMax(); i < max; i++) {\n let elem = this.dim_.getElementAt(i);\n let tabs = this._getUnitTables();\n let uA = tabs.getUnitsByDimension(new Dimension(i));\n if(uA == null)\n throw(new Error(`Can't find base unit for dimension ${i}`));\n this.name_ = uA.name + elem;\n }\n return num;\n\n } // end mutateCoherent\n\n\n /**\n * This function converts between mol and mass (in either direction)\n * using the molecular weight of the substance. It assumes that the\n * isMolMassCommensurable\" function has been called to check that the units are\n * commensurable.\n *\n * @param amt the quantity of this unit to be converted\n * @param toUnit the target/to unit for which the converted # is wanted\n * @param molecularWeight the molecular weight of the substance for which the\n * conversion is being made\n * @return the equivalent amount in toUnit\n */\n convertMolMass(amt, toUnit, molecularWeight) {\n // In the calculations below we are treating \"molecularWeight\" (measured in\n // a.m.u) as the molar weight (measured in g/mol). The values are the same,\n // though the units differ.\n\n // Determine the number of powers of mol we have to convert to mass.\n // Typically this will be just 1, or -1, but not necessarily. If it is a\n // negative number, then we are really converting mass to moles.\n const molPowersToConvert = this.moleExp_ - toUnit.moleExp_;\n // A simple mole unit has a magnitude of avogadro's number. Get that\n // number now (since not everyone agrees on what it is, and what is\n // being used in this system might change).\n let tabs = this._getUnitTables();\n let avoNum = tabs.getUnitByCode('mol').magnitude_ ;\n // For each molPowersToConvert, we need to multiply the mol unit by the\n // molar weight (g/mol) and divide by avoNum (1/mol) to get a weight per\n // molecule. (Note that the magnitude_ of each unit will contain factors of\n // avoNum, of which we are thus getting rid of some).\n let moleUnitFactor = Math.pow(molecularWeight/avoNum, molPowersToConvert);\n // The new value is proportional to this.magnitude_, amt, and\n // moleUnitFactor, and inversely proportional to toUnit_.magnitude.\n return this.magnitude_/toUnit.magnitude_ * moleUnitFactor * amt;\n } // end convertMolMass\n\n\n /**\n * This function converts between equivalants and mass (in either direction)\n * using the charge of the substance. It assumes that the\n * isEqMassCommensurable\" function has been called to check that the units are\n * commensurable.\n *\n * @param {number} amt - The amount of this unit to be converted.\n * @param {object} toUnit - The target/to unit for which the converted number is wanted.\n * @param {number} molecularWeight - The molecular weight of the substance for which the conversion is being made.\n * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made.\n * @returns {number} - The amount in the specified toUnit.\n */\n convertEqMass(amt, toUnit, molecularWeight, charge) {\n // Determine the number of powers of mass we have to convert to equivalents.\n // Typically this will be just 1, or -1, but not necessarily. If it is a\n // negative number, then we are converting in the opposite direciton.\n // Because the units are presumed commensurable, we can use the\n // equivalentExp_ instead of the mass dimension.\n const massPowersToConvert = toUnit.equivalentExp_ - this.equivalentExp_ ;\n // Calculate equivalent mass by dividing molecular weight by charge\n let equivalentMass = molecularWeight / charge;\n // Get Avogadro's number from the unit tables\n let avogadroNumber = this._getUnitTables().getUnitByCode('mol').magnitude_ ;\n // Calculate equivalents by dividing mass by equivalent mass, for each\n // power to be converted.\n let equivalents = this.magnitude_ * amt / Math.pow(equivalentMass, massPowersToConvert);\n // Calculate mole factor by dividing the magnitude of the equivalent unit by\n // Avogadro's number. toUnit may have a prefix (e.g. meq) and we need to adjust for that, for\n // each massPowersToConvert.\n let moleFactor = toUnit.magnitude_ / Math.pow(avogadroNumber, massPowersToConvert);\n // Adjust equivalents by dividing by the mole factor\n let adjustedEquivalents = equivalents / moleFactor;\n // Return the adjusted equivalents\n return adjustedEquivalents;\n } // end convertMassToEq\n\n\n /**\n * Converts a unit with eq/mol/mass to another unit with eq/mol/mass. It\n * assumes the units an commensurable, which can be checked via\n * isEqMolMassCommensurable. It also assumes that the powers of eq/mol/mass\n * are different between the two units; otherwise it would be more efficient\n * to call one of the other convert... functions.\n *\n * @param {number} amt - The amount of this unit to be converted.\n * @param {object} toUnit - The target/to unit for which the converted number is wanted.\n * @param {number} molecularWeight - The molecular weight of the substance for which the conversion is being made.\n * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made.\n * @returns {number} - The equivalent amount in the specified equivalent unit.\n */\n convertEqMolMass(amt, toUnit, molecularWeight, charge) {\n // Handle the equivalent differences. It important for the following\n // calculations (for consistency) that we consider the difference in\n // equivalent powers and not mol powers, so we are not calling\n // convertEqToMol, in case its implementation changes.\n // See convertEqToMol for details. One difference is that we do not scale\n // by magnitude_ until the end.\n const eqPowersToConvert = this.equivalentExp_ - toUnit.equivalentExp_;\n const molAmt = amt / Math.pow(charge, eqPowersToConvert);\n // Now for the mol/mass converstion part, we consider only the mass power\n // differences, and not the mol power differences (which were partially\n // handled in the eq/mol step above).\n // Again, see convertMolToMass for details on the calculations.\n const tabs = this._getUnitTables();\n const d = tabs.getMassDimensionIndex();\n const massPowersToConvert = this.dim_.getElementAt(d) - toUnit.dim_.getElementAt(d);\n const molPowersToConvert = -massPowersToConvert; // so the formulas follow convertMolToMass\n const avoNum = tabs.getUnitByCode('mol').magnitude_ ;\n let moleUnitFactor = Math.pow(molecularWeight/avoNum, molPowersToConvert);\n return this.magnitude_/toUnit.magnitude_ * moleUnitFactor * molAmt;\n }\n\n\n /**\n * Checks if the given unit is an equivalent unit.\n *\n * Note: equivalent units are also be molar units, so a unit can return true for\n * both isEquivalentUnit and isMolarUnit.\n *\n * @returns {boolean} - Returns true if the unit is an equivalent unit, false otherwise.\n */\n isEquivalentUnit() {\n return this.equivalentExp_ !== 0;\n } // end isEquivalentUnit\n\n /**\n * Checks if the given unit is a molar unit.\n *\n * @returns {boolean} - Returns true if the unit is a molar unit, false otherwise.\n */\n isMolarUnit() {\n return this.moleExp_ !== 0;\n } // end isMolarUnit\n\n\n /**\n * This function converts between equivalants and moles (in either direction)\n * using the charge of the substance. It assumes that the\n * isEqMolCommensurable\" function has been called to check that the units are\n * commensurable.\n\n * As with the other \"convert\" functions, it assumes the appropriate\n * \"is...Commensurable\" function has been called.\n *\n * @param {number} amt - The amount of this unit for which the conversion is being made.\n * @param {object} toUnit - The target unit for which the converted number is wanted.\n * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made.\n * @return {number} - The amount in molToUnit.\n */\n convertEqMol(amt, toUnit, charge) {\n // Determine the number of powers of eq we have to convert to mol.\n // Typically this will be just 1, or -1, but not necessarily. If it is a\n // negative number, then we are really converting mol to eq.\n const eqPowersToConvert = this.equivalentExp_ - toUnit.equivalentExp_;\n\n // A simple mole unit has a magnitude of avogadro's number.\n // So does 'eq' (equivalent) because in ucum it is defined as 1 mol, though\n // that does not account for the charge. Therefore, we don't need to\n // account for that factor in this conversion.\n\n // The conversion from equivalents to moles is based on the principle that\n // one equivalent is equal to 1/charge moles (per eqPowersToConvert).\n // The relative magnitude is accounted for via the current unit's magnitude\n // (this.magnitude_) and the target unit's magnitude (molToUnit.magnitude_)\n // For each eqPowersToConvert, we need to divide by the charge.\n return amt * (this.magnitude_ / toUnit.magnitude_) / Math.pow(charge, eqPowersToConvert);\n } // end convertEqMol\n\n\n /**\n * Mutates this unit into a unit on a ratio scale and converts a specified\n * number of units to an appropriate value for this converted unit\n *\n * @param num the number of this unit before it's converted\n * @return the magnitude of this unit after it's converted\n * @throw an error if the dimensions differ\n */\n mutateRatio(num) {\n if (this.cnv_ == null)\n return this.mutateCoherent(num);\n else\n return num;\n\n } // end mutateRatio\n\n\n /**\n * Multiplies this unit with a scalar. Special meaning for\n * special units so that (0.1*B) is 1 dB.\n *\n * This function DOES NOT modify this unit.\n *\n * @param s the value by which this unit is to be multiplied\n * @return a copy this unit multiplied by s\n * */\n multiplyThis(s) {\n\n let retUnit = this.clone() ;\n if (retUnit.cnv_ != null)\n retUnit.cnvPfx_ *= s;\n else\n retUnit.magnitude_ *= s;\n let mulVal = s.toString();\n retUnit.name_ = this._concatStrs(mulVal, '*', this.name_, '[', ']');\n retUnit.csCode_ = this._concatStrs(mulVal, '.', this.csCode_, '(', ')');\n retUnit.ciCode_ = this._concatStrs(mulVal, '.', this.ciCode_, '(', ')');\n retUnit.printSymbol_ = this._concatStrs(mulVal, '.', this.printSymbol_,\n '(', ')');\n\n return retUnit;\n\n } // end multiplyThis\n\n\n /**\n * Multiplies this unit with another unit. If one of the\n * units is a non-ratio unit the other must be dimensionless or\n * else an exception is thrown.\n *\n * This function does NOT modify this unit\n * @param unit2 the unit to be multiplied with this one\n * @return this unit after it is multiplied\n * @throws an error if one of the units is not on a ratio-scale\n * and the other is not dimensionless.\n */\n multiplyThese(unit2) {\n\n var retUnit = this.clone() ;\n\n if (retUnit.cnv_ != null) {\n if (unit2.cnv_ == null && (!unit2.dim_ || unit2.dim_.isZero()))\n retUnit.cnvPfx_ *= unit2.magnitude_;\n else\n throw (new Error(`Attempt to multiply non-ratio unit ${retUnit.name_} ` +\n 'failed.'));\n } // end if this unit has a conversion function\n\n else if (unit2.cnv_ != null) {\n if (!retUnit.dim_ || retUnit.dim_.isZero()) {\n retUnit.cnvPfx_ = unit2.cnvPfx_ * retUnit.magnitude_;\n retUnit.magnitude_ = unit2.magnitude_;\n retUnit.cnv_ = unit2.cnv_ ;\n }\n else\n throw (new Error(`Attempt to multiply non-ratio unit ${unit2.name_}`));\n } // end if unit2 has a conversion function\n\n // else neither unit has a conversion function\n else {\n retUnit.magnitude_ *= unit2.magnitude_;\n } // end if unit2 does not have a conversion function\n\n // If this.dim_ isn't there, clone the dimension in unit2 - if dimVec_\n // is a dimension in unit2.dim_; else just transfer it to this dimension\n if (!retUnit.dim_ || (retUnit.dim_ && !retUnit.dim_.dimVec_)) {\n if (unit2.dim_)\n retUnit.dim_ = unit2.dim_.clone();\n else\n retUnit.dim_ = unit2.dim_;\n }\n // Else this.dim_ is there. If there is a dimension for unit2,\n // add it to this one.\n else if (unit2.dim_ && unit2.dim_ instanceof Dimension) {\n retUnit.dim_.add(unit2.dim_);\n }\n\n // Add the values of equivalentExp_ and moleExp for the two units\n retUnit.equivalentExp_ += unit2.equivalentExp_;\n retUnit.moleExp_ += unit2.moleExp_;\n\n // Concatenate the unit info (name, code, etc) for all cases\n // where the multiplication was performed (an error wasn't thrown)\n retUnit.name_ = this._concatStrs(retUnit.name_, '*', unit2.name_, '[', ']');\n retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '.', unit2.csCode_,\n '(', ')');\n if (retUnit.ciCode_ && unit2.ciCode_)\n retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '.', unit2.ciCode_,\n '(', ')');\n else if (unit2.ciCode_)\n retUnit.ciCode_ = unit2.ciCode_;\n retUnit.resetFieldsForDerivedUnit();\n if (retUnit.printSymbol_ && unit2.printSymbol_)\n retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '.',\n unit2.printSymbol_, '(', ')');\n else if (unit2.printSymbol_)\n retUnit.printSymbol_ = unit2.printSymbol_;\n\n // A unit that has the arbitrary attribute taints any unit created from it\n // via an arithmetic operation. Taint accordingly\n // if (!retUnit.isMole_)\n // retUnit.isMole_ = unit2.isMole_ ;\n if (!retUnit.isArbitrary_)\n retUnit.isArbitrary_ = unit2.isArbitrary_;\n\n // Likewise for special units\n if (!retUnit.isSpecial_)\n retUnit.isSpecial_ = unit2.isSpecial_;\n\n return retUnit ;\n\n } // end multiplyThese\n\n\n /**\n * Clears fields like isBase_, synonyms_, etc. when a unit has been cloned\n * from a known unit but it being used to construct a derived unit.\n */\n resetFieldsForDerivedUnit() {\n this.guidance_ = '';\n this.synonyms_ = null;\n this.isBase_ = false;\n }\n\n\n /**\n * Divides this unit by another unit. If this unit is not on a ratio\n * scale an exception is raised. Mutating to a ratio scale unit\n * is not possible for a unit, only for a measurement.\n *\n * This unit is NOT modified by this function.\n * @param unit2 the unit by which to divide this one\n * @return this unit after it is divided by unit2\n * @throws an error if either of the units is not on a ratio scale.\n * */\n divide(unit2) {\n\n var retUnit = this.clone();\n\n if (retUnit.cnv_ != null)\n throw (new Error(`Attempt to divide non-ratio unit ${retUnit.name_}`));\n if (unit2.cnv_ != null)\n throw (new Error(`Attempt to divide by non-ratio unit ${unit2.name_}`));\n\n if (retUnit.name_ && unit2.name_)\n retUnit.name_ = this._concatStrs(retUnit.name_, '/', unit2.name_, '[', ']');\n else if (unit2.name_)\n retUnit.name_ = unit2.invertString(unit2.name_);\n\n retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '/', unit2.csCode_,\n '(', ')');\n\n if (retUnit.ciCode_ && unit2.ciCode_)\n retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '/', unit2.ciCode_,\n '(', ')');\n else if (unit2.ciCode_)\n retUnit.ciCode_ = unit2.invertString(unit2.ciCode_) ;\n\n retUnit.resetFieldsForDerivedUnit();\n\n retUnit.magnitude_ /= unit2.magnitude_;\n\n if (retUnit.printSymbol_ && unit2.printSymbol_)\n retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '/',\n unit2.printSymbol_, '(', ')');\n else if (unit2.printSymbol_)\n retUnit.printSymbol_ = unit2.invertString(unit2.printSymbol_);\n\n // Continue if unit2 has a dimension object.\n // If this object has a dimension object, subtract unit2's dim_ object from\n // this one. The sub method will take care of cases where the dimVec_ arrays\n // are missing on one or both dim_ objects.\n if (unit2.dim_) {\n if (retUnit.dim_) {\n if (retUnit.dim_.isNull())\n retUnit.dim_.assignZero();\n retUnit.dim_ = retUnit.dim_.sub(unit2.dim_);\n } // end if this.dim_ exists\n\n // Else if this dim_ object is missing, clone unit2's dim_ object\n // and give the inverted clone to this unit.\n else\n retUnit.dim_ = unit2.dim_.clone().minus();\n } // end if unit2 has a dimension object\n\n // Update the mole exponent count by subtracting the count for unit2 from\n // the count for this unit.\n retUnit.moleExp_ -= unit2.moleExp_ ;\n // Also update the equivalent exponent.\n retUnit.equivalentExp_ -= unit2.equivalentExp_;\n\n // A unit that has the arbitrary attribute taints any unit created from\n // it via an arithmetic operation. Taint accordingly\n // if (!retUnit.isMole_)\n // retUnit.isMole_ = unit2.isMole_ ;\n if (!retUnit.isArbitrary_)\n retUnit.isArbitrary_ = unit2.isArbitrary_;\n\n return retUnit;\n\n } // end divide\n\n\n /**\n * This function is not actually used by the other code, except for some test\n * code, and might not be adequately tested.\n *\n * Invert this unit with respect to multiplication. If this unit is not\n * on a ratio scale an exception is thrown. Mutating to a ratio scale unit\n * is not possible for a unit, only for a measurement (the magnitude and\n * dimension).\n *\n * This unit is modified by this function.\n * @return this unit after being inverted\n * @throws and error if this unit is not on a ratio scale\n */\n invert() {\n var retUnit = this.clone() ;\n if (this.cnv_ != null)\n throw (new Error(`Attempt to invert a non-ratio unit - ${this.name_}`));\n\n retUnit.name_ = this.invertString(this.name_);\n retUnit.magnitude_ = 1/this.magnitude_ ;\n retUnit.dim_.minus();\n\n // Also update equivalentExp_ and moleExp\n retUnit.equivalentExp_ = -this.equivalentExp_;\n retUnit.moleExp_ = -this.moleExp_;\n\n return retUnit;\n\n } // end invert\n\n\n /**\n * Inverts a string, where the string is assumed to be a code or a name\n * of a division operation where the string is the divisor and the dividend\n * is blank.\n *\n * @param the string to be inverted\n * @return the inverted string\n */\n invertString(theString) {\n\n if (theString.length > 0) {\n // replace('<!', '</') is here to make sure closing html tags like </sup> are intact. See LF-2830.\n let stringRep = theString.replace('/', \"!\").replace('.', '/').replace('<!', '</').replace(\"!\", '.');\n switch(stringRep.charAt(0)) {\n case '.' : theString = stringRep.substr(1); break;\n case '/' : theString = stringRep; break;\n default : theString = \"/\" + stringRep;\n }\n }\n return theString;\n\n } // end invertString\n\n\n /**\n * This function handles concatenation of two strings and an operator.\n * It's called to build unit data, e.g., unit name, unit code, etc., from\n * two different units, joined by the specified operator.\n *\n * @param str1 the first string to appear in the result\n * @param operator the operator ('*', '.' or '/') to appear between the strings\n * @param str2 the second string to appear in the result\n * @param startChar the starting character to be used, when needed, to\n * enclose a string\n * @param endChar the ending character to be used, when needed, to enclose\n * a string\n * @returns the built string\n */\n _concatStrs(str1, operator, str2, startChar, endChar) {\n\n return this._buildOneString(str1, startChar, endChar) +\n operator + this._buildOneString(str2, startChar, endChar) ;\n }\n\n\n /**\n * This function handles creation of one string to be included in a\n * concatenated string. Basically it checks to see if the string\n * needs to be enclosed either in parentheses or square brackets.\n *\n * The string is enclosed if it is not a number, is not already enclosed in a pair of\n * parentheses or square brackets, and includes a period, and asterisk,\n * a slash or a blank space.\n *\n * @param str the string\n * @param startChar starting enclosing character\n * @param endChar ending enclosing character\n * @returns the string\n */\n _buildOneString(str, startChar, endChar) {\n let ret = '' ;\n if (intUtils_.isNumericString(str)) {\n ret = str;\n }\n else {\n if (str.charAt(0) === '(' && str.endsWith(')') || str.charAt(0) === '[' && str.endsWith(']')) {\n ret = str;\n }\n else if (/[./* ]/.test(str)) {\n ret = startChar + str + endChar ;\n }\n else {\n ret = str ;\n }\n }\n return ret ;\n }\n\n\n /**\n * This function is not actually used by the other code, except for some test\n * code, and might not be adequately tested.\n *\n * Raises the unit to a power. For example\n * kg.m/s2 raised to the -2 power would be kg-2.m-2/s-4\n *\n * If this unit is not on a ratio scale an error is thrown. Mutating\n * to a ratio scale unit is not possible for a unit, only for a\n * measurement (magnitude and dimension).\n *\n * This is based on the pow method in Gunter Schadow's java version,\n * although it uses javascript capabilities to simplify the processing.\n *\n * This unit is modified by this function\n *\n * @param p the power to with this unit is to be raise\n * @return this unit after it is raised\n * @throws an error if this unit is not on a ratio scale.\n */\n power(p) {\n\n if (this.cnv_ != null)\n throw (new Error(`Attempt to raise a non-ratio unit, ${this.name_}, ` +\n 'to a power.'));\n\n var retUnit = this.clone() ;\n //this.name_ = UnitString.pow(this.name_, p);\n // the above line is replaced with the code below, as the pow method\n // never actually existing in the UnitString class. (Tried to use\n // Schadow java code but this way ended up being a lot easier).\n let uStr = this.csCode_ ;\n let uArray = uStr.match(/([./]|[^./]+)/g) ;\n let arLen = uArray.length;\n\n for (let i = 0; i < arLen; i++) {\n let un = uArray[i] ;\n if (un !== '/' && un !== '.') {\n let nun = parseInt(un);\n if (isInteger(nun))\n uArray[i] = (Math.pow(nun, p).toString());\n else {\n let uLen = un.length ;\n for (let u = uLen - 1; u >= 0; u--) {\n let uChar = parseInt(un[u]);\n if (!isInteger(uChar)) {\n if (un[u] === '-' || un[u] === '+') {\n u--;\n }\n if (u < uLen - 1) {\n let exp = parseInt(un.substr(u));\n exp = Math.pow(exp, p);\n uArray[i] = un.substr(0, u) + exp.toString();\n u = -1;\n }\n else {\n uArray[i] += p.toString();\n u = -1;\n } // end if there are/aren't some numbers at the end\n u = -1;\n } // end if this character is not a number\n } // end searching backwards for start of exponent\n } // end if this element is not a number\n } // end if the current element is not an operator\n } // end do for each element of the units array\n\n // reassemble the updated units array to a string\n retUnit.csCode_ = uArray.join('');\n\n retUnit.magnitude_ = Math.pow(this.magnitude_, p);\n if (retUnit.dim_) {\n retUnit.dim_.mul(p);\n }\n\n // Also update equivalentExp_ and moleExp\n retUnit.equivalentExp_ *= p;\n retUnit.moleExp_ *= p;\n\n return retUnit;\n\n } // end power\n\n\n /*\n * This function tests this unit against the unit passed in to see if the\n * two are mole to mass commensurable. It assumes that one of the units\n * is a mole-based unit and the other is a mass-based unit. It also assumes\n * that the mole-based unit has a single mole unit in the numerator and that\n * the mass-based unit has a single mass unit in the numerator. It does NOT\n * check to validate those assumptions.\n *\n * The check is made by setting the dimension vector element corresponding\n * to the base mass unit (gram) in the mole unit, and then comparing the\n * two dimension vectors. If they match, the units are commensurable.\n * Otherwise they are not.\n *\n * @param unit2 the unit to be compared to this one\n * @returns boolean indicating commensurability\n */\n isMolMassCommensurable(unit2) {\n let tabs = this._getUnitTables();\n let d = tabs.getMassDimensionIndex();\n // Add the moleExp_ values to the mass values in the dimension vectors\n // of each unit, and then compare them.\n const unit1Dim = this.dim_.clone();\n unit1Dim.setElementAt(d, (unit1Dim.getElementAt(d) + this.moleExp_));\n const unit2Dim = unit2.dim_.clone();\n unit2Dim.setElementAt(d, (unit2Dim.getElementAt(d) + unit2.moleExp_));\n return (unit1Dim.equals(unit2Dim));\n }\n\n\n /**\n * This function tests this unit against the unit passed in to see if the\n * two are eq to mass commensurable. It assumes that one of the units\n * is a eq-based unit and the other is a mass-based unit. It also assumes\n * that the eq-based unit has a single eq unit in the numerator and that\n * the mass-based unit has a single mass unit in the numerator. It does NOT\n * check to validate those assumptions.\n *\n * The check is made by setting the dimension vector element corresponding\n * to the base mass unit (gram) in the eq unit, and then comparing the\n * two dimension vectors. If they match, the units are commensurable.\n * Otherwise they are not.\n *\n * @param {Unit} unit2 the unit to be compared to this one\n * @returns {boolean} boolean indicating commensurability\n */\n isEqMassCommensurable(unit2) {\n let tabs = this._getUnitTables();\n let d = tabs.getMassDimensionIndex();\n // Add the equivalentExp_ values to the mass values in the dimension vectors\n // of each unit, and then compare them.\n const unit1Dim = this.dim_.clone();\n unit1Dim.setElementAt(d, (unit1Dim.getElementAt(d) + this.equivalentExp_));\n const unit2Dim = unit2.dim_.clone();\n unit2Dim.setElementAt(d, (unit2Dim.getElementAt(d) + unit2.equivalentExp_));\n return (unit1Dim.equals(unit2Dim));\n }\n\n /**\n * This function tests this unit against the unit passed in to see if the\n * two are eq to mass commensurable-- that the equivalents could be converted\n * to the mass or vice-versa, in a way that makes the units commensurable.\n *\n * The check is made by adding the mole dimension to the equivalent dimension\n * and comparing that result for the two units, along with the units'\n * dimension vectors. If they match, the units are\n * commensurable. Otherwise they are not.\n *\n * @param {Unit} unit2 the unit to be compared to this one\n * @returns {boolean} boolean indicating commensurability\n */\n isEqMolCommensurable(unit2) {\n const unit1Sum = this.equivalentExp_ + this.moleExp_;\n const unit2Sum = unit2.equivalentExp_ + unit2.moleExp_;\n return unit1Sum == unit2Sum && this.dim_.equals(unit2.dim_);\n }\n\n\n /**\n * This function tests this unit against the unit passed in to see if the\n * two are commensurable if eq, mol, and mass units are converted in some\n * direction.\n *\n * The check is made by adding the eq, mol, and mass dimensions\n * and comparing that result for the two units, along with the units'\n * dimension vectors. If they match, the units are\n * commensurable. Otherwise they are not.\n *\n * @param {Unit} unit2 the unit to be compared to this one\n * @returns {boolean} boolean indicating commensurability\n */\n isEqMolMassCommensurable(unit2) {\n const d = this._getUnitTables().getMassDimensionIndex();\n const unit1Dim = this.dim_.clone();\n unit1Dim.setElementAt(d, unit1Dim.getElementAt(d) + this.equivalentExp_ +\n this.moleExp_);\n const unit2Dim = unit2.dim_.clone();\n unit2Dim.setElementAt(d, unit2Dim.getElementAt(d) + unit2.equivalentExp_ +\n unit2.moleExp_);\n return unit1Dim.equals(unit2Dim);\n }\n\n\n /**\n * This returns the UnitTables singleton object. Including the require\n * statement included here causes a circular dependency condition that\n * resulted in the UnitTables object not being defined for the Unit object.\n * sigh. Thanks, Paul, for figuring this out.\n *\n * @private\n */\n _getUnitTables() {\n if (!UnitTables)\n UnitTables = require('./unitTables.js').UnitTables;\n return UnitTables.getInstance();\n }\n\n} // end Unit class\n","/**\n * This class handles the parsing of a unit string into a unit object\n */\n\nvar Ucum = require('./config.js').Ucum;\nvar Unit = require('./unit.js').Unit;\nvar UnitTables = require('./unitTables.js').UnitTables;\nvar PrefixTables = require('./prefixTables.js').PrefixTables;\n\nimport * as intUtils_ from \"./ucumInternalUtils.js\";\n\nexport class UnitString {\n\n /**\n * Constructor\n */\n constructor() {\n\n // Get instances of the unit and prefix tables and the utilities\n this.utabs_ = UnitTables.getInstance();\n this.pfxTabs_ = PrefixTables.getInstance();\n\n // Set emphasis characters to defaults. These are used to emphasize\n // certain characters or strings in user messages. They can be reset in\n // the useHTMLInMessages method.\n this.openEmph_ = Ucum.openEmph_;\n this.closeEmph_ = Ucum.closeEmph_;\n\n // Set the braces message to blank. This message is displayed for each\n // validation request on the web page, but is included separately as\n // a note on the validation spreadsheet. The useBraceMsgForEachString\n // method should be used to set the message to be displayed for each\n // unit string.\n this.bracesMsg_ = '';\n\n // Set the flags used, with indices, as place holders in unit strings\n // for parenthetical strings and strings within braces.\n this.parensFlag_ = \"parens_placeholder\"; // in lieu of Jehoshaphat\n this.pFlagLen_ = this.parensFlag_.length;\n this.braceFlag_ = \"braces_placeholder\"; // in lieu of Nebuchadnezzar\n this.bFlagLen_ = this.braceFlag_.length;\n\n // Initialize the message start/end strings, which will be set when\n // parseString is called.\n this.vcMsgStart_ = null;\n this.vcMsgEnd_ = null;\n\n // Arrays used by multiple methods within this class to hold persistent\n // data. Just gets too bulky to pass these guys around.\n\n // Messages to be returned to the calling function\n this.retMsg_ = [] ;\n\n // Units for parenthetical unit strings\n this.parensUnits_ = [] ;\n\n // annotation text for annotations found in unit strings\n this.annotations_ = [] ;\n\n // suggestions for unit strings that for which no unit was found\n this.suggestions = [] ;\n } // end constructor\n\n\n // The start of an error message about an invalid annotation character.\n static INVALID_ANNOTATION_CHAR_MSG = 'An invalid character was found in the annotation ';\n\n // A regular expression for validating annotation strings.\n static VALID_ANNOTATION_REGEX = /^\\{[!-z|~]*\\}$/;\n\n /**\n * Sets the emphasis strings to the HTML used in the webpage display - or\n * blanks them out, depending on the use parameter.\n *\n * @param use flag indicating whether or not to use the html message format;\n * defaults to true\n */\n useHTMLInMessages(use) {\n if (use === undefined || use) {\n this.openEmph_ = Ucum.openEmphHTML_;\n this.closeEmph_ = Ucum.closeEmphHTML_;\n }\n else {\n this.openEmph_ = Ucum.openEmph_;\n this.closeEmph_ = Ucum.closeEmph_;\n }\n } // end useHTMLInMessages\n\n\n /**\n * Sets the braces message to be displayed for each unit string validation\n * requested, as appropriate.\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 || use)\n this.bracesMsg_ = Ucum.bracesMsg_;\n else\n this.bracesMsg_ = '';\n }\n\n\n /**\n * Parses a unit string, returns a unit, a possibly updated version of\n * the string passed in, and messages and suggestions where appropriate.\n *\n * The string returned may be updated if the input string contained unit\n * names, e.g., \"pound\". The unit code ([lb_av] for pound) is placed in\n * the string returned, a the returned messages array includes a note\n * explaining the substitution.\n *\n * @param uStr the string defining 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 * optional, defaults to 'validate'\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 an array containing:\n * the unit object or null if a unit could not be created. In cases where\n * a fix was found for a problem string, .e.g., 2.mg for 2mg, a unit will\n * be returned but an error message will also be returned, describing\n * the substitution;\n * the possibly updated unit string passed in;\n * an array of any user messages (informational, error or warning)\n * generated (or an empty array); and\n * a suggestions array of hash objects (1 or more). Each hash contains\n * 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 array will not contain a suggestions array if a valid unit\n * was found or if suggestions were not requested.\n * @throws an error if nothing was specified.\n */\n parseString(uStr, valConv, suggest) {\n\n uStr = uStr.trim();\n // Make sure we have something to work with\n if (uStr === '' || uStr === null) {\n throw (new Error('Please specify a unit expression to be validated.'));\n }\n\n if (valConv === 'validate') {\n this.vcMsgStart_ = Ucum.valMsgStart_;\n this.vcMsgEnd_ = Ucum.valMsgEnd_;\n }\n else {\n this.vcMsgStart_ = Ucum.cnvMsgStart_;\n this.vcMsgEnd_ = Ucum.cnvMsgEnd_;\n }\n\n if (suggest === undefined || suggest === false) {\n this.suggestions_ = null;\n }\n else {\n this.suggestions_ = [] ;\n }\n\n this.retMsg_ = [];\n this.parensUnits_ = [];\n this.annotations_ = [] ;\n\n let origString = uStr;\n let retObj = [];\n\n // Extract any annotations, i.e., text enclosed in braces ({}) from the\n // string before further processing. Store each one in this.annotations_\n // array and put a placeholder in the string for the annotation. Do\n // this before other processing in case an annotation contains characters\n // that will be interpreted as parenthetical markers or operators in\n // subsequent processing.\n\n uStr = this._getAnnotations(uStr);\n if (this.retMsg_.length > 0) {\n retObj[0] = null;\n retObj[1] = null;\n }\n else {\n // Flag used to block further processing on an unrecoverable error\n let endProcessing = this.retMsg_.length > 0;\n\n // First check for one of the \"special\" units. If it's one of those, put\n // in a substitution phrase for it to avoid having it separated on its\n // embedded operator. This will only happen, by the way, if it is\n // preceded by a prefix or followed by an operator and another unit.\n let sUnit = null ;\n for (sUnit in Ucum.specUnits_) {\n while (uStr.indexOf(sUnit) !== -1)\n uStr = uStr.replace(sUnit, Ucum.specUnits_[sUnit]);\n }\n\n // Check for spaces and throw an error if any are found. The spec\n // explicitly forbids spaces except in annotations, which is why any\n // annotations are extracted before this check is made.\n if (uStr.indexOf(' ') > -1) {\n throw (new Error('Blank spaces are not allowed in unit expressions.'));\n } // end if blanks were found in the string\n\n // assign the array returned to retObj. It will contain 2 elements:\n // the unit returned in position 0; and the origString (possibly\n // modified) in position 1. The origString in position 1 will not\n // be changed by subsequent processing.\n retObj = this._parseTheString(uStr, origString);\n let finalUnit = retObj[0];\n\n // Do a final check to make sure that finalUnit is a unit and not\n // just a number. Something like \"8/{HCP}\" will return a \"unit\" of 8\n // - which is not a unit. Hm - evidently it is. So just create a unit\n // object for it.\n if (intUtils_.isIntegerUnit(finalUnit) || typeof finalUnit === 'number') {\n finalUnit = new Unit({\n 'csCode_': origString,\n 'ciCode_': origString,\n 'magnitude_': finalUnit,\n 'name_': origString\n });\n retObj[0] = finalUnit;\n } // end final check\n } // end if no annotation errors were found\n\n retObj[2] = this.retMsg_;\n if (this.suggestions_ && this.suggestions_.length > 0)\n retObj[3] = this.suggestions_ ;\n return retObj;\n\n } // end parseString\n\n\n /**\n * Parses a unit string, returns a unit, a possibly updated version of\n * the string passed in, and messages where appropriate. This should\n * only be called from within this class (or by test code).\n *\n * The string returned may be updated if the input string contained unit\n * names, e.g., \"pound\". The unit code ([lb_av] for pound) is placed in\n * the string returned, a the returned messages array includes a note\n * explaining the substitution.\n *\n * @param uStr the string defining the unit\n * @param origString the original unit string passed in\n *\n * @returns\n * an array containing:\n * the unit object (or null if there were problems creating the unit); and\n * the possibly updated unit string passed in.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * the this.parensUnits_ array is referenced and possibly populated by\n * methods called within this one\n * the this.annotations_ array is referenced by methods called within\n * this one\n * the this.suggestions_ array may be populated by methods called within\n * this one\n */\n _parseTheString(uStr, origString) {\n\n // Unit to be returned\n let finalUnit = null;\n\n // Flag used to block further processing on an unrecoverable error\n let endProcessing = this.retMsg_.length > 0;\n\n // Call _processParens to search for and process any/all parenthetical\n // strings in uStr. Units created for parenthetical strings will be\n // stored in the this.parensUnits_ array.\n let parensResp = this._processParens(uStr, origString);\n endProcessing = parensResp[2];\n\n // The array used to hold the units and their operators.\n let uArray = [];\n\n // Continue if we didn't hit a problem\n if (!endProcessing) {\n uStr = parensResp[0];\n origString = parensResp[1];\n\n // Call _makeUnitsArray to convert the string to an array of unit\n // descriptors with operators.\n let mkUArray = this._makeUnitsArray(uStr, origString);\n\n endProcessing = mkUArray[2] ;\n if (!endProcessing) {\n uArray = mkUArray[0];\n origString = mkUArray[1];\n // Create a unit object out of each un element\n let uLen = uArray.length;\n for (let u1 = 0; u1 < uLen; u1++) {\n //for (let u1 = 0; u1 < uLen && !endProcessing; u1++) {\n let curCode = uArray[u1]['un'];\n\n // Determine the type of the \"un\" attribute of the current array element\n\n // Check to see if it's a number. If so write the number version of\n // the number back to the \"un\" attribute and move on\n if (intUtils_.isIntegerUnit(curCode)) {\n uArray[u1]['un'] = Number(curCode);\n }\n\n else {\n // The current unit array element is a string. Check now to see\n // if it is or contains a parenthesized unit from this.parensUnits_.\n // If so, call _getParens to process the string and get the unit.\n\n if (curCode.indexOf(this.parensFlag_) >= 0) {\n let parenUnit = this._getParensUnit(curCode, origString);\n // if we couldn't process the string, set the end flag and bypass\n // further processing.\n if (!endProcessing)\n endProcessing = parenUnit[1];\n\n // If we're good, put the unit in the uArray and replace the\n // curCode, which contains the parentheses placeholders, etc.,\n // with the unit's code - including any substitutions.\n if (!endProcessing) {\n uArray[u1]['un'] = parenUnit[0];\n }\n } // end if the curCode contains a parenthesized unit\n\n // Else it's not a parenthetical unit and not a number. Call\n // _makeUnit to create a unit for it.\n else {\n let uRet = this._makeUnit(curCode, origString);\n // If we didn't get a unit, set the endProcessing flag.\n if (uRet[0] === null) {\n endProcessing = true;\n }\n else {\n uArray[u1]['un'] = uRet[0];\n origString = uRet[1];\n }\n } // end if the curCode is not a parenthetical expression\n } // end if the \"un\" array is a not a number\n } // end do for each element in the units array\n } // end if _makeUnitsArray did not return an error\n } // end if _processParens did not find an error that causes a stop\n\n // If we're still good, continue\n if (!endProcessing) {\n // Process the units (and numbers) to create one final unit object\n if ((uArray[0] === null || uArray[0] === ' ' ||\n uArray[0]['un'] === undefined || uArray[0]['un'] === null)\n && this.retMsg_.length === 0) {\n // not sure what this might be, but this is a safeguard\n this.retMsg_.push(`Unit string (${origString}) did not contain ` +\n `anything that could be used to create a unit, or else something ` +\n `that is not handled yet by this package. Sorry`);\n endProcessing = true;\n }\n }\n if (!endProcessing) {\n finalUnit = this._performUnitArithmetic(uArray, origString);\n }\n return [finalUnit, origString];\n } // end _parseTheString\n\n\n /**\n * Extracts all annotations from a unit string, replacing them with\n * placeholders for later evaluation. The annotations are stored in the\n * this.annotations_ array. This should only be called from within this\n * class (or by test code).\n *\n * @param uString the unit string being parsed\n * @returns the string after the annotations are replaced with placeholders\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * the this.annotations_ array is populated by this method\n */\n _getAnnotations(uString) {\n let openBrace = uString.indexOf('{');\n while (openBrace >= 0) {\n\n let closeBrace = uString.indexOf('}');\n if (closeBrace < 0) {\n this.retMsg_.push('Missing closing brace for annotation starting at ' +\n this.openEmph_ + uString.substr(openBrace) +\n this.closeEmph_);\n openBrace = -1;\n }\n else {\n let braceStr = uString.substring(openBrace, closeBrace + 1);\n // Check for valid characters in the annotation.\n if (!UnitString.VALID_ANNOTATION_REGEX.test(braceStr)) {\n this.retMsg_.push(UnitString.INVALID_ANNOTATION_CHAR_MSG +\n this.openEmph_ + braceStr + this.closeEmph_);\n openBrace = -1; // end search for annotations\n }\n else {\n let aIdx = this.annotations_.length.toString();\n uString = uString.replace(braceStr, this.braceFlag_ + aIdx +\n this.braceFlag_);\n this.annotations_.push(braceStr);\n openBrace = uString.indexOf('{');\n }\n }\n } // end do while we have an opening brace\n\n // check for a stray/unmatched closing brace\n if (this.retMsg_.length == 0) { // if there were no other errors above\n let closeBrace = uString.indexOf('}');\n if (closeBrace >= 0)\n this.retMsg_.push('Missing opening brace for closing brace found at ' +\n this.openEmph_ + uString.substring(0, closeBrace + 1) +\n this.closeEmph_);\n }\n return uString;\n } // end _getAnnotations\n\n\n /**\n * Finds and processes any/all parenthesized unit strings. This should only\n * be called from within this class (or by test code).\n *\n * Nested parenthesized strings are processed from the inside out. The\n * parseString function is called from within this one for each parenthesized\n * unit string, and the resulting unit object is stored in this.parensUnits_,\n * to be processed after all strings are translated to units.\n *\n * A placeholder is placed in the unit string returned to indicate that the\n * unit object should be obtained from the this.parensUnits_ array. The\n * placeholder consists of the parenthesis flag (this.parensFlag_) followed\n * by the index of the unit in this.parensUnits_ followed by this.parensFlag_.\n *\n * @param uString the unit string being parsed, where this will be the full\n * string the first time this is called and parenthesized strings on any\n * subsequent calls\n * @param origString the original string first passed in to parseString\n * @returns\n * an array containing:\n * the string after the parentheses are replaced;\n * the original string; and\n * a boolean flag indicating whether or not an error occurred that\n * should stop processing.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * this this.parensUnits_ array will be populated with units found for\n * parenthetical unit strings\n */\n _processParens(uString, origString) {\n\n // Unit strings array and index\n let uStrArray = [];\n let uStrAryPos = 0;\n let stopProcessing = false;\n\n let pu = this.parensUnits_.length;\n\n // Count of characters trimmed off the beginning of the unit string (uString)\n // as units are removed from it; used for error messages to provide\n // context.\n let trimmedCt = 0;\n\n // Break the unit string into pieces that consist of text outside of\n // parenthetical strings and placeholders for the parenthetical units.\n // This method is called recursively for parenthetical strings and the units\n // returned are stored in the this.parensUnits_ array.\n while (uString !== \"\" && !stopProcessing) {\n let openCt = 0;\n let closeCt = 0;\n let openPos = uString.indexOf('(');\n\n // If an opening parenthesis was not found, check for an unmatched\n // close parenthesis. If one was found report the error and end\n // processing.\n if (openPos < 0) {\n let closePos = uString.indexOf(')');\n if (closePos >= 0) {\n let theMsg = `Missing open parenthesis for close ` +\n `parenthesis at ${uString.substring(0, closePos + trimmedCt)}` +\n `${this.openEmph_}${uString.substr(closePos, 1)}${this.closeEmph_}`;\n if (closePos < uString.length - 1) {\n theMsg += `${uString.substr(closePos + 1)}`;\n }\n this.retMsg_.push(theMsg);\n uStrArray[uStrAryPos] = uString;\n stopProcessing = true;\n } // end if a close parenthesis was found\n\n // If no parentheses were found in the current unit string, transfer\n // it to the units array and blank out the string, which will end\n // the search for parenthetical units.\n else {\n uStrArray[uStrAryPos] = uString;\n uString = \"\";\n } // end if no close parenthesis was found\n } // end if no open parenthesis was found\n\n // Otherwise an open parenthesis was found. Process the string that\n // includes the parenthetical group\n else {\n openCt += 1;\n // Write the text before the parentheses (if any) to the unit strings array\n let uLen = uString.length;\n if (openPos > 0) {\n uStrArray[uStrAryPos++] = uString.substr(0, openPos);\n }\n\n // Find the matching closePos, i.e., the one that closes the\n // parenthetical group that this one opens. Look also for\n // another open parenthesis, in case this includes nested parenthetical\n // strings. This continues until it finds the same number of close\n // parentheses as open parentheses, or runs out of string to check.\n // In the case of nested parentheses this will identify the outer set\n // of parentheses.\n let closePos = 0;\n let c = openPos + 1;\n for (; c < uLen && openCt != closeCt; c++) {\n if (uString[c] === '(')\n openCt += 1;\n else if (uString[c] === ')')\n closeCt += 1;\n }\n\n // Put a placeholder for the group in the unit strings array and recursively\n // call this method for the parenthetical group. Put the unit returned\n // in this.parensUnits_. Set the unit string to whatever follows\n // the position of the closing parenthesis for this group, to be\n // processed by the next iteration of this loop. If there's nothing\n // left uString is set to \"\".\n if (openCt === closeCt) {\n closePos = c;\n uStrArray[uStrAryPos++] = this.parensFlag_ + pu.toString() + this.parensFlag_;\n let parseResp = this._parseTheString(\n uString.substring(openPos + 1, closePos - 1), origString);\n if (parseResp[0] === null)\n stopProcessing = true;\n else if (uString[openPos + 1] === '/') {\n // If the term inside the parenthesis starts with '/', fail the validation. See LF-2854.\n this.retMsg_.push(\"Unary operator '/' is only allowed at the beginning of the main term, not inside a parenthesis.\");\n stopProcessing = true;\n }\n else {\n origString = parseResp[1];\n this.parensUnits_[pu++] = parseResp[0];\n uString = uString.substr(closePos);\n trimmedCt = closePos;\n }\n } // end if the number of open and close parentheses matched\n\n // If the number of open and close parentheses doesn't match, indicate\n // an error.\n else {\n uStrArray.push(origString.substr(openPos));\n this.retMsg_.push(`Missing close parenthesis for open parenthesis at ` +\n `${origString.substring(0, openPos + trimmedCt)}` +\n `${this.openEmph_}${origString.substr(openPos, 1)}` +\n `${this.closeEmph_}${origString.substr(openPos + 1)}`);\n stopProcessing = true;\n }\n } // end if an open parenthesis was found\n } // end do while the input string is not empty\n if (stopProcessing)\n this.parensUnits_ = [];\n return [uStrArray.join(''), origString, stopProcessing]\n } // end _processParens\n\n\n /**\n * Breaks the unit string into an array of unit descriptors and operators.\n * If a unit descriptor consists of a number preceding a unit code, with\n * no multiplication operator, e.g., 2mg instead of 2.mg, it is handled\n * as if it were a parenthetical expression.\n *\n * This should only be called from within this class (or by test code).\n *\n * @param uStr the unit string being parsed\n * @param origString the original string passed to parseString\n * @returns\n * an array containing:\n * the array representing the unit string;\n * the original string passed in, possibly updated with corrections; and\n * and a flag indicating whether or not processing can continue.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n */\n _makeUnitsArray(uStr, origString) {\n\n // Separate the string into pieces based on delimiters / (division) and .\n // (multiplication). The idea is to get an array of units on which we\n // can then perform any operations (prefixes, multiplication, division).\n\n let uArray1 = uStr.match(/([./]|[^./]+)/g);\n let endProcessing = false ;\n let uArray = [];\n let startNumCheck = /(^[0-9]+)(\\[?[a-zA-Z\\_0-9a-zA-Z\\_]+\\]?$)/ ;\n\n // If the first element in the array is the division operator (/), the\n // string started with '/'. Add a first element containing 1 to the\n // array, which will cause the correct computation to be performed (inversion).\n if (uArray1[0] === \"/\") {\n uArray1.unshift(\"1\");\n }\n // If the first element in the array is the multiplication operator (.)\n // return an error.\n else if (uArray1[0] === '.') {\n this.retMsg_.push(`${origString} is not a valid UCUM code. ` +\n `The multiplication operator at the beginning of the expression is ` +\n `not valid. A multiplication operator must appear only between ` +\n `two codes.`);\n endProcessing = true ;\n }\n if (!endProcessing) {\n // Check to see if there is a number preceding a unit code, e.g., 2mg\n // If so, update the first element to remove the number (2mg -> mg) and\n // add two elements to the beginning of the array - the number and the\n // multiplication operator.\n\n if (!intUtils_.isNumericString(uArray1[0])) {\n let numRes = uArray1[0].match(startNumCheck);\n if (numRes && numRes.length === 3 && numRes[1] !== '' &&\n numRes[2] !== '' && numRes[2].indexOf(this.braceFlag_) !== 0) {\n let dispVal = numRes[2] ;\n\n if (!endProcessing && numRes[2].indexOf(this.parensFlag_) !== -1) {\n let parensback = this._getParensUnit(numRes[2], origString);\n numRes[2] = parensback[0]['csCode_'];\n dispVal = `(${numRes[2]})`;\n endProcessing = parensback[1];\n }\n if (!endProcessing) {\n this.retMsg_.push(`${numRes[1]}${dispVal} is not a valid UCUM code.` +\n ` ${this.vcMsgStart_}${numRes[1]}.${dispVal}${this.vcMsgEnd_}`);\n origString = origString.replace(`${numRes[1]}${dispVal}`,\n `${numRes[1]}.${dispVal}`);\n uArray1[0] = numRes[2];\n uArray1.unshift(numRes[1], '.');\n }\n }\n } // end if the first element is not a number (only)\n\n // Create an array of unit/operator objects. The unit is, for now, the\n // string containing the unit code (e.g., Hz for hertz) including\n // a possible prefix and exponent. The operator is the operator to be\n // applied to that unit and the one preceding it. So, a.b would give\n // us two objects. The first will have a unit of a, and a blank operator\n // (because it's the first unit). The second would have a unit of b\n // and the multiplication operator (.).\n if (!endProcessing) {\n let u1 = uArray1.length;\n uArray = [{op: \"\", un: uArray1[0]}];\n for (let n = 1; n < u1; n++) {\n\n // check to make sure that we don't have two operators together, e.g.,\n // mg./K. If so, let the user know the problem.\n let theOp = uArray1[n++];\n // oh wait - check to make sure something is even there, that the\n // user didn't end the expression with an operator.\n if (!uArray1[n]) {\n this.retMsg_.push(`${origString} is not a valid UCUM code. ` +\n `It is terminated with the operator ${this.openEmph_}` +\n `${theOp}${this.closeEmph_}.`);\n n = u1;\n endProcessing = true;\n }\n else if (Ucum.validOps_.indexOf(uArray1[n]) !== -1) {\n this.retMsg_.push(`${origString} is not a valid UCUM code. ` +\n `A unit code is missing between${this.openEmph_}` +\n `${theOp}${this.closeEmph_}and${this.openEmph_}` +\n `${uArray1[n]}${this.closeEmph_}in${this.openEmph_}` +\n `${theOp}${uArray1[n]}${this.closeEmph_}.`);\n n = u1;\n endProcessing = true;\n }\n else {\n // Check to see if a number precedes a unit code.\n // If so, send the element to _processParens, inserting the multiplication\n // operator where it belongs. Treating it as parenthetical keeps it from\n // being interpreted incorrectly because of operator parentheses. For\n // example, if the whole string is mg/2kJ we don't want to rewrite it as\n // mg/2.kJ - because mg/2 would be performed, followed by .kJ. Instead,\n // handling 2kJ as a parenthesized unit will make sure mg is divided by\n // 2.kJ.\n if (!intUtils_.isNumericString(uArray1[n])) {\n let numRes2 = uArray1[n].match(startNumCheck);\n if (numRes2 && numRes2.length === 3 && numRes2[1] !== '' &&\n numRes2[2] !== '' && numRes2[2].indexOf(this.braceFlag_) !== 0) {\n let invalidString = numRes2[0];\n if (!endProcessing && numRes2[2].indexOf(this.parensFlag_) !== -1) {\n let parensback = this._getParensUnit(numRes2[2], origString);\n numRes2[2] = parensback[0]['csCode_'];\n invalidString = `(${numRes2[2]})`;\n endProcessing = parensback[1];\n if (!endProcessing) {\n this.retMsg_.push(`${numRes2[1]}${invalidString} is not a ` +\n `valid UCUM code. ${this.vcMsgStart_}${numRes2[1]}.${invalidString}` +\n `${this.vcMsgEnd_}`);\n let parensString = `(${numRes2[1]}.${invalidString})`;\n origString = origString.replace(`${numRes2[1]}${invalidString}`,\n parensString);\n let nextParens = this._processParens(parensString, origString);\n endProcessing = nextParens[2];\n if (!endProcessing) {\n uArray.push({op: theOp, un: nextParens[0]});\n }\n //uArray.push({op: '.', un: numRes2[2]});\n }\n } // end if the string represents a parenthesized unit\n else {\n let parensStr = '(' + numRes2[1] + '.' + numRes2[2] + ')';\n let parensResp = this._processParens(parensStr, origString);\n // if a \"stop processing\" flag was returned, set the n index to end\n // the loop and set the endProcessing flag\n if (parensResp[2]) {\n n = u1;\n endProcessing = true;\n }\n else {\n this.retMsg_.push(`${numRes2[0]} is not a ` +\n `valid UCUM code. ${this.vcMsgStart_}${numRes2[1]}.${numRes2[2]}` +\n `${this.vcMsgEnd_}`);\n origString = origString.replace(numRes2[0], parensStr);\n uArray.push({op: theOp, un: parensResp[0]});\n } // end if no error on the processParens call\n } // end if the string does not represent a parenthesized unit\n } // end if the string is a number followed by a string\n else {\n uArray.push({op: theOp, un: uArray1[n]});\n }\n }\n else {\n uArray.push({op: theOp, un: uArray1[n]});\n }\n } // end if there isn't a missing operator or unit code\n } // end do for each element in uArray1\n } // end if a processing error didn't occur in getParensUnit\n } // end if the string did not begin with a '.' with no following digit\n return [uArray, origString, endProcessing];\n } // end _makeUnitsArray\n\n\n /**\n * Takes a unit string containing parentheses flags and returns the unit they\n * represent. Any text found before and/or after the parenthetical\n * expression is checked to see if we can tell what the user meant and\n * let them know what it should have been. For example, 2(mg), which\n * would resolve to 2mg, should be 2.mg.\n *\n * This should only be called from within this class (or by test code).\n *\n * @param pStr the string being parsed\n * @param origString the original unit string passed in; passed through\n * to _getAnnonText if annotation flags are found in any text preceding\n * or following the parenthetical unit\n * @returns\n * an array containing\n * the unit object; and\n * a flag indicating whether or not processing should be ended.\n * True indicates that the string was invalid and no corrections\n * (substitutions or suggestions) could be found;\n * False indicates that it was either valid or substitutions/suggestions\n * were made.\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * this this.parensUnits_ array contains the units that are acquired by\n * this method\n * @throws an error if an invalid parensUnit index was found. This is\n * a processing error.\n */\n _getParensUnit(pStr, origString) {\n let endProcessing = false;\n let retAry = [];\n let retUnit = null;\n let befAnnoText = null;\n let aftAnnoText = null;\n\n // Get the location of the flags. We're assuming there are only two\n // because _processParens takes care of nesting. By the time we get\n // here we should not be looking a nested parens. Also get any text\n // before and after the parentheses. Once we get the unit we update\n // the input string with the unit's csCode_, which will wipe out any\n // before and after text\n let psIdx = pStr.indexOf(this.parensFlag_);\n let befText = null;\n if (psIdx > 0) {\n befText = pStr.substring(0, psIdx);\n }\n let peIdx = pStr.lastIndexOf(this.parensFlag_);\n let aftText = null;\n if (peIdx + this.pFlagLen_ < pStr.length) {\n aftText = pStr.substr(peIdx + this.pFlagLen_);\n }\n\n // Get the text between the flags\n let pNumText = pStr.substring(psIdx + this.pFlagLen_, peIdx);\n\n // Make sure the index is a number, and if it is, get the unit from the\n // this.parensUnits_ array\n if (intUtils_.isNumericString(pNumText)) {\n retUnit = this.parensUnits_[Number(pNumText)];\n if (!intUtils_.isIntegerUnit(retUnit)) {\n pStr = retUnit.csCode_;\n }\n else {\n pStr = retUnit ;\n }\n }\n // If it's not a number, it's a programming error. Throw a fit.\n else {\n throw (new Error(`Processing error - invalid parens number ${pNumText} ` +\n `found in ${pStr}.`));\n }\n\n // If there's something in front of the starting parentheses flag, check to\n // see if it's a number or an annotation.\n if (befText) {\n // If it's a number, assume that multiplication was assumed\n if (intUtils_.isNumericString(befText)) {\n let nMag = retUnit.getProperty('magnitude_');\n nMag *= Number(befText);\n retUnit.assignVals({'magnitude_': nMag});\n pStr = `${befText}.${pStr}`;\n this.retMsg_.push(`${befText}${pStr} is not a valid UCUM code.\\n` +\n this.vcMsgStart_ + pStr + this.vcMsgEnd_);\n }\n else {\n if (befText.indexOf(this.braceFlag_) >= 0) {\n let annoRet = this._getAnnoText(befText, origString);\n // if we found not only an annotation, but text before or after\n // the annotation (remembering that this is all before the\n // parentheses) throw an error - because we don't know what\n // to do with it. Could it be missing an operator?\n if (annoRet[1] || annoRet[2]) {\n throw (new Error(`Text found before the parentheses (` +\n `${befText}) included an annotation along with other text ` +\n `for parenthetical unit ${retUnit.csCode_}`));\n }\n // Otherwise put the annotation after the unit string and note\n // the misplacement.\n pStr += annoRet[0];\n this.retMsg_.push(`The annotation ${annoRet[0]} before the unit ` +\n `code is invalid.\\n` + this.vcMsgStart_ + pStr + this.vcMsgEnd_);\n }\n // else the text before the parentheses is neither a number nor\n // an annotation. Record an error.\n else {\n this.retMsg_.push(`${befText} preceding the unit code ${pStr} ` +\n `is invalid. Unable to make a substitution.`);\n endProcessing = true;\n } // end if a brace was found\n } // end if text preceding the parentheses was not a number\n } // end if there was text before the parentheses\n\n // Process any text after the parentheses\n if (aftText) {\n // if it's an annotation, get it and add it to the pStr\n if (aftText.indexOf(this.braceFlag_) >= 0) {\n let annoRet = this._getAnnoText(aftText, origString);\n // if we found not only an annotation, but text before or after\n // the annotation (remembering that this is all after the\n // parentheses) throw an error - because we don't know what\n // to do with it. Could it be missing an operator?\n if (annoRet[1] || annoRet[2]) {\n throw (new Error(`Text found after the parentheses (` +\n `${aftText}) included an annotation along with other text ` +\n `for parenthetical unit ${retUnit.csCode_}`));\n }\n // Otherwise put the annotation after the unit string - no message\n // needed.\n pStr += annoRet[0];\n }\n // Otherwise check to see if it's an exponent. If so, warn the\n // user that it's not valid - but try it anyway\n else {\n\n if (intUtils_.isNumericString(aftText)) {\n retUnit = null;\n let msg = `An exponent (${aftText}) following a parenthesis ` +\n `is invalid as of revision 1.9 of the UCUM Specification.`;\n // Add the suggestion only if the string in the parenthesis don't end with a number.\n if (!pStr.match(/\\d$/)) {\n pStr += aftText;\n msg += '\\n ' + this.vcMsgStart_ + pStr + this.vcMsgEnd_;\n }\n this.retMsg_.push(msg);\n endProcessing = true;\n }\n // else the text after the parentheses is neither a number nor\n // an annotation. Record an error.\n else {\n this.retMsg_.push(`Text ${aftText} following the unit code ${pStr} ` +\n `is invalid. Unable to make a substitution.`);\n endProcessing = true;\n } // end if text following the parentheses not an exponent\n } // end if text following the parentheses is not an annotation\n } // end if there is text following the parentheses\n if (!endProcessing) {\n if (!retUnit) {\n retUnit = new Unit({\n 'csCode_': pStr,\n 'magnitude_': 1,\n 'name_': pStr});\n }\n else if (intUtils_.isIntegerUnit(retUnit)) {\n retUnit = new Unit({'csCode_': retUnit,\n 'magnitude_': retUnit,\n 'name_': retUnit});\n }\n else {\n retUnit.csCode_ = pStr;\n }\n }\n return [retUnit, endProcessing];\n } // end _getParensUnit\n\n /**\n * Takes a unit string containing annotation flags and returns the\n * annotation they represent. This also returns any text found before\n * the annotation and any found after the annotation.\n *\n * This should only be called from within this class (or by test code).\n * NEEDS FIX in next branch to handle string with multiple annotations.\n *\n * @param pStr the string being parsed\n * @param origString the original string being parsed; used in error msg\n * thrown for an invalid index to the annotations array\n * @returns\n * an array containing\n * the annotation for the pStr;\n * any text found before the annotation; and\n * any text found after the annotation.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * the this.annotations_ array is used as the source for the annotations text\n * @throws an error if for a processing error - an invalid annotation index.\n */\n _getAnnoText(pStr, origString) {\n\n // if the starting braces flag is not at index 0, get the starting\n // text and the adjust the pStr to omit it.\n let asIdx = pStr.indexOf(this.braceFlag_);\n let startText = (asIdx > 0) ? pStr.substring(0, asIdx) : null;\n if (asIdx !== 0) {\n pStr = pStr.substr(asIdx);\n }\n\n // Get the location of the end flag and, if text follows it, get the text\n let aeIdx = pStr.indexOf(this.braceFlag_, 1);\n let endText = ((aeIdx + this.bFlagLen_) < pStr.length) ?\n pStr.substr(aeIdx + this.bFlagLen_) : null;\n\n // Get the index of the annotation in this.annotations_.\n // Check it to make sure it's valid, and if not, throw an error\n let idx = pStr.substring(this.bFlagLen_, aeIdx);\n let idxNum = Number(idx);\n if (!intUtils_.isNumericString(idx) || idxNum >= this.annotations_.length) {\n throw (new Error(`Processing Error - invalid annotation index ${idx} found ` +\n `in ${pStr} that was created from ${origString}`));\n }\n\n // Replace the flags and annotation index with the annotation expression\n pStr = this.annotations_[idxNum];\n return [pStr, startText, endText];\n } // end _getAnnoText\n\n\n /**\n * Takes a unit string and looks for suggested units. This should be\n * called for unit strings that cannot be resolved to unit codes. The\n * string is searched for in the synonyms table found in the UnitTables\n * class. That table includes all synonyms and unit names for the units\n * in the unit data table.\n *\n * @param pStr the string being parsed\n * @returns an object that contains an element named 'status', whose\n * value indicates the status of the request:\n * 'succeeded' indicates that synonyms were found;\n * 'failed' indicates that no synonyms were found; or\n * 'error' which indicates that an error occurred\n *\n * the this.retMsg_ array will be updated with a message indicating whether\n * or not synonyms/suggestions were found\n * the this.suggestions_ array will be updated with a hash (added to the\n * array if it already contains others) that 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 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 */\n _getSuggestions(pStr) {\n\n let retObj = intUtils_.getSynonyms(pStr);\n if (retObj['status'] === 'succeeded') {\n let suggSet = {} ;\n suggSet['msg'] = `${pStr} is not a valid UCUM code. We found possible ` +\n `units that might be what was meant:`;\n suggSet['invalidUnit'] = pStr ;\n let synLen = retObj['units'].length ;\n suggSet['units'] = [] ;\n for (let s = 0; s < synLen; s++) {\n let unit = retObj['units'][s];\n let unitArray = [unit['code'], unit['name'], unit['guidance']];\n\n suggSet['units'].push(unitArray) ;\n }\n this.suggestions_.push(suggSet);\n }\n else {\n this.retMsg_.push(`${pStr} is not a valid UCUM code. No alternatives ` +\n `were found.`);\n }\n return retObj['status'] ;\n } // end getSuggestions\n\n\n /**\n * Creates a unit object from a string defining one unit. The string\n * should consist of a unit code for a unit already defined (base or\n * otherwise). It may include a prefix and an exponent, e.g., cm2\n * (centimeter squared). This should only be called from within this\n * class (or by test code).\n *\n * @params uCode the string defining the unit\n * @param origString the original string to be parsed; used to provide\n * context for messages\n * @returns\n * an array containing:\n * a unit object, or null if there were problems creating the unit; and\n * the origString passed in, which may be updated if a unit name was\n * translated to a unit code.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * the this.suggestions_ array will be populated if no unit (with or without\n * substitutions) could be found and suggestions were requested\n */\n _makeUnit(uCode, origString) {\n\n // First try the code just as is, without looking for annotations,\n // prefixes, exponents, or elephants.\n let retUnit = this.utabs_.getUnitByCode(uCode);\n if (retUnit) {\n retUnit = retUnit.clone();\n }\n\n // If we found it, we're done. No need to parse for those elephants (or\n // other stuff).\n else if (uCode.indexOf(this.braceFlag_) >= 0) {\n let getAnnoRet = this._getUnitWithAnnotation(uCode, origString);\n retUnit = getAnnoRet[0];\n if (retUnit) {\n origString = getAnnoRet[1];\n }\n // If a unit is not found, retUnit will be returned null and\n // the this.retMsg_ array will contain a message describing the problem.\n // If a unit is found, of course, all is good. So ... nothing left\n // to see here, move along.\n } // end if the uCode includes an annotation\n\n else {\n\n // So we didn't find a unit for the full uCode or for one with\n // annotations. Try looking for a unit that uses a carat (^)\n // instead of an asterisk (*)\n\n if (uCode.indexOf('^') > -1) {\n let tryCode = uCode.replace('^', '*');\n retUnit = this.utabs_.getUnitByCode(tryCode);\n if (retUnit) {\n retUnit = retUnit.clone();\n retUnit.csCode_ = retUnit.csCode_.replace('*', '^');\n retUnit.ciCode_ = retUnit.ciCode_.replace('*', '^');\n }\n }\n // If we still don't have a unit, try assuming a modifier (prefix and/or\n // exponent) and look for a unit without the modifier\n if (!retUnit) {\n\n // Well, first see if it's one of the special units. If so,\n // replace the placeholder text with the actual unit string, keeping\n // whatever text (probably a prefix) goes with the unit string.\n let sUnit = null;\n for (sUnit in Ucum.specUnits_) {\n if (uCode.indexOf(Ucum.specUnits_[sUnit]) !== -1)\n uCode = uCode.replace(Ucum.specUnits_[sUnit], sUnit);\n }\n retUnit = this.utabs_.getUnitByCode(uCode);\n if (retUnit)\n retUnit = retUnit.clone();\n }\n if (!retUnit) {\n\n let origCode = uCode;\n let origUnit = null;\n let exp = null;\n let pfxCode = null;\n let pfxObj = null;\n let pfxVal = null;\n\n // Look first for an exponent. If we got one, separate it out and\n // try to get the unit again\n let codeAndExp = this._isCodeWithExponent(uCode);\n let isIntegerUnitWithExp = false;\n if (codeAndExp) {\n uCode = codeAndExp[0];\n exp = codeAndExp[1];\n isIntegerUnitWithExp = intUtils_.isIntegerUnit(uCode);\n origUnit = isIntegerUnitWithExp ?\n new Unit({'csCode_' : uCode,\n 'ciCode_' : uCode,\n 'magnitude_' : Number(uCode),\n 'name_' : uCode}) :\n this.utabs_.getUnitByCode(uCode);\n }\n\n // If an exponent is found but it's not a valid number, e.g. \"2-1\",\n // mark the unit invalid. Otherwise, the \"-1\" part will be ignored\n // because parseInt(\"2-1\") results in 2. See LF-2870.\n if (exp && isNaN(exp)) {\n retUnit = null;\n this.retMsg_.push(`${origCode} is not a valid UCUM code.`);\n }\n else {\n // If we still don't have a unit, separate out the prefix, if any,\n // and try without it.\n if (!origUnit && uCode.length > 1) {\n // Try for a single character prefix first, then for a two-digit prefix\n pfxCode = '';\n do {\n pfxCode += uCode.charAt(0);\n uCode = uCode.substr(1);\n pfxObj = this.pfxTabs_.getPrefixByCode(pfxCode);\n if (pfxObj) {\n pfxVal = pfxObj.getValue();\n // try again for the unit\n origUnit = this.utabs_.getUnitByCode(uCode);\n }\n } while (!origUnit && pfxCode.length < 2 && uCode.length > 1)\n\n // Reject the unit we found if it might have another prefix. (??)\n // Such things are in our tables through the LOINC source_\n // (ucum.csv) which has guidance and synonyms. I think it should be\n // safe to exclude anything whose source is LOINC from having a\n // prefix.\n if (origUnit && origUnit.source_ == 'LOINC')\n origUnit = null;\n } // end if we didn't get a unit after removing an exponent\n\n // If we still haven't found anything, we're done looking.\n // (We tried with the full unit string, with the unit string\n // without the exponent, the unit string without a prefix,\n // common errors, etc. That's all we can try).\n if (!origUnit) {\n let bracketRet = this._getUnitAfterAddingBrackets(origCode, origString);\n retUnit = bracketRet[0];\n origString = bracketRet[1];\n if (!retUnit) {\n let nameRet = this._getUnitByName(origCode, origString);\n retUnit = nameRet[0];\n origString = nameRet[1];\n if (!retUnit) {\n // BUT if the user asked for suggestions, at least look for them\n if (this.suggestions_) {\n let suggestStat = this._getSuggestions(origCode);\n }\n else {\n this.retMsg_.push(`${origCode} is not a valid UCUM code.`);\n }\n }\n }\n }\n else {\n // Otherwise we found a unit object. Clone it and then apply the\n // prefix and exponent, if any, to it. And remove the guidance.\n retUnit = origUnit.clone();\n // If we are here, this is only part of the full unit string, so it is\n // not a base unit, and the synonyms will mostly likely not be correct for the full\n // string.\n retUnit.resetFieldsForDerivedUnit();\n let theDim = retUnit.getProperty('dim_');\n let theMag = retUnit.getProperty('magnitude_');\n let theName = retUnit.getProperty('name_');\n let theCiCode = retUnit.getProperty('ciCode_');\n let thePrintSymbol = retUnit.getProperty('printSymbol_');\n // If there is an exponent for the unit, apply it to the dimension\n // and magnitude now\n if (exp) {\n // Special units cannot be raised to a power\n if (retUnit.isSpecial_) {\n this.retMsg_.push(`Special units like ${retUnit.name_} cannot be raised to a power.`);\n retUnit = null;\n }\n else {\n exp = parseInt(exp);\n if (theDim)\n theDim = theDim.mul(exp);\n retUnit.equivalentExp_ *= exp;\n retUnit.moleExp_ *= exp;\n theMag = Math.pow(theMag, exp);\n retUnit.assignVals({'magnitude_': theMag});\n\n // If there is also a prefix, apply the exponent to the prefix.\n if (pfxObj) {\n // We don't need to consider pfxObj.getExp(), because when\n // present that is reflected in the pfxVal. However, in some\n // cases one can avoid floating-point math inaccuracies by using\n // that exponent instead of relying on pfxVal. For example:\n // 1e-66 = Math.pow(10, -3*22) = Math.pow(0.001, 22) = 1.0000000000000005e-66\n // (This is the from the test case of the unit mg% raised to the 22nd power (mg%22).)\n // This does not help in all cases, but it does help the above\n // test case (which is in our web API service test code).\n let pfxExp = pfxObj.getExp();\n if (pfxExp) {\n // This is relying on the fact that pfxExp is null when\n // the prefix base is not 10.\n pfxVal = Math.pow(10, exp * pfxExp);\n }\n else {\n pfxVal = Math.pow(pfxVal, exp);\n }\n }\n } // end else - prefix and exponent handling for non-special units\n } // end if there's an exponent\n\n if (retUnit) {\n // Now apply the prefix, if there is one, to the conversion\n // prefix or the magnitude\n if (pfxObj) {\n if (retUnit.cnv_) {\n retUnit.assignVals({'cnvPfx_': pfxVal});\n }\n else {\n theMag *= pfxVal;\n retUnit.assignVals({'magnitude_': theMag})\n }\n }\n // if we have a prefix and/or an exponent, add them to the unit\n // attributes - name, csCode, ciCode and print symbol\n let theCode = retUnit.csCode_;\n if (pfxObj) {\n theName = pfxObj.getName() + theName;\n theCode = pfxCode + theCode;\n theCiCode = pfxObj.getCiCode() + theCiCode;\n thePrintSymbol = pfxObj.getPrintSymbol() + thePrintSymbol;\n retUnit.assignVals({\n 'name_': theName,\n 'csCode_': theCode,\n 'ciCode_': theCiCode,\n 'printSymbol_': thePrintSymbol\n });\n }\n if (exp) {\n let expStr = exp.toString();\n const intergerUnitExpSign = isIntegerUnitWithExp && exp > 0 ? '+' : '';\n retUnit.assignVals({\n 'name_': theName + '<sup>' + expStr + '</sup>',\n 'csCode_': theCode + intergerUnitExpSign + expStr,\n 'ciCode_': theCiCode + intergerUnitExpSign + expStr,\n 'printSymbol_': thePrintSymbol + '<sup>' + expStr + '</sup>'\n });\n }\n }\n } // end if an original unit was found (without prefix and/or exponent)\n } // end if an invalid exponent wasn't found\n } // end if we didn't get a unit for the full unit code (w/out modifiers)\n } // end if we didn't find the unit on the first try, before parsing\n return [retUnit, origString];\n } // end _makeUnit\n\n\n /**\n * Checks whether an otherwise unresolved unit code matches a unit name.\n *\n * @param uCode the unit code or name to check\n * @param origString the original full string submitted to parseString\n * @returns an array containing the unit object found, or null, and origString\n */\n _getUnitByName(uCode, origString) {\n\n let retUnit = null;\n let retUnitAry = this.utabs_.getUnitByName(uCode);\n if (retUnitAry && retUnitAry.length > 0) {\n retUnit = retUnitAry[0].clone();\n let mString = 'The UCUM code for ' + uCode + ' is ' +\n retUnit.csCode_ + '.\\n' + this.vcMsgStart_ +\n retUnit.csCode_ + this.vcMsgEnd_;\n let dupMsg = false;\n for (let r = 0; r < this.retMsg_.length && !dupMsg; r++)\n dupMsg = this.retMsg_[r] === mString;\n if (!dupMsg)\n this.retMsg_.push(mString);\n const escapedCode = uCode.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n let rStr = new RegExp('(^|[./(])(' + escapedCode + ')($|[./)\\\\-\\\\d{])');\n const updatedOrigString = origString.replace(rStr, '$1' + retUnit.csCode_ + '$3');\n if (updatedOrigString == origString) {\n // This should not happen, if the processing has been correct. However, if it does happen, we\n // still have to change origString to signal that the input unit is invalid.\n // There is a test present to make sure this message does not appear from the top-level APIs in\n // ucumLhcUtils.js.\n // Ideally, this problem would be signalled some other way, but that would be a bigger change.\n origString += ' (Unable to update the unit expression with a suggested replacement.)';\n }\n else {\n origString = updatedOrigString;\n }\n }\n return [retUnit, origString];\n } // end _getUnitByName\n\n\n /**\n * Checks whether an otherwise unresolved unit code can be found after adding\n * square brackets, e.g., degF -> [degF]. If a bracketed unit is found,\n * origString is modified to include the suggested replacement.\n *\n * @param uCode the unit code to check\n * @param origString the original full string submitted to parseString\n * @returns an array containing the unit object found, or null, and the possibly\n * modified origString\n */\n _getUnitAfterAddingBrackets(uCode, origString) {\n\n let retUnit = null;\n const addBrackets = '[' + uCode + ']' ;\n const bracketUnit = this.utabs_.getUnitByCode(addBrackets);\n if (bracketUnit) {\n retUnit = bracketUnit.clone();\n const escapedCode = uCode.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const leadingUnitBoundary = '(^|[./(])';\n const trailingUnitBoundary = '($|[./)\\\\-\\\\d{])';\n const rStr = new RegExp(leadingUnitBoundary + '(' + escapedCode + ')' +\n trailingUnitBoundary);\n const updatedOrigString = origString.replace(rStr, '$1' + addBrackets + '$3');\n if (updatedOrigString == origString) {\n // This should not happen, if the processing has been correct. However, if it does happen, we\n // still have to change origString to signal that the input unit is invalid.\n // There is a test present to make sure this message does not appear from the top-level APIs in\n // ucumLhcUtils.js.\n // Ideally, this problem would be signalled some other way, but that would be a bigger change.\n origString += ' (Unable to update the unit expression with a suggested replacement.)';\n }\n else {\n origString = updatedOrigString;\n }\n this.retMsg_.push(`${uCode} is not a valid unit expression, but ` +\n `${addBrackets} is.\\n` + this.vcMsgStart_ +\n `${addBrackets} (${retUnit.name_})${this.vcMsgEnd_}`);\n }\n return [retUnit, origString];\n } // end _getUnitAfterAddingBrackets\n\n\n /**\n * This method handles unit creation when an annotation is included\n * in the unit string. This basically isolates and retrieves the\n * annotation and then calls _makeUnit to try to get a unit from\n * any text that precedes or follows the annotation.\n *\n * @param uCode the string defining the unit\n * @param origString the original full string submitted to parseString\n * @returns the unit object found, or null if one could not be found\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n */\n _getUnitWithAnnotation(uCode, origString) {\n\n let retUnit = null;\n\n // Get the annotation and anything that precedes or follows it.\n let annoRet = this._getAnnoText(uCode, origString);\n let annoText = annoRet[0];\n let befAnnoText = annoRet[1];\n let aftAnnoText = annoRet[2];\n\n // Add the warning about annotations - just once.\n\n if (this.bracesMsg_ && this.retMsg_.indexOf(this.bracesMsg_) === -1)\n this.retMsg_.push(this.bracesMsg_);\n\n // If there's no text before or after the annotation, it's probably\n // something that should be interpreted as a 1, e.g., {KCT'U}.\n // HOWEVER, it could also be a case where someone used braces instead\n // of brackets, e.g., {degF} instead of [degF]. Check for that before\n // we assume it should be a 1.\n let msgLen = this.retMsg_.length;\n if (!befAnnoText && !aftAnnoText) {\n let tryBrackets = '[' + annoText.substring(1, annoText.length - 1) + ']';\n let mkUnitRet = this._makeUnit(tryBrackets, origString);\n\n // Nearly anything inside braces is valid, so we don't want to change the\n // unit, but we can put the found unit in the message as a sort of\n // warning.\n if (mkUnitRet[0]) {\n retUnit = uCode;\n this.retMsg_.push(`${annoText} is a valid unit expression, but ` +\n `did you mean ${tryBrackets} (${mkUnitRet[0].name_})?`);\n }\n else {\n // remove error message generated for trybrackets\n if (this.retMsg_.length > msgLen) {\n this.retMsg_.pop();\n }\n }\n\n // This is the case where the string is only this annotation.\n // Create and return a unit object, as we do for numeric units in\n // parseString.\n retUnit = new Unit({\n 'csCode_': annoText,\n 'ciCode_': annoText,\n 'magnitude_': 1,\n 'name_': annoText\n });\n\n } // end if it's only an annotation\n\n else {\n // if there's text before and no text after, assume the text before\n // the annotation is the unit code (with an annotation following it).\n // Call _makeUnit for the text before the annotation.\n if (befAnnoText && !aftAnnoText) {\n // make sure that what's before the annoText is not a number, e.g.,\n // /100{cells}. But f it is a number, just set the return unit to\n // the number.\n if (intUtils_.isIntegerUnit(befAnnoText)) {\n retUnit = new Unit({'csCode_' : befAnnoText + annoText,\n 'ciCode_' : befAnnoText + annoText.toUpperCase(),\n 'magnitude_' : Number(befAnnoText),\n 'name_': befAnnoText + annoText});\n }\n // Otherwise try to find a unit\n else {\n let mkUnitRet = this._makeUnit(befAnnoText, origString);\n\n // if a unit was returned\n if (mkUnitRet[0]) {\n retUnit = mkUnitRet[0];\n retUnit.csCode_ += annoText;\n origString = mkUnitRet[1];\n }\n // Otherwise add a not found message\n else {\n this.retMsg_.push(`Unable to find a unit for ${befAnnoText} that ` +\n `precedes the annotation ${annoText}.`);\n }\n }\n }\n // else if there's only text after the annotation, try for a unit\n // from the after text and assume the user put the annotation in\n // the wrong place (and tell them)\n else if (!befAnnoText && aftAnnoText) {\n\n // Again, test for a number and if it is a number, set the return\n // unit to the number.\n if (intUtils_.isIntegerUnit(aftAnnoText)) {\n retUnit = aftAnnoText + annoText ;\n this.retMsg_.push(`The annotation ${annoText} before the `\n `${aftAnnoText} is invalid.\\n` + this.vcMsgStart_ + retUnit +\n this.vcMsgEnd_);\n }\n else {\n let mkUnitRet = this._makeUnit(aftAnnoText, origString);\n if (mkUnitRet[0]) {\n retUnit = mkUnitRet[0];\n retUnit.csCode_ += annoText;\n origString = retUnit.csCode_;\n this.retMsg_.push(`The annotation ${annoText} before the unit ` +\n `code is invalid.\\n` + this.vcMsgStart_ + retUnit.csCode_ +\n this.vcMsgEnd_);\n }\n // Otherwise add a not found message\n else {\n this.retMsg_.push(`Unable to find a unit for ${befAnnoText} that ` +\n `follows the annotation ${annoText}.`);\n }\n }\n }\n // else it's got text before AND after the annotation. Now what?\n // For now this is an error. This may be a case of a missing\n // operator but that is not handled yet.\n else {\n this.retMsg_.push(`Unable to find a unit for ${befAnnoText}${annoText}` +\n `${aftAnnoText}.\\nWe are not sure how to interpret text both before ` +\n `and after the annotation. Sorry`);\n }\n } // else if there's text before/and or after the annotation\n\n return [retUnit , origString];\n\n } // end _getUnitWithAnnotations\n\n\n /**\n * Performs unit arithmetic for the units in the units array. That array\n * contains units/numbers and the operators (division or multiplication) to\n * be performed on each unit/unit or unit/number pair in the array. This\n * should only be called from within this class (or by test code).\n *\n * @params uArray the array that contains the units, numbers and operators\n * derived from the unit string passed in to parseString\n * @param origString the original string to be parsed; used to provide\n * context for messages\n *\n * @returns a single unit object that is the result of the unit arithmetic\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n */\n _performUnitArithmetic(uArray, origString) {\n\n let finalUnit = uArray[0]['un'];\n if (intUtils_.isIntegerUnit(finalUnit)) {\n finalUnit = new Unit({'csCode_' : finalUnit, 'ciCode_' : finalUnit,\n 'magnitude_' : Number(finalUnit),\n 'name_' : finalUnit}) ;\n }\n let uLen = uArray.length ;\n let endProcessing = false ;\n // Perform the arithmetic for the units, starting with the first 2 units.\n // We only need to do the arithmetic if we have more than one unit.\n for (let u2 = 1; (u2 < uLen) && !endProcessing; u2++) {\n let nextUnit = uArray[u2]['un'];\n if (intUtils_.isIntegerUnit(nextUnit)) {\n nextUnit = new Unit({'csCode_' : nextUnit, 'ciCode_' : nextUnit,\n 'magnitude_' : Number(nextUnit),\n 'name_': nextUnit});\n }\n if (nextUnit === null ||\n ((typeof nextUnit !== 'number') && (!nextUnit.getProperty))) {\n let msgString = `Unit string (${origString}) contains unrecognized ` +\n 'element' ;\n if (nextUnit) {\n msgString += ` (${this.openEmph_}${nextUnit.toString()}` +\n `${this.closeEmph_})`;\n }\n msgString += '; could not parse full string. Sorry';\n this.retMsg_.push(msgString);\n endProcessing = true;\n }\n else {\n try {\n // Is the operation division?\n let thisOp = uArray[u2]['op'];\n let isDiv = thisOp === '/';\n\n // Perform the operation. Both the finalUnit and nextUnit\n // are unit objects.\n isDiv ? finalUnit = finalUnit.divide(nextUnit) :\n finalUnit = finalUnit.multiplyThese(nextUnit);\n }\n catch (err) {\n this.retMsg_.unshift(err.message) ;\n endProcessing = true ;\n finalUnit = null ;\n }\n } // end if we have another valid unit/number to process\n } // end do for each unit after the first one\n return finalUnit ;\n } // end _performUnitArithmetic\n\n\n /**\n * This tests a string to see if it starts with characters and ends with\n * digits. This is used to test for an exponent on a UCUM code (or what\n * we think might be a UCUM code). This is broken out to a separate\n * function so that the regular expression can be verified to provide the\n * results we expect, in case someone changes it. (Per Paul Lynch)\n * See \"Test _isCodeWithExponent method\" in testUnitString.spec.js\n *\n * This particular regex has been tweaked several times. This one\n * works with the following test strings:\n * \"m[H2O]-21 gives [\"m[H2O]-21\", \"m[H2O]\", \"-21\"]\n * \"m[H2O]+21 gives [\"m[H2O]+21\", \"m[H2O]\", \"+21\"]\n * \"m[H2O]21 gives [\"m[H2O]-21\", \"m[H2O]\", \"21\"]\n * \"s2\" gives [\"s2\", \"s, \"2\"]\n * \"kg\" gives null\n * \"m[H2O]\" gives null\n * \"m[H2O]23X\" gives null\n *\n * @params uCode the code being tested\n * @returns an array containing: (1) the code without the exponent (or\n * trailing number); and (2) the exponent/trailing number. Returns null\n * if there is no trailing number or something follows the trailing\n * number, or if the first part is not characters.\n */\n _isCodeWithExponent(uCode) {\n\n let ret = [] ;\n let res = uCode.match(/(^[^\\-\\+]+?)([\\-\\+\\d]+)$/);\n\n // If we got a return with an exponent, separate the exponent from the\n // unit and return both (as separate values)\n if (res && res[2] && res[2] !== \"\") {\n ret.push(res[1]);\n ret.push(res[2]);\n } // end if we got an exponent\n else {\n ret = null ;\n }\n return ret ;\n } // end _isCodeWithExponent\n\n} // end class UnitString\n\n\n/**\n * This function exists ONLY until the original UnitString 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 UnitString object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * @return the singleton UnitString object.\n */\nUnitString.getInstance = function(){\n return new UnitString();\n} ;\n\n/*\n// Perform the first request for the object, to set the getInstance method.\nUnitString.getInstance();\n\n*/\n","/**\n * This class manages Hashtables that provide references to\n * defined units.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar Ucum = require('./config.js').Ucum;\n\nclass UnitTablesFactory {\n\n /**\n * Constructor. This creates the empty unit tables (hashes) once. After the\n * tables are created, it redefines this constructor to throw an error\n * stating that the constructor is no longer available and that the\n * getInstance function must be used. Here's a description of the first\n * and then all subsequent calls to this constructor.\n *\n * First call to constructor:\n * 1. creates OBJECT1\n * 2. initializes attributes of OBJECT1\n * 3. stores reference to OBJECT1.prototype in holdthis local variable\n * 4. redefines OBJECT1 as a function that throws an error\n * 5. defines the getInstance function (which is also defined outside of\n * the class definition - see below).\n *\n * All subsequent calls to constructor:\n * 1. throw error message referring to getInstance\n * 2. call getInstance, returns this - which is OBJECT1.\n */\n constructor() {\n\n /**\n * Tracks units by name\n * @type hash - key is the name;\n * value is an array of references to the Unit objects\n * with the name. More than one unit may have the same\n * name, e.g., \"second\", which is shared by the base unit\n * with the code = \"s\" and the unit with code = \"'\".\n */\n this.unitNames_ = {};\n\n /**\n * Tracks units by code using case-sensitive version.\n *\n * @type hash - key is the code;\n * value is the reference to the Unit object. Codes must\n * be unique.\n */\n this.unitCodes_ = {};\n\n /**\n * Keeps track of the order in which units are defined. The order is\n * important because unit definitions build on previous definitions.\n *\n * @type {Array}\n */\n this.codeOrder_ = [] ;\n\n /**\n * Tracks units by unit strings, e.g., cm-1\n *\n * @type hash - key is the unit string\n * value is an array of unit objects with that ciUnitString.\n */\n this.unitStrings_ = {};\n\n /**\n * Tracks units by Dimension vector\n *\n * @type hash - key is the dimension vector (not the object, just the\n * vector);\n * value is an array of references to the Unit objects\n * with that vector. More than one unit may have the same\n * unit vector, and this can be used to provide a list\n * of commensurable units.\n */\n this.unitDimensions_ = {};\n\n /**\n * Maps synonyms to units. Not built until first requested.\n *\n * @type hash - key is the synonym\n * value is an array of references to Unit objects that\n * include that synonym.\n */\n this.unitSynonyms_ = {};\n\n /*\n * Holds onto the index of the index of the dimension vector flag for\n * the base mass unit (gram). This is set when the base unit (gram) is\n * created, and is stored here so that it doesn't have to be found\n * over and over again to try to determine whether or not a unit is\n * mass-based (for mole<->mass conversions)\n *\n * @type integer\n */\n this.massDimIndex_ = 0;\n\n /**\n * Map of indices in the dimension vector to base unit symbols.\n */\n this.dimVecIndexToBaseUnit_ = {};\n }\n\n\n /**\n * Provides the number of unit objects written to the tables, using the\n * codes table since codes must be unique.\n *\n * @returns count of the number of unit objects in the unitCodes_ table.\n */\n unitsCount() {\n return Object.keys(this.unitCodes_).length ;\n }\n\n\n /**\n * Adds a Unit object to the tables.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws passes on an error if one is thrown by the called functions for\n * a problem with the unit code or unit name\n */\n addUnit(theUnit) {\n\n let uName = theUnit['name_'] ;\n if (uName) {\n this.addUnitName(theUnit);\n }\n\n this.addUnitCode(theUnit);\n this.addUnitString(theUnit);\n\n try {\n if (theUnit['dim_'].getProperty('dimVec_'))\n this.addUnitDimension(theUnit);\n }\n catch(err){\n // do nothing - throws error if the property is null\n // and that's OK here.\n }\n\n if (theUnit.isBase_) {\n const dimVec = theUnit.dim_.dimVec_;\n let nonZeroIndex;\n for (let i=0, len=dimVec.length; nonZeroIndex==undefined && i<len; ++i) {\n if (dimVec[i] != 0)\n nonZeroIndex = i;\n }\n this.dimVecIndexToBaseUnit_[nonZeroIndex] = theUnit.csCode_;\n }\n } // end addUnit\n\n\n /**\n * Adds a Unit object to the unitNames_ table. More than one unit\n * can have the same name, e.g., the two units with the name \"second\",\n * where the code for one of them is 's' and the code for the other is\n * \"'\". Because of this, an array of unit objects is stored for the\n * name. In most cases it will be an array of one object, but this\n * clarifies that there may be more than one.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unit has no name\n */\n addUnitName(theUnit) {\n\n let uName = theUnit['name_'];\n\n if (uName) {\n if (this.unitNames_[uName])\n this.unitNames_[uName].push(theUnit);\n else\n this.unitNames_[uName] = [theUnit];\n }\n else\n throw(new Error('UnitTables.addUnitName called for a unit with no name. ' +\n `Unit code = ${theUnit['csCode_']}.`));\n\n } // end addUnitName\n\n\n /**\n * Adds a Unit object to the unitCodes_, unitUcCodes_, unitLcCodes_ and\n * codeOrder_ tables. This also sets the mass dimension index when the\n * base mass unit (gram) is read.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unitCodes_ table already contains a unit with\n * the code\n */\n addUnitCode(theUnit) {\n\n let uCode = theUnit['csCode_'];\n if (uCode) {\n\n if (this.unitCodes_[uCode])\n throw(new Error(`UnitTables.addUnitCode called, already contains entry for ` +\n `unit with code = ${uCode}`));\n else {\n this.unitCodes_[uCode] = theUnit;\n this.codeOrder_.push(uCode);\n if (uCode == 'g') {\n let dimVec = theUnit.dim_.dimVec_;\n let d = 0;\n for (; d < dimVec.length && dimVec[d] < 1; d++) ;\n this.massDimIndex_ = d;\n }\n }\n }\n else\n throw(new Error('UnitTables.addUnitCode called for unit that has ' +\n 'no code.')) ;\n\n } // end addUnitCode\n\n\n /**\n * Adds a unit object to the unitStrings_ table. More than one unit\n * can have the same string, so an array of unit objects is stored\n * for the string. The unit string is the string that creates a non-base\n * unit, e.g., a Newton has a unit code of N, a name of Newton, and a\n * unitString of kg.m/s2.\n *\n * If the unit has no string, nothing is stored and no error is reported.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n */\n addUnitString(theUnit) {\n\n let uString = null;\n if (Ucum.caseSensitive_ == true)\n uString = theUnit['csUnitString_'];\n else\n uString = theUnit['ciUnitString_'];\n\n if (uString) {\n let uEntry = {mag: theUnit['baseFactorStr_'], unit: theUnit};\n if (this.unitStrings_[uString])\n this.unitStrings_[uString].push(uEntry);\n else\n this.unitStrings_[uString] = [uEntry];\n }\n } // end addUnitString\n\n\n /**\n * Adds a Unit object to the unitDimensions_ table. More than one unit\n * can have the same dimension (commensurable units have the same dimension).\n * Because of this, an array of unit objects is stored for the\n * dimension.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unit has no dimension\n */\n addUnitDimension(theUnit) {\n\n let uDim = theUnit['dim_'].getProperty('dimVec_');\n\n if (uDim) {\n if (this.unitDimensions_[uDim])\n this.unitDimensions_[uDim].push(theUnit);\n else\n this.unitDimensions_[uDim] = [theUnit];\n }\n else\n throw(new Error('UnitTables.addUnitDimension called for a unit with no dimension. ' +\n `Unit code = ${theUnit['csCode_']}.`));\n\n } // end addUnitDimension\n\n\n /**\n * Builds the unitSynonyms_ table. This is called the first time the\n * getUnitsBySynonym method is called. The table/hash contains each word\n * (once) from each synonym as well as each word from each unit name.\n *\n * Hash keys are the words. Hash values are an array of unit codes for\n * each unit that has that word in its synonyms or name.\n *\n * @returns nothing\n */\n buildUnitSynonyms() {\n\n for (let code in this.unitCodes_) {\n let theUnit = this.unitCodes_[code];\n let uSyns = theUnit.synonyms_ ;\n\n // If the current unit has synonyms, process each synonym (often multiples)\n if (uSyns) {\n let synsAry = uSyns.split(';');\n if (synsAry[0] !== '') {\n let aLen = synsAry.length;\n for (let a = 0; a < aLen; a++) {\n let theSyn = synsAry[a].trim();\n\n // call addSynonymCodes to process each word in the\n // synonym, e.g., \"British fluid ounces\"\n this.addSynonymCodes(code, theSyn) ;\n } // end do for each synonym\n } // end if the current unit has a non-null synonym attribute\n } // end if the unit has any synonyms\n\n // Now call addSynonymCodes to process each word in the unit's name\n this.addSynonymCodes(code, theUnit.name_) ;\n } // end do for each unit\n } // end buildUnitSynonyms\n\n\n /**\n * Adds unit code entries to the synonyms table for a string containing\n * one or more words to be considered as synonyms.\n *\n * @param theCode the unit code to be connected to the synonyms\n * @param theSynonyms a string containing one or more words to be\n * considered synonyms (and thus to be added to the unitSynonyms hash).\n */\n addSynonymCodes(theCode, theSynonyms) {\n\n let words = theSynonyms.split(' ');\n let wLen = words.length;\n\n for (let w = 0; w < wLen; w++) {\n let word = words[w];\n\n // if there is already a synonyms entry for the word,\n // get the array of unit codes currently assigned to\n // the word and add the code for the current word to\n // the synonyms array if it's not already there.\n if (this.unitSynonyms_[word]) {\n let synCodes = this.unitSynonyms_[word];\n if (synCodes.indexOf(theCode) === -1) {\n this.unitSynonyms_[word].push(theCode);\n }\n }\n // else there are no synonyms entry for the word. Create a\n // synonyms array for the word, setting it to contain the unit code.\n else {\n this.unitSynonyms_[word] = [theCode];\n }\n } // end do for each word in the synonyms being processed\n\n } // end addSynonymCodes\n\n\n /**\n * Returns a unit object with a case-sensitive code matching the\n * uCode parameter, or null if no unit is found with that code.\n *\n * @param uCode the code of the unit to be returned\n * @returns the unit object or null if it is not found\n */\n getUnitByCode(uCode) {\n let retUnit = null ;\n if (uCode) {\n retUnit = this.unitCodes_[uCode];\n }\n return retUnit ;\n }\n\n\n /**\n * Returns a array of unit objects based on the unit's name. Usually this\n * will be an array of one, but there may be more, since unit names are\n * not necessarily unique.\n *\n * @param uName the name of the unit to be returned. If more than one\n * unit has the same name and you only want one specific unit, append the\n * csCode of the unit you want to the end of the name, separated by the\n * Ucum.codeSep_ value, e.g., inch - [in_i] vs. inch - [in_us].\n * @returns null if no unit was found for the specified name OR an array of\n * unit objects with the specified name. Normally this will be an array\n * of one object.\n * @throws an error if no name is provided to search on\n */\n getUnitByName(uName) {\n\n if (uName === null || uName === undefined) {\n throw (new Error('Unable to find unit by name because no name was provided.'));\n }\n let sepPos = uName.indexOf(Ucum.codeSep_);\n let uCode = null;\n if (sepPos >= 1) {\n uCode = uName.substr(sepPos + Ucum.codeSep_.length);\n uName = uName.substr(0, sepPos);\n }\n let retUnits = this.unitNames_[uName] ;\n if (retUnits) {\n let uLen = retUnits.length ;\n\n if (uCode && uLen > 1) {\n let i = 0;\n for (; retUnits[i].csCode_ !== uCode && i < uLen; i++);\n if (i < uLen)\n retUnits = [retUnits[i]];\n else {\n retUnits = null;\n }\n } // end if we need to find both a name and a code\n } // end if we got an array of units\n return retUnits ;\n\n } // end getUnitByName\n\n\n /**\n * Returns an array of unit objects with the specified unit string.\n * The array may contain one or more unit reference objects.\n * Or none, if no units have a matching unit string (which is not\n * considered an error)\n *\n * @param name the name of the unit to be returned\n * @returns the array of unit references or null if none were found\n */\n getUnitByString(uString) {\n let retAry = null ;\n if (uString) {\n retAry = this.unitStrings_[uString] ;\n if (retAry === undefined)\n retAry = null;\n }\n return retAry ;\n }\n\n\n /**\n * Returns a array of unit objects based on the unit's dimension vector.\n *\n * @param uName the dimension vector of the units to be returned.\n *\n * @returns null if no unit was found for the specified vector OR an array of\n * one or more unit objects with the specified vector.\n * @throws an error if no vector is provided to search on\n * logs an error to the console if no unit is found\n */\n getUnitsByDimension(uDim) {\n\n let unitsArray = null ;\n if (uDim === null || uDim === undefined) {\n throw (new Error('Unable to find unit by because no dimension ' +\n 'vector was provided.'));\n }\n\n unitsArray = this.unitDimensions_[uDim] ;\n if (unitsArray === undefined || unitsArray === null) {\n console.log(`Unable to find unit with dimension = ${uDim}`);\n }\n\n return unitsArray ;\n\n } // end getUnitsByDimension\n\n\n /**\n * Returns a array of unit objects that include the specified synonym.\n *\n * @param uSyn the synonym of the units to be returned.\n *\n * @returns an object with two of the following three elements:\n * 'status' will be error, failed or succeeded\n * 'msg' will be included for returns with status = error or failed and\n * will explain why the request did not return any units\n * 'units' any array of unit objects with the specified synonym will be\n * returned for requests with status = succeeded\n */\n getUnitBySynonym(uSyn) {\n\n let retObj = {} ;\n let unitsArray = [];\n\n try {\n if (uSyn === null || uSyn === undefined) {\n retObj['status'] = 'error' ;\n throw (new Error('Unable to find unit by synonym because no synonym ' +\n 'was provided.'));\n }\n // If this is the first request for a unit by synonym, build the hash map\n if (Object.keys(this.unitSynonyms_).length === 0) {\n this.buildUnitSynonyms();\n }\n let foundCodes = [];\n foundCodes = this.unitSynonyms_[uSyn];\n if (foundCodes) {\n retObj['status'] = 'succeeded';\n let fLen = foundCodes.length;\n for (let f = 0; f < fLen; f++) {\n unitsArray.push(this.unitCodes_[foundCodes[f]]);\n }\n retObj['units'] = unitsArray ;\n }\n if (unitsArray.length === 0) {\n retObj['status'] = 'failed' ;\n retObj['msg'] = `Unable to find any units with synonym = ${uSyn}`;\n }\n }\n catch(err) {\n retObj['msg'] = err.message ;\n }\n return retObj ;\n } // end getUnitBySynonym\n\n\n /**\n * Gets a list of all unit names in the Unit tables\n *\n * @returns an array of the unit names\n */\n getAllUnitNames() {\n return Object.keys(this.unitNames_);\n } // end getAllUnitNames\n\n\n /**\n * Gets a list of all unit names in the tables. Where more than one\n * unit has the same name, the unit code, in parentheses, is appended\n * to the end of the name.\n *\n * @returns {Array}\n */\n getUnitNamesList() {\n let nameList = [];\n let codes = Object.keys(this.unitCodes_);\n codes.sort(this.compareCodes) ;\n let uLen = codes.length;\n for (let i = 0; i < uLen; i++) {\n nameList[i] = codes[i] + Ucum.codeSep_ + this.unitCodes_[codes[i]].name_\n } // end do for each code\n return nameList ;\n }\n\n\n /*\n * Returns the mass dimension index\n * @returns this.massDimIndex_\n */\n getMassDimensionIndex() {\n return this.massDimIndex_ ;\n }\n\n /**\n * This provides a sort function for unit codes so that sorting ignores\n * square brackets and case.\n *\n * @param a first value\n * @param b second value\n * @returns -1 if a is should fall before b; otherwise 1.\n */\n compareCodes(a, b) {\n a = a.replace(/[\\[\\]]/g, '');\n a = a.toLowerCase();\n b = b.replace(/[\\[\\]]/g, '');\n b = b.toLowerCase();\n return (a < b) ? -1 : 1 ;\n }\n\n\n /**\n * Gets a list of all unit codes in the Unit tables\n *\n * @returns an array of the unit names\n */\n getAllUnitCodes() {\n return Object.keys(this.unitCodes_);\n } // end getAllUnitNames\n\n\n /**\n * This is used to get all unit objects. Currently it is used\n * to get the objects to write to the json ucum definitions file\n * that is used to provide prefix and unit definition objects for\n * conversions and validations.\n *\n * @returns an array containing all unit objects, ordered by definition\n * order\n */\n allUnitsByDef() {\n\n let unitsList = [];\n let uLen = this.codeOrder_.length ;\n for (let u = 0; u < uLen; u++) {\n unitsList.push(this.getUnitByCode(this.codeOrder_[u]));\n }\n return unitsList ;\n } // end allUnitsByDef\n\n\n /**\n * This is used to get all unit objects, ordered by unit name. Currently it\n * is used to create a csv list of all units.\n * @param sep separator character (or string) to be used to separate each\n * column in the output. Optional, defaults to '|' if not specified.\n * (Used to use ; but the synonyms use that extensively). Don't use a\n * comma or any other punctuation found in the output data.\n * @returns a buffer containing all unit objects, ordered by name\n * order\n */\n allUnitsByName(cols, sep) {\n if (sep === undefined || sep === null)\n sep = '|';\n let unitBuff = '';\n let unitsList = this.getAllUnitNames();\n let uLen = unitsList.length;\n let cLen = cols.length;\n for (let i = 0; i < uLen; i++) {\n let nameRecs = this.getUnitByName(unitsList[i]);\n for (let u = 0; u < nameRecs.length; u++) {\n let rec = nameRecs[u];\n for (let c = 0; c < cLen; c++) {\n if (c > 0)\n unitBuff += sep;\n if (cols[c] === 'dim_') {\n if (rec.dim_ !== null && rec.dim_ !== undefined &&\n rec.dim_.dimVec_ instanceof Array)\n unitBuff += '[' + rec.dim_.dimVec_.join(',') + ']';\n else\n unitBuff += '';\n }\n else {\n let cbuf = rec[cols[c]];\n if (typeof cbuf === 'string')\n unitBuff += cbuf.replace(/[\\n\\r]/g, ' ');\n else\n unitBuff += cbuf ;\n }\n } // end do for each column requested\n unitBuff += '\\r\\n';\n } // end do for each unit in the unit names array\n }\n return unitBuff ;\n } // end allUnitsByName\n\n\n /**\n * This creates a list of all units in the tables. It uses the byCode\n * table, and uses the codeOrder_ array to determine the order in which\n * the units are listed.\n *\n * @param doLong boolean indicating how much to output. If true, all data\n * from the unit objects is included. If false, only a few major values\n * are included.\n * @param sep separator character (or string) to be used to separate each\n * column in the output. Optional, defaults to '|' if not specified.\n * (Used to use ; but the synonyms use that extensively).\n * @returns {string} buffer containing all the listings\n */\n printUnits(doLong, sep) {\n if (doLong === undefined)\n doLong = false ;\n if (sep === undefined)\n sep = '|';\n let codeList = '';\n let uLen = this.codeOrder_.length ;\n let unitString = 'csCode' + sep ;\n if (doLong) {\n unitString += 'ciCode' + sep ;\n }\n unitString += 'name' + sep ;\n if (doLong)\n unitString += 'isBase' + sep ;\n unitString += 'magnitude' + sep + 'dimension' + sep + 'from unit(s)' + sep +\n 'value' + sep + 'function' + sep ;\n if (doLong)\n unitString += 'property' + sep + 'printSymbol' + sep + 'synonyms' + sep +\n 'source' + sep + 'class' + sep + 'isMetric' + sep +\n 'variable' + sep + 'isSpecial' + sep + 'isAbitrary' + sep ;\n unitString += 'comment';\n codeList = unitString + '\\n' ;\n\n for (let u = 0; u < uLen; u++) {\n let curUnit = this.getUnitByCode(this.codeOrder_[u]);\n unitString = this.codeOrder_[u] + sep ;\n if (doLong) {\n unitString += curUnit.getProperty('ciCode_') + sep ;\n }\n unitString += curUnit.getProperty('name_') + sep ;\n if (doLong) {\n if (curUnit.getProperty('isBase_'))\n unitString += 'true' + sep ;\n else\n unitString += 'false' + sep ;\n }\n unitString += curUnit.getProperty('magnitude_') + sep;\n let curDim = curUnit.getProperty('dim_');\n if (curDim) {\n unitString += curDim.dimVec_ + sep ;\n }\n else {\n unitString += 'null' + sep;\n }\n if (curUnit.csUnitString_)\n unitString += curUnit.csUnitString_ + sep + curUnit.baseFactor_ + sep ;\n else\n unitString += 'null' + sep + 'null' + sep;\n\n if (curUnit.cnv_)\n unitString += curUnit.cnv_ + sep ;\n else\n unitString += 'null' + sep ;\n\n if (doLong) {\n unitString += curUnit.getProperty('property_') + sep +\n curUnit.getProperty('printSymbol_') + sep +\n curUnit.getProperty('synonyms_') + sep +\n curUnit.getProperty('source_') + sep +\n curUnit.getProperty('class_') + sep +\n curUnit.getProperty('isMetric_') + sep +\n curUnit.getProperty('variable_') + sep +\n curUnit.getProperty('isSpecial_') + sep +\n curUnit.getProperty('isArbitrary_') + sep ;\n }\n if (curUnit.defError_)\n unitString += 'problem parsing this one, deferred to later.' ;\n codeList += unitString + '\\n' ;\n }\n return codeList ;\n }\n\n} // end UnitTablesFactory\n\n\n// Create a singleton instance and (to preserve the existing API) an object that\n// provides that instance via getInstance().\nvar unitTablesInstance = new UnitTablesFactory();\nexport const UnitTables = {\n getInstance: function() {\n return unitTablesInstance;\n }\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","/**\n * This exports definitions for ucum classes that need references to them\n * available to the demo code. The actual code will be in the ucumPkg\n * library found in the dist directory. This file provides the hooks to\n * those classes within the library.\n */\n\nexport var Ucum = require(\"./config.js\").Ucum;\nexport var UcumLhcUtils = require(\"./ucumLhcUtils.js\").UcumLhcUtils;\nexport var UnitTables = require(\"./unitTables.js\").UnitTables;"],"names":["root","factory","exports","module","define","amd","this","Number","isFinite","value","Infinity","require","isInteger","val","Math","floor","dimLen_","validOps_","codeSep_","valMsgStart_","valMsgEnd_","cnvMsgStart_","cnvMsgEnd_","openEmph_","closeEmph_","openEmphHTML_","closeEmphHTML_","bracesMsg_","needMoleWeightMsg_","needEqWeightMsg_","needEqChargeMsg_","csvCols_","inputKey_","specUnits_","UC","Dimension","dimSetting","_classCallCheck","Ucum","Error","assignZero","Array","length","concat","JSON","stringify","dimVec_","d","push","key","indexPos","ret","propertyName","charAt","join","dim2","_typeof","i","s","isEqual","dimVec2","undefined","allZero","that","assignDim","obj","config","data","_config","prepareConfig","map","unpackItem","bind","prototype","isArray","item","result","forEach","keyArr","place","Prefix","attrs","code_","ciCode_","name_","printSymbol_","value_","parseFloat","exp_","prefix2","prefixTablesInstance","PrefixTablesFactory","byCode_","byValue_","Object","keys","prefixBuff","pList","pLen","p","pfx","getPrefixByValue","prefixList","sort","getPrefixByCode","prefixObj","getCode","getValue","code","getInstance","UcumFunctions","funcs","cnvTo","x","cnvFrom","log","LN10","pow","exp","LN2","tan","atan","sqrt","func","fname","toLowerCase","f","theSyn","resp","retObj","UnitTables","getUnitBySynonym","aLen","a","theUnit","csCode_","guidance_","str","test","theString","num","isNaN","Pfx","PfxT","Un","Utab","unpackArray","UcumJsonDefs","jsonDefs","prefixes","units","unitsCount","pTab","PrefixTables","plen","newPref","add","uTab","ulen","u","newUnit","Unit","addUnit","_ucumJsonDefs","intUtils_","e","WeakMap","r","__esModule","o","__proto__","default","has","get","set","_t","hasOwnProperty","call","defineProperty","getOwnPropertyDescriptor","_interopRequireWildcard","Symbol","iterator","constructor","_defineProperties","t","enumerable","configurable","writable","_toPropertyKey","toPrimitive","TypeError","String","_toPrimitive","UnitString","UcumLhcUtils","n","ucumJsonDefs","loadJsonDefs","uStrParser_","massDimIndex_","getMassDimensionIndex","use","useHTMLInMessages","useBraceMsgForEachString","uStr","suggest","valConv","getSpecifiedUnit","status","fromUnit","toUnit","moleExp_","equivalentExp_","dim_","getElementAt","fromUnitCode","fromVal","toUnitCode","options","arguments","_options$suggest","_options$molecularWei","molecularWeight","_options$charge","charge","returnObj","trim","_checkFromVal","parseResp","convertType","detectConversionType","msgCountBeforeConvert","convertFrom","err","message","isMolMassCommensurable","convertMolMass","isEqMassCommensurable","convertEqMass","isEqMolCommensurable","convertEqMol","isEqMolMassCommensurable","convertEqMolMass","inputUnitLookup","_inputUnitLookup$retM","unit","msg","retMsg","isArbitrary_","_unit$dim_","unitToExp","dimVec","baseUnitString","dimVecIndexToBaseUnit","dimVecIndexToBaseUnit_","len","retUnitLookup","retUnit","magnitude","toString","fromUnitIsSpecial","isSpecial_","responseObj","isNumericString","getSynonyms","uName","utab","getUnitByCode","parseString","console","unshift","origString","fromName","categoryList","commUnits","fromDim","getProperty","getUnitsByDimension","filter","indexOf","category_","_ucumFunctions","isBase_","property_","magnitude_","class_","isMetric_","variable_","cnv_","cnvPfx_","synonyms_","source_","loincProperty_","csUnitString_","ciUnitString_","baseFactorStr_","baseFactor_","defError_","_createClass","vals","uKey","_this","getOwnPropertyNames","clone","unit2","_this2","equals","thisAttr","u2Attr","keyLen","match","k","isNull","fromCnv","fromMag","forName","f_from","convertCoherent","max","getMax","elem","uA","_getUnitTables","name","amt","molPowersToConvert","avoNum","moleUnitFactor","massPowersToConvert","equivalentMass","avogadroNumber","eqPowersToConvert","molAmt","tabs","mutateCoherent","mulVal","_concatStrs","isZero","resetFieldsForDerivedUnit","invertString","sub","minus","stringRep","replace","substr","str1","operator","str2","startChar","endChar","_buildOneString","endsWith","uArray","arLen","un","nun","parseInt","uLen","uChar","mul","unit1Dim","setElementAt","unit2Dim","_templateObject","slice","freeze","defineProperties","raw","_defineProperty","utabs_","pfxTabs_","parensFlag_","pFlagLen_","braceFlag_","bFlagLen_","vcMsgStart_","vcMsgEnd_","retMsg_","parensUnits_","annotations_","suggestions","suggestions_","_getAnnotations","sUnit","finalUnit","_parseTheString","isIntegerUnit","endProcessing","parensResp","_processParens","mkUArray","_makeUnitsArray","u1","curCode","parenUnit","_getParensUnit","uRet","_makeUnit","_performUnitArithmetic","uString","openBrace","closeBrace","braceStr","substring","VALID_ANNOTATION_REGEX","aIdx","INVALID_ANNOTATION_CHAR_MSG","uStrArray","uStrAryPos","stopProcessing","pu","trimmedCt","openCt","closeCt","openPos","closePos","theMsg","c","uArray1","startNumCheck","numRes","dispVal","parensback","op","theOp","numRes2","invalidString","parensStr","parensString","nextParens","pStr","psIdx","befText","peIdx","lastIndexOf","aftText","pNumText","nMag","assignVals","annoRet","_getAnnoText","asIdx","startText","aeIdx","endText","idx","idxNum","suggSet","synLen","unitArray","uCode","getAnnoRet","_getUnitWithAnnotation","tryCode","origCode","origUnit","pfxCode","pfxObj","pfxVal","codeAndExp","_isCodeWithExponent","isIntegerUnitWithExp","theDim","theMag","theName","theCiCode","thePrintSymbol","pfxExp","getExp","theCode","getName","getCiCode","getPrintSymbol","expStr","intergerUnitExpSign","bracketRet","_getUnitAfterAddingBrackets","nameRet","_getUnitByName","_getSuggestions","retUnitAry","getUnitByName","mString","dupMsg","escapedCode","rStr","RegExp","updatedOrigString","addBrackets","bracketUnit","leadingUnitBoundary","annoText","befAnnoText","aftAnnoText","msgLen","toUpperCase","mkUnitRet","tryBrackets","pop","u2","nextUnit","msgString","divide","multiplyThese","res","unitTablesInstance","UnitTablesFactory","unitNames_","unitCodes_","codeOrder_","unitStrings_","unitDimensions_","unitSynonyms_","addUnitName","addUnitCode","addUnitString","addUnitDimension","nonZeroIndex","caseSensitive_","uEntry","mag","uDim","uSyns","synsAry","split","addSynonymCodes","theSynonyms","words","wLen","w","word","sepPos","retUnits","retAry","unitsArray","uSyn","foundCodes","buildUnitSynonyms","fLen","nameList","codes","compareCodes","b","unitsList","cols","sep","unitBuff","getAllUnitNames","cLen","nameRecs","rec","cbuf","doLong","codeList","unitString","curUnit","curDim","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}
1
+ {"version":3,"file":"ucum-lhc.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAiB,QAAID,IAErBD,EAAc,QAAIC,GACnB,CATD,CASGK,KAAM,I,iCCPTH,EAAOD,QAAUK,OAAOC,UAAY,SAAUC,GAC7C,QAA0B,iBAAVA,GAAsBA,GAAUA,GAASA,IAAUC,KAAYD,KAAU,IAC1F,C,aCFA,IAAID,EAAWG,EAAQ,KACvBR,EAAOD,QAAUK,OAAOK,WAAa,SAASC,GAC5C,MAAsB,iBAARA,GACZL,EAASK,IACTC,KAAKC,MAAMF,KAASA,CACxB,C,0ECCeX,EAAAA,KAAG,CAgBhBc,QAAS,EAOTC,UAAW,CAAC,IAAK,KAOjBC,SAAW,KAGXC,aAAe,gBACfC,WAAa,IACbC,aAAe,wBACfC,WAAa,IAQbC,UAAY,MAOZC,WAAa,MAObC,cAAgB,2BAOhBC,eAAiB,WAMjBC,WAAa,sJASbC,mBAAqB,yJASrBC,iBAAmB,0HASnBC,iBAAmB,gHAQnBC,SAAW,CACT,sBAAwB,UACxB,iBAAmB,iBACnB,iBAAmB,QACnB,SAAa,YACb,OAAW,UACX,SAAa,YACb,SAAa,aAMfC,UAAY,sBASXC,WAAa,CAAE,WAAa,iBACb,kBAAoB,kB,0rBC7HtC,IAAIC,EAAKvB,EAAQ,KACbC,EAAYD,EAAQ,KACFT,EAAAA,EAAA,WAuBpB,SAAAiC,EAAYC,GAEV,G,4FAFsBC,CAAA,KAAAF,GAEE,IAApBD,EAAGI,KAAKtB,QACV,MAAM,IAAIuB,MAAM,yEAGlB,GAAIH,QACF9B,KAAKkC,kBAEF,GAAIJ,aAA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E,GAC5C,QAAqBnf,IAAjBof,EACH,OAAOA,EAAa/iB,QAGrB,IAAIC,EAAS2iB,EAAyBE,GAAY,CAGjD9iB,QAAS,CAAC,GAOX,OAHAgjB,EAAoBF,GAAU7iB,EAAQA,EAAOD,QAAS6iB,GAG/C5iB,EAAOD,OACf,C,wHCfeA,EAAAA,KAAAA,EAAAA,KAAAA,KACQA,EAAAA,aAAAA,EAAAA,KAAAA,aACFA,EAAAA,WAAAA,EAAAA,KAAAA,U","sources":["webpack://ucumPkg/webpack/universalModuleDefinition","webpack://ucumPkg/./node_modules/is-finite/index.js","webpack://ucumPkg/./node_modules/is-integer/index.js","webpack://ucumPkg/./source/config.js","webpack://ucumPkg/./source/dimension.js","webpack://ucumPkg/./source/jsonArrayPack.js","webpack://ucumPkg/./source/prefix.js","webpack://ucumPkg/./source/prefixTables.js","webpack://ucumPkg/./source/ucumFunctions.js","webpack://ucumPkg/./source/ucumInternalUtils.js","webpack://ucumPkg/./source/ucumJsonDefs.js","webpack://ucumPkg/./source/ucumLhcUtils.js","webpack://ucumPkg/./source/unit.js","webpack://ucumPkg/./source/unitString.js","webpack://ucumPkg/./source/unitTables.js","webpack://ucumPkg/webpack/bootstrap","webpack://ucumPkg/./source/ucumPkg.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ucumPkg\"] = factory();\n\telse\n\t\troot[\"ucumPkg\"] = factory();\n})(this, () => {\nreturn ","'use strict';\n\nmodule.exports = Number.isFinite || function (value) {\n\treturn !(typeof value !== 'number' || value !== value || value === Infinity || value === -Infinity);\n};\n","// https://github.com/paulmillr/es6-shim\n// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isinteger\nvar isFinite = require(\"is-finite\");\nmodule.exports = Number.isInteger || function(val) {\n return typeof val === \"number\" &&\n isFinite(val) &&\n Math.floor(val) === val;\n};\n","/*\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","/**\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","/**\n * This file provides functions to reduce the size of an array of objects of the same structure in JSON.\n */\nconst pushFn = Array.prototype.push;\n\nfunction isObject(value) {\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\n/**\n * Makes human readable config used to pack/unpack array of objects of the same structure to store with packed data.\n * @param {Object} refObj - reference item of array of objects of the same structure\n * @returns {Array}\n */\nfunction createConfig(refObj) {\n return Object.keys(refObj).reduce((config, key) => {\n if (isObject(refObj[key])) {\n pushFn.apply(config, createConfig(refObj[key]).map(keyTail => [key, ...[].concat(keyTail)]));\n } else {\n config.push(key);\n }\n return config;\n }, [])\n}\n\n/**\n * Prepares config created with createConfig function to use in packItem/unpackItem functions.\n * @param {Array} config\n * @returns {Array}\n */\nfunction prepareConfig(config) {\n return config.map(key => Array.isArray(key) ? key : [key]);\n}\n\n/**\n * Converts an object to an array of values in the order of keys from configuration array.\n * @param {Array} config - configuration array\n * @param {Object} item - input object\n * @returns {Array}\n */\nfunction packItem(config, item) {\n if (config.join() !== prepareConfig(createConfig(item)).join()) {\n throw new Error('Object of unusual structure')\n }\n\n return config.map(keyArr => {\n let place = item;\n keyArr.forEach(key => {\n place = place[key];\n if (place === undefined) {\n throw new Error('Object of unusual structure')\n }\n });\n return place;\n });\n}\n\n/**\n * Performs the reverse of packItem function.\n * @param {Array} config - configuration array\n * @param {Array} item - input object\n * @returns {Object}\n */\nfunction unpackItem(config, item) {\n let result = {};\n\n config.forEach((keyArr, i) => {\n let place = result;\n for (let i = 0; i < keyArr.length - 1; i++) {\n place = place[keyArr[i]] = place[keyArr[i]] || {};\n }\n place[keyArr[keyArr.length - 1]] = item[i];\n });\n\n return result;\n}\n\n/**\n * Reduces size of an array of objects of the same structure before serialize it to JSON\n * @param {Array} arr\n * @returns {Object}\n */\nexport function packArray(arr) {\n if (arr && arr.length) {\n const config = createConfig(arr[0]),\n _config = prepareConfig(config);\n\n if (config.length) {\n return {\n config: config,\n data: arr.map(packItem.bind(null, _config))\n };\n }\n }\n\n return {\n config: [],\n data: arr\n };\n}\n\n/**\n * Restores an array of objects of the same structure after deserializing this object from JSON\n * @param {Object} obj\n * @returns {Array}\n */\nexport function unpackArray(obj) {\n const config = obj && obj.config;\n\n if (config) {\n if (config.length && obj.data) {\n const _config = prepareConfig(config);\n\n return obj.data.map(unpackItem.bind(null, _config));\n } else {\n return obj.data;\n }\n }\n\n return obj;\n}","/**\n * Prefix objects are defined in this file.\n */\n\n/**\n * This class implements the prefix object. Prefixes are used as multipliers\n * for units, e.g., km for kilometers\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nvar Ucum = require('./config.js');\n\nexport class Prefix {\n\n /**\n * Creates a single prefix object.\n *\n * @param attrs a hash of the values to use in creating the prefix object.\n * They should be:\n * code_ - which is the case-sensitive code used for the prefix,\n * e.g., k for kilo\n * ciCode_ - which is the case-insensitive code used for the prefix,\n * e.g., K for kilo\n * name_ - which is the name of the prefix, e.g., kilo\n * printSymbol_ - which is the print symbol for the prefix, e.g., k for kilo\n * value_ - which is teh value to use in multiplying the magnitude of\n * a unit, e.g., for a prefix of c the value will be .01.\n * exp_ - which is the exponent used to get the value. For decimal based\n * prefixes the base is 10 and the exp_ is applied to 10, e.g., for a\n * prefix of c, the exponent will be -2. For prefixes that are not\n * decimal based, this will be null (but must not be undefined).\n *\n * @throws an error if the not all required parameters are provided\n */\n constructor(attrs) {\n\n if (attrs['code_'] === undefined || attrs['code_'] === null ||\n attrs['name_'] === undefined || attrs['name_'] === null ||\n attrs['value_'] === undefined || attrs['value_'] === null ||\n attrs['exp_'] === undefined) {\n throw(new Error('Prefix constructor called missing one or more parameters. ' +\n 'Prefix codes (cs or ci), name, value and exponent must all be specified ' +\n 'and all but the exponent must not be null.'));\n }\n\n /**\n * The prefix code, e.g., k for kilo. This should be the case-sensitive\n * code. Since there's no way to check to see if it's the case-sensitive\n * one as opposed to the case-insensitive one (because although\n * case-insensitive codes all seem to be uppercase, some case-sensitive\n * codes are also all uppercase), we'll just have to believe that the\n * right one was passed in.\n */\n this.code_ = attrs['code_'];\n\n /**\n * The case-insensitive code, e.g., K for kilo\n */\n this.ciCode_ = attrs['ciCode_'];\n\n /**\n * The prefix name, e.g., kilo\n */\n this.name_ = attrs['name_'];\n\n /**\n * The printSymbol for the prefix, e.g., k for kilo\n */\n this.printSymbol_ = attrs['printSymbol_'];\n\n /**\n * The value to use in multiplying the magnitude of a unit\n */\n if (typeof attrs['value_'] === 'string')\n this.value_ = parseFloat(attrs['value_']);\n else\n this.value_ = attrs['value_'] ;\n\n /**\n * The exponent used to create the value from 10. For prefixes that are\n * not based on 10, this will be null.\n */\n this.exp_ = attrs['exp_'] ;\n\n } // end constructor\n\n\n /**\n * Returns the value for the current prefix object\n * @return the value for the prefix object with the specified code\n * */\n getValue() {\n return this.value_;\n }\n\n\n /**\n * Returns the prefix code for the current prefix object\n * @return the code for the current prefix object\n */\n getCode() {\n return this.code_;\n }\n\n\n /**\n * Returns the case-insensitive code for the current prefix object\n * @return the case_insensitive code for the current prefix object\n */\n getCiCode() {\n return this.ciCode_;\n }\n\n\n /**\n * Returns the prefix name for the current prefix object\n * @return the name for the current prefix object\n */\n getName() {\n return this.name_;\n }\n\n\n /**\n * Returns the print symbol for the current prefix object\n * @return the print symbol for the current prefix object\n */\n getPrintSymbol() {\n return this.printSymbol_;\n }\n\n\n /**\n * Returns the exponent for the current prefix object\n * @return the exponent for the current prefix object\n */\n getExp() {\n return this.exp_;\n }\n\n\n /**\n * Provides way to tell if one prefix equals another. The second prefix\n * must match all attribute values.\n *\n * @param prefix2 prefix object to check for a match\n * @return true for a match; false if one or more attributes don't match\n */\n equals(prefix2) {\n return this.code_ === prefix2.code_ &&\n this.ciCode_ === prefix2.ciCode_ &&\n this.name_ === prefix2.name_ &&\n this.printSymbol_ === prefix2.printSymbol_ &&\n this.value_ === prefix2.value_ &&\n this.exp_ === prefix2.exp_ ;\n }\n} // end Prefix class\n","/**\n * The tables of defined prefixes is defined in this file.\n */\n\n/**\n * This class implements the table of multiplier prefixes.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nexport class PrefixTablesFactory {\n\n /**\n * Constructor. This creates the empty PrefixTable hashes once.\n * There is one hash whose key is the prefix code and one whose\n * key is the prefix value.\n *\n * Implementation of this as a singleton is based on the UnitTables\n * implementation. See that class for details.\n */\n constructor(){\n this.byCode_ = {} ;\n this.byValue_ = {};\n }\n\n\n /**\n * Provides the number of prefix objects in each table\n * @returns count of the number of prefix objects in each table\n */\n prefixCount() {\n return Object.keys(this.byCode_).length ;\n }\n\n\n /**\n * This is used to get all prefix objects by value. Currently it is used\n * to create a csv file with all prefixes and units.\n * @returns csv string containing all prefix objects, ordered by value.\n */\n allPrefixesByValue() {\n let prefixBuff = '';\n let pList = Object.keys(this.byValue_);\n //pList.sort() ;\n let pLen = pList.length;\n for (let p = 0; p < pLen; p++) {\n let pfx = this.getPrefixByValue(pList[p]) ;\n prefixBuff += pfx.code_ + ',' + pfx.name_ + ',,' + pfx.value_ + '\\r\\n';\n }\n return prefixBuff ;\n }\n\n /**\n * This is used to get all prefix objects. Currently it is used\n * to get the objects to write to the json ucum definitions file\n * that is used to provide prefix and unit definition objects for\n * conversions and validations.\n *\n * @returns an array containing all prefix objects, ordered by code.\n */\n allPrefixesByCode() {\n let prefixList = [];\n let pList = Object.keys(this.byCode_);\n pList.sort() ;\n let pLen = pList.length;\n for (let p = 0; p < pLen; p++) {\n prefixList.push(this.getPrefixByCode(pList[p])) ;\n }\n return prefixList ;\n }\n\n /**\n * Adds a prefix object to the tables\n *\n * @param prefixObj the object to be added to the tables\n */\n add(prefixObj){\n this.byCode_[prefixObj.getCode()] = prefixObj;\n this.byValue_[prefixObj.getValue()] = prefixObj;\n }\n\n\n /**\n * Tests whether a prefix object is found for a specified code. This\n * is used to determine whether or not a prefix object has been created\n * for the code.\n *\n * @param code the code to be used to find the prefix object\n * @return boolean indicating whether or not a prefix object was found\n * for the specified code\n */\n isDefined(code) {\n return this.byCode_[code] !== null && this.byCode_[code] !== undefined ;\n }\n\n\n /**\n * Obtains a prefix object for a specified code.\n *\n * @param code the code to be used to find the prefix object\n * @return the prefix object found, or null if nothing was found\n */\n getPrefixByCode(code) {\n return this.byCode_[code];\n }\n\n\n /**\n * Obtains a prefix object for a specified value.\n *\n * @param value the value to be used to find the prefix object\n * @return the prefix object found, or null if nothing was found\n */\n getPrefixByValue(value) {\n return this.byValue_[value];\n }\n\n} // end PrefixTablesFactory class\n\n\n// Create a singleton instance and (to preserve the existing API) an object that\n// provides that instance via getInstance().\nvar prefixTablesInstance = new PrefixTablesFactory();\nexport const PrefixTables = {\n getInstance: function() {\n return prefixTablesInstance;\n }\n}\n","/*\n * This class manages the special functions used by some units.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nclass UcumFunctions {\n\n /**\n * Constructor\n *\n * Creates the singleton object that contains the list of functions used\n * to convert special units.\n */\n constructor() {\n\n // Create the hash containing the function pairs\n this.funcs = {};\n\n // Celsius - convert to Celsius from kelvin and from Celsius to kelvin\n // where kelvin is the base unit for temperature\n this.funcs['cel'] = {cnvTo : function(x){return x - 273.15;},\n cnvFrom : function(x){return x + 273.15;}};\n\n // Fahrenheit - convert to Fahrenheit from kelvin and from Fahrenheit to\n // kelvin - which is the base unit for temperature\n this.funcs['degf'] = {cnvTo : function(x){return x - 459.67;},\n cnvFrom : function(x){return x + 459.67;}};\n\n // Reaumur - convert between Reaumur and Kelvin. Because of the way the\n // calling code in the Units class is set up (in the convertFrom method),\n // what is given here as the convertTo function is actually the convert\n // from method and vice versa.\n //this.funcs['degre'] = {cnvTo : function(x){return x + 273.15;},\n // cnvFrom : function(x){return x - 273.15;}};\n this.funcs['degre'] = {cnvTo : function(x){return x - 273.15;},\n cnvFrom : function(x){return x + 273.15;}};\n\n // pH - convert to pH from moles per liter and from moles per liter to pH\n // where a mole is an amount of a substance (a count of particles)\n this.funcs['ph'] = {cnvTo : function(x){return - Math.log(x) / Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, -x);}};\n\n // ln - natural logarithm (base e 2.71828) - apply (cnvTo) and invert (cnvFrom)\n // and 2ln - two times the natural logarithm\n this.funcs['ln'] = {cnvTo : function(x){return Math.log(x);},\n cnvFrom : function(x){return Math.exp(x);}};\n this.funcs['2ln'] = {cnvTo : function(x){return 2 * Math.log(x);},\n cnvFrom : function(x){return Math.exp(x / 2);}};\n\n // lg - the decadic logarithm (base 10)\n this.funcs['lg'] = {cnvTo : function(x){return Math.log(x) / Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x);}};\n this.funcs['10lg'] = {cnvTo : function(x){return 10 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 10);}};\n this.funcs['20lg'] = {cnvTo : function(x){return 20 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 20);}};\n // The plain text ucum units file uses '2lg'\n this.funcs['2lg'] = {cnvTo : function(x){return 2 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 2);}};\n // The xml essence ucum file uses lgTimes2\n this.funcs['lgtimes2'] = this.funcs['2lg'];\n\n // ld - dual logarithm (base 2)\n this.funcs['ld'] = {cnvTo : function(x){return Math.log(x)/Math.LN2;},\n cnvFrom : function(x){return Math.pow(2, x);}};\n\n // tan - tangent\n this.funcs['100tan'] = {cnvTo : function(x){return Math.tan(x) * 100;},\n cnvFrom : function(x){return Math.atan(x/100);}};\n // the xml essence ucum file uses both 100tan and tanTimes100\n this.funcs['tanTimes100'] = this.funcs['100tan'] ;\n\n // sqrt - square root\n this.funcs['sqrt'] = {cnvTo : function(x){return Math.sqrt(x);},\n cnvFrom : function(x){return x*x;}};\n\n // inv - inverse\n this.funcs['inv'] = {cnvTo : function(x){return 1.0 / x;},\n cnvFrom : function(x){return 1.0 / x;}};\n\n // homeopathic potency functions\n this.funcs['hpX'] = {cnvTo : function(x){return -(this.funcs['lg'](x));},\n cnvFrom : function(x){return Math.pow(10, -x);}};\n\n this.funcs['hpC'] = {cnvTo : function(x){\n return -(this.func['ln'](x))/this.funcs['ln'](100);},\n cnvFrom : function(x){return Math.pow(100, -x);}};\n\n this.funcs['hpM'] = {cnvTo : function(x){\n return -(this.funcs['ln'](x))/this.funcs['ln'](1000);},\n cnvFrom : function(x){return Math.pow(1000, -x);}};\n\n this.funcs['hpQ'] = {cnvTo : function(x){\n return -(this.funcs['ln'](x))/this.funcs['ln'](50000);},\n cnvFrom : function(x){return Math.pow(50000, -x);}};\n\n } // end of constructor\n\n\n /**\n * Returns the function with the name specified\n *\n * @param fname name of the function to be returned\n * @return the function with the specified name\n * @throws an error message if the function is not found\n */\n forName(fname) {\n fname = fname.toLowerCase();\n\n let f = this.funcs[fname] ;\n if (f === null)\n throw(new Error(`Requested function ${fname} is not defined`));\n return f;\n }\n\n\n /**\n * Returns a flag indicating whether or not the function has been\n * defined.\n *\n * @param fname name of the function in question\n * @return true if it has been defined; false if not\n */\n isDefined(fname) {\n fname = fname.toLowerCase();\n return this.funcs[fname] !== null;\n }\n\n} // end of UcumFunctions class\n\nexport default new UcumFunctions(); // one singleton instance\n","/**\n * Internal utilities used by multiple UCUM classes. For example,\n * isNumericString is used by both the UnitString and UcumLhcUtils\n * classes. If it's in the UnitString class the UcumLhcUtils class\n * needs to require the UnitString class. But the checkSynonyms\n * class is used by the UnitString class - but was in the UcumLhcUtils\n * class. Requiring the UcumLhcUtils class from the UnitString class\n * made everything break (cyclical requires).\n *\n * So now they're here.\n */\n\n/**\n * This module implements internal ucum utilities.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar UnitTables = require('./unitTables.js').UnitTables ;\n\n\n/**\n * This function tests a string to see if it contains only numbers (digits,\n * a period, leading - or +). This code was taken from a stackoverflow\n * solution:\n * https://stackoverflow.com/questions/175739/is-there-a-built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number/42356340#42356340\n *\n * @params theString\n * @returns true if the string contains only numbers; false otherwise\n */\nexport function isNumericString(theString) {\n let num = \"\" + theString; //coerce num to be a string\n return !isNaN(num) && !isNaN(parseFloat(num));\n} // end isNumericString\n\n\n/**\n * Checks whether a string qualifies as an integer unit. Section 2.2.8 (\"integer\n * numbers\", says, \"A positive integer number may appear in place of a simple\n * unit symbol. Only a pure string of decimal digits (‘0’–‘9’) is\n * interpreted as a number.\"\n * Note: This leaves open the question of whether \"0\" is a valid unit, since\n * it is positive, but you can't measure anything in units of zero.\n * @param str the string to check\n */\nexport function isIntegerUnit(str) {\n return /^\\d+$/.test(str);\n}\n\n\n/**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for. This is assumed to be\n * a string and not undefined. The calling method should do any\n * necessary checking before calling this.\n * @returns a hash with up to three elements:\n * 'status' contains the status of the request, which can be 'error',\n * 'failed' or succeeded';\n * 'msg' which contains a message for an error or if no units were found; and\n * 'units' which is an array that contains one array for each unit found:\n * the unit's csCode_, the unit's name_, and the unit's guidance_\n *\n */\nexport function getSynonyms(theSyn) {\n\n let retObj = {} ;\n let utab = UnitTables.getInstance();\n let resp = {} ;\n resp = utab.getUnitBySynonym(theSyn);\n\n // If we didn't get any units, transfer the status and message\n if (!resp['units']) {\n retObj['status'] = resp['status'];\n retObj['msg'] = resp['msg'];\n }\n else {\n retObj['status'] = 'succeeded';\n let aLen = resp['units'].length ;\n retObj['units'] = [];\n for (let a = 0; a < aLen; a++) {\n let theUnit = resp['units'][a];\n retObj['units'][a] = {\n 'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_};\n } // end do for all units returned\n } // end if we got a units list\n return retObj ;\n\n} // end getSynonyms\n\n","/**\n * This class handles opening, reading and loading the JSON file of ucum\n * definitions (prefixes, base units, and unit atoms).\n *\n * @author Lee Mericle\n *\n */\n\nvar Pfx = require(\"./prefix.js\");\nvar PfxT = require(\"./prefixTables.js\");\nvar Un = require(\"./unit.js\");\nvar Utab = require('./unitTables.js');\nvar unpackArray = require('./jsonArrayPack.js').unpackArray;\n\nexport class UcumJsonDefs {\n\n /**\n * This method loads the JSON prefix and unit objects into the prefix and\n * unit tables.\n *\n * @returns nothing\n */\n loadJsonDefs() {\n // requiring the file will take care of opening it for use\n const jsonDefs = require('../data/ucumDefs.min.json');\n jsonDefs.prefixes = unpackArray(jsonDefs.prefixes);\n jsonDefs.units = unpackArray(jsonDefs.units);\n\n if (Utab.UnitTables.getInstance().unitsCount() === 0) {\n\n let pTab = PfxT.PrefixTables.getInstance();\n let prefixes = jsonDefs[\"prefixes\"];\n let plen = prefixes.length;\n\n for (let p = 0; p < plen; p++) {\n let newPref = new Pfx.Prefix(prefixes[p]);\n pTab.add(newPref);\n }\n\n let uTab = Utab.UnitTables.getInstance();\n let units = jsonDefs[\"units\"];\n let ulen = units.length;\n\n for (let u = 0; u < ulen; u++) {\n let newUnit = new Un.Unit(units[u]);\n uTab.addUnit(newUnit);\n }\n } // end if the data has not already been loaded\n } // end loadJsonDefs\n\n} // end UcumJsonDefs class\n\nvar ucumJsonDefs = new UcumJsonDefs();\nexport {ucumJsonDefs};\n","/**\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 // Get a copy of the mass dimension index.\n this.massDimIndex_ = UnitTables.getInstance().getMassDimensionIndex();\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// Note that below when the value of ConversionType is mol|mass, it refers to\n// either a conversion from mol to mass or from mass to mol.\n/**\n * @typedef {\n * 'normal',\n * 'mol|mass',\n * 'eq|mass',\n * 'eq|mol',\n * 'eq|mol|mass'\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;\n if (fromUnit.moleExp_ == toUnit.moleExp_ &&\n fromUnit.equivalentExp_ == toUnit.equivalentExp_) {\n // Since the powers of the equivalents and mole in the units are the same in both\n // units, no conversion is going to happen between mass, mol, and eq.\n // There is the possibility that someone is trying to convert 'g' to 'g2',\n // but we will handle that as the \"normal\" case (and later find it invalid).\n conversionType = 'normal';\n }\n else if (fromUnit.equivalentExp_ == toUnit.equivalentExp_) {\n // In this case, the units have the same power of equivalents, so (because\n // it is not the first case) the units have different powers of mol and mass,\n // so this must be a conversion between mol and mass.\n conversionType = 'mol|mass';\n }\n else if (fromUnit.moleExp_ == toUnit.moleExp_) {\n // In this case, the units have the same power of mol, so (because\n // it is not the first case) the units have different powers of equivalents and mass,\n // so this must be a conversion between equivalents and mass.\n conversionType = 'eq|mass';\n }\n else if (fromUnit.dim_.getElementAt(this.massDimIndex_) ==\n toUnit.dim_.getElementAt(this.massDimIndex_)) {\n // In this case, the units have the same power of mass, so (because\n // it is not the first case) the units have different powers of equivalents and mol,\n // so this must be a conversion between equivalents and moles.\n conversionType = 'eq|mol';\n }\n else {\n // In this case, the units have different powers of mass, mol, and\n // equivalents, so there is a conversion between mass, mol, and\n // equivalents.\n conversionType = 'eq|mol|mass';\n }\n\n return conversionType;\n } // end detectConversionType\n\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 = {\n 'status': 'failed',\n 'toVal': null,\n 'msg': []\n };\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 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 const convertType = this.detectConversionType(fromUnit, toUnit);\n const msgCountBeforeConvert = returnObj['msg'].length;\n switch (convertType) {\n case 'normal':\n try {\n returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);\n } catch (err) {\n returnObj['msg'].push(err.message);\n }\n break;\n case 'mol|mass':\n if (!fromUnit.isMolMassCommensurable(toUnit)) {\n returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n break;\n }\n if (!molecularWeight) {\n returnObj['msg'].push(Ucum.needMoleWeightMsg_);\n break;\n }\n returnObj['toVal'] = fromUnit.convertMolMass(fromVal, toUnit, molecularWeight);\n break;\n case 'eq|mass':\n if (!fromUnit.isEqMassCommensurable(toUnit)) {\n returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n break;\n }\n if (!molecularWeight) {\n returnObj['msg'].push(Ucum.needEqWeightMsg_);\n }\n if (!charge) {\n returnObj['msg'].push(Ucum.needEqChargeMsg_);\n }\n if (!returnObj['msg'].length) {\n returnObj['toVal'] = fromUnit.convertEqMass(fromVal, toUnit, molecularWeight, charge);\n }\n break;\n case 'eq|mol':\n if (!fromUnit.isEqMolCommensurable(toUnit)) {\n returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n break;\n }\n if (!charge) {\n returnObj['msg'].push(Ucum.needEqChargeMsg_);\n break;\n }\n returnObj['toVal'] = fromUnit.convertEqMol(fromVal, toUnit, charge);\n break;\n case 'eq|mol|mass':\n if (!fromUnit.isEqMolMassCommensurable(toUnit)) {\n returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`);\n break;\n }\n if (!molecularWeight) {\n returnObj['msg'].push(Ucum.needEqWeightMsg_);\n }\n if (!charge) {\n returnObj['msg'].push(Ucum.needEqChargeMsg_);\n }\n if (!returnObj['msg'].length) {\n returnObj['toVal'] = fromUnit.convertEqMolMass(fromVal, toUnit, molecularWeight, charge);\n }\n break;\n default:\n returnObj['msg'].push(\"Unknown conversion type. No conversion was attempted.\");\n }\n if (returnObj['msg'].length > msgCountBeforeConvert) {\n // If one or more failure messages are pushed into returnObj['msg']\n // in the switch statement, mark the status as 'failed'.\n returnObj['status'] = 'failed';\n } else {\n // Set the return object to show success.\n returnObj['status'] = 'succeeded';\n returnObj['fromUnit'] = fromUnit;\n returnObj['toUnit'] = toUnit;\n }\n } // end if we have the from and to units\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. If necessary, you can filter the list of units by\n * specifying a list of unit categories that should be in the resulting list.\n *\n * @param {string} fromName - the name/unit string of the \"from\" unit\n * @param {string[] | null} [categoryList] - the list of unit categories;\n * this parameter is optional, defaults to null if not specified;\n * possible list values: 'Clinical', 'Nonclinical', 'Obsolete', 'Constant'\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, categoryList = null) {\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 if (categoryList) {\n commUnits = commUnits.filter((item) => {\n return categoryList.indexOf(item.category_) !== -1;\n });\n }\n }\n } // end if the from unit has a dimension vector\n } // end if we found a \"from\" unit\n return [commUnits , retMsg];\n } // end commensurablesList\n\n} // end UcumLhcUtils class\n\n\n/**\n * This function exists ONLY until the original UcumLhcUtils constructor\n * is called for the first time. It's defined here in case getInstance\n * is called before the constructor. This calls the constructor.\n *\n * The constructor redefines the getInstance function to return the\n * singleton UcumLhcUtils object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * NO LONGER TRUE - not implemented as a singleton. This method retained to\n * avoid problems with calls to it that exist throughout the code.\n *\n * @return the (formerly singleton) UcumLhcUtils object.\n */\nUcumLhcUtils.getInstance = function(){\n return new UcumLhcUtils();\n} ;\n","\n/**\n * This class represents one unit of measure. It includes\n * functions to cover constructor, accessor, and assignment tasks as\n * well as operators to calculate multiplication, division and raising\n * to a power.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nvar Ucum = require('./config.js').Ucum;\nvar Dimension = require('./dimension.js').Dimension;\nimport funcs from \"./ucumFunctions.js\";\nvar UnitTables;\n\nvar isInteger = require(\"is-integer\");\nimport * as intUtils_ from \"./ucumInternalUtils.js\";\n\nexport class Unit {\n\n /**\n * Constructor.\n *\n * @param attrs an optional parameter that may be:\n * a string, which is parsed by the unit parser, which creates\n * the unit from the parsed string; or\n * a hash containing all or some values for the attributes of\n * the unit, where the keys are the attribute names, without a\n * trailing underscore, e.g., name instead of name_; or\n * null, in which case an empty hash is created and used to\n * set the values forthe attributes.\n * If a hash (empty or not) is used, attributes for which no value\n * is specified are assigned a default value.\n *\n */\n constructor(attrs = {}) {\n\n // Process the attrs hash passed in, which may be empty.\n // Create and assign values (from the attrs hash or defaults) to all\n // attributes. From Class Declarations in Understanding ECMAScript,\n // https://leanpub.com/understandinges6/read/#leanpub-auto-class-declarations,\n // \"Own properties, properties that occur on the instance rather than the\n // prototype, can only be created inside of a class constructor or method.\n // It's recommended to create all possible own properties inside of the\n // constructor function so there's a single place that's responsible for\n // all of them.\"\n\n /*\n * Flag indicating whether or not this is a base unit\n */\n this.isBase_ = attrs['isBase_'] || false ;\n\n /*\n * The unit name, e.g., meter\n */\n this.name_ = attrs['name_'] || '';\n\n /*\n * The unit's case-sensitive code, e.g., m\n */\n this.csCode_ = attrs['csCode_'] || '';\n\n /*\n * The unit's case-insensitive code, e.g., M\n */\n this.ciCode_ = attrs['ciCode_'] || '';\n\n /*\n * The unit's property, e.g., length\n */\n this.property_ = attrs['property_'] || '';\n\n /*\n * The magnitude of the unit, e.g., 3600/3937 for a yard,\n * where a yard - 3600/3973 * m(eter). The Dimension\n * property specifies the meter - which is the unit on which\n * a yard is based, and this magnitude specifies how to figure\n * this unit based on the base unit.\n */\n this.magnitude_ = attrs['magnitude_'] || 1;\n\n /*\n * The Dimension object of the unit\n */\n if (attrs['dim_'] === undefined || attrs['dim_'] === null) {\n this.dim_ = new Dimension();\n }\n // When the unit data stored in json format is reloaded, the dimension data\n // is recognized as a a hash, not as a Dimension object.\n else if (attrs['dim_']['dimVec_'] !== undefined) {\n this.dim_ = new Dimension(attrs['dim_']['dimVec_']) ;\n }\n else if (attrs['dim_'] instanceof Dimension) {\n this.dim_ = attrs['dim_'];\n }\n else if (attrs['dim_'] instanceof Array || isInteger(attrs['dim_'])) {\n this.dim_ = new Dimension(attrs['dim_']) ;\n }\n else {\n this.dim_ = new Dimension();\n }\n /*\n * The print symbol of the unit, e.g., m\n */\n this.printSymbol_ = attrs['printSymbol_'] || null;\n\n /*\n * The class of the unit, where given, e.g., dimless\n */\n this.class_ = attrs['class_'] || null;\n\n /*\n * A flag indicating whether or not the unit is metric\n */\n this.isMetric_ = attrs['isMetric_'] || false;\n\n /*\n * The \"variable\" - which I think is used only for base units\n * The symbol for the variable as used in equations, e.g., s for distance\n */\n this.variable_ = attrs['variable_'] || null ; // comes from 'dim' in XML\n\n /*\n * The conversion function\n */\n this.cnv_ = attrs['cnv_'] || null;\n\n /*\n * The conversion prefix\n */\n this.cnvPfx_ = attrs['cnvPfx_'] || 1;\n\n /*\n * Flag indicating whether or not this is a \"special\" unit, i.e., is\n * constructed using a function specific to the measurement, e.g.,\n * fahrenheit and celsius\n */\n this.isSpecial_ = attrs['isSpecial_'] || false ;\n\n /*\n * Flag indicating whether or not this is an arbitrary unit\n */\n this.isArbitrary_ = attrs['isArbitrary_'] || false;\n\n /*\n * Integer indicating what level of exponent applies to a mole-based portion\n * of the unit. So, for the unit \"mol\", this will be 1. For \"mol2\" this\n * will be 2. For \"1/mol\" this will be -1. Any unit that does not include\n * a mole will have a 0 in this field. This is used to determine\n * commensurability for mole<->mass conversions.\n */\n this.moleExp_ = attrs['moleExp_'] || 0;\n\n /**\n * Flag indicating whether or not this is a equivalent mole unit\n */\n this.equivalentExp_ = attrs['equivalentExp_'] || 0;\n\n /*\n * Added when added LOINC list of units\n * synonyms are used by the autocompleter to enhance lookup capabilities\n * while source says where the unit first shows up. Current sources are\n * UCUM - which are units from the https://ucum.org/ucum specification and LOINC -\n * which are units from the LOINC data.\n */\n this.synonyms_ = attrs['synonyms_'] || null ;\n this.source_ = attrs['source_'] || null ;\n this.loincProperty_ = attrs['loincProperty_'] || null;\n this.category_ = attrs['category_'] || null;\n this.guidance_ = attrs['guidance_'] || null;\n\n /*\n * Used to compute dimension; storing for now until I complete\n * unit definition parsing\n */\n /*\n * Case sensitive (cs) and case insensitive (ci) base unit strings,\n * includes exponent and prefix if applicable - specified in\n * <value Unit=x UNIT=X value=\"nnn\">nnn</value> -- the unit part --\n * in the ucum-essence.xml file, and may be specified by a user\n * when requesting conversion or validation of a unit string. The\n * magnitude (base factor) is used with this to determine the new unit.\n * For example, a Newton (unit code N) is created from the string\n * kg.m/s2, and the value of 1 (base factor defined below). An hour\n * (unit code h) is created from the unit min (minute) with a value\n * of 60.\n */\n this.csUnitString_ = attrs['csUnitString_'] || null ;\n this.ciUnitString_ = attrs['ciUnitString_'] || null ;\n\n /*\n * String and numeric versions of factor applied to unit specified in\n * <value Unit=x UNIT=X value=\"nnn\">nnn</value> -- the value part\n */\n this.baseFactorStr_ = attrs['baseFactorStr_'] || null;\n this.baseFactor_ = attrs['baseFactor_'] || null;\n\n /*\n * Flag used to indicate units where the definition process failed\n * when parsing units from the official units definitions file\n * (currently using the ucum-essence.xml file). We keep these\n * so that we can use them to at least validate them as valid\n * units, but we don't try to convert them. This is temporary\n * and only to account for instances where the code does not\n * take into account various special cases in the xml file.\n *\n * This is NOT used when trying to validate a unit string\n * submitted during a conversion or validation attempt.\n */\n this.defError_ = attrs['defError_'] || false ;\n\n\n } // end constructor\n\n\n /**\n * Assign the unity (= dimensionless unit 1) to this unit.\n *\n * @return this unit\n */\n assignUnity() {\n this.name_ = \"\" ;\n this.magnitude_ = 1 ;\n if (!this.dim_)\n this.dim_ = new Dimension();\n this.dim_.assignZero() ;\n this.cnv_ = null ;\n this.cnvPfx_ = 1 ;\n return this;\n\n } // end assignUnity\n\n\n /**\n * This assigns one or more values, as provided in the hash passed in,\n * to this unit.\n *\n * @param vals hash of values to be assigned to the attributes\n * specified by the key(s), which should be the attribute\n * name without the trailing underscore, e.g., name instead\n * of name_.\n * @return nothing\n */\n assignVals(vals) {\n for (let key in vals) {\n let uKey = key.charAt(key.length - 1) !== '_' ? key + '_' : key ;\n if (this.hasOwnProperty(uKey))\n this[uKey] = vals[key];\n else\n throw(new Error(`Parameter error; ${key} is not a property of a Unit`));\n }\n } // end assignVals\n\n\n /**\n * This creates a clone of this unit.\n *\n * @return the clone\n */\n clone() {\n let retUnit = new Unit() ;\n Object.getOwnPropertyNames(this).forEach(val => {\n if (val === 'dim_') {\n if (this['dim_'])\n retUnit['dim_'] = this['dim_'].clone();\n else\n retUnit['dim_'] = null;\n }\n else\n retUnit[val] = this[val];\n });\n return retUnit ;\n\n } // end clone\n\n\n /**\n * This assigns all properties of a unit passed to it to this unit.\n *\n * @param unit2 the unit whose properties are to be assigned to this one.\n * @return nothing; this unit is updated\n */\n assign(unit2) {\n Object.getOwnPropertyNames(unit2).forEach(val => {\n if (val === 'dim_') {\n if (unit2['dim_'])\n this['dim_'] = unit2['dim_'].clone();\n else\n this['dim_'] = null;\n }\n else {\n this[val] = unit2[val];\n }\n });\n } // end assign\n\n\n /**\n * This determines whether or not object properties of the unit\n * passed in are equal to the corresponding properties in this unit.\n * The following properties are the only ones checked:\n * magnitude_, dim_, cnv_ and cnvPfx_\n *\n * @param unit2 the unit whose properties are to be checked.\n * @return boolean indicating whether or not they match\n */\n equals(unit2) {\n\n return (this.magnitude_ === unit2.magnitude_ &&\n this.cnv_ === unit2.cnv_ &&\n this.cnvPfx_ === unit2.cnvPfx_ &&\n ((this.dim_ === null && unit2.dim_ === null) ||\n this.dim_.equals(unit2.dim_)));\n\n } // end equals\n\n\n /**\n * This method compares every attribute of two objects to determine\n * if they all match.\n *\n * @param unit2 the unit that is to be compared to this unit\n * @return boolean indicating whether or not every attribute matches\n */\n fullEquals(unit2) {\n\n let thisAttr = Object.keys(this).sort();\n let u2Attr = Object.keys(unit2).sort();\n\n let keyLen = thisAttr.length ;\n let match = (keyLen === u2Attr.length);\n\n // check each attribute. Dimension objects have to checked using\n // the equals function of the Dimension class.\n for (let k = 0; k < keyLen && match; k++) {\n if (thisAttr[k] === u2Attr[k]) {\n if (thisAttr[k] === 'dim_')\n match = this.dim_.equals(unit2.dim_);\n else\n match = this[thisAttr[k]] === unit2[thisAttr[k]];\n }\n else\n match = false ;\n } // end do for each key and attribute\n return match ;\n }// end of fullEquals\n\n\n /**\n * This returns the value of the property named by the parameter\n * passed in.\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 unit\n * @throws an error if the property is not found for this unit\n */\n getProperty(propertyName) {\n let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName :\n propertyName + '_' ;\n return this[uProp] ;\n\n } // end getProperty\n\n\n /**\n * Takes a measurement consisting of a number of units and a unit and returns\n * the equivalent number of this unit. So, 15 mL would translate\n * to 1 tablespoon if this object is a tablespoon.\n *\n * Note that the number returned may not be what is normally expected.\n * For example, converting 10 Celsius units to Fahrenheit would \"normally\"\n * return a value of 50. But in this case you'll get back something like\n * 49.99999999999994.\n *\n * If either unit is an arbitrary unit an exception is raised.\n *\n * @param num the magnitude for the unit to be translated (e.g. 15 for 15 mL)\n * @param fromUnit the unit to be translated to one of this type (e.g. a mL unit)\n *\n * @return the number of converted units (e.g. 1 for 1 tablespoon)\n * @throws an error if the dimension of the fromUnit differs from this unit's\n * dimension\n */\n convertFrom(num, fromUnit) {\n let newNum = 0.0 ;\n\n if (this.isArbitrary_)\n throw (new Error(`Attempt to convert to arbitrary unit \"${this.csCode_}\"`));\n if (fromUnit.isArbitrary_)\n throw (new Error(`Attempt to convert arbitrary unit \"${fromUnit.csCode_}\"`));\n\n // reject request if both units have dimensions that are not equal\n if (fromUnit.dim_ && this.dim_ && !(fromUnit.dim_.equals(this.dim_))) {\n // check first to see if a mole<->mass conversion is appropriate\n if (this.isMolMassCommensurable(fromUnit)) {\n throw(new Error(Ucum.needMoleWeightMsg_));\n }\n else {\n throw(new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` +\n `to ${this.csCode_}.`));\n }\n }\n // reject request if there is a \"from\" dimension but no \"to\" dimension\n if (fromUnit.dim_ && (!this.dim_ || this.dim_.isNull())) {\n throw(new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` +\n `to ${this.csCode_}.`));\n }\n\n // reject request if there is a \"to\" dimension but no \"from\" dimension\n if (this.dim_ && (!fromUnit.dim_ || fromUnit.dim_.isNull())) {\n throw(new Error(`Sorry. ${fromUnit.csCode_} cannot be converted ` +\n `to ${this.csCode_}.`));\n }\n\n let fromCnv = fromUnit.cnv_ ;\n let fromMag = fromUnit.magnitude_ ;\n\n let x;\n if (fromCnv != null) {\n // turn num * fromUnit.magnitude into its ratio scale equivalent,\n // e.g., convert Celsius to Kelvin\n let fromFunc = funcs.forName(fromCnv);\n x = fromFunc.cnvFrom(num * fromUnit.cnvPfx_) * fromMag;\n //x = fromFunc.cnvFrom(num * fromMag) * fromUnit.cnvPfx_;\n }\n else {\n x = num * fromMag;\n }\n\n if (this.cnv_ != null) {\n // turn mag * origUnit on ratio scale into a non-ratio unit,\n // e.g. convert Kelvin to Fahrenheit\n let toFunc = funcs.forName(this.cnv_);\n newNum = toFunc.cnvTo(x / this.magnitude_) / this.cnvPfx_;\n }\n else {\n newNum = x / this.magnitude_;\n }\n\n return newNum;\n\n } // end convertFrom\n\n\n /**\n * Takes a number and a target unit and returns the number for a measurement\n * of this unit that corresponds to the number of the target unit passed in.\n * So, 1 tablespoon (where this unit represents a tablespoon) would translate\n * to 15 mL.\n *\n * See the note on convertFrom about return values.\n *\n * @param mag the magnitude for this unit (e.g. 1 for 1 tablespoon)\n * @param toUnit the unit to which this unit is to be translated\n * (e.g. an mL unit)\n *\n * @return the converted number value (e.g. 15 mL)\n * @throws an error if the dimension of the toUnit differs from this unit's\n * dimension\n */\n convertTo(num, toUnit) {\n\n return toUnit.convertFrom(num, this) ;\n\n } // end convertTo\n\n\n /**\n * Takes a given number of this unit returns the number of this unit\n * if it is converted into a coherent unit. Does not change this unit.\n *\n * If this is a coherent unit already, just gives back the number\n * passed in.\n *\n * @param num the number for the coherent version of this unit\n * @return the number for the coherent version of this unit\n */\n convertCoherent(num) {\n\n // convert mag' * u' into canonical number * u on ratio scale\n if(this.cnv_ !== null)\n num = this.cnv_.f_from(num / this.cnvPfx_) * this.magnitude_;\n\n return num;\n\n } // end convertCoherent\n\n\n /**\n * Mutates this unit into a coherent unit and converts a given number of\n * units to the appropriate value for this unit as a coherent unit\n *\n * @param num the number for this unit before conversion\n * @return the number of this unit after conversion\n * @throws an error if the dimensions differ\n */\n mutateCoherent(num) {\n\n // convert mu' * u' into canonical mu * u on ratio scale\n num = this.convertCoherent(num) ;\n\n // mutate to coherent unit\n this.magnitude_ = 1;\n this.cnv_ = null;\n this.cnvPfx_ = 1;\n this.name_ = \"\";\n\n // build a name as a term of coherent base units\n // This is probably ALL WRONG and a HORRIBLE MISTAKE\n // but until we figure out what the heck the name being\n // built here really is, it will have to stay.\n for (let i = 0, max = Dimension.getMax(); i < max; i++) {\n let elem = this.dim_.getElementAt(i);\n let tabs = this._getUnitTables();\n let uA = tabs.getUnitsByDimension(new Dimension(i));\n if(uA == null)\n throw(new Error(`Can't find base unit for dimension ${i}`));\n this.name_ = uA.name + elem;\n }\n return num;\n\n } // end mutateCoherent\n\n\n /**\n * This function converts between mol and mass (in either direction)\n * using the molecular weight of the substance. It assumes that the\n * isMolMassCommensurable\" function has been called to check that the units are\n * commensurable.\n *\n * @param amt the quantity of this unit to be converted\n * @param toUnit the target/to unit for which the converted # is wanted\n * @param molecularWeight the molecular weight of the substance for which the\n * conversion is being made\n * @return the equivalent amount in toUnit\n */\n convertMolMass(amt, toUnit, molecularWeight) {\n // In the calculations below we are treating \"molecularWeight\" (measured in\n // a.m.u) as the molar weight (measured in g/mol). The values are the same,\n // though the units differ.\n\n // Determine the number of powers of mol we have to convert to mass.\n // Typically this will be just 1, or -1, but not necessarily. If it is a\n // negative number, then we are really converting mass to moles.\n const molPowersToConvert = this.moleExp_ - toUnit.moleExp_;\n // A simple mole unit has a magnitude of avogadro's number. Get that\n // number now (since not everyone agrees on what it is, and what is\n // being used in this system might change).\n let tabs = this._getUnitTables();\n let avoNum = tabs.getUnitByCode('mol').magnitude_ ;\n // For each molPowersToConvert, we need to multiply the mol unit by the\n // molar weight (g/mol) and divide by avoNum (1/mol) to get a weight per\n // molecule. (Note that the magnitude_ of each unit will contain factors of\n // avoNum, of which we are thus getting rid of some).\n let moleUnitFactor = Math.pow(molecularWeight/avoNum, molPowersToConvert);\n // The new value is proportional to this.magnitude_, amt, and\n // moleUnitFactor, and inversely proportional to toUnit_.magnitude.\n return this.magnitude_/toUnit.magnitude_ * moleUnitFactor * amt;\n } // end convertMolMass\n\n\n /**\n * This function converts between equivalants and mass (in either direction)\n * using the charge of the substance. It assumes that the\n * isEqMassCommensurable\" function has been called to check that the units are\n * commensurable.\n *\n * @param {number} amt - The amount of this unit to be converted.\n * @param {object} toUnit - The target/to unit for which the converted number is wanted.\n * @param {number} molecularWeight - The molecular weight of the substance for which the conversion is being made.\n * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made.\n * @returns {number} - The amount in the specified toUnit.\n */\n convertEqMass(amt, toUnit, molecularWeight, charge) {\n // Determine the number of powers of mass we have to convert to equivalents.\n // Typically this will be just 1, or -1, but not necessarily. If it is a\n // negative number, then we are converting in the opposite direciton.\n // Because the units are presumed commensurable, we can use the\n // equivalentExp_ instead of the mass dimension.\n const massPowersToConvert = toUnit.equivalentExp_ - this.equivalentExp_ ;\n // Calculate equivalent mass by dividing molecular weight by charge\n let equivalentMass = molecularWeight / charge;\n // Get Avogadro's number from the unit tables\n let avogadroNumber = this._getUnitTables().getUnitByCode('mol').magnitude_ ;\n // Calculate equivalents by dividing mass by equivalent mass, for each\n // power to be converted.\n let equivalents = this.magnitude_ * amt / Math.pow(equivalentMass, massPowersToConvert);\n // Calculate mole factor by dividing the magnitude of the equivalent unit by\n // Avogadro's number. toUnit may have a prefix (e.g. meq) and we need to adjust for that, for\n // each massPowersToConvert.\n let moleFactor = toUnit.magnitude_ / Math.pow(avogadroNumber, massPowersToConvert);\n // Adjust equivalents by dividing by the mole factor\n let adjustedEquivalents = equivalents / moleFactor;\n // Return the adjusted equivalents\n return adjustedEquivalents;\n } // end convertMassToEq\n\n\n /**\n * Converts a unit with eq/mol/mass to another unit with eq/mol/mass. It\n * assumes the units an commensurable, which can be checked via\n * isEqMolMassCommensurable. It also assumes that the powers of eq/mol/mass\n * are different between the two units; otherwise it would be more efficient\n * to call one of the other convert... functions.\n *\n * @param {number} amt - The amount of this unit to be converted.\n * @param {object} toUnit - The target/to unit for which the converted number is wanted.\n * @param {number} molecularWeight - The molecular weight of the substance for which the conversion is being made.\n * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made.\n * @returns {number} - The equivalent amount in the specified equivalent unit.\n */\n convertEqMolMass(amt, toUnit, molecularWeight, charge) {\n // Handle the equivalent differences. It important for the following\n // calculations (for consistency) that we consider the difference in\n // equivalent powers and not mol powers, so we are not calling\n // convertEqToMol, in case its implementation changes.\n // See convertEqToMol for details. One difference is that we do not scale\n // by magnitude_ until the end.\n const eqPowersToConvert = this.equivalentExp_ - toUnit.equivalentExp_;\n const molAmt = amt / Math.pow(charge, eqPowersToConvert);\n // Now for the mol/mass converstion part, we consider only the mass power\n // differences, and not the mol power differences (which were partially\n // handled in the eq/mol step above).\n // Again, see convertMolToMass for details on the calculations.\n const tabs = this._getUnitTables();\n const d = tabs.getMassDimensionIndex();\n const massPowersToConvert = this.dim_.getElementAt(d) - toUnit.dim_.getElementAt(d);\n const molPowersToConvert = -massPowersToConvert; // so the formulas follow convertMolToMass\n const avoNum = tabs.getUnitByCode('mol').magnitude_ ;\n let moleUnitFactor = Math.pow(molecularWeight/avoNum, molPowersToConvert);\n return this.magnitude_/toUnit.magnitude_ * moleUnitFactor * molAmt;\n }\n\n\n /**\n * Checks if the given unit is an equivalent unit.\n *\n * Note: equivalent units are also be molar units, so a unit can return true for\n * both isEquivalentUnit and isMolarUnit.\n *\n * @returns {boolean} - Returns true if the unit is an equivalent unit, false otherwise.\n */\n isEquivalentUnit() {\n return this.equivalentExp_ !== 0;\n } // end isEquivalentUnit\n\n /**\n * Checks if the given unit is a molar unit.\n *\n * @returns {boolean} - Returns true if the unit is a molar unit, false otherwise.\n */\n isMolarUnit() {\n return this.moleExp_ !== 0;\n } // end isMolarUnit\n\n\n /**\n * This function converts between equivalants and moles (in either direction)\n * using the charge of the substance. It assumes that the\n * isEqMolCommensurable\" function has been called to check that the units are\n * commensurable.\n\n * As with the other \"convert\" functions, it assumes the appropriate\n * \"is...Commensurable\" function has been called.\n *\n * @param {number} amt - The amount of this unit for which the conversion is being made.\n * @param {object} toUnit - The target unit for which the converted number is wanted.\n * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made.\n * @return {number} - The amount in molToUnit.\n */\n convertEqMol(amt, toUnit, charge) {\n // Determine the number of powers of eq we have to convert to mol.\n // Typically this will be just 1, or -1, but not necessarily. If it is a\n // negative number, then we are really converting mol to eq.\n const eqPowersToConvert = this.equivalentExp_ - toUnit.equivalentExp_;\n\n // A simple mole unit has a magnitude of avogadro's number.\n // So does 'eq' (equivalent) because in ucum it is defined as 1 mol, though\n // that does not account for the charge. Therefore, we don't need to\n // account for that factor in this conversion.\n\n // The conversion from equivalents to moles is based on the principle that\n // one equivalent is equal to 1/charge moles (per eqPowersToConvert).\n // The relative magnitude is accounted for via the current unit's magnitude\n // (this.magnitude_) and the target unit's magnitude (molToUnit.magnitude_)\n // For each eqPowersToConvert, we need to divide by the charge.\n return amt * (this.magnitude_ / toUnit.magnitude_) / Math.pow(charge, eqPowersToConvert);\n } // end convertEqMol\n\n\n /**\n * Mutates this unit into a unit on a ratio scale and converts a specified\n * number of units to an appropriate value for this converted unit\n *\n * @param num the number of this unit before it's converted\n * @return the magnitude of this unit after it's converted\n * @throw an error if the dimensions differ\n */\n mutateRatio(num) {\n if (this.cnv_ == null)\n return this.mutateCoherent(num);\n else\n return num;\n\n } // end mutateRatio\n\n\n /**\n * Multiplies this unit with a scalar. Special meaning for\n * special units so that (0.1*B) is 1 dB.\n *\n * This function DOES NOT modify this unit.\n *\n * @param s the value by which this unit is to be multiplied\n * @return a copy this unit multiplied by s\n * */\n multiplyThis(s) {\n\n let retUnit = this.clone() ;\n if (retUnit.cnv_ != null)\n retUnit.cnvPfx_ *= s;\n else\n retUnit.magnitude_ *= s;\n let mulVal = s.toString();\n retUnit.name_ = this._concatStrs(mulVal, '*', this.name_, '[', ']');\n retUnit.csCode_ = this._concatStrs(mulVal, '.', this.csCode_, '(', ')');\n retUnit.ciCode_ = this._concatStrs(mulVal, '.', this.ciCode_, '(', ')');\n retUnit.printSymbol_ = this._concatStrs(mulVal, '.', this.printSymbol_,\n '(', ')');\n\n return retUnit;\n\n } // end multiplyThis\n\n\n /**\n * Multiplies this unit with another unit. If one of the\n * units is a non-ratio unit the other must be dimensionless or\n * else an exception is thrown.\n *\n * This function does NOT modify this unit\n * @param unit2 the unit to be multiplied with this one\n * @return this unit after it is multiplied\n * @throws an error if one of the units is not on a ratio-scale\n * and the other is not dimensionless.\n */\n multiplyThese(unit2) {\n\n var retUnit = this.clone() ;\n\n if (retUnit.cnv_ != null) {\n if (unit2.cnv_ == null && (!unit2.dim_ || unit2.dim_.isZero()))\n retUnit.cnvPfx_ *= unit2.magnitude_;\n else\n throw (new Error(`Attempt to multiply non-ratio unit ${retUnit.name_} ` +\n 'failed.'));\n } // end if this unit has a conversion function\n\n else if (unit2.cnv_ != null) {\n if (!retUnit.dim_ || retUnit.dim_.isZero()) {\n retUnit.cnvPfx_ = unit2.cnvPfx_ * retUnit.magnitude_;\n retUnit.magnitude_ = unit2.magnitude_;\n retUnit.cnv_ = unit2.cnv_ ;\n }\n else\n throw (new Error(`Attempt to multiply non-ratio unit ${unit2.name_}`));\n } // end if unit2 has a conversion function\n\n // else neither unit has a conversion function\n else {\n retUnit.magnitude_ *= unit2.magnitude_;\n } // end if unit2 does not have a conversion function\n\n // If this.dim_ isn't there, clone the dimension in unit2 - if dimVec_\n // is a dimension in unit2.dim_; else just transfer it to this dimension\n if (!retUnit.dim_ || (retUnit.dim_ && !retUnit.dim_.dimVec_)) {\n if (unit2.dim_)\n retUnit.dim_ = unit2.dim_.clone();\n else\n retUnit.dim_ = unit2.dim_;\n }\n // Else this.dim_ is there. If there is a dimension for unit2,\n // add it to this one.\n else if (unit2.dim_ && unit2.dim_ instanceof Dimension) {\n retUnit.dim_.add(unit2.dim_);\n }\n\n // Add the values of equivalentExp_ and moleExp for the two units\n retUnit.equivalentExp_ += unit2.equivalentExp_;\n retUnit.moleExp_ += unit2.moleExp_;\n\n // Concatenate the unit info (name, code, etc) for all cases\n // where the multiplication was performed (an error wasn't thrown)\n retUnit.name_ = this._concatStrs(retUnit.name_, '*', unit2.name_, '[', ']');\n retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '.', unit2.csCode_,\n '(', ')');\n if (retUnit.ciCode_ && unit2.ciCode_)\n retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '.', unit2.ciCode_,\n '(', ')');\n else if (unit2.ciCode_)\n retUnit.ciCode_ = unit2.ciCode_;\n retUnit.resetFieldsForDerivedUnit();\n if (retUnit.printSymbol_ && unit2.printSymbol_)\n retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '.',\n unit2.printSymbol_, '(', ')');\n else if (unit2.printSymbol_)\n retUnit.printSymbol_ = unit2.printSymbol_;\n\n // A unit that has the arbitrary attribute taints any unit created from it\n // via an arithmetic operation. Taint accordingly\n // if (!retUnit.isMole_)\n // retUnit.isMole_ = unit2.isMole_ ;\n if (!retUnit.isArbitrary_)\n retUnit.isArbitrary_ = unit2.isArbitrary_;\n\n // Likewise for special units\n if (!retUnit.isSpecial_)\n retUnit.isSpecial_ = unit2.isSpecial_;\n\n return retUnit ;\n\n } // end multiplyThese\n\n\n /**\n * Clears fields like isBase_, synonyms_, etc. when a unit has been cloned\n * from a known unit but it being used to construct a derived unit.\n */\n resetFieldsForDerivedUnit() {\n this.guidance_ = '';\n this.synonyms_ = null;\n this.isBase_ = false;\n }\n\n\n /**\n * Divides this unit by another unit. If this unit is not on a ratio\n * scale an exception is raised. Mutating to a ratio scale unit\n * is not possible for a unit, only for a measurement.\n *\n * This unit is NOT modified by this function.\n * @param unit2 the unit by which to divide this one\n * @return this unit after it is divided by unit2\n * @throws an error if either of the units is not on a ratio scale.\n * */\n divide(unit2) {\n\n var retUnit = this.clone();\n\n if (retUnit.cnv_ != null)\n throw (new Error(`Attempt to divide non-ratio unit ${retUnit.name_}`));\n if (unit2.cnv_ != null)\n throw (new Error(`Attempt to divide by non-ratio unit ${unit2.name_}`));\n\n if (retUnit.name_ && unit2.name_)\n retUnit.name_ = this._concatStrs(retUnit.name_, '/', unit2.name_, '[', ']');\n else if (unit2.name_)\n retUnit.name_ = unit2.invertString(unit2.name_);\n\n retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '/', unit2.csCode_,\n '(', ')');\n\n if (retUnit.ciCode_ && unit2.ciCode_)\n retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '/', unit2.ciCode_,\n '(', ')');\n else if (unit2.ciCode_)\n retUnit.ciCode_ = unit2.invertString(unit2.ciCode_) ;\n\n retUnit.resetFieldsForDerivedUnit();\n\n retUnit.magnitude_ /= unit2.magnitude_;\n\n if (retUnit.printSymbol_ && unit2.printSymbol_)\n retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '/',\n unit2.printSymbol_, '(', ')');\n else if (unit2.printSymbol_)\n retUnit.printSymbol_ = unit2.invertString(unit2.printSymbol_);\n\n // Continue if unit2 has a dimension object.\n // If this object has a dimension object, subtract unit2's dim_ object from\n // this one. The sub method will take care of cases where the dimVec_ arrays\n // are missing on one or both dim_ objects.\n if (unit2.dim_) {\n if (retUnit.dim_) {\n if (retUnit.dim_.isNull())\n retUnit.dim_.assignZero();\n retUnit.dim_ = retUnit.dim_.sub(unit2.dim_);\n } // end if this.dim_ exists\n\n // Else if this dim_ object is missing, clone unit2's dim_ object\n // and give the inverted clone to this unit.\n else\n retUnit.dim_ = unit2.dim_.clone().minus();\n } // end if unit2 has a dimension object\n\n // Update the mole exponent count by subtracting the count for unit2 from\n // the count for this unit.\n retUnit.moleExp_ -= unit2.moleExp_ ;\n // Also update the equivalent exponent.\n retUnit.equivalentExp_ -= unit2.equivalentExp_;\n\n // A unit that has the arbitrary attribute taints any unit created from\n // it via an arithmetic operation. Taint accordingly\n // if (!retUnit.isMole_)\n // retUnit.isMole_ = unit2.isMole_ ;\n if (!retUnit.isArbitrary_)\n retUnit.isArbitrary_ = unit2.isArbitrary_;\n\n return retUnit;\n\n } // end divide\n\n\n /**\n * This function is not actually used by the other code, except for some test\n * code, and might not be adequately tested.\n *\n * Invert this unit with respect to multiplication. If this unit is not\n * on a ratio scale an exception is thrown. Mutating to a ratio scale unit\n * is not possible for a unit, only for a measurement (the magnitude and\n * dimension).\n *\n * This unit is modified by this function.\n * @return this unit after being inverted\n * @throws and error if this unit is not on a ratio scale\n */\n invert() {\n var retUnit = this.clone() ;\n if (this.cnv_ != null)\n throw (new Error(`Attempt to invert a non-ratio unit - ${this.name_}`));\n\n retUnit.name_ = this.invertString(this.name_);\n retUnit.magnitude_ = 1/this.magnitude_ ;\n retUnit.dim_.minus();\n\n // Also update equivalentExp_ and moleExp\n retUnit.equivalentExp_ = -this.equivalentExp_;\n retUnit.moleExp_ = -this.moleExp_;\n\n return retUnit;\n\n } // end invert\n\n\n /**\n * Inverts a string, where the string is assumed to be a code or a name\n * of a division operation where the string is the divisor and the dividend\n * is blank.\n *\n * @param the string to be inverted\n * @return the inverted string\n */\n invertString(theString) {\n\n if (theString.length > 0) {\n // replace('<!', '</') is here to make sure closing html tags like </sup> are intact. See LF-2830.\n let stringRep = theString.replace('/', \"!\").replace('.', '/').replace('<!', '</').replace(\"!\", '.');\n switch(stringRep.charAt(0)) {\n case '.' : theString = stringRep.substr(1); break;\n case '/' : theString = stringRep; break;\n default : theString = \"/\" + stringRep;\n }\n }\n return theString;\n\n } // end invertString\n\n\n /**\n * This function handles concatenation of two strings and an operator.\n * It's called to build unit data, e.g., unit name, unit code, etc., from\n * two different units, joined by the specified operator.\n *\n * @param str1 the first string to appear in the result\n * @param operator the operator ('*', '.' or '/') to appear between the strings\n * @param str2 the second string to appear in the result\n * @param startChar the starting character to be used, when needed, to\n * enclose a string\n * @param endChar the ending character to be used, when needed, to enclose\n * a string\n * @returns the built string\n */\n _concatStrs(str1, operator, str2, startChar, endChar) {\n\n return this._buildOneString(str1, startChar, endChar) +\n operator + this._buildOneString(str2, startChar, endChar) ;\n }\n\n\n /**\n * This function handles creation of one string to be included in a\n * concatenated string. Basically it checks to see if the string\n * needs to be enclosed either in parentheses or square brackets.\n *\n * The string is enclosed if it is not a number, is not already enclosed in a pair of\n * parentheses or square brackets, and includes a period, and asterisk,\n * a slash or a blank space.\n *\n * @param str the string\n * @param startChar starting enclosing character\n * @param endChar ending enclosing character\n * @returns the string\n */\n _buildOneString(str, startChar, endChar) {\n let ret = '' ;\n if (intUtils_.isNumericString(str)) {\n ret = str;\n }\n else {\n if (str.charAt(0) === '(' && str.endsWith(')') || str.charAt(0) === '[' && str.endsWith(']')) {\n ret = str;\n }\n else if (/[./* ]/.test(str)) {\n ret = startChar + str + endChar ;\n }\n else {\n ret = str ;\n }\n }\n return ret ;\n }\n\n\n /**\n * This function is not actually used by the other code, except for some test\n * code, and might not be adequately tested.\n *\n * Raises the unit to a power. For example\n * kg.m/s2 raised to the -2 power would be kg-2.m-2/s-4\n *\n * If this unit is not on a ratio scale an error is thrown. Mutating\n * to a ratio scale unit is not possible for a unit, only for a\n * measurement (magnitude and dimension).\n *\n * This is based on the pow method in Gunter Schadow's java version,\n * although it uses javascript capabilities to simplify the processing.\n *\n * This unit is modified by this function\n *\n * @param p the power to with this unit is to be raise\n * @return this unit after it is raised\n * @throws an error if this unit is not on a ratio scale.\n */\n power(p) {\n\n if (this.cnv_ != null)\n throw (new Error(`Attempt to raise a non-ratio unit, ${this.name_}, ` +\n 'to a power.'));\n\n var retUnit = this.clone() ;\n //this.name_ = UnitString.pow(this.name_, p);\n // the above line is replaced with the code below, as the pow method\n // never actually existing in the UnitString class. (Tried to use\n // Schadow java code but this way ended up being a lot easier).\n let uStr = this.csCode_ ;\n let uArray = uStr.match(/([./]|[^./]+)/g) ;\n let arLen = uArray.length;\n\n for (let i = 0; i < arLen; i++) {\n let un = uArray[i] ;\n if (un !== '/' && un !== '.') {\n let nun = parseInt(un);\n if (isInteger(nun))\n uArray[i] = (Math.pow(nun, p).toString());\n else {\n let uLen = un.length ;\n for (let u = uLen - 1; u >= 0; u--) {\n let uChar = parseInt(un[u]);\n if (!isInteger(uChar)) {\n if (un[u] === '-' || un[u] === '+') {\n u--;\n }\n if (u < uLen - 1) {\n let exp = parseInt(un.substr(u));\n exp = Math.pow(exp, p);\n uArray[i] = un.substr(0, u) + exp.toString();\n u = -1;\n }\n else {\n uArray[i] += p.toString();\n u = -1;\n } // end if there are/aren't some numbers at the end\n u = -1;\n } // end if this character is not a number\n } // end searching backwards for start of exponent\n } // end if this element is not a number\n } // end if the current element is not an operator\n } // end do for each element of the units array\n\n // reassemble the updated units array to a string\n retUnit.csCode_ = uArray.join('');\n\n retUnit.magnitude_ = Math.pow(this.magnitude_, p);\n if (retUnit.dim_) {\n retUnit.dim_.mul(p);\n }\n\n // Also update equivalentExp_ and moleExp\n retUnit.equivalentExp_ *= p;\n retUnit.moleExp_ *= p;\n\n return retUnit;\n\n } // end power\n\n\n /*\n * This function tests this unit against the unit passed in to see if the\n * two are mole to mass commensurable. It assumes that one of the units\n * is a mole-based unit and the other is a mass-based unit. It also assumes\n * that the mole-based unit has a single mole unit in the numerator and that\n * the mass-based unit has a single mass unit in the numerator. It does NOT\n * check to validate those assumptions.\n *\n * The check is made by setting the dimension vector element corresponding\n * to the base mass unit (gram) in the mole unit, and then comparing the\n * two dimension vectors. If they match, the units are commensurable.\n * Otherwise they are not.\n *\n * @param unit2 the unit to be compared to this one\n * @returns boolean indicating commensurability\n */\n isMolMassCommensurable(unit2) {\n let tabs = this._getUnitTables();\n let d = tabs.getMassDimensionIndex();\n // Add the moleExp_ values to the mass values in the dimension vectors\n // of each unit, and then compare them.\n const unit1Dim = this.dim_.clone();\n unit1Dim.setElementAt(d, (unit1Dim.getElementAt(d) + this.moleExp_));\n const unit2Dim = unit2.dim_.clone();\n unit2Dim.setElementAt(d, (unit2Dim.getElementAt(d) + unit2.moleExp_));\n return (unit1Dim.equals(unit2Dim));\n }\n\n\n /**\n * This function tests this unit against the unit passed in to see if the\n * two are eq to mass commensurable. It assumes that one of the units\n * is a eq-based unit and the other is a mass-based unit. It also assumes\n * that the eq-based unit has a single eq unit in the numerator and that\n * the mass-based unit has a single mass unit in the numerator. It does NOT\n * check to validate those assumptions.\n *\n * The check is made by setting the dimension vector element corresponding\n * to the base mass unit (gram) in the eq unit, and then comparing the\n * two dimension vectors. If they match, the units are commensurable.\n * Otherwise they are not.\n *\n * @param {Unit} unit2 the unit to be compared to this one\n * @returns {boolean} boolean indicating commensurability\n */\n isEqMassCommensurable(unit2) {\n let tabs = this._getUnitTables();\n let d = tabs.getMassDimensionIndex();\n // Add the equivalentExp_ values to the mass values in the dimension vectors\n // of each unit, and then compare them.\n const unit1Dim = this.dim_.clone();\n unit1Dim.setElementAt(d, (unit1Dim.getElementAt(d) + this.equivalentExp_));\n const unit2Dim = unit2.dim_.clone();\n unit2Dim.setElementAt(d, (unit2Dim.getElementAt(d) + unit2.equivalentExp_));\n return (unit1Dim.equals(unit2Dim));\n }\n\n /**\n * This function tests this unit against the unit passed in to see if the\n * two are eq to mass commensurable-- that the equivalents could be converted\n * to the mass or vice-versa, in a way that makes the units commensurable.\n *\n * The check is made by adding the mole dimension to the equivalent dimension\n * and comparing that result for the two units, along with the units'\n * dimension vectors. If they match, the units are\n * commensurable. Otherwise they are not.\n *\n * @param {Unit} unit2 the unit to be compared to this one\n * @returns {boolean} boolean indicating commensurability\n */\n isEqMolCommensurable(unit2) {\n const unit1Sum = this.equivalentExp_ + this.moleExp_;\n const unit2Sum = unit2.equivalentExp_ + unit2.moleExp_;\n return unit1Sum == unit2Sum && this.dim_.equals(unit2.dim_);\n }\n\n\n /**\n * This function tests this unit against the unit passed in to see if the\n * two are commensurable if eq, mol, and mass units are converted in some\n * direction.\n *\n * The check is made by adding the eq, mol, and mass dimensions\n * and comparing that result for the two units, along with the units'\n * dimension vectors. If they match, the units are\n * commensurable. Otherwise they are not.\n *\n * @param {Unit} unit2 the unit to be compared to this one\n * @returns {boolean} boolean indicating commensurability\n */\n isEqMolMassCommensurable(unit2) {\n const d = this._getUnitTables().getMassDimensionIndex();\n const unit1Dim = this.dim_.clone();\n unit1Dim.setElementAt(d, unit1Dim.getElementAt(d) + this.equivalentExp_ +\n this.moleExp_);\n const unit2Dim = unit2.dim_.clone();\n unit2Dim.setElementAt(d, unit2Dim.getElementAt(d) + unit2.equivalentExp_ +\n unit2.moleExp_);\n return unit1Dim.equals(unit2Dim);\n }\n\n\n /**\n * This returns the UnitTables singleton object. Including the require\n * statement included here causes a circular dependency condition that\n * resulted in the UnitTables object not being defined for the Unit object.\n * sigh. Thanks, Paul, for figuring this out.\n *\n * @private\n */\n _getUnitTables() {\n if (!UnitTables)\n UnitTables = require('./unitTables.js').UnitTables;\n return UnitTables.getInstance();\n }\n\n} // end Unit class\n","/**\n * This class handles the parsing of a unit string into a unit object\n */\n\nvar Ucum = require('./config.js').Ucum;\nvar Unit = require('./unit.js').Unit;\nvar UnitTables = require('./unitTables.js').UnitTables;\nvar PrefixTables = require('./prefixTables.js').PrefixTables;\n\nimport * as intUtils_ from \"./ucumInternalUtils.js\";\n\nexport class UnitString {\n\n /**\n * Constructor\n */\n constructor() {\n\n // Get instances of the unit and prefix tables and the utilities\n this.utabs_ = UnitTables.getInstance();\n this.pfxTabs_ = PrefixTables.getInstance();\n\n // Set emphasis characters to defaults. These are used to emphasize\n // certain characters or strings in user messages. They can be reset in\n // the useHTMLInMessages method.\n this.openEmph_ = Ucum.openEmph_;\n this.closeEmph_ = Ucum.closeEmph_;\n\n // Set the braces message to blank. This message is displayed for each\n // validation request on the web page, but is included separately as\n // a note on the validation spreadsheet. The useBraceMsgForEachString\n // method should be used to set the message to be displayed for each\n // unit string.\n this.bracesMsg_ = '';\n\n // Set the flags used, with indices, as place holders in unit strings\n // for parenthetical strings and strings within braces.\n this.parensFlag_ = \"parens_placeholder\"; // in lieu of Jehoshaphat\n this.pFlagLen_ = this.parensFlag_.length;\n this.braceFlag_ = \"braces_placeholder\"; // in lieu of Nebuchadnezzar\n this.bFlagLen_ = this.braceFlag_.length;\n\n // Initialize the message start/end strings, which will be set when\n // parseString is called.\n this.vcMsgStart_ = null;\n this.vcMsgEnd_ = null;\n\n // Arrays used by multiple methods within this class to hold persistent\n // data. Just gets too bulky to pass these guys around.\n\n // Messages to be returned to the calling function\n this.retMsg_ = [] ;\n\n // Units for parenthetical unit strings\n this.parensUnits_ = [] ;\n\n // annotation text for annotations found in unit strings\n this.annotations_ = [] ;\n\n // suggestions for unit strings that for which no unit was found\n this.suggestions = [] ;\n } // end constructor\n\n\n // The start of an error message about an invalid annotation character.\n static INVALID_ANNOTATION_CHAR_MSG = 'An invalid character was found in the annotation ';\n\n // A regular expression for validating annotation strings.\n static VALID_ANNOTATION_REGEX = /^\\{[!-z|~]*\\}$/;\n\n /**\n * Sets the emphasis strings to the HTML used in the webpage display - or\n * blanks them out, depending on the use parameter.\n *\n * @param use flag indicating whether or not to use the html message format;\n * defaults to true\n */\n useHTMLInMessages(use) {\n if (use === undefined || use) {\n this.openEmph_ = Ucum.openEmphHTML_;\n this.closeEmph_ = Ucum.closeEmphHTML_;\n }\n else {\n this.openEmph_ = Ucum.openEmph_;\n this.closeEmph_ = Ucum.closeEmph_;\n }\n } // end useHTMLInMessages\n\n\n /**\n * Sets the braces message to be displayed for each unit string validation\n * requested, as appropriate.\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 || use)\n this.bracesMsg_ = Ucum.bracesMsg_;\n else\n this.bracesMsg_ = '';\n }\n\n\n /**\n * Parses a unit string, returns a unit, a possibly updated version of\n * the string passed in, and messages and suggestions where appropriate.\n *\n * The string returned may be updated if the input string contained unit\n * names, e.g., \"pound\". The unit code ([lb_av] for pound) is placed in\n * the string returned, a the returned messages array includes a note\n * explaining the substitution.\n *\n * @param uStr the string defining 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 * optional, defaults to 'validate'\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 an array containing:\n * the unit object or null if a unit could not be created. In cases where\n * a fix was found for a problem string, .e.g., 2.mg for 2mg, a unit will\n * be returned but an error message will also be returned, describing\n * the substitution;\n * the possibly updated unit string passed in;\n * an array of any user messages (informational, error or warning)\n * generated (or an empty array); and\n * a suggestions array of hash objects (1 or more). Each hash contains\n * 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 array will not contain a suggestions array if a valid unit\n * was found or if suggestions were not requested.\n * @throws an error if nothing was specified.\n */\n parseString(uStr, valConv, suggest) {\n\n uStr = uStr.trim();\n // Make sure we have something to work with\n if (uStr === '' || uStr === null) {\n throw (new Error('Please specify a unit expression to be validated.'));\n }\n\n if (valConv === 'validate') {\n this.vcMsgStart_ = Ucum.valMsgStart_;\n this.vcMsgEnd_ = Ucum.valMsgEnd_;\n }\n else {\n this.vcMsgStart_ = Ucum.cnvMsgStart_;\n this.vcMsgEnd_ = Ucum.cnvMsgEnd_;\n }\n\n if (suggest === undefined || suggest === false) {\n this.suggestions_ = null;\n }\n else {\n this.suggestions_ = [] ;\n }\n\n this.retMsg_ = [];\n this.parensUnits_ = [];\n this.annotations_ = [] ;\n\n let origString = uStr;\n let retObj = [];\n\n // Extract any annotations, i.e., text enclosed in braces ({}) from the\n // string before further processing. Store each one in this.annotations_\n // array and put a placeholder in the string for the annotation. Do\n // this before other processing in case an annotation contains characters\n // that will be interpreted as parenthetical markers or operators in\n // subsequent processing.\n\n uStr = this._getAnnotations(uStr);\n if (this.retMsg_.length > 0) {\n retObj[0] = null;\n retObj[1] = null;\n }\n else {\n // Flag used to block further processing on an unrecoverable error\n let endProcessing = this.retMsg_.length > 0;\n\n // First check for one of the \"special\" units. If it's one of those, put\n // in a substitution phrase for it to avoid having it separated on its\n // embedded operator. This will only happen, by the way, if it is\n // preceded by a prefix or followed by an operator and another unit.\n let sUnit = null ;\n for (sUnit in Ucum.specUnits_) {\n while (uStr.indexOf(sUnit) !== -1)\n uStr = uStr.replace(sUnit, Ucum.specUnits_[sUnit]);\n }\n\n // Check for spaces and throw an error if any are found. The spec\n // explicitly forbids spaces except in annotations, which is why any\n // annotations are extracted before this check is made.\n if (uStr.indexOf(' ') > -1) {\n throw (new Error('Blank spaces are not allowed in unit expressions.'));\n } // end if blanks were found in the string\n\n // assign the array returned to retObj. It will contain 2 elements:\n // the unit returned in position 0; and the origString (possibly\n // modified) in position 1. The origString in position 1 will not\n // be changed by subsequent processing.\n retObj = this._parseTheString(uStr, origString);\n let finalUnit = retObj[0];\n\n // Do a final check to make sure that finalUnit is a unit and not\n // just a number. Something like \"8/{HCP}\" will return a \"unit\" of 8\n // - which is not a unit. Hm - evidently it is. So just create a unit\n // object for it.\n if (intUtils_.isIntegerUnit(finalUnit) || typeof finalUnit === 'number') {\n finalUnit = new Unit({\n 'csCode_': origString,\n 'ciCode_': origString,\n 'magnitude_': finalUnit,\n 'name_': origString\n });\n retObj[0] = finalUnit;\n } // end final check\n } // end if no annotation errors were found\n\n retObj[2] = this.retMsg_;\n if (this.suggestions_ && this.suggestions_.length > 0)\n retObj[3] = this.suggestions_ ;\n return retObj;\n\n } // end parseString\n\n\n /**\n * Parses a unit string, returns a unit, a possibly updated version of\n * the string passed in, and messages where appropriate. This should\n * only be called from within this class (or by test code).\n *\n * The string returned may be updated if the input string contained unit\n * names, e.g., \"pound\". The unit code ([lb_av] for pound) is placed in\n * the string returned, a the returned messages array includes a note\n * explaining the substitution.\n *\n * @param uStr the string defining the unit\n * @param origString the original unit string passed in\n *\n * @returns\n * an array containing:\n * the unit object (or null if there were problems creating the unit); and\n * the possibly updated unit string passed in.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * the this.parensUnits_ array is referenced and possibly populated by\n * methods called within this one\n * the this.annotations_ array is referenced by methods called within\n * this one\n * the this.suggestions_ array may be populated by methods called within\n * this one\n */\n _parseTheString(uStr, origString) {\n\n // Unit to be returned\n let finalUnit = null;\n\n // Flag used to block further processing on an unrecoverable error\n let endProcessing = this.retMsg_.length > 0;\n\n // Call _processParens to search for and process any/all parenthetical\n // strings in uStr. Units created for parenthetical strings will be\n // stored in the this.parensUnits_ array.\n let parensResp = this._processParens(uStr, origString);\n endProcessing = parensResp[2];\n\n // The array used to hold the units and their operators.\n let uArray = [];\n\n // Continue if we didn't hit a problem\n if (!endProcessing) {\n uStr = parensResp[0];\n origString = parensResp[1];\n\n // Call _makeUnitsArray to convert the string to an array of unit\n // descriptors with operators.\n let mkUArray = this._makeUnitsArray(uStr, origString);\n\n endProcessing = mkUArray[2] ;\n if (!endProcessing) {\n uArray = mkUArray[0];\n origString = mkUArray[1];\n // Create a unit object out of each un element\n let uLen = uArray.length;\n for (let u1 = 0; u1 < uLen; u1++) {\n //for (let u1 = 0; u1 < uLen && !endProcessing; u1++) {\n let curCode = uArray[u1]['un'];\n\n // Determine the type of the \"un\" attribute of the current array element\n\n // Check to see if it's a number. If so write the number version of\n // the number back to the \"un\" attribute and move on\n if (intUtils_.isIntegerUnit(curCode)) {\n uArray[u1]['un'] = Number(curCode);\n }\n\n else {\n // The current unit array element is a string. Check now to see\n // if it is or contains a parenthesized unit from this.parensUnits_.\n // If so, call _getParens to process the string and get the unit.\n\n if (curCode.indexOf(this.parensFlag_) >= 0) {\n let parenUnit = this._getParensUnit(curCode, origString);\n // if we couldn't process the string, set the end flag and bypass\n // further processing.\n if (!endProcessing)\n endProcessing = parenUnit[1];\n\n // If we're good, put the unit in the uArray and replace the\n // curCode, which contains the parentheses placeholders, etc.,\n // with the unit's code - including any substitutions.\n if (!endProcessing) {\n uArray[u1]['un'] = parenUnit[0];\n }\n } // end if the curCode contains a parenthesized unit\n\n // Else it's not a parenthetical unit and not a number. Call\n // _makeUnit to create a unit for it.\n else {\n let uRet = this._makeUnit(curCode, origString);\n // If we didn't get a unit, set the endProcessing flag.\n if (uRet[0] === null) {\n endProcessing = true;\n }\n else {\n uArray[u1]['un'] = uRet[0];\n origString = uRet[1];\n }\n } // end if the curCode is not a parenthetical expression\n } // end if the \"un\" array is a not a number\n } // end do for each element in the units array\n } // end if _makeUnitsArray did not return an error\n } // end if _processParens did not find an error that causes a stop\n\n // If we're still good, continue\n if (!endProcessing) {\n // Process the units (and numbers) to create one final unit object\n if ((uArray[0] === null || uArray[0] === ' ' ||\n uArray[0]['un'] === undefined || uArray[0]['un'] === null)\n && this.retMsg_.length === 0) {\n // not sure what this might be, but this is a safeguard\n this.retMsg_.push(`Unit string (${origString}) did not contain ` +\n `anything that could be used to create a unit, or else something ` +\n `that is not handled yet by this package. Sorry`);\n endProcessing = true;\n }\n }\n if (!endProcessing) {\n finalUnit = this._performUnitArithmetic(uArray, origString);\n }\n return [finalUnit, origString];\n } // end _parseTheString\n\n\n /**\n * Extracts all annotations from a unit string, replacing them with\n * placeholders for later evaluation. The annotations are stored in the\n * this.annotations_ array. This should only be called from within this\n * class (or by test code).\n *\n * @param uString the unit string being parsed\n * @returns the string after the annotations are replaced with placeholders\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * the this.annotations_ array is populated by this method\n */\n _getAnnotations(uString) {\n let openBrace = uString.indexOf('{');\n while (openBrace >= 0) {\n\n let closeBrace = uString.indexOf('}');\n if (closeBrace < 0) {\n this.retMsg_.push('Missing closing brace for annotation starting at ' +\n this.openEmph_ + uString.substr(openBrace) +\n this.closeEmph_);\n openBrace = -1;\n }\n else {\n let braceStr = uString.substring(openBrace, closeBrace + 1);\n // Check for valid characters in the annotation.\n if (!UnitString.VALID_ANNOTATION_REGEX.test(braceStr)) {\n this.retMsg_.push(UnitString.INVALID_ANNOTATION_CHAR_MSG +\n this.openEmph_ + braceStr + this.closeEmph_);\n openBrace = -1; // end search for annotations\n }\n else {\n let aIdx = this.annotations_.length.toString();\n uString = uString.replace(braceStr, this.braceFlag_ + aIdx +\n this.braceFlag_);\n this.annotations_.push(braceStr);\n openBrace = uString.indexOf('{');\n }\n }\n } // end do while we have an opening brace\n\n // check for a stray/unmatched closing brace\n if (this.retMsg_.length == 0) { // if there were no other errors above\n let closeBrace = uString.indexOf('}');\n if (closeBrace >= 0)\n this.retMsg_.push('Missing opening brace for closing brace found at ' +\n this.openEmph_ + uString.substring(0, closeBrace + 1) +\n this.closeEmph_);\n }\n return uString;\n } // end _getAnnotations\n\n\n /**\n * Finds and processes any/all parenthesized unit strings. This should only\n * be called from within this class (or by test code).\n *\n * Nested parenthesized strings are processed from the inside out. The\n * parseString function is called from within this one for each parenthesized\n * unit string, and the resulting unit object is stored in this.parensUnits_,\n * to be processed after all strings are translated to units.\n *\n * A placeholder is placed in the unit string returned to indicate that the\n * unit object should be obtained from the this.parensUnits_ array. The\n * placeholder consists of the parenthesis flag (this.parensFlag_) followed\n * by the index of the unit in this.parensUnits_ followed by this.parensFlag_.\n *\n * @param uString the unit string being parsed, where this will be the full\n * string the first time this is called and parenthesized strings on any\n * subsequent calls\n * @param origString the original string first passed in to parseString\n * @returns\n * an array containing:\n * the string after the parentheses are replaced;\n * the original string; and\n * a boolean flag indicating whether or not an error occurred that\n * should stop processing.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * this this.parensUnits_ array will be populated with units found for\n * parenthetical unit strings\n */\n _processParens(uString, origString) {\n\n // Unit strings array and index\n let uStrArray = [];\n let uStrAryPos = 0;\n let stopProcessing = false;\n\n let pu = this.parensUnits_.length;\n\n // Count of characters trimmed off the beginning of the unit string (uString)\n // as units are removed from it; used for error messages to provide\n // context.\n let trimmedCt = 0;\n\n // Break the unit string into pieces that consist of text outside of\n // parenthetical strings and placeholders for the parenthetical units.\n // This method is called recursively for parenthetical strings and the units\n // returned are stored in the this.parensUnits_ array.\n while (uString !== \"\" && !stopProcessing) {\n let openCt = 0;\n let closeCt = 0;\n let openPos = uString.indexOf('(');\n\n // If an opening parenthesis was not found, check for an unmatched\n // close parenthesis. If one was found report the error and end\n // processing.\n if (openPos < 0) {\n let closePos = uString.indexOf(')');\n if (closePos >= 0) {\n let theMsg = `Missing open parenthesis for close ` +\n `parenthesis at ${uString.substring(0, closePos + trimmedCt)}` +\n `${this.openEmph_}${uString.substr(closePos, 1)}${this.closeEmph_}`;\n if (closePos < uString.length - 1) {\n theMsg += `${uString.substr(closePos + 1)}`;\n }\n this.retMsg_.push(theMsg);\n uStrArray[uStrAryPos] = uString;\n stopProcessing = true;\n } // end if a close parenthesis was found\n\n // If no parentheses were found in the current unit string, transfer\n // it to the units array and blank out the string, which will end\n // the search for parenthetical units.\n else {\n uStrArray[uStrAryPos] = uString;\n uString = \"\";\n } // end if no close parenthesis was found\n } // end if no open parenthesis was found\n\n // Otherwise an open parenthesis was found. Process the string that\n // includes the parenthetical group\n else {\n openCt += 1;\n // Write the text before the parentheses (if any) to the unit strings array\n let uLen = uString.length;\n if (openPos > 0) {\n uStrArray[uStrAryPos++] = uString.substr(0, openPos);\n }\n\n // Find the matching closePos, i.e., the one that closes the\n // parenthetical group that this one opens. Look also for\n // another open parenthesis, in case this includes nested parenthetical\n // strings. This continues until it finds the same number of close\n // parentheses as open parentheses, or runs out of string to check.\n // In the case of nested parentheses this will identify the outer set\n // of parentheses.\n let closePos = 0;\n let c = openPos + 1;\n for (; c < uLen && openCt != closeCt; c++) {\n if (uString[c] === '(')\n openCt += 1;\n else if (uString[c] === ')')\n closeCt += 1;\n }\n\n // Put a placeholder for the group in the unit strings array and recursively\n // call this method for the parenthetical group. Put the unit returned\n // in this.parensUnits_. Set the unit string to whatever follows\n // the position of the closing parenthesis for this group, to be\n // processed by the next iteration of this loop. If there's nothing\n // left uString is set to \"\".\n if (openCt === closeCt) {\n closePos = c;\n uStrArray[uStrAryPos++] = this.parensFlag_ + pu.toString() + this.parensFlag_;\n let parseResp = this._parseTheString(\n uString.substring(openPos + 1, closePos - 1), origString);\n if (parseResp[0] === null)\n stopProcessing = true;\n else if (uString[openPos + 1] === '/') {\n // If the term inside the parenthesis starts with '/', fail the validation. See LF-2854.\n this.retMsg_.push(\"Unary operator '/' is only allowed at the beginning of the main term, not inside a parenthesis.\");\n stopProcessing = true;\n }\n else {\n origString = parseResp[1];\n this.parensUnits_[pu++] = parseResp[0];\n uString = uString.substr(closePos);\n trimmedCt = closePos;\n }\n } // end if the number of open and close parentheses matched\n\n // If the number of open and close parentheses doesn't match, indicate\n // an error.\n else {\n uStrArray.push(origString.substr(openPos));\n this.retMsg_.push(`Missing close parenthesis for open parenthesis at ` +\n `${origString.substring(0, openPos + trimmedCt)}` +\n `${this.openEmph_}${origString.substr(openPos, 1)}` +\n `${this.closeEmph_}${origString.substr(openPos + 1)}`);\n stopProcessing = true;\n }\n } // end if an open parenthesis was found\n } // end do while the input string is not empty\n if (stopProcessing)\n this.parensUnits_ = [];\n return [uStrArray.join(''), origString, stopProcessing]\n } // end _processParens\n\n\n /**\n * Breaks the unit string into an array of unit descriptors and operators.\n * If a unit descriptor consists of a number preceding a unit code, with\n * no multiplication operator, e.g., 2mg instead of 2.mg, it is handled\n * as if it were a parenthetical expression.\n *\n * This should only be called from within this class (or by test code).\n *\n * @param uStr the unit string being parsed\n * @param origString the original string passed to parseString\n * @returns\n * an array containing:\n * the array representing the unit string;\n * the original string passed in, possibly updated with corrections; and\n * and a flag indicating whether or not processing can continue.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n */\n _makeUnitsArray(uStr, origString) {\n\n // Separate the string into pieces based on delimiters / (division) and .\n // (multiplication). The idea is to get an array of units on which we\n // can then perform any operations (prefixes, multiplication, division).\n\n let uArray1 = uStr.match(/([./]|[^./]+)/g);\n let endProcessing = false ;\n let uArray = [];\n let startNumCheck = /(^[0-9]+)(\\[?[a-zA-Z\\_0-9a-zA-Z\\_]+\\]?$)/ ;\n\n // If the first element in the array is the division operator (/), the\n // string started with '/'. Add a first element containing 1 to the\n // array, which will cause the correct computation to be performed (inversion).\n if (uArray1[0] === \"/\") {\n uArray1.unshift(\"1\");\n }\n // If the first element in the array is the multiplication operator (.)\n // return an error.\n else if (uArray1[0] === '.') {\n this.retMsg_.push(`${origString} is not a valid UCUM code. ` +\n `The multiplication operator at the beginning of the expression is ` +\n `not valid. A multiplication operator must appear only between ` +\n `two codes.`);\n endProcessing = true ;\n }\n if (!endProcessing) {\n // Check to see if there is a number preceding a unit code, e.g., 2mg\n // If so, update the first element to remove the number (2mg -> mg) and\n // add two elements to the beginning of the array - the number and the\n // multiplication operator.\n\n if (!intUtils_.isNumericString(uArray1[0])) {\n let numRes = uArray1[0].match(startNumCheck);\n if (numRes && numRes.length === 3 && numRes[1] !== '' &&\n numRes[2] !== '' && numRes[2].indexOf(this.braceFlag_) !== 0) {\n let dispVal = numRes[2] ;\n\n if (!endProcessing && numRes[2].indexOf(this.parensFlag_) !== -1) {\n let parensback = this._getParensUnit(numRes[2], origString);\n numRes[2] = parensback[0]['csCode_'];\n dispVal = `(${numRes[2]})`;\n endProcessing = parensback[1];\n }\n if (!endProcessing) {\n this.retMsg_.push(`${numRes[1]}${dispVal} is not a valid UCUM code.` +\n ` ${this.vcMsgStart_}${numRes[1]}.${dispVal}${this.vcMsgEnd_}`);\n origString = origString.replace(`${numRes[1]}${dispVal}`,\n `${numRes[1]}.${dispVal}`);\n uArray1[0] = numRes[2];\n uArray1.unshift(numRes[1], '.');\n }\n }\n } // end if the first element is not a number (only)\n\n // Create an array of unit/operator objects. The unit is, for now, the\n // string containing the unit code (e.g., Hz for hertz) including\n // a possible prefix and exponent. The operator is the operator to be\n // applied to that unit and the one preceding it. So, a.b would give\n // us two objects. The first will have a unit of a, and a blank operator\n // (because it's the first unit). The second would have a unit of b\n // and the multiplication operator (.).\n if (!endProcessing) {\n let u1 = uArray1.length;\n uArray = [{op: \"\", un: uArray1[0]}];\n for (let n = 1; n < u1; n++) {\n\n // check to make sure that we don't have two operators together, e.g.,\n // mg./K. If so, let the user know the problem.\n let theOp = uArray1[n++];\n // oh wait - check to make sure something is even there, that the\n // user didn't end the expression with an operator.\n if (!uArray1[n]) {\n this.retMsg_.push(`${origString} is not a valid UCUM code. ` +\n `It is terminated with the operator ${this.openEmph_}` +\n `${theOp}${this.closeEmph_}.`);\n n = u1;\n endProcessing = true;\n }\n else if (Ucum.validOps_.indexOf(uArray1[n]) !== -1) {\n this.retMsg_.push(`${origString} is not a valid UCUM code. ` +\n `A unit code is missing between${this.openEmph_}` +\n `${theOp}${this.closeEmph_}and${this.openEmph_}` +\n `${uArray1[n]}${this.closeEmph_}in${this.openEmph_}` +\n `${theOp}${uArray1[n]}${this.closeEmph_}.`);\n n = u1;\n endProcessing = true;\n }\n else {\n // Check to see if a number precedes a unit code.\n // If so, send the element to _processParens, inserting the multiplication\n // operator where it belongs. Treating it as parenthetical keeps it from\n // being interpreted incorrectly because of operator parentheses. For\n // example, if the whole string is mg/2kJ we don't want to rewrite it as\n // mg/2.kJ - because mg/2 would be performed, followed by .kJ. Instead,\n // handling 2kJ as a parenthesized unit will make sure mg is divided by\n // 2.kJ.\n if (!intUtils_.isNumericString(uArray1[n])) {\n let numRes2 = uArray1[n].match(startNumCheck);\n if (numRes2 && numRes2.length === 3 && numRes2[1] !== '' &&\n numRes2[2] !== '' && numRes2[2].indexOf(this.braceFlag_) !== 0) {\n let invalidString = numRes2[0];\n if (!endProcessing && numRes2[2].indexOf(this.parensFlag_) !== -1) {\n let parensback = this._getParensUnit(numRes2[2], origString);\n numRes2[2] = parensback[0]['csCode_'];\n invalidString = `(${numRes2[2]})`;\n endProcessing = parensback[1];\n if (!endProcessing) {\n this.retMsg_.push(`${numRes2[1]}${invalidString} is not a ` +\n `valid UCUM code. ${this.vcMsgStart_}${numRes2[1]}.${invalidString}` +\n `${this.vcMsgEnd_}`);\n let parensString = `(${numRes2[1]}.${invalidString})`;\n origString = origString.replace(`${numRes2[1]}${invalidString}`,\n parensString);\n let nextParens = this._processParens(parensString, origString);\n endProcessing = nextParens[2];\n if (!endProcessing) {\n uArray.push({op: theOp, un: nextParens[0]});\n }\n //uArray.push({op: '.', un: numRes2[2]});\n }\n } // end if the string represents a parenthesized unit\n else {\n let parensStr = '(' + numRes2[1] + '.' + numRes2[2] + ')';\n let parensResp = this._processParens(parensStr, origString);\n // if a \"stop processing\" flag was returned, set the n index to end\n // the loop and set the endProcessing flag\n if (parensResp[2]) {\n n = u1;\n endProcessing = true;\n }\n else {\n this.retMsg_.push(`${numRes2[0]} is not a ` +\n `valid UCUM code. ${this.vcMsgStart_}${numRes2[1]}.${numRes2[2]}` +\n `${this.vcMsgEnd_}`);\n origString = origString.replace(numRes2[0], parensStr);\n uArray.push({op: theOp, un: parensResp[0]});\n } // end if no error on the processParens call\n } // end if the string does not represent a parenthesized unit\n } // end if the string is a number followed by a string\n else {\n uArray.push({op: theOp, un: uArray1[n]});\n }\n }\n else {\n uArray.push({op: theOp, un: uArray1[n]});\n }\n } // end if there isn't a missing operator or unit code\n } // end do for each element in uArray1\n } // end if a processing error didn't occur in getParensUnit\n } // end if the string did not begin with a '.' with no following digit\n return [uArray, origString, endProcessing];\n } // end _makeUnitsArray\n\n\n /**\n * Takes a unit string containing parentheses flags and returns the unit they\n * represent. Any text found before and/or after the parenthetical\n * expression is checked to see if we can tell what the user meant and\n * let them know what it should have been. For example, 2(mg), which\n * would resolve to 2mg, should be 2.mg.\n *\n * This should only be called from within this class (or by test code).\n *\n * @param pStr the string being parsed\n * @param origString the original unit string passed in; passed through\n * to _getAnnonText if annotation flags are found in any text preceding\n * or following the parenthetical unit\n * @returns\n * an array containing\n * the unit object; and\n * a flag indicating whether or not processing should be ended.\n * True indicates that the string was invalid and no corrections\n * (substitutions or suggestions) could be found;\n * False indicates that it was either valid or substitutions/suggestions\n * were made.\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * this this.parensUnits_ array contains the units that are acquired by\n * this method\n * @throws an error if an invalid parensUnit index was found. This is\n * a processing error.\n */\n _getParensUnit(pStr, origString) {\n let endProcessing = false;\n let retAry = [];\n let retUnit = null;\n let befAnnoText = null;\n let aftAnnoText = null;\n\n // Get the location of the flags. We're assuming there are only two\n // because _processParens takes care of nesting. By the time we get\n // here we should not be looking a nested parens. Also get any text\n // before and after the parentheses. Once we get the unit we update\n // the input string with the unit's csCode_, which will wipe out any\n // before and after text\n let psIdx = pStr.indexOf(this.parensFlag_);\n let befText = null;\n if (psIdx > 0) {\n befText = pStr.substring(0, psIdx);\n }\n let peIdx = pStr.lastIndexOf(this.parensFlag_);\n let aftText = null;\n if (peIdx + this.pFlagLen_ < pStr.length) {\n aftText = pStr.substr(peIdx + this.pFlagLen_);\n }\n\n // Get the text between the flags\n let pNumText = pStr.substring(psIdx + this.pFlagLen_, peIdx);\n\n // Make sure the index is a number, and if it is, get the unit from the\n // this.parensUnits_ array\n if (intUtils_.isNumericString(pNumText)) {\n retUnit = this.parensUnits_[Number(pNumText)];\n if (!intUtils_.isIntegerUnit(retUnit)) {\n pStr = retUnit.csCode_;\n }\n else {\n pStr = retUnit ;\n }\n }\n // If it's not a number, it's a programming error. Throw a fit.\n else {\n throw (new Error(`Processing error - invalid parens number ${pNumText} ` +\n `found in ${pStr}.`));\n }\n\n // If there's something in front of the starting parentheses flag, check to\n // see if it's a number or an annotation.\n if (befText) {\n // If it's a number, assume that multiplication was assumed\n if (intUtils_.isNumericString(befText)) {\n let nMag = retUnit.getProperty('magnitude_');\n nMag *= Number(befText);\n retUnit.assignVals({'magnitude_': nMag});\n pStr = `${befText}.${pStr}`;\n this.retMsg_.push(`${befText}${pStr} is not a valid UCUM code.\\n` +\n this.vcMsgStart_ + pStr + this.vcMsgEnd_);\n }\n else {\n if (befText.indexOf(this.braceFlag_) >= 0) {\n let annoRet = this._getAnnoText(befText, origString);\n // if we found not only an annotation, but text before or after\n // the annotation (remembering that this is all before the\n // parentheses) throw an error - because we don't know what\n // to do with it. Could it be missing an operator?\n if (annoRet[1] || annoRet[2]) {\n throw (new Error(`Text found before the parentheses (` +\n `${befText}) included an annotation along with other text ` +\n `for parenthetical unit ${retUnit.csCode_}`));\n }\n // Otherwise put the annotation after the unit string and note\n // the misplacement.\n pStr += annoRet[0];\n this.retMsg_.push(`The annotation ${annoRet[0]} before the unit ` +\n `code is invalid.\\n` + this.vcMsgStart_ + pStr + this.vcMsgEnd_);\n }\n // else the text before the parentheses is neither a number nor\n // an annotation. Record an error.\n else {\n this.retMsg_.push(`${befText} preceding the unit code ${pStr} ` +\n `is invalid. Unable to make a substitution.`);\n endProcessing = true;\n } // end if a brace was found\n } // end if text preceding the parentheses was not a number\n } // end if there was text before the parentheses\n\n // Process any text after the parentheses\n if (aftText) {\n // if it's an annotation, get it and add it to the pStr\n if (aftText.indexOf(this.braceFlag_) >= 0) {\n let annoRet = this._getAnnoText(aftText, origString);\n // if we found not only an annotation, but text before or after\n // the annotation (remembering that this is all after the\n // parentheses) throw an error - because we don't know what\n // to do with it. Could it be missing an operator?\n if (annoRet[1] || annoRet[2]) {\n throw (new Error(`Text found after the parentheses (` +\n `${aftText}) included an annotation along with other text ` +\n `for parenthetical unit ${retUnit.csCode_}`));\n }\n // Otherwise put the annotation after the unit string - no message\n // needed.\n pStr += annoRet[0];\n }\n // Otherwise check to see if it's an exponent. If so, warn the\n // user that it's not valid - but try it anyway\n else {\n\n if (intUtils_.isNumericString(aftText)) {\n retUnit = null;\n let msg = `An exponent (${aftText}) following a parenthesis ` +\n `is invalid as of revision 1.9 of the UCUM Specification.`;\n // Add the suggestion only if the string in the parenthesis don't end with a number.\n if (!pStr.match(/\\d$/)) {\n pStr += aftText;\n msg += '\\n ' + this.vcMsgStart_ + pStr + this.vcMsgEnd_;\n }\n this.retMsg_.push(msg);\n endProcessing = true;\n }\n // else the text after the parentheses is neither a number nor\n // an annotation. Record an error.\n else {\n this.retMsg_.push(`Text ${aftText} following the unit code ${pStr} ` +\n `is invalid. Unable to make a substitution.`);\n endProcessing = true;\n } // end if text following the parentheses not an exponent\n } // end if text following the parentheses is not an annotation\n } // end if there is text following the parentheses\n if (!endProcessing) {\n if (!retUnit) {\n retUnit = new Unit({\n 'csCode_': pStr,\n 'magnitude_': 1,\n 'name_': pStr});\n }\n else if (intUtils_.isIntegerUnit(retUnit)) {\n retUnit = new Unit({'csCode_': retUnit,\n 'magnitude_': retUnit,\n 'name_': retUnit});\n }\n else {\n retUnit.csCode_ = pStr;\n }\n }\n return [retUnit, endProcessing];\n } // end _getParensUnit\n\n /**\n * Takes a unit string containing annotation flags and returns the\n * annotation they represent. This also returns any text found before\n * the annotation and any found after the annotation.\n *\n * This should only be called from within this class (or by test code).\n * NEEDS FIX in next branch to handle string with multiple annotations.\n *\n * @param pStr the string being parsed\n * @param origString the original string being parsed; used in error msg\n * thrown for an invalid index to the annotations array\n * @returns\n * an array containing\n * the annotation for the pStr;\n * any text found before the annotation; and\n * any text found after the annotation.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * the this.annotations_ array is used as the source for the annotations text\n * @throws an error if for a processing error - an invalid annotation index.\n */\n _getAnnoText(pStr, origString) {\n\n // if the starting braces flag is not at index 0, get the starting\n // text and the adjust the pStr to omit it.\n let asIdx = pStr.indexOf(this.braceFlag_);\n let startText = (asIdx > 0) ? pStr.substring(0, asIdx) : null;\n if (asIdx !== 0) {\n pStr = pStr.substr(asIdx);\n }\n\n // Get the location of the end flag and, if text follows it, get the text\n let aeIdx = pStr.indexOf(this.braceFlag_, 1);\n let endText = ((aeIdx + this.bFlagLen_) < pStr.length) ?\n pStr.substr(aeIdx + this.bFlagLen_) : null;\n\n // Get the index of the annotation in this.annotations_.\n // Check it to make sure it's valid, and if not, throw an error\n let idx = pStr.substring(this.bFlagLen_, aeIdx);\n let idxNum = Number(idx);\n if (!intUtils_.isNumericString(idx) || idxNum >= this.annotations_.length) {\n throw (new Error(`Processing Error - invalid annotation index ${idx} found ` +\n `in ${pStr} that was created from ${origString}`));\n }\n\n // Replace the flags and annotation index with the annotation expression\n pStr = this.annotations_[idxNum];\n return [pStr, startText, endText];\n } // end _getAnnoText\n\n\n /**\n * Takes a unit string and looks for suggested units. This should be\n * called for unit strings that cannot be resolved to unit codes. The\n * string is searched for in the synonyms table found in the UnitTables\n * class. That table includes all synonyms and unit names for the units\n * in the unit data table.\n *\n * @param pStr the string being parsed\n * @returns an object that contains an element named 'status', whose\n * value indicates the status of the request:\n * 'succeeded' indicates that synonyms were found;\n * 'failed' indicates that no synonyms were found; or\n * 'error' which indicates that an error occurred\n *\n * the this.retMsg_ array will be updated with a message indicating whether\n * or not synonyms/suggestions were found\n * the this.suggestions_ array will be updated with a hash (added to the\n * array if it already contains others) that 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 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 */\n _getSuggestions(pStr) {\n\n let retObj = intUtils_.getSynonyms(pStr);\n if (retObj['status'] === 'succeeded') {\n let suggSet = {} ;\n suggSet['msg'] = `${pStr} is not a valid UCUM code. We found possible ` +\n `units that might be what was meant:`;\n suggSet['invalidUnit'] = pStr ;\n let synLen = retObj['units'].length ;\n suggSet['units'] = [] ;\n for (let s = 0; s < synLen; s++) {\n let unit = retObj['units'][s];\n let unitArray = [unit['code'], unit['name'], unit['guidance']];\n\n suggSet['units'].push(unitArray) ;\n }\n this.suggestions_.push(suggSet);\n }\n else {\n this.retMsg_.push(`${pStr} is not a valid UCUM code. No alternatives ` +\n `were found.`);\n }\n return retObj['status'] ;\n } // end getSuggestions\n\n\n /**\n * Creates a unit object from a string defining one unit. The string\n * should consist of a unit code for a unit already defined (base or\n * otherwise). It may include a prefix and an exponent, e.g., cm2\n * (centimeter squared). This should only be called from within this\n * class (or by test code).\n *\n * @params uCode the string defining the unit\n * @param origString the original string to be parsed; used to provide\n * context for messages\n * @returns\n * an array containing:\n * a unit object, or null if there were problems creating the unit; and\n * the origString passed in, which may be updated if a unit name was\n * translated to a unit code.\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n * the this.suggestions_ array will be populated if no unit (with or without\n * substitutions) could be found and suggestions were requested\n */\n _makeUnit(uCode, origString) {\n\n // First try the code just as is, without looking for annotations,\n // prefixes, exponents, or elephants.\n let retUnit = this.utabs_.getUnitByCode(uCode);\n if (retUnit) {\n retUnit = retUnit.clone();\n }\n\n // If we found it, we're done. No need to parse for those elephants (or\n // other stuff).\n else if (uCode.indexOf(this.braceFlag_) >= 0) {\n let getAnnoRet = this._getUnitWithAnnotation(uCode, origString);\n retUnit = getAnnoRet[0];\n if (retUnit) {\n origString = getAnnoRet[1];\n }\n // If a unit is not found, retUnit will be returned null and\n // the this.retMsg_ array will contain a message describing the problem.\n // If a unit is found, of course, all is good. So ... nothing left\n // to see here, move along.\n } // end if the uCode includes an annotation\n\n else {\n\n // So we didn't find a unit for the full uCode or for one with\n // annotations. Try looking for a unit that uses a carat (^)\n // instead of an asterisk (*)\n\n if (uCode.indexOf('^') > -1) {\n let tryCode = uCode.replace('^', '*');\n retUnit = this.utabs_.getUnitByCode(tryCode);\n if (retUnit) {\n retUnit = retUnit.clone();\n retUnit.csCode_ = retUnit.csCode_.replace('*', '^');\n retUnit.ciCode_ = retUnit.ciCode_.replace('*', '^');\n }\n }\n // If we still don't have a unit, try assuming a modifier (prefix and/or\n // exponent) and look for a unit without the modifier\n if (!retUnit) {\n\n // Well, first see if it's one of the special units. If so,\n // replace the placeholder text with the actual unit string, keeping\n // whatever text (probably a prefix) goes with the unit string.\n let sUnit = null;\n for (sUnit in Ucum.specUnits_) {\n if (uCode.indexOf(Ucum.specUnits_[sUnit]) !== -1)\n uCode = uCode.replace(Ucum.specUnits_[sUnit], sUnit);\n }\n retUnit = this.utabs_.getUnitByCode(uCode);\n if (retUnit)\n retUnit = retUnit.clone();\n }\n if (!retUnit) {\n\n let origCode = uCode;\n let origUnit = null;\n let exp = null;\n let pfxCode = null;\n let pfxObj = null;\n let pfxVal = null;\n\n // Look first for an exponent. If we got one, separate it out and\n // try to get the unit again\n let codeAndExp = this._isCodeWithExponent(uCode);\n let isIntegerUnitWithExp = false;\n if (codeAndExp) {\n uCode = codeAndExp[0];\n exp = codeAndExp[1];\n isIntegerUnitWithExp = intUtils_.isIntegerUnit(uCode);\n origUnit = isIntegerUnitWithExp ?\n new Unit({'csCode_' : uCode,\n 'ciCode_' : uCode,\n 'magnitude_' : Number(uCode),\n 'name_' : uCode}) :\n this.utabs_.getUnitByCode(uCode);\n }\n\n // If an exponent is found but it's not a valid number, e.g. \"2-1\",\n // mark the unit invalid. Otherwise, the \"-1\" part will be ignored\n // because parseInt(\"2-1\") results in 2. See LF-2870.\n if (exp && isNaN(exp)) {\n retUnit = null;\n this.retMsg_.push(`${origCode} is not a valid UCUM code.`);\n }\n else {\n // If we still don't have a unit, separate out the prefix, if any,\n // and try without it.\n if (!origUnit && uCode.length > 1) {\n // Try for a single character prefix first, then for a two-digit prefix\n pfxCode = '';\n do {\n pfxCode += uCode.charAt(0);\n uCode = uCode.substr(1);\n pfxObj = this.pfxTabs_.getPrefixByCode(pfxCode);\n if (pfxObj) {\n pfxVal = pfxObj.getValue();\n // try again for the unit\n origUnit = this.utabs_.getUnitByCode(uCode);\n }\n } while (!origUnit && pfxCode.length < 2 && uCode.length > 1)\n\n // Reject the unit we found if it might have another prefix. (??)\n // Such things are in our tables through the LOINC source_\n // (ucum.csv) which has guidance and synonyms. I think it should be\n // safe to exclude anything whose source is LOINC from having a\n // prefix.\n if (origUnit && origUnit.source_ == 'LOINC')\n origUnit = null;\n } // end if we didn't get a unit after removing an exponent\n\n // If we still haven't found anything, we're done looking.\n // (We tried with the full unit string, with the unit string\n // without the exponent, the unit string without a prefix,\n // common errors, etc. That's all we can try).\n if (!origUnit) {\n let bracketRet = this._getUnitAfterAddingBrackets(origCode, origString);\n retUnit = bracketRet[0];\n origString = bracketRet[1];\n if (!retUnit) {\n let nameRet = this._getUnitByName(origCode, origString);\n retUnit = nameRet[0];\n origString = nameRet[1];\n if (!retUnit) {\n // BUT if the user asked for suggestions, at least look for them\n if (this.suggestions_) {\n let suggestStat = this._getSuggestions(origCode);\n }\n else {\n this.retMsg_.push(`${origCode} is not a valid UCUM code.`);\n }\n }\n }\n }\n else {\n // Otherwise we found a unit object. Clone it and then apply the\n // prefix and exponent, if any, to it. And remove the guidance.\n retUnit = origUnit.clone();\n // If we are here, this is only part of the full unit string, so it is\n // not a base unit, and the synonyms will mostly likely not be correct for the full\n // string.\n retUnit.resetFieldsForDerivedUnit();\n let theDim = retUnit.getProperty('dim_');\n let theMag = retUnit.getProperty('magnitude_');\n let theName = retUnit.getProperty('name_');\n let theCiCode = retUnit.getProperty('ciCode_');\n let thePrintSymbol = retUnit.getProperty('printSymbol_');\n // If there is an exponent for the unit, apply it to the dimension\n // and magnitude now\n if (exp) {\n // Special units cannot be raised to a power\n if (retUnit.isSpecial_) {\n this.retMsg_.push(`Special units like ${retUnit.name_} cannot be raised to a power.`);\n retUnit = null;\n }\n else {\n exp = parseInt(exp);\n if (theDim)\n theDim = theDim.mul(exp);\n retUnit.equivalentExp_ *= exp;\n retUnit.moleExp_ *= exp;\n theMag = Math.pow(theMag, exp);\n retUnit.assignVals({'magnitude_': theMag});\n\n // If there is also a prefix, apply the exponent to the prefix.\n if (pfxObj) {\n // We don't need to consider pfxObj.getExp(), because when\n // present that is reflected in the pfxVal. However, in some\n // cases one can avoid floating-point math inaccuracies by using\n // that exponent instead of relying on pfxVal. For example:\n // 1e-66 = Math.pow(10, -3*22) = Math.pow(0.001, 22) = 1.0000000000000005e-66\n // (This is the from the test case of the unit mg% raised to the 22nd power (mg%22).)\n // This does not help in all cases, but it does help the above\n // test case (which is in our web API service test code).\n let pfxExp = pfxObj.getExp();\n if (pfxExp) {\n // This is relying on the fact that pfxExp is null when\n // the prefix base is not 10.\n pfxVal = Math.pow(10, exp * pfxExp);\n }\n else {\n pfxVal = Math.pow(pfxVal, exp);\n }\n }\n } // end else - prefix and exponent handling for non-special units\n } // end if there's an exponent\n\n if (retUnit) {\n // Now apply the prefix, if there is one, to the conversion\n // prefix or the magnitude\n if (pfxObj) {\n if (retUnit.cnv_) {\n retUnit.assignVals({'cnvPfx_': pfxVal});\n }\n else {\n theMag *= pfxVal;\n retUnit.assignVals({'magnitude_': theMag})\n }\n }\n // if we have a prefix and/or an exponent, add them to the unit\n // attributes - name, csCode, ciCode and print symbol\n let theCode = retUnit.csCode_;\n if (pfxObj) {\n theName = pfxObj.getName() + theName;\n theCode = pfxCode + theCode;\n theCiCode = pfxObj.getCiCode() + theCiCode;\n thePrintSymbol = pfxObj.getPrintSymbol() + thePrintSymbol;\n retUnit.assignVals({\n 'name_': theName,\n 'csCode_': theCode,\n 'ciCode_': theCiCode,\n 'printSymbol_': thePrintSymbol\n });\n }\n if (exp) {\n let expStr = exp.toString();\n const intergerUnitExpSign = isIntegerUnitWithExp && exp > 0 ? '+' : '';\n retUnit.assignVals({\n 'name_': theName + '<sup>' + expStr + '</sup>',\n 'csCode_': theCode + intergerUnitExpSign + expStr,\n 'ciCode_': theCiCode + intergerUnitExpSign + expStr,\n 'printSymbol_': thePrintSymbol + '<sup>' + expStr + '</sup>'\n });\n }\n }\n } // end if an original unit was found (without prefix and/or exponent)\n } // end if an invalid exponent wasn't found\n } // end if we didn't get a unit for the full unit code (w/out modifiers)\n } // end if we didn't find the unit on the first try, before parsing\n return [retUnit, origString];\n } // end _makeUnit\n\n\n /**\n * Checks whether an otherwise unresolved unit code matches a unit name.\n *\n * @param uCode the unit code or name to check\n * @param origString the original full string submitted to parseString\n * @returns an array containing the unit object found, or null, and origString\n */\n _getUnitByName(uCode, origString) {\n\n let retUnit = null;\n let retUnitAry = this.utabs_.getUnitByName(uCode);\n if (retUnitAry && retUnitAry.length > 0) {\n retUnit = retUnitAry[0].clone();\n let mString = 'The UCUM code for ' + uCode + ' is ' +\n retUnit.csCode_ + '.\\n' + this.vcMsgStart_ +\n retUnit.csCode_ + this.vcMsgEnd_;\n let dupMsg = false;\n for (let r = 0; r < this.retMsg_.length && !dupMsg; r++)\n dupMsg = this.retMsg_[r] === mString;\n if (!dupMsg)\n this.retMsg_.push(mString);\n const escapedCode = uCode.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n let rStr = new RegExp('(^|[./(])(' + escapedCode + ')($|[./)\\\\-\\\\d{])');\n const updatedOrigString = origString.replace(rStr, '$1' + retUnit.csCode_ + '$3');\n if (updatedOrigString == origString) {\n // This should not happen, if the processing has been correct. However, if it does happen, we\n // still have to change origString to signal that the input unit is invalid.\n // There is a test present to make sure this message does not appear from the top-level APIs in\n // ucumLhcUtils.js.\n // Ideally, this problem would be signalled some other way, but that would be a bigger change.\n origString += ' (Unable to update the unit expression with a suggested replacement.)';\n }\n else {\n origString = updatedOrigString;\n }\n }\n return [retUnit, origString];\n } // end _getUnitByName\n\n\n /**\n * Checks whether an otherwise unresolved unit code can be found after adding\n * square brackets, e.g., degF -> [degF]. If a bracketed unit is found,\n * origString is modified to include the suggested replacement.\n *\n * @param uCode the unit code to check\n * @param origString the original full string submitted to parseString\n * @returns an array containing the unit object found, or null, and the possibly\n * modified origString\n */\n _getUnitAfterAddingBrackets(uCode, origString) {\n\n let retUnit = null;\n const addBrackets = '[' + uCode + ']' ;\n const bracketUnit = this.utabs_.getUnitByCode(addBrackets);\n if (bracketUnit) {\n retUnit = bracketUnit.clone();\n const escapedCode = uCode.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n const leadingUnitBoundary = '(^|[./(])';\n const trailingUnitBoundary = '($|[./)\\\\-\\\\d{])';\n const rStr = new RegExp(leadingUnitBoundary + '(' + escapedCode + ')' +\n trailingUnitBoundary);\n const updatedOrigString = origString.replace(rStr, '$1' + addBrackets + '$3');\n if (updatedOrigString == origString) {\n // This should not happen, if the processing has been correct. However, if it does happen, we\n // still have to change origString to signal that the input unit is invalid.\n // There is a test present to make sure this message does not appear from the top-level APIs in\n // ucumLhcUtils.js.\n // Ideally, this problem would be signalled some other way, but that would be a bigger change.\n origString += ' (Unable to update the unit expression with a suggested replacement.)';\n }\n else {\n origString = updatedOrigString;\n }\n this.retMsg_.push(`${uCode} is not a valid unit expression, but ` +\n `${addBrackets} is.\\n` + this.vcMsgStart_ +\n `${addBrackets} (${retUnit.name_})${this.vcMsgEnd_}`);\n }\n return [retUnit, origString];\n } // end _getUnitAfterAddingBrackets\n\n\n /**\n * This method handles unit creation when an annotation is included\n * in the unit string. This basically isolates and retrieves the\n * annotation and then calls _makeUnit to try to get a unit from\n * any text that precedes or follows the annotation.\n *\n * @param uCode the string defining the unit\n * @param origString the original full string submitted to parseString\n * @returns the unit object found, or null if one could not be found\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n */\n _getUnitWithAnnotation(uCode, origString) {\n\n let retUnit = null;\n\n // Get the annotation and anything that precedes or follows it.\n let annoRet = this._getAnnoText(uCode, origString);\n let annoText = annoRet[0];\n let befAnnoText = annoRet[1];\n let aftAnnoText = annoRet[2];\n\n // Add the warning about annotations - just once.\n\n if (this.bracesMsg_ && this.retMsg_.indexOf(this.bracesMsg_) === -1)\n this.retMsg_.push(this.bracesMsg_);\n\n // If there's no text before or after the annotation, it's probably\n // something that should be interpreted as a 1, e.g., {KCT'U}.\n // HOWEVER, it could also be a case where someone used braces instead\n // of brackets, e.g., {degF} instead of [degF]. Check for that before\n // we assume it should be a 1.\n let msgLen = this.retMsg_.length;\n if (!befAnnoText && !aftAnnoText) {\n let tryBrackets = '[' + annoText.substring(1, annoText.length - 1) + ']';\n let mkUnitRet = this._makeUnit(tryBrackets, origString);\n\n // Nearly anything inside braces is valid, so we don't want to change the\n // unit, but we can put the found unit in the message as a sort of\n // warning.\n if (mkUnitRet[0]) {\n retUnit = uCode;\n this.retMsg_.push(`${annoText} is a valid unit expression, but ` +\n `did you mean ${tryBrackets} (${mkUnitRet[0].name_})?`);\n }\n else {\n // remove error message generated for trybrackets\n if (this.retMsg_.length > msgLen) {\n this.retMsg_.pop();\n }\n }\n\n // This is the case where the string is only this annotation.\n // Create and return a unit object, as we do for numeric units in\n // parseString.\n retUnit = new Unit({\n 'csCode_': annoText,\n 'ciCode_': annoText,\n 'magnitude_': 1,\n 'name_': annoText\n });\n\n } // end if it's only an annotation\n\n else {\n // if there's text before and no text after, assume the text before\n // the annotation is the unit code (with an annotation following it).\n // Call _makeUnit for the text before the annotation.\n if (befAnnoText && !aftAnnoText) {\n // make sure that what's before the annoText is not a number, e.g.,\n // /100{cells}. But f it is a number, just set the return unit to\n // the number.\n if (intUtils_.isIntegerUnit(befAnnoText)) {\n retUnit = new Unit({'csCode_' : befAnnoText + annoText,\n 'ciCode_' : befAnnoText + annoText.toUpperCase(),\n 'magnitude_' : Number(befAnnoText),\n 'name_': befAnnoText + annoText});\n }\n // Otherwise try to find a unit\n else {\n let mkUnitRet = this._makeUnit(befAnnoText, origString);\n\n // if a unit was returned\n if (mkUnitRet[0]) {\n retUnit = mkUnitRet[0];\n retUnit.csCode_ += annoText;\n origString = mkUnitRet[1];\n }\n // Otherwise add a not found message\n else {\n this.retMsg_.push(`Unable to find a unit for ${befAnnoText} that ` +\n `precedes the annotation ${annoText}.`);\n }\n }\n }\n // else if there's only text after the annotation, try for a unit\n // from the after text and assume the user put the annotation in\n // the wrong place (and tell them)\n else if (!befAnnoText && aftAnnoText) {\n\n // Again, test for a number and if it is a number, set the return\n // unit to the number.\n if (intUtils_.isIntegerUnit(aftAnnoText)) {\n retUnit = aftAnnoText + annoText ;\n this.retMsg_.push(`The annotation ${annoText} before the `\n `${aftAnnoText} is invalid.\\n` + this.vcMsgStart_ + retUnit +\n this.vcMsgEnd_);\n }\n else {\n let mkUnitRet = this._makeUnit(aftAnnoText, origString);\n if (mkUnitRet[0]) {\n retUnit = mkUnitRet[0];\n retUnit.csCode_ += annoText;\n origString = retUnit.csCode_;\n this.retMsg_.push(`The annotation ${annoText} before the unit ` +\n `code is invalid.\\n` + this.vcMsgStart_ + retUnit.csCode_ +\n this.vcMsgEnd_);\n }\n // Otherwise add a not found message\n else {\n this.retMsg_.push(`Unable to find a unit for ${befAnnoText} that ` +\n `follows the annotation ${annoText}.`);\n }\n }\n }\n // else it's got text before AND after the annotation. Now what?\n // For now this is an error. This may be a case of a missing\n // operator but that is not handled yet.\n else {\n this.retMsg_.push(`Unable to find a unit for ${befAnnoText}${annoText}` +\n `${aftAnnoText}.\\nWe are not sure how to interpret text both before ` +\n `and after the annotation. Sorry`);\n }\n } // else if there's text before/and or after the annotation\n\n return [retUnit , origString];\n\n } // end _getUnitWithAnnotations\n\n\n /**\n * Performs unit arithmetic for the units in the units array. That array\n * contains units/numbers and the operators (division or multiplication) to\n * be performed on each unit/unit or unit/number pair in the array. This\n * should only be called from within this class (or by test code).\n *\n * @params uArray the array that contains the units, numbers and operators\n * derived from the unit string passed in to parseString\n * @param origString the original string to be parsed; used to provide\n * context for messages\n *\n * @returns a single unit object that is the result of the unit arithmetic\n *\n * the this.retMsg_ array will be updated with any user messages\n * (informational, error or warning) generated by this or called methods\n */\n _performUnitArithmetic(uArray, origString) {\n\n let finalUnit = uArray[0]['un'];\n if (intUtils_.isIntegerUnit(finalUnit)) {\n finalUnit = new Unit({'csCode_' : finalUnit, 'ciCode_' : finalUnit,\n 'magnitude_' : Number(finalUnit),\n 'name_' : finalUnit}) ;\n }\n let uLen = uArray.length ;\n let endProcessing = false ;\n // Perform the arithmetic for the units, starting with the first 2 units.\n // We only need to do the arithmetic if we have more than one unit.\n for (let u2 = 1; (u2 < uLen) && !endProcessing; u2++) {\n let nextUnit = uArray[u2]['un'];\n if (intUtils_.isIntegerUnit(nextUnit)) {\n nextUnit = new Unit({'csCode_' : nextUnit, 'ciCode_' : nextUnit,\n 'magnitude_' : Number(nextUnit),\n 'name_': nextUnit});\n }\n if (nextUnit === null ||\n ((typeof nextUnit !== 'number') && (!nextUnit.getProperty))) {\n let msgString = `Unit string (${origString}) contains unrecognized ` +\n 'element' ;\n if (nextUnit) {\n msgString += ` (${this.openEmph_}${nextUnit.toString()}` +\n `${this.closeEmph_})`;\n }\n msgString += '; could not parse full string. Sorry';\n this.retMsg_.push(msgString);\n endProcessing = true;\n }\n else {\n try {\n // Is the operation division?\n let thisOp = uArray[u2]['op'];\n let isDiv = thisOp === '/';\n\n // Perform the operation. Both the finalUnit and nextUnit\n // are unit objects.\n isDiv ? finalUnit = finalUnit.divide(nextUnit) :\n finalUnit = finalUnit.multiplyThese(nextUnit);\n }\n catch (err) {\n this.retMsg_.unshift(err.message) ;\n endProcessing = true ;\n finalUnit = null ;\n }\n } // end if we have another valid unit/number to process\n } // end do for each unit after the first one\n return finalUnit ;\n } // end _performUnitArithmetic\n\n\n /**\n * This tests a string to see if it starts with characters and ends with\n * digits. This is used to test for an exponent on a UCUM code (or what\n * we think might be a UCUM code). This is broken out to a separate\n * function so that the regular expression can be verified to provide the\n * results we expect, in case someone changes it. (Per Paul Lynch)\n * See \"Test _isCodeWithExponent method\" in testUnitString.spec.js\n *\n * This particular regex has been tweaked several times. This one\n * works with the following test strings:\n * \"m[H2O]-21 gives [\"m[H2O]-21\", \"m[H2O]\", \"-21\"]\n * \"m[H2O]+21 gives [\"m[H2O]+21\", \"m[H2O]\", \"+21\"]\n * \"m[H2O]21 gives [\"m[H2O]-21\", \"m[H2O]\", \"21\"]\n * \"s2\" gives [\"s2\", \"s, \"2\"]\n * \"kg\" gives null\n * \"m[H2O]\" gives null\n * \"m[H2O]23X\" gives null\n *\n * @params uCode the code being tested\n * @returns an array containing: (1) the code without the exponent (or\n * trailing number); and (2) the exponent/trailing number. Returns null\n * if there is no trailing number or something follows the trailing\n * number, or if the first part is not characters.\n */\n _isCodeWithExponent(uCode) {\n\n let ret = [] ;\n let res = uCode.match(/(^[^\\-\\+]+?)([\\-\\+\\d]+)$/);\n\n // If we got a return with an exponent, separate the exponent from the\n // unit and return both (as separate values)\n if (res && res[2] && res[2] !== \"\") {\n ret.push(res[1]);\n ret.push(res[2]);\n } // end if we got an exponent\n else {\n ret = null ;\n }\n return ret ;\n } // end _isCodeWithExponent\n\n} // end class UnitString\n\n\n/**\n * This function exists ONLY until the original UnitString 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 UnitString object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * @return the singleton UnitString object.\n */\nUnitString.getInstance = function(){\n return new UnitString();\n} ;\n\n/*\n// Perform the first request for the object, to set the getInstance method.\nUnitString.getInstance();\n\n*/\n","/**\n * This class manages Hashtables that provide references to\n * defined units.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar Ucum = require('./config.js').Ucum;\n\nclass UnitTablesFactory {\n\n /**\n * Constructor. This creates the empty unit tables (hashes) once. After the\n * tables are created, it redefines this constructor to throw an error\n * stating that the constructor is no longer available and that the\n * getInstance function must be used. Here's a description of the first\n * and then all subsequent calls to this constructor.\n *\n * First call to constructor:\n * 1. creates OBJECT1\n * 2. initializes attributes of OBJECT1\n * 3. stores reference to OBJECT1.prototype in holdthis local variable\n * 4. redefines OBJECT1 as a function that throws an error\n * 5. defines the getInstance function (which is also defined outside of\n * the class definition - see below).\n *\n * All subsequent calls to constructor:\n * 1. throw error message referring to getInstance\n * 2. call getInstance, returns this - which is OBJECT1.\n */\n constructor() {\n\n /**\n * Tracks units by name\n * @type hash - key is the name;\n * value is an array of references to the Unit objects\n * with the name. More than one unit may have the same\n * name, e.g., \"second\", which is shared by the base unit\n * with the code = \"s\" and the unit with code = \"'\".\n */\n this.unitNames_ = {};\n\n /**\n * Tracks units by code using case-sensitive version.\n *\n * @type hash - key is the code;\n * value is the reference to the Unit object. Codes must\n * be unique.\n */\n this.unitCodes_ = {};\n\n /**\n * Keeps track of the order in which units are defined. The order is\n * important because unit definitions build on previous definitions.\n *\n * @type {Array}\n */\n this.codeOrder_ = [] ;\n\n /**\n * Tracks units by unit strings, e.g., cm-1\n *\n * @type hash - key is the unit string\n * value is an array of unit objects with that ciUnitString.\n */\n this.unitStrings_ = {};\n\n /**\n * Tracks units by Dimension vector\n *\n * @type hash - key is the dimension vector (not the object, just the\n * vector);\n * value is an array of references to the Unit objects\n * with that vector. More than one unit may have the same\n * unit vector, and this can be used to provide a list\n * of commensurable units.\n */\n this.unitDimensions_ = {};\n\n /**\n * Maps synonyms to units. Not built until first requested.\n *\n * @type hash - key is the synonym\n * value is an array of references to Unit objects that\n * include that synonym.\n */\n this.unitSynonyms_ = {};\n\n /*\n * Holds onto the index of the index of the dimension vector flag for\n * the base mass unit (gram). This is set when the base unit (gram) is\n * created, and is stored here so that it doesn't have to be found\n * over and over again to try to determine whether or not a unit is\n * mass-based (for mole<->mass conversions)\n *\n * @type integer\n */\n this.massDimIndex_ = 0;\n\n /**\n * Map of indices in the dimension vector to base unit symbols.\n */\n this.dimVecIndexToBaseUnit_ = {};\n }\n\n\n /**\n * Provides the number of unit objects written to the tables, using the\n * codes table since codes must be unique.\n *\n * @returns count of the number of unit objects in the unitCodes_ table.\n */\n unitsCount() {\n return Object.keys(this.unitCodes_).length ;\n }\n\n\n /**\n * Adds a Unit object to the tables.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws passes on an error if one is thrown by the called functions for\n * a problem with the unit code or unit name\n */\n addUnit(theUnit) {\n\n let uName = theUnit['name_'] ;\n if (uName) {\n this.addUnitName(theUnit);\n }\n\n this.addUnitCode(theUnit);\n this.addUnitString(theUnit);\n\n try {\n if (theUnit['dim_'].getProperty('dimVec_'))\n this.addUnitDimension(theUnit);\n }\n catch(err){\n // do nothing - throws error if the property is null\n // and that's OK here.\n }\n\n if (theUnit.isBase_) {\n const dimVec = theUnit.dim_.dimVec_;\n let nonZeroIndex;\n for (let i=0, len=dimVec.length; nonZeroIndex==undefined && i<len; ++i) {\n if (dimVec[i] != 0)\n nonZeroIndex = i;\n }\n this.dimVecIndexToBaseUnit_[nonZeroIndex] = theUnit.csCode_;\n }\n } // end addUnit\n\n\n /**\n * Adds a Unit object to the unitNames_ table. More than one unit\n * can have the same name, e.g., the two units with the name \"second\",\n * where the code for one of them is 's' and the code for the other is\n * \"'\". Because of this, an array of unit objects is stored for the\n * name. In most cases it will be an array of one object, but this\n * clarifies that there may be more than one.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unit has no name\n */\n addUnitName(theUnit) {\n\n let uName = theUnit['name_'];\n\n if (uName) {\n if (this.unitNames_[uName])\n this.unitNames_[uName].push(theUnit);\n else\n this.unitNames_[uName] = [theUnit];\n }\n else\n throw(new Error('UnitTables.addUnitName called for a unit with no name. ' +\n `Unit code = ${theUnit['csCode_']}.`));\n\n } // end addUnitName\n\n\n /**\n * Adds a Unit object to the unitCodes_, unitUcCodes_, unitLcCodes_ and\n * codeOrder_ tables. This also sets the mass dimension index when the\n * base mass unit (gram) is read.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unitCodes_ table already contains a unit with\n * the code\n */\n addUnitCode(theUnit) {\n\n let uCode = theUnit['csCode_'];\n if (uCode) {\n\n if (this.unitCodes_[uCode])\n throw(new Error(`UnitTables.addUnitCode called, already contains entry for ` +\n `unit with code = ${uCode}`));\n else {\n this.unitCodes_[uCode] = theUnit;\n this.codeOrder_.push(uCode);\n if (uCode == 'g') {\n let dimVec = theUnit.dim_.dimVec_;\n let d = 0;\n for (; d < dimVec.length && dimVec[d] < 1; d++) ;\n this.massDimIndex_ = d;\n }\n }\n }\n else\n throw(new Error('UnitTables.addUnitCode called for unit that has ' +\n 'no code.')) ;\n\n } // end addUnitCode\n\n\n /**\n * Adds a unit object to the unitStrings_ table. More than one unit\n * can have the same string, so an array of unit objects is stored\n * for the string. The unit string is the string that creates a non-base\n * unit, e.g., a Newton has a unit code of N, a name of Newton, and a\n * unitString of kg.m/s2.\n *\n * If the unit has no string, nothing is stored and no error is reported.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n */\n addUnitString(theUnit) {\n\n let uString = null;\n if (Ucum.caseSensitive_ == true)\n uString = theUnit['csUnitString_'];\n else\n uString = theUnit['ciUnitString_'];\n\n if (uString) {\n let uEntry = {mag: theUnit['baseFactorStr_'], unit: theUnit};\n if (this.unitStrings_[uString])\n this.unitStrings_[uString].push(uEntry);\n else\n this.unitStrings_[uString] = [uEntry];\n }\n } // end addUnitString\n\n\n /**\n * Adds a Unit object to the unitDimensions_ table. More than one unit\n * can have the same dimension (commensurable units have the same dimension).\n * Because of this, an array of unit objects is stored for the\n * dimension.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unit has no dimension\n */\n addUnitDimension(theUnit) {\n\n let uDim = theUnit['dim_'].getProperty('dimVec_');\n\n if (uDim) {\n if (this.unitDimensions_[uDim])\n this.unitDimensions_[uDim].push(theUnit);\n else\n this.unitDimensions_[uDim] = [theUnit];\n }\n else\n throw(new Error('UnitTables.addUnitDimension called for a unit with no dimension. ' +\n `Unit code = ${theUnit['csCode_']}.`));\n\n } // end addUnitDimension\n\n\n /**\n * Builds the unitSynonyms_ table. This is called the first time the\n * getUnitsBySynonym method is called. The table/hash contains each word\n * (once) from each synonym as well as each word from each unit name.\n *\n * Hash keys are the words. Hash values are an array of unit codes for\n * each unit that has that word in its synonyms or name.\n *\n * @returns nothing\n */\n buildUnitSynonyms() {\n\n for (let code in this.unitCodes_) {\n let theUnit = this.unitCodes_[code];\n let uSyns = theUnit.synonyms_ ;\n\n // If the current unit has synonyms, process each synonym (often multiples)\n if (uSyns) {\n let synsAry = uSyns.split(';');\n if (synsAry[0] !== '') {\n let aLen = synsAry.length;\n for (let a = 0; a < aLen; a++) {\n let theSyn = synsAry[a].trim();\n\n // call addSynonymCodes to process each word in the\n // synonym, e.g., \"British fluid ounces\"\n this.addSynonymCodes(code, theSyn) ;\n } // end do for each synonym\n } // end if the current unit has a non-null synonym attribute\n } // end if the unit has any synonyms\n\n // Now call addSynonymCodes to process each word in the unit's name\n this.addSynonymCodes(code, theUnit.name_) ;\n } // end do for each unit\n } // end buildUnitSynonyms\n\n\n /**\n * Adds unit code entries to the synonyms table for a string containing\n * one or more words to be considered as synonyms.\n *\n * @param theCode the unit code to be connected to the synonyms\n * @param theSynonyms a string containing one or more words to be\n * considered synonyms (and thus to be added to the unitSynonyms hash).\n */\n addSynonymCodes(theCode, theSynonyms) {\n\n let words = theSynonyms.split(' ');\n let wLen = words.length;\n\n for (let w = 0; w < wLen; w++) {\n let word = words[w];\n\n // if there is already a synonyms entry for the word,\n // get the array of unit codes currently assigned to\n // the word and add the code for the current word to\n // the synonyms array if it's not already there.\n if (this.unitSynonyms_[word]) {\n let synCodes = this.unitSynonyms_[word];\n if (synCodes.indexOf(theCode) === -1) {\n this.unitSynonyms_[word].push(theCode);\n }\n }\n // else there are no synonyms entry for the word. Create a\n // synonyms array for the word, setting it to contain the unit code.\n else {\n this.unitSynonyms_[word] = [theCode];\n }\n } // end do for each word in the synonyms being processed\n\n } // end addSynonymCodes\n\n\n /**\n * Returns a unit object with a case-sensitive code matching the\n * uCode parameter, or null if no unit is found with that code.\n *\n * @param uCode the code of the unit to be returned\n * @returns the unit object or null if it is not found\n */\n getUnitByCode(uCode) {\n let retUnit = null ;\n if (uCode) {\n retUnit = this.unitCodes_[uCode];\n }\n return retUnit ;\n }\n\n\n /**\n * Returns a array of unit objects based on the unit's name. Usually this\n * will be an array of one, but there may be more, since unit names are\n * not necessarily unique.\n *\n * @param uName the name of the unit to be returned. If more than one\n * unit has the same name and you only want one specific unit, append the\n * csCode of the unit you want to the end of the name, separated by the\n * Ucum.codeSep_ value, e.g., inch - [in_i] vs. inch - [in_us].\n * @returns null if no unit was found for the specified name OR an array of\n * unit objects with the specified name. Normally this will be an array\n * of one object.\n * @throws an error if no name is provided to search on\n */\n getUnitByName(uName) {\n\n if (uName === null || uName === undefined) {\n throw (new Error('Unable to find unit by name because no name was provided.'));\n }\n let sepPos = uName.indexOf(Ucum.codeSep_);\n let uCode = null;\n if (sepPos >= 1) {\n uCode = uName.substr(sepPos + Ucum.codeSep_.length);\n uName = uName.substr(0, sepPos);\n }\n let retUnits = this.unitNames_[uName] ;\n if (retUnits) {\n let uLen = retUnits.length ;\n\n if (uCode && uLen > 1) {\n let i = 0;\n for (; retUnits[i].csCode_ !== uCode && i < uLen; i++);\n if (i < uLen)\n retUnits = [retUnits[i]];\n else {\n retUnits = null;\n }\n } // end if we need to find both a name and a code\n } // end if we got an array of units\n return retUnits ;\n\n } // end getUnitByName\n\n\n /**\n * Returns an array of unit objects with the specified unit string.\n * The array may contain one or more unit reference objects.\n * Or none, if no units have a matching unit string (which is not\n * considered an error)\n *\n * @param name the name of the unit to be returned\n * @returns the array of unit references or null if none were found\n */\n getUnitByString(uString) {\n let retAry = null ;\n if (uString) {\n retAry = this.unitStrings_[uString] ;\n if (retAry === undefined)\n retAry = null;\n }\n return retAry ;\n }\n\n\n /**\n * Returns a array of unit objects based on the unit's dimension vector.\n *\n * @param uName the dimension vector of the units to be returned.\n *\n * @returns null if no unit was found for the specified vector OR an array of\n * one or more unit objects with the specified vector.\n * @throws an error if no vector is provided to search on\n * logs an error to the console if no unit is found\n */\n getUnitsByDimension(uDim) {\n\n let unitsArray = null ;\n if (uDim === null || uDim === undefined) {\n throw (new Error('Unable to find unit by because no dimension ' +\n 'vector was provided.'));\n }\n\n unitsArray = this.unitDimensions_[uDim] ;\n if (unitsArray === undefined || unitsArray === null) {\n console.log(`Unable to find unit with dimension = ${uDim}`);\n }\n\n return unitsArray ;\n\n } // end getUnitsByDimension\n\n\n /**\n * Returns a array of unit objects that include the specified synonym.\n *\n * @param uSyn the synonym of the units to be returned.\n *\n * @returns an object with two of the following three elements:\n * 'status' will be error, failed or succeeded\n * 'msg' will be included for returns with status = error or failed and\n * will explain why the request did not return any units\n * 'units' any array of unit objects with the specified synonym will be\n * returned for requests with status = succeeded\n */\n getUnitBySynonym(uSyn) {\n\n let retObj = {} ;\n let unitsArray = [];\n\n try {\n if (uSyn === null || uSyn === undefined) {\n retObj['status'] = 'error' ;\n throw (new Error('Unable to find unit by synonym because no synonym ' +\n 'was provided.'));\n }\n // If this is the first request for a unit by synonym, build the hash map\n if (Object.keys(this.unitSynonyms_).length === 0) {\n this.buildUnitSynonyms();\n }\n let foundCodes = [];\n foundCodes = this.unitSynonyms_[uSyn];\n if (foundCodes) {\n retObj['status'] = 'succeeded';\n let fLen = foundCodes.length;\n for (let f = 0; f < fLen; f++) {\n unitsArray.push(this.unitCodes_[foundCodes[f]]);\n }\n retObj['units'] = unitsArray ;\n }\n if (unitsArray.length === 0) {\n retObj['status'] = 'failed' ;\n retObj['msg'] = `Unable to find any units with synonym = ${uSyn}`;\n }\n }\n catch(err) {\n retObj['msg'] = err.message ;\n }\n return retObj ;\n } // end getUnitBySynonym\n\n\n /**\n * Gets a list of all unit names in the Unit tables\n *\n * @returns an array of the unit names\n */\n getAllUnitNames() {\n return Object.keys(this.unitNames_);\n } // end getAllUnitNames\n\n\n /**\n * Gets a list of all unit names in the tables. Where more than one\n * unit has the same name, the unit code, in parentheses, is appended\n * to the end of the name.\n *\n * @returns {Array}\n */\n getUnitNamesList() {\n let nameList = [];\n let codes = Object.keys(this.unitCodes_);\n codes.sort(this.compareCodes) ;\n let uLen = codes.length;\n for (let i = 0; i < uLen; i++) {\n nameList[i] = codes[i] + Ucum.codeSep_ + this.unitCodes_[codes[i]].name_\n } // end do for each code\n return nameList ;\n }\n\n\n /*\n * Returns the mass dimension index\n * @returns this.massDimIndex_\n */\n getMassDimensionIndex() {\n return this.massDimIndex_ ;\n }\n\n /**\n * This provides a sort function for unit codes so that sorting ignores\n * square brackets and case.\n *\n * @param a first value\n * @param b second value\n * @returns -1 if a is should fall before b; otherwise 1.\n */\n compareCodes(a, b) {\n a = a.replace(/[\\[\\]]/g, '');\n a = a.toLowerCase();\n b = b.replace(/[\\[\\]]/g, '');\n b = b.toLowerCase();\n return (a < b) ? -1 : 1 ;\n }\n\n\n /**\n * Gets a list of all unit codes in the Unit tables\n *\n * @returns an array of the unit names\n */\n getAllUnitCodes() {\n return Object.keys(this.unitCodes_);\n } // end getAllUnitNames\n\n\n /**\n * This is used to get all unit objects. Currently it is used\n * to get the objects to write to the json ucum definitions file\n * that is used to provide prefix and unit definition objects for\n * conversions and validations.\n *\n * @returns an array containing all unit objects, ordered by definition\n * order\n */\n allUnitsByDef() {\n\n let unitsList = [];\n let uLen = this.codeOrder_.length ;\n for (let u = 0; u < uLen; u++) {\n unitsList.push(this.getUnitByCode(this.codeOrder_[u]));\n }\n return unitsList ;\n } // end allUnitsByDef\n\n\n /**\n * This is used to get all unit objects, ordered by unit name. Currently it\n * is used to create a csv list of all units.\n * @param sep separator character (or string) to be used to separate each\n * column in the output. Optional, defaults to '|' if not specified.\n * (Used to use ; but the synonyms use that extensively). Don't use a\n * comma or any other punctuation found in the output data.\n * @returns a buffer containing all unit objects, ordered by name\n * order\n */\n allUnitsByName(cols, sep) {\n if (sep === undefined || sep === null)\n sep = '|';\n let unitBuff = '';\n let unitsList = this.getAllUnitNames();\n let uLen = unitsList.length;\n let cLen = cols.length;\n for (let i = 0; i < uLen; i++) {\n let nameRecs = this.getUnitByName(unitsList[i]);\n for (let u = 0; u < nameRecs.length; u++) {\n let rec = nameRecs[u];\n for (let c = 0; c < cLen; c++) {\n if (c > 0)\n unitBuff += sep;\n if (cols[c] === 'dim_') {\n if (rec.dim_ !== null && rec.dim_ !== undefined &&\n rec.dim_.dimVec_ instanceof Array)\n unitBuff += '[' + rec.dim_.dimVec_.join(',') + ']';\n else\n unitBuff += '';\n }\n else {\n let cbuf = rec[cols[c]];\n if (typeof cbuf === 'string')\n unitBuff += cbuf.replace(/[\\n\\r]/g, ' ');\n else\n unitBuff += cbuf ;\n }\n } // end do for each column requested\n unitBuff += '\\r\\n';\n } // end do for each unit in the unit names array\n }\n return unitBuff ;\n } // end allUnitsByName\n\n\n /**\n * This creates a list of all units in the tables. It uses the byCode\n * table, and uses the codeOrder_ array to determine the order in which\n * the units are listed.\n *\n * @param doLong boolean indicating how much to output. If true, all data\n * from the unit objects is included. If false, only a few major values\n * are included.\n * @param sep separator character (or string) to be used to separate each\n * column in the output. Optional, defaults to '|' if not specified.\n * (Used to use ; but the synonyms use that extensively).\n * @returns {string} buffer containing all the listings\n */\n printUnits(doLong, sep) {\n if (doLong === undefined)\n doLong = false ;\n if (sep === undefined)\n sep = '|';\n let codeList = '';\n let uLen = this.codeOrder_.length ;\n let unitString = 'csCode' + sep ;\n if (doLong) {\n unitString += 'ciCode' + sep ;\n }\n unitString += 'name' + sep ;\n if (doLong)\n unitString += 'isBase' + sep ;\n unitString += 'magnitude' + sep + 'dimension' + sep + 'from unit(s)' + sep +\n 'value' + sep + 'function' + sep ;\n if (doLong)\n unitString += 'property' + sep + 'printSymbol' + sep + 'synonyms' + sep +\n 'source' + sep + 'class' + sep + 'isMetric' + sep +\n 'variable' + sep + 'isSpecial' + sep + 'isAbitrary' + sep ;\n unitString += 'comment';\n codeList = unitString + '\\n' ;\n\n for (let u = 0; u < uLen; u++) {\n let curUnit = this.getUnitByCode(this.codeOrder_[u]);\n unitString = this.codeOrder_[u] + sep ;\n if (doLong) {\n unitString += curUnit.getProperty('ciCode_') + sep ;\n }\n unitString += curUnit.getProperty('name_') + sep ;\n if (doLong) {\n if (curUnit.getProperty('isBase_'))\n unitString += 'true' + sep ;\n else\n unitString += 'false' + sep ;\n }\n unitString += curUnit.getProperty('magnitude_') + sep;\n let curDim = curUnit.getProperty('dim_');\n if (curDim) {\n unitString += curDim.dimVec_ + sep ;\n }\n else {\n unitString += 'null' + sep;\n }\n if (curUnit.csUnitString_)\n unitString += curUnit.csUnitString_ + sep + curUnit.baseFactor_ + sep ;\n else\n unitString += 'null' + sep + 'null' + sep;\n\n if (curUnit.cnv_)\n unitString += curUnit.cnv_ + sep ;\n else\n unitString += 'null' + sep ;\n\n if (doLong) {\n unitString += curUnit.getProperty('property_') + sep +\n curUnit.getProperty('printSymbol_') + sep +\n curUnit.getProperty('synonyms_') + sep +\n curUnit.getProperty('source_') + sep +\n curUnit.getProperty('class_') + sep +\n curUnit.getProperty('isMetric_') + sep +\n curUnit.getProperty('variable_') + sep +\n curUnit.getProperty('isSpecial_') + sep +\n curUnit.getProperty('isArbitrary_') + sep ;\n }\n if (curUnit.defError_)\n unitString += 'problem parsing this one, deferred to later.' ;\n codeList += unitString + '\\n' ;\n }\n return codeList ;\n }\n\n} // end UnitTablesFactory\n\n\n// Create a singleton instance and (to preserve the existing API) an object that\n// provides that instance via getInstance().\nvar unitTablesInstance = new UnitTablesFactory();\nexport const UnitTables = {\n getInstance: function() {\n return unitTablesInstance;\n }\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","/**\n * This exports definitions for ucum classes that need references to them\n * available to the demo code. The actual code will be in the ucumPkg\n * library found in the dist directory. This file provides the hooks to\n * those classes within the library.\n */\n\nexport var Ucum = require(\"./config.js\").Ucum;\nexport var UcumLhcUtils = require(\"./ucumLhcUtils.js\").UcumLhcUtils;\nexport var UnitTables = require(\"./unitTables.js\").UnitTables;"],"names":["root","factory","exports","module","define","amd","this","Number","isFinite","value","Infinity","require","isInteger","val","Math","floor","dimLen_","validOps_","codeSep_","valMsgStart_","valMsgEnd_","cnvMsgStart_","cnvMsgEnd_","openEmph_","closeEmph_","openEmphHTML_","closeEmphHTML_","bracesMsg_","needMoleWeightMsg_","needEqWeightMsg_","needEqChargeMsg_","csvCols_","inputKey_","specUnits_","UC","Dimension","dimSetting","_classCallCheck","Ucum","Error","assignZero","Array","length","concat","JSON","stringify","dimVec_","d","push","key","indexPos","ret","propertyName","charAt","join","dim2","_typeof","i","s","isEqual","dimVec2","undefined","allZero","that","assignDim","obj","config","data","_config","prepareConfig","map","unpackItem","bind","prototype","isArray","item","result","forEach","keyArr","place","Prefix","attrs","code_","ciCode_","name_","printSymbol_","value_","parseFloat","exp_","prefix2","prefixTablesInstance","PrefixTablesFactory","byCode_","byValue_","Object","keys","prefixBuff","pList","pLen","p","pfx","getPrefixByValue","prefixList","sort","getPrefixByCode","prefixObj","getCode","getValue","code","getInstance","UcumFunctions","funcs","cnvTo","x","cnvFrom","log","LN10","pow","exp","LN2","tan","atan","sqrt","func","fname","toLowerCase","f","theSyn","resp","retObj","UnitTables","getUnitBySynonym","aLen","a","theUnit","csCode_","guidance_","str","test","theString","num","isNaN","Pfx","PfxT","Un","Utab","unpackArray","UcumJsonDefs","jsonDefs","prefixes","units","unitsCount","pTab","PrefixTables","plen","newPref","add","uTab","ulen","u","newUnit","Unit","addUnit","_ucumJsonDefs","intUtils_","e","WeakMap","r","__esModule","o","__proto__","default","has","get","set","_t","hasOwnProperty","call","defineProperty","getOwnPropertyDescriptor","_interopRequireWildcard","Symbol","iterator","constructor","_defineProperties","t","enumerable","configurable","writable","_toPropertyKey","toPrimitive","TypeError","String","_toPrimitive","UnitString","UcumLhcUtils","n","ucumJsonDefs","loadJsonDefs","uStrParser_","massDimIndex_","getMassDimensionIndex","use","useHTMLInMessages","useBraceMsgForEachString","uStr","suggest","valConv","getSpecifiedUnit","status","fromUnit","toUnit","moleExp_","equivalentExp_","dim_","getElementAt","fromUnitCode","fromVal","toUnitCode","options","arguments","_options$suggest","_options$molecularWei","molecularWeight","_options$charge","charge","returnObj","trim","_checkFromVal","parseResp","convertType","detectConversionType","msgCountBeforeConvert","convertFrom","err","message","isMolMassCommensurable","convertMolMass","isEqMassCommensurable","convertEqMass","isEqMolCommensurable","convertEqMol","isEqMolMassCommensurable","convertEqMolMass","inputUnitLookup","_inputUnitLookup$retM","unit","msg","retMsg","isArbitrary_","_unit$dim_","unitToExp","dimVec","baseUnitString","dimVecIndexToBaseUnit","dimVecIndexToBaseUnit_","len","retUnitLookup","retUnit","magnitude","toString","fromUnitIsSpecial","isSpecial_","responseObj","isNumericString","getSynonyms","uName","utab","getUnitByCode","parseString","console","unshift","origString","fromName","categoryList","commUnits","fromDim","getProperty","getUnitsByDimension","filter","indexOf","category_","_ucumFunctions","isBase_","property_","magnitude_","class_","isMetric_","variable_","cnv_","cnvPfx_","synonyms_","source_","loincProperty_","csUnitString_","ciUnitString_","baseFactorStr_","baseFactor_","defError_","_createClass","vals","uKey","_this","getOwnPropertyNames","clone","unit2","_this2","equals","thisAttr","u2Attr","keyLen","match","k","isNull","fromCnv","fromMag","forName","f_from","convertCoherent","max","getMax","elem","uA","_getUnitTables","name","amt","molPowersToConvert","avoNum","moleUnitFactor","massPowersToConvert","equivalentMass","avogadroNumber","eqPowersToConvert","molAmt","tabs","mutateCoherent","mulVal","_concatStrs","isZero","resetFieldsForDerivedUnit","invertString","sub","minus","stringRep","replace","substr","str1","operator","str2","startChar","endChar","_buildOneString","endsWith","uArray","arLen","un","nun","parseInt","uLen","uChar","mul","unit1Dim","setElementAt","unit2Dim","_templateObject","slice","freeze","defineProperties","raw","_defineProperty","utabs_","pfxTabs_","parensFlag_","pFlagLen_","braceFlag_","bFlagLen_","vcMsgStart_","vcMsgEnd_","retMsg_","parensUnits_","annotations_","suggestions","suggestions_","_getAnnotations","sUnit","finalUnit","_parseTheString","isIntegerUnit","endProcessing","parensResp","_processParens","mkUArray","_makeUnitsArray","u1","curCode","parenUnit","_getParensUnit","uRet","_makeUnit","_performUnitArithmetic","uString","openBrace","closeBrace","braceStr","substring","VALID_ANNOTATION_REGEX","aIdx","INVALID_ANNOTATION_CHAR_MSG","uStrArray","uStrAryPos","stopProcessing","pu","trimmedCt","openCt","closeCt","openPos","closePos","theMsg","c","uArray1","startNumCheck","numRes","dispVal","parensback","op","theOp","numRes2","invalidString","parensStr","parensString","nextParens","pStr","psIdx","befText","peIdx","lastIndexOf","aftText","pNumText","nMag","assignVals","annoRet","_getAnnoText","asIdx","startText","aeIdx","endText","idx","idxNum","suggSet","synLen","unitArray","uCode","getAnnoRet","_getUnitWithAnnotation","tryCode","origCode","origUnit","pfxCode","pfxObj","pfxVal","codeAndExp","_isCodeWithExponent","isIntegerUnitWithExp","theDim","theMag","theName","theCiCode","thePrintSymbol","pfxExp","getExp","theCode","getName","getCiCode","getPrintSymbol","expStr","intergerUnitExpSign","bracketRet","_getUnitAfterAddingBrackets","nameRet","_getUnitByName","_getSuggestions","retUnitAry","getUnitByName","mString","dupMsg","escapedCode","rStr","RegExp","updatedOrigString","addBrackets","bracketUnit","leadingUnitBoundary","annoText","befAnnoText","aftAnnoText","msgLen","toUpperCase","mkUnitRet","tryBrackets","pop","u2","nextUnit","msgString","divide","multiplyThese","res","unitTablesInstance","UnitTablesFactory","unitNames_","unitCodes_","codeOrder_","unitStrings_","unitDimensions_","unitSynonyms_","addUnitName","addUnitCode","addUnitString","addUnitDimension","nonZeroIndex","caseSensitive_","uEntry","mag","uDim","uSyns","synsAry","split","addSynonymCodes","theSynonyms","words","wLen","w","word","sepPos","retUnits","retAry","unitsArray","uSyn","foundCodes","buildUnitSynonyms","fLen","nameList","codes","compareCodes","b","unitsList","cols","sep","unitBuff","getAllUnitNames","cLen","nameRecs","rec","cbuf","doLong","codeList","unitString","curUnit","curDim","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__"],"sourceRoot":""}