@lhncbc/ucum-lhc 4.1.2 → 4.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../source/ucumXmlDocument.js"],"names":["Prefix","require","PrefixTables","Unit","UnitString","UnitTables","packArray","jsonfile","xmldoc","fs","essenceFile_","xmlInput_","UcumXmlDocument","constructor","data","readFileSync","XmlDocument","moleCodes_","holdThis","prototype","Error","exports","self","getInstance","parseXml","parsePrefixes","childrenNamed","parseBaseUnits","parseUnitStrings","writeJsonFile","writeVersionText","prefixes","plen","length","p","curPfx","attrs","attr","Code","CODE","childNamed","val","pValNode","Math","pow","ptab","isDefined","newPref","add","unitNodes","blen","utab","b","curBUnit","dim","newUnit","addUnit","unitStrings","uStrParser","stopNow","alen","a","haveUnit","curUA","toUpperCase","sym","symVal","replace","trim","symI","toString","compressed","sub","sup","isMetric","isArbitrary","class","valNode","includes","isSpecial","funcNode","name","parseFloat","value","slashPos","indexOf","ar","split","UNIT","substr","exp","parseInt","console","log","PI","retObj","parseString","ret","retString","retMsg","getProperty","newMag","err","message","uList","printUnits","writeFileSync","encoding","mode","flag","licenseText","pfxTabs","pfxArray","allPrefixesByCode","uTabs","uArray","allUnitsByDef","defsHash","dt","Date","spaces","rootNode","versionNum","version","revNum","revision","rootString","dateIdx","nextDolIdx","revDate","versionText"],"mappings":";;;;;;;AAAA;;;;;;;AAOA,IAAIA,MAAM,GAAGC,OAAO,CAAC,aAAD,CAAP,CAAuBD,MAApC;;AACA,IAAIE,YAAY,GAAGD,OAAO,CAAC,mBAAD,CAAP,CAA6BC,YAAhD;;AACA,IAAIC,IAAI,GAAGF,OAAO,CAAC,WAAD,CAAP,CAAqBE,IAAhC;;AACA,IAAIC,UAAU,GAAGH,OAAO,CAAC,iBAAD,CAAP,CAA2BG,UAA5C;;AACA,IAAIC,UAAU,GAAGJ,OAAO,CAAC,iBAAD,CAAP,CAA2BI,UAA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zD,OAAP,CAAe,YAAf,EAA6B,EAA7B,CAAT;AACAyD,IAAAA,MAAM,GAAGA,MAAM,CAACzD,OAAP,CAAe,GAAf,EAAoB,EAApB,CAAT;AACAyD,IAAAA,MAAM,GAAGA,MAAM,CAACxD,IAAP,EAAT;AACA,QAAI0D,UAAU,GAAGL,QAAQ,CAACnD,QAAT,CAAkB;AAACC,MAAAA,UAAU,EAAC;AAAZ,KAAlB,CAAjB;AACA,QAAIwD,OAAO,GAAGD,UAAU,CAACzC,OAAX,CAAmB,QAAnB,CAAd;AACAyC,IAAAA,UAAU,GAAGA,UAAU,CAACrC,MAAX,CAAkBsC,OAAO,GAAG,CAA5B,CAAb;AACA,QAAIC,UAAU,GAAGF,UAAU,CAACzC,OAAX,CAAmB,GAAnB,CAAjB;AACA,QAAI4C,OAAO,GAAGH,UAAU,CAACrC,MAAX,CAAkB,CAAlB,EAAqBuC,UAArB,EAAkC7D,OAAlC,CAA0C,GAA1C,EAA8C,EAA9C,CAAd;AACA8D,IAAAA,OAAO,GAAGA,OAAO,CAAC7D,IAAR,EAAV;AACA,QAAI8D,WAAW,GAAI,WAAUR,UAAW,cAAaE,MAAO,IAA1C,GACR,SAAQK,OAAQ,EAD1B;AAGAxH,IAAAA,EAAE,CAACiG,aAAH,CAAiB,gCAAjB,EACEwB,WADF,EACe;AAACvB,MAAAA,QAAQ,EAAE,MAAX;AAAmBC,MAAAA,IAAI,EAAE,KAAzB;AAAgCC,MAAAA,IAAI,EAAE;AAAtC,KADf;AAED,GAzd0B,CAydzB;;;AAzdyB,C,CA2d3B;;AAGF;;;;;;;;;;;;;;;AAWAjG,eAAe,CAACW,WAAhB,GAA8B,YAAU;AACtC,SAAO,IAAIX,eAAJ,EAAP;AACD,CAFD,C,CAIA;AACA;;;AACAA,eAAe,CAACW,WAAhB","sourcesContent":["/**\n * This class handles opening, reading and parsing the XML file of ucum\n * definitions (prefixes, base units, and unit atoms).\n *\n * @author Lee Mericle\n *\n */\nvar Prefix = require(\"./prefix.js\").Prefix;\nvar PrefixTables = require(\"./prefixTables.js\").PrefixTables;\nvar Unit = require(\"./unit.js\").Unit;\nvar UnitString = require(\"./unitString.js\").UnitString;\nvar UnitTables = require('./unitTables.js').UnitTables;\nvar packArray = require('./jsonArrayPack.js').packArray;\nvar jsonfile = require('jsonfile');\n\nvar xmldoc = require('xmldoc');\nvar fs = require('fs');\n\nvar essenceFile_ = '../data/ucum-essence.xml';\n\n/**\n * The full xml document\n * @type XmlDocument\n */\nvar xmlInput_ = null;\n\nexport class UcumXmlDocument {\n\n\n /**\n * Constructor. This reads the XML document (essenceFile_) into the\n * xmldoc object, which is an object used by the xmldoc class available\n * from GitHub - https://github.com/nfarina/xmldoc. The object provides\n * methods to read the file and access its contents.\n *\n */\n constructor() {\n // read the XML file and create an xmlDocument object from it.\n let data = fs.readFileSync(essenceFile_);\n xmlInput_ = new xmldoc.XmlDocument(data);\n\n // Array of unit codes in the ucum-essence.xml file that indicate a\n // mole based unit. The moleExp_ attribute for these units needs to be\n // set, but there doesn't seem to be an algorithmic way to find these.\n // Creation of unit objects after this file is processed will pick up\n // the moleExp_ value from the base mole unit, but the ones defined in\n // this file will not necessarily do that.\n this.moleCodes_ = ['mol', 'eq', 'osm', 'kat', 'U' ];\n\n // Make this a singleton. See UnitTables constructor for details.\n\n let holdThis = UcumXmlDocument.prototype;\n UcumXmlDocument = function () {\n throw (new Error('UcumXmlDocument is a Singleton. ' +\n 'Use UcumXmlDocument.getInstance() instead.'));\n };\n if (exports)\n exports.UcumXmlDocument = UcumXmlDocument;\n UcumXmlDocument.prototype = holdThis;\n\n let self = this ;\n UcumXmlDocument.getInstance = function(){return self} ;\n }\n\n\n /**\n * This method controls parsing of the XML into objects used by this\n * program. It uses separate methods to parse the prefixes, the\n * base units, and the units.\n *\n * @returns nothing\n */\n parseXml() {\n\n this.parsePrefixes(xmlInput_.childrenNamed(\"prefix\"));\n this.parseBaseUnits(xmlInput_.childrenNamed(\"base-unit\")) ;\n this.parseUnitStrings(xmlInput_.childrenNamed(\"unit\")) ;\n\n // Create or replace the json file of the prefix and unit definitions\n this.writeJsonFile();\n this.writeVersionText();\n\n }\n\n\n /**\n * Creates prefix objects from the xml prefix nodes passed in and gets\n * them added to the prefix tables.\n *\n * @params prefixes the array of prefix nodes from the xml file, in the\n * order in which the nodes are defined in that file.\n *\n * @returns nothing\n */\n parsePrefixes(prefixes) {\n\n\n let plen = prefixes.length ;\n\n for (let p = 0; p < plen; p++) {\n let curPfx = prefixes[p];\n let attrs = {} ;\n\n attrs[\"code_\"] = curPfx.attr.Code;\n attrs[\"ciCode_\"] = curPfx.attr.CODE;\n attrs[\"name_\"] = curPfx.childNamed('name').val;\n attrs[\"printSymbol_\"] = curPfx.childNamed('printSymbol').val;\n\n // Set the prefix value. If there is a <sup> element in the\n // value node, then this is a base 10 based prefix (10 to the x power).\n // Set the value to 10 taken to the indicated power.\n // Otherwise this is not 10 based and the value contains the\n // actual value for the prefix.\n let pValNode = curPfx.childNamed('value') ;\n attrs[\"value_\"] = null;\n attrs[\"exp_\"] = pValNode.childNamed('sup');\n if (attrs[\"exp_\"] != null) {\n attrs[\"exp_\"] = attrs[\"exp_\"].val;\n attrs[\"value_\"] = Math.pow(10, attrs[\"exp_\"]);\n }\n else {\n attrs[\"value_\"] = pValNode.val;\n attrs[\"exp_\"] = null;\n }\n\n // Make sure the prefix has not already been created. If it hasn't,\n // create the prefix object and then add it to the prefix tables.\n let ptab = PrefixTables.getInstance();\n if (ptab.isDefined(attrs[\"code_\"])) {\n throw(new Error('Prefix constructor called for prefix already ' +\n `defined; code = ${attrs[\"code_\"]}`));\n }\n else {\n let newPref = new Prefix(attrs);\n ptab.add(newPref);\n }\n }\n } // end parsePrefixes\n\n\n /**\n * Creates base unit objects from the xml nodes passed in and adds\n * them to the unit tables.\n *\n * @params unitNodes the array of base unit nodes from the xml file, in the\n * order in which the nodes are defined in that file. (Order is important\n * for all units).\n *\n * @returns nothing\n */\n parseBaseUnits(unitNodes) {\n let blen = unitNodes.length ;\n let utab = UnitTables.getInstance() ;\n for (let b = 0; b < blen; b++) {\n let curBUnit = unitNodes[b];\n let attrs = {} ;\n attrs['isBase_'] = true ;\n attrs['name_'] = curBUnit.childNamed('name').val ;\n attrs['csCode_'] = curBUnit.attr.Code ;\n attrs['ciCode_'] = curBUnit.attr.CODE ;\n attrs['property_'] = curBUnit.childNamed('property').val;\n attrs['variable_'] = curBUnit.attr.dim ;\n attrs['printSymbol_'] = curBUnit.childNamed('printSymbol').val;\n attrs['dim_'] = b ;\n attrs['source_'] = 'UCUM';\n let newUnit = new Unit(attrs);\n utab.addUnit(newUnit) ;\n }\n } // end parseBaseUnits\n\n\n /**\n * Creates non-base unit objects from the xml nodes passed in and adds\n * them to the unit tables.\n *\n * @params unitStrings the array of non-base unit nodes from the xml file, in the\n * order in which the nodes are defined in that file. (Order is important\n * for all units).\n *\n * @returns nothing\n */\n parseUnitStrings(unitStrings) {\n\n let utab = UnitTables.getInstance() ;\n let uStrParser = UnitString.getInstance();\n let stopNow = false ;\n let alen = unitStrings.length ;\n for (let a = 0; a < alen && !stopNow; a++) {\n let haveUnit = true;\n let curUA = unitStrings[a];\n let attrs = {};\n attrs['isBase_'] = false;\n attrs['source_'] = 'UCUM';\n attrs['name_'] = curUA.childNamed('name').val;\n attrs['csCode_'] = curUA.attr.Code;\n if (curUA.attr.CODE)\n attrs['ciCode_'] = curUA.attr.CODE;\n else\n attrs['ciCode_'] = curUA.attr.Code.toUpperCase();\n attrs['property_'] = curUA.childNamed('property').val;\n if (curUA.childNamed('printSymbol')) {\n let sym = curUA.childNamed('printSymbol') ;\n let symVal = sym.val;\n symVal = symVal.replace(/\\n/g, \"\");\n symVal = symVal.trim();\n let symI = sym.childNamed('i');\n if (symI)\n //symVal = '<i>' + symI.val + '</>';\n symVal = symI.toString({compressed:true});\n let sub = sym.childNamed('sub');\n let sup = sym.childNamed('sup');\n if (sub)\n symVal += sub.toString({compressed:true});\n if (sup)\n symVal += sup.toString({compressed:true});\n\n attrs['printSymbol_'] = symVal;\n }\n if (curUA.attr.isMetric === \"yes\")\n attrs['isMetric_'] = true ;\n else\n attrs['isMetric_'] = false ;\n if (curUA.attr.isArbitrary)\n attrs['isArbitrary_'] = true ;\n else\n attrs['isArbitrary_'] = false ;\n if (curUA.attr.class) {\n attrs['class_'] = curUA.attr.class;\n }\n let valNode = curUA.childNamed('value');\n if (this.moleCodes_.includes(curUA.attr.Code))\n attrs['moleExp_'] = 1;\n else\n attrs['moleExp_'] = 0;\n\n\n // Process special units\n if (curUA.attr.isSpecial) {\n attrs['isSpecial_'] = curUA.attr.isSpecial === \"yes\";\n let funcNode = valNode.childNamed('function');\n attrs['cnv_'] = funcNode.attr.name;\n attrs['csUnitString_'] = funcNode.attr.Unit;\n if (attrs['csUnitString_'] === '1') {\n attrs['baseFactor_'] = 1 ;\n }\n else if (attrs['csCode_'] === '[pH]') {\n attrs['baseFactor_'] = parseFloat(funcNode.attr.value) ;\n }\n else {\n let slashPos = attrs['csUnitString_'].indexOf('/');\n let ar = [];\n\n // unit string = K/9 or K/4 or m2/s4/Hz\n if (slashPos >= 0) {\n ar = attrs['csUnitString_'].split('/');\n }\n // unit string = K/9 or K/4\n if ((slashPos >= 0) && (ar.length === 2)) {\n attrs['csUnitString_'] = ar[0];\n attrs['baseFactor_'] = parseFloat(funcNode.attr.value/ar[1]);\n }\n // unit string = 10*-5.Pa\n else if (attrs['csCode_'] === 'B[SPL]') {\n attrs['baseFactor_'] = Math.pow(10, -5) * 2 ;\n attrs['csUnitString_'] = \"Pa\" ;\n }\n // unit string = m1/s4/Hz, K, deg, V, mV, uV, nV, W, kW\n else {\n attrs['baseFactor_'] = parseFloat(funcNode.attr.value);\n }\n } // end if the unit string is not 1\n } // end if the unit is special\n\n else {\n // what I'm calling the unit string is the string that defines the\n // unit based on other units, e.g., rad2 (radian squared) to define\n // a steradian unit. It's not necessarily a proper base unit, although\n // it ultimately builds on base units.\n attrs['csUnitString_'] = valNode.attr.Unit;\n attrs['ciUnitString_'] = valNode.attr.UNIT;\n\n // what I'm calling the factor here (string and number versions)\n // is the magnitude used in conjunction with the unit string to define\n // the new unit, e.g., 3 for a yard that is based in the definition\n // of feet.\n\n attrs['baseFactorStr_'] = valNode.attr.value;\n if (attrs['csCode_'] === '[pi]')\n attrs['baseFactor_'] = parseFloat(attrs['baseFactorStr_']);\n else if (valNode.childNamed('sup')) {\n attrs['baseFactor_'] = parseFloat(valNode.attr.value) ;\n }\n else {\n attrs['baseFactor_'] = parseFloat(valNode.val);\n }\n } // end if this is not a special unit\n\n // Arbitrary units are defined in the UCUM spec as \"not of any\n // specific dimension and are not commensurable with any other\n // unit\" (3.2.24). All arbitrary units in the units definition\n // XML file currently have a unit string of 1 and a base factor of 1\n // except the \"international unit\" with a code of [IU]. Its\n // unit string is the \"international unit\" with a code of [iU],\n // which is also an arbitrary unit - with a unit string of 1.\n // So I am assuming [IU] is just another code for the same unit.\n if (attrs['isArbitrary_'] === true) {\n attrs['magnitude_'] = 1;\n attrs['dim_'] = null;\n }\n\n // units with class = \"dimless\" don't have dimension arrays.\n // They're things like the number pi or the number 10 or percent.\n // Haven't figured out how to handle them yet.\n else if (attrs['class_'] === 'dimless' ||\n attrs['csCode_'] === 'mol') {\n attrs['dim_'] = null ;\n // figure the magnitude based on the unit string\n // if it's 1, the magnitude is the value specified for\n // the base factor, e.g., 3.141592653589793238462 ... for pi\n if (attrs['csUnitString_'] === '1') {\n attrs['magnitude_'] = attrs['baseFactor_'];\n }\n // else if the unit string starts with 10*, the magnitude is\n // 10 to the power specified following 10* e.g., unit = 10*-2\n // for the \"%\" unit. Except for the mole, which is that\n // multiplied by the base factor, which in this case (only,\n // I think) is not 1.\n else if (attrs['csUnitString_'].substr(0,3) == \"10*\") {\n let exp = parseInt(attrs['csUnitString_'].substr(3));\n attrs['magnitude_'] = Math.pow(10, exp) ;\n if (attrs['baseFactor_'] !== 1) {\n attrs['magnitude_'] *= attrs['baseFactor_'];\n }\n }\n // else I don't know what it is.\n else {\n attrs['defError_'] = true ;\n console.log('unexpected dimless unit definition, unit code ' +\n 'is ' + attrs['csCode_']) ;\n }\n } // end if this is a unit with class = dimless\n\n // Handle carat of gold alloys - which doesn't get a dimension\n //\n else if (attrs['csCode_'] === \"[car_Au]\") {\n attrs['magnitude_'] = 1/24 ;\n attrs['dim_'] = null ;\n }\n else {\n\n // Make sure there's a unit string to base the new unit on. There\n // should be, but I'm just checking here to make sure. And omit\n // ones with a unit string of 1. That won't do us any good.\n if (attrs['csUnitString_'] && attrs['csUnitString_'] !== '1' &&\n attrs['csUnitString_'] !== 1) {\n\n haveUnit = false;\n // Handle some special cases\n // 1. the Oersted unit, whose string is /[pi].A/m and whose\n // value is 250. Set the baseFactor to 250/[pi] and\n // the unit string to A/m\n if (attrs['csCode_'] === 'Oe') {\n attrs['baseFactor_'] = 250 / Math.PI;\n attrs['csUnitString_'] = \"A/m\"\n }\n // 2. Strings that start with '/'. Set the function to\n // the inverse function and trim the '/' off the front\n // of the string.\n else if (attrs['csUnitString_'][0] === '/') {\n attrs['cnv_'] = 'inv';\n attrs['csUnitString_'] = attrs['csUnitString_'].substr(1);\n }\n // 3. the Svedberg unit, whose string is 10*-13.s. Set the\n // base factor to 10*-13 and the unit string to s.\n else if (attrs['csCode_'] === '[S]') {\n attrs['baseFactor_'] = Math.pow(10, -13);\n attrs['csUnitString_'] = 's';\n }\n // 4. permeability of vaccuum - code [mu_0], unit given is\n // 4.[pi].10*-7.N/A2\n else if (attrs['csCode_'] === '[mu_0]') {\n attrs['baseFactor_'] = 4 * Math.PI * Math.pow(10, -7);\n attrs['csUnitString_'] = 'N/A2';\n }\n // The unit string parser will use the unit(s) named in the\n // string to create a new unit with the appropriate dimension\n // object and magnitude before it's multiplied by the one\n // specified in the input node.\n try {\n let retObj = uStrParser.parseString(attrs['csUnitString_'],\n 'validate', false);\n let ret = retObj[0];\n let retString = retObj[1];\n let retMsg = retObj[2];\n\n // Get the dimension object and magnitude (and adjust by\n // specified magnitude factor) from the unit created and\n // assign them to the attributes we'll use to create the\n // unit for this listing.\n if (ret) {\n attrs['dim_'] = ret.getProperty('dim_');\n let newMag = ret.getProperty('magnitude_');\n newMag *= attrs['baseFactor_'];\n attrs['magnitude_'] = newMag;\n haveUnit = true ;\n }\n // if there's no unit, report an error\n else {\n attrs['defError_'] = true;\n console.log(`unit definition error; code = ${attrs['csCode_']}; `+\n `msg = ${retMsg}`);\n attrs['dim_'] = null;\n attrs['magnitude_'] = null;\n }\n }\n catch(err) {\n console.log('error thrown from unit parsing code for unit name ' +\n attrs['name_'] + '\\n' + err.message);\n stopNow = true;\n }\n } // end if there is a unit string to parse\n } // end if this is not a dimless unit\n\n if (haveUnit) {\n // Now create the unit we want based on the attributes we've\n // accumulated from the xml input and from figuring the dimension\n // and magnitude. Add it to the unit tables\n let newUnit = new Unit(attrs);\n utab.addUnit(newUnit);\n\n // for now, create a list of the units created and save it to a file\n // for debugging. This is a temporary file.\n let uList = utab.printUnits();\n fs.writeFileSync('UnitsList.txt', uList,\n {encoding: 'utf8', mode: 0o666, flag: 'w'});\n } // end if have a parsed unit\n } // end for a => - to alen\n\n } // end parseUnitStrings\n\n\n /**\n * This writes out the ucumDefs data file, which contains all prefixes and\n * units (base units and others) read and parsed from the XML file.\n *\n * This creates or replace the file \"ucumDefs.json\" in the data directory.\n */\n writeJsonFile() {\n\n let licenseText = \"The following data (prefixes and units) was generated \" +\n \"by the UCUM LHC code from the UCUM data and selected \" +\n \"LOINC combinations of UCUM units. The license for \" +\n \"the UCUM LHC code (demo and library code as well as \" +\n \"the combined units) is located at \" +\n \"https://github.com/lhncbc/ucum-lhc/blob/LICENSE.md.\" ;\n let pfxTabs = PrefixTables.getInstance() ;\n let pfxArray = pfxTabs.allPrefixesByCode();\n let uTabs = UnitTables.getInstance();\n let uArray = uTabs.allUnitsByDef();\n\n let defsHash = { 'license' : licenseText,\n 'prefixes' : packArray(pfxArray),\n 'units' : packArray(uArray)};\n let dt = new Date();\n jsonfile.writeFileSync('../data/ucumDefs.json',\n defsHash,\n {spaces: 2, encoding: 'utf8', mode: 0o644, flag: 'w'});\n jsonfile.writeFileSync('../data/ucumDefs.min.json',\n defsHash,\n {encoding: 'utf8', mode: 0o644, flag: 'w'});\n } // end writeJsonFile\n\n /**\n * This writes out the ucumDefs data file, which contains all prefixes and\n * units (base units and others) read and parsed from the XML file.\n *\n * This creates the file in the data directory and appends the\n * current Date object value to \"ucumDefs\" so that this does not run\n * into problems with a previously existing file.\n */\n writeVersionText() {\n\n let rootNode = xmlInput_;\n let versionNum = rootNode.attr.version;\n let revNum = rootNode.attr.revision;\n revNum = revNum.replace('$Revision:', '');\n revNum = revNum.replace('$', '');\n revNum = revNum.trim();\n let rootString = rootNode.toString({compressed:true});\n let dateIdx = rootString.indexOf('$Date:');\n rootString = rootString.substr(dateIdx + 6);\n let nextDolIdx = rootString.indexOf('$');\n let revDate = rootString.substr(0, nextDolIdx ).replace('$','');\n revDate = revDate.trim();\n let versionText = `version ${versionNum}, revision ${revNum}, ` +\n `dated ${revDate}`;\n\n fs.writeFileSync('../data/ucumEssenceVersion.txt',\n versionText, {encoding: 'utf8', mode: 0o644, flag: 'w'});\n } // end writeVersionText\n\n} // end UcumXmlDocument\n\n\n/**\n * This function exists ONLY until the original UcumXmlDocument 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 UcumXmlDocument object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * @return the singleton UcumXmlDocument object.\n */\nUcumXmlDocument.getInstance = function(){\n return new UcumXmlDocument();\n}\n\n// Perform the first request for the document object, to get the\n// getInstance method set.\nUcumXmlDocument.getInstance();"],"file":"ucumXmlDocument.js"}
1
+ {"version":3,"sources":["../source/ucumXmlDocument.js"],"names":["Prefix","require","PrefixTables","Unit","UnitString","UnitTables","packArray","jsonfile","xmldoc","fs","essenceFile_","xmlInput_","UcumXmlDocument","constructor","data","readFileSync","XmlDocument","moleCodes_","holdThis","prototype","Error","exports","self","getInstance","parseXml","parsePrefixes","childrenNamed","parseBaseUnits","parseUnitStrings","writeJsonFile","writeVersionText","prefixes","plen","length","p","curPfx","attrs","attr","Code","CODE","childNamed","val","pValNode","Math","pow","ptab","isDefined","newPref","add","unitNodes","blen","utab","b","curBUnit","dim","newUnit","addUnit","unitStrings","uStrParser","stopNow","alen","a","haveUnit","curUA","toUpperCase","sym","symVal","replace","trim","symI","toString","compressed","sub","sup","isMetric","isArbitrary","class","valNode","indexOf","isSpecial","funcNode","name","parseFloat","value","slashPos","ar","split","UNIT","substr","exp","parseInt","console","log","PI","retObj","parseString","ret","retString","retMsg","getProperty","newMag","err","message","uList","printUnits","writeFileSync","encoding","mode","flag","licenseText","pfxTabs","pfxArray","allPrefixesByCode","uTabs","uArray","allUnitsByDef","defsHash","dt","Date","spaces","rootNode","versionNum","version","revNum","revision","rootString","dateIdx","nextDolIdx","revDate","versionText"],"mappings":";;;;;;;AAAA;;;;;;;AAOA,IAAIA,MAAM,GAAGC,OAAO,CAAC,aAAD,CAAP,CAAuBD,MAApC;;AACA,IAAIE,YAAY,GAAGD,OAAO,CAAC,mBAAD,CAAP,CAA6BC,YAAhD;;AACA,IAAIC,IAAI,GAAGF,OAAO,CAAC,WAAD,CAAP,CAAqBE,IAAhC;;AACA,IAAIC,UAAU,GAAGH,OAAO,CAAC,iBAAD,CAAP,CAA2BG,UAA5C;;AACA,IAAIC,UAAU,GAAGJ,OAAO,CAAC,iBAAD,CAAP,CAA2BI,UAA5C;;AACA,IAAIC,SAAS,GAAGL,OAAO,CAAC,oBAAD,CAAP,CAA8BK,SAA9C;;AACA,IAAIC,QAAQ,GAAGN,OAAO,CAAC,UAAD,CAAtB;;AAEA,IAAIO,MAAM,GAAGP,OAAO,CAAC,QAAD,CAApB;;AACA,IAAIQ,EAAE,GAAGR,OAAO,CAAC,IAAD,CAAhB;;AAEA,IAAIS,YAAY,GAAG,0BAAnB;AAEA;;;;;AAIA,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AjB;AACA,QAAIuD,OAAO,GAAGD,UAAU,CAAC/C,OAAX,CAAmB,QAAnB,CAAd;AACA+C,IAAAA,UAAU,GAAGA,UAAU,CAACrC,MAAX,CAAkBsC,OAAO,GAAG,CAA5B,CAAb;AACA,QAAIC,UAAU,GAAGF,UAAU,CAAC/C,OAAX,CAAmB,GAAnB,CAAjB;AACA,QAAIkD,OAAO,GAAGH,UAAU,CAACrC,MAAX,CAAkB,CAAlB,EAAqBuC,UAArB,EAAkC5D,OAAlC,CAA0C,GAA1C,EAA8C,EAA9C,CAAd;AACA6D,IAAAA,OAAO,GAAGA,OAAO,CAAC5D,IAAR,EAAV;AACA,QAAI6D,WAAW,GAAI,WAAUR,UAAW,cAAaE,MAAO,IAA1C,GACR,SAAQK,OAAQ,EAD1B;AAGAvH,IAAAA,EAAE,CAACgG,aAAH,CAAiB,gCAAjB,EACEwB,WADF,EACe;AAACvB,MAAAA,QAAQ,EAAE,MAAX;AAAmBC,MAAAA,IAAI,EAAE,KAAzB;AAAgCC,MAAAA,IAAI,EAAE;AAAtC,KADf;AAED,GAzd0B,CAydzB;;;AAzdyB,C,CA2d3B;;AAGF;;;;;;;;;;;;;;;AAWAhG,eAAe,CAACW,WAAhB,GAA8B,YAAU;AACtC,SAAO,IAAIX,eAAJ,EAAP;AACD,CAFD,C,CAIA;AACA;;;AACAA,eAAe,CAACW,WAAhB","sourcesContent":["/**\n * This class handles opening, reading and parsing the XML file of ucum\n * definitions (prefixes, base units, and unit atoms).\n *\n * @author Lee Mericle\n *\n */\nvar Prefix = require(\"./prefix.js\").Prefix;\nvar PrefixTables = require(\"./prefixTables.js\").PrefixTables;\nvar Unit = require(\"./unit.js\").Unit;\nvar UnitString = require(\"./unitString.js\").UnitString;\nvar UnitTables = require('./unitTables.js').UnitTables;\nvar packArray = require('./jsonArrayPack.js').packArray;\nvar jsonfile = require('jsonfile');\n\nvar xmldoc = require('xmldoc');\nvar fs = require('fs');\n\nvar essenceFile_ = '../data/ucum-essence.xml';\n\n/**\n * The full xml document\n * @type XmlDocument\n */\nvar xmlInput_ = null;\n\nexport class UcumXmlDocument {\n\n\n /**\n * Constructor. This reads the XML document (essenceFile_) into the\n * xmldoc object, which is an object used by the xmldoc class available\n * from GitHub - https://github.com/nfarina/xmldoc. The object provides\n * methods to read the file and access its contents.\n *\n */\n constructor() {\n // read the XML file and create an xmlDocument object from it.\n let data = fs.readFileSync(essenceFile_);\n xmlInput_ = new xmldoc.XmlDocument(data);\n\n // Array of unit codes in the ucum-essence.xml file that indicate a\n // mole based unit. The moleExp_ attribute for these units needs to be\n // set, but there doesn't seem to be an algorithmic way to find these.\n // Creation of unit objects after this file is processed will pick up\n // the moleExp_ value from the base mole unit, but the ones defined in\n // this file will not necessarily do that.\n this.moleCodes_ = ['mol', 'eq', 'osm', 'kat', 'U' ];\n\n // Make this a singleton. See UnitTables constructor for details.\n\n let holdThis = UcumXmlDocument.prototype;\n UcumXmlDocument = function () {\n throw (new Error('UcumXmlDocument is a Singleton. ' +\n 'Use UcumXmlDocument.getInstance() instead.'));\n };\n if (exports)\n exports.UcumXmlDocument = UcumXmlDocument;\n UcumXmlDocument.prototype = holdThis;\n\n let self = this ;\n UcumXmlDocument.getInstance = function(){return self} ;\n }\n\n\n /**\n * This method controls parsing of the XML into objects used by this\n * program. It uses separate methods to parse the prefixes, the\n * base units, and the units.\n *\n * @returns nothing\n */\n parseXml() {\n\n this.parsePrefixes(xmlInput_.childrenNamed(\"prefix\"));\n this.parseBaseUnits(xmlInput_.childrenNamed(\"base-unit\")) ;\n this.parseUnitStrings(xmlInput_.childrenNamed(\"unit\")) ;\n\n // Create or replace the json file of the prefix and unit definitions\n this.writeJsonFile();\n this.writeVersionText();\n\n }\n\n\n /**\n * Creates prefix objects from the xml prefix nodes passed in and gets\n * them added to the prefix tables.\n *\n * @params prefixes the array of prefix nodes from the xml file, in the\n * order in which the nodes are defined in that file.\n *\n * @returns nothing\n */\n parsePrefixes(prefixes) {\n\n\n let plen = prefixes.length ;\n\n for (let p = 0; p < plen; p++) {\n let curPfx = prefixes[p];\n let attrs = {} ;\n\n attrs[\"code_\"] = curPfx.attr.Code;\n attrs[\"ciCode_\"] = curPfx.attr.CODE;\n attrs[\"name_\"] = curPfx.childNamed('name').val;\n attrs[\"printSymbol_\"] = curPfx.childNamed('printSymbol').val;\n\n // Set the prefix value. If there is a <sup> element in the\n // value node, then this is a base 10 based prefix (10 to the x power).\n // Set the value to 10 taken to the indicated power.\n // Otherwise this is not 10 based and the value contains the\n // actual value for the prefix.\n let pValNode = curPfx.childNamed('value') ;\n attrs[\"value_\"] = null;\n attrs[\"exp_\"] = pValNode.childNamed('sup');\n if (attrs[\"exp_\"] != null) {\n attrs[\"exp_\"] = attrs[\"exp_\"].val;\n attrs[\"value_\"] = Math.pow(10, attrs[\"exp_\"]);\n }\n else {\n attrs[\"value_\"] = pValNode.val;\n attrs[\"exp_\"] = null;\n }\n\n // Make sure the prefix has not already been created. If it hasn't,\n // create the prefix object and then add it to the prefix tables.\n let ptab = PrefixTables.getInstance();\n if (ptab.isDefined(attrs[\"code_\"])) {\n throw(new Error('Prefix constructor called for prefix already ' +\n `defined; code = ${attrs[\"code_\"]}`));\n }\n else {\n let newPref = new Prefix(attrs);\n ptab.add(newPref);\n }\n }\n } // end parsePrefixes\n\n\n /**\n * Creates base unit objects from the xml nodes passed in and adds\n * them to the unit tables.\n *\n * @params unitNodes the array of base unit nodes from the xml file, in the\n * order in which the nodes are defined in that file. (Order is important\n * for all units).\n *\n * @returns nothing\n */\n parseBaseUnits(unitNodes) {\n let blen = unitNodes.length ;\n let utab = UnitTables.getInstance() ;\n for (let b = 0; b < blen; b++) {\n let curBUnit = unitNodes[b];\n let attrs = {} ;\n attrs['isBase_'] = true ;\n attrs['name_'] = curBUnit.childNamed('name').val ;\n attrs['csCode_'] = curBUnit.attr.Code ;\n attrs['ciCode_'] = curBUnit.attr.CODE ;\n attrs['property_'] = curBUnit.childNamed('property').val;\n attrs['variable_'] = curBUnit.attr.dim ;\n attrs['printSymbol_'] = curBUnit.childNamed('printSymbol').val;\n attrs['dim_'] = b ;\n attrs['source_'] = 'UCUM';\n let newUnit = new Unit(attrs);\n utab.addUnit(newUnit) ;\n }\n } // end parseBaseUnits\n\n\n /**\n * Creates non-base unit objects from the xml nodes passed in and adds\n * them to the unit tables.\n *\n * @params unitStrings the array of non-base unit nodes from the xml file, in the\n * order in which the nodes are defined in that file. (Order is important\n * for all units).\n *\n * @returns nothing\n */\n parseUnitStrings(unitStrings) {\n\n let utab = UnitTables.getInstance() ;\n let uStrParser = UnitString.getInstance();\n let stopNow = false ;\n let alen = unitStrings.length ;\n for (let a = 0; a < alen && !stopNow; a++) {\n let haveUnit = true;\n let curUA = unitStrings[a];\n let attrs = {};\n attrs['isBase_'] = false;\n attrs['source_'] = 'UCUM';\n attrs['name_'] = curUA.childNamed('name').val;\n attrs['csCode_'] = curUA.attr.Code;\n if (curUA.attr.CODE)\n attrs['ciCode_'] = curUA.attr.CODE;\n else\n attrs['ciCode_'] = curUA.attr.Code.toUpperCase();\n attrs['property_'] = curUA.childNamed('property').val;\n if (curUA.childNamed('printSymbol')) {\n let sym = curUA.childNamed('printSymbol') ;\n let symVal = sym.val;\n symVal = symVal.replace(/\\n/g, \"\");\n symVal = symVal.trim();\n let symI = sym.childNamed('i');\n if (symI)\n //symVal = '<i>' + symI.val + '</>';\n symVal = symI.toString({compressed:true});\n let sub = sym.childNamed('sub');\n let sup = sym.childNamed('sup');\n if (sub)\n symVal += sub.toString({compressed:true});\n if (sup)\n symVal += sup.toString({compressed:true});\n\n attrs['printSymbol_'] = symVal;\n }\n if (curUA.attr.isMetric === \"yes\")\n attrs['isMetric_'] = true ;\n else\n attrs['isMetric_'] = false ;\n if (curUA.attr.isArbitrary)\n attrs['isArbitrary_'] = true ;\n else\n attrs['isArbitrary_'] = false ;\n if (curUA.attr.class) {\n attrs['class_'] = curUA.attr.class;\n }\n let valNode = curUA.childNamed('value');\n if (this.moleCodes_.indexOf(curUA.attr.Code) !== -1)\n attrs['moleExp_'] = 1;\n else\n attrs['moleExp_'] = 0;\n\n\n // Process special units\n if (curUA.attr.isSpecial) {\n attrs['isSpecial_'] = curUA.attr.isSpecial === \"yes\";\n let funcNode = valNode.childNamed('function');\n attrs['cnv_'] = funcNode.attr.name;\n attrs['csUnitString_'] = funcNode.attr.Unit;\n if (attrs['csUnitString_'] === '1') {\n attrs['baseFactor_'] = 1 ;\n }\n else if (attrs['csCode_'] === '[pH]') {\n attrs['baseFactor_'] = parseFloat(funcNode.attr.value) ;\n }\n else {\n let slashPos = attrs['csUnitString_'].indexOf('/');\n let ar = [];\n\n // unit string = K/9 or K/4 or m2/s4/Hz\n if (slashPos >= 0) {\n ar = attrs['csUnitString_'].split('/');\n }\n // unit string = K/9 or K/4\n if ((slashPos >= 0) && (ar.length === 2)) {\n attrs['csUnitString_'] = ar[0];\n attrs['baseFactor_'] = parseFloat(funcNode.attr.value/ar[1]);\n }\n // unit string = 10*-5.Pa\n else if (attrs['csCode_'] === 'B[SPL]') {\n attrs['baseFactor_'] = Math.pow(10, -5) * 2 ;\n attrs['csUnitString_'] = \"Pa\" ;\n }\n // unit string = m1/s4/Hz, K, deg, V, mV, uV, nV, W, kW\n else {\n attrs['baseFactor_'] = parseFloat(funcNode.attr.value);\n }\n } // end if the unit string is not 1\n } // end if the unit is special\n\n else {\n // what I'm calling the unit string is the string that defines the\n // unit based on other units, e.g., rad2 (radian squared) to define\n // a steradian unit. It's not necessarily a proper base unit, although\n // it ultimately builds on base units.\n attrs['csUnitString_'] = valNode.attr.Unit;\n attrs['ciUnitString_'] = valNode.attr.UNIT;\n\n // what I'm calling the factor here (string and number versions)\n // is the magnitude used in conjunction with the unit string to define\n // the new unit, e.g., 3 for a yard that is based in the definition\n // of feet.\n\n attrs['baseFactorStr_'] = valNode.attr.value;\n if (attrs['csCode_'] === '[pi]')\n attrs['baseFactor_'] = parseFloat(attrs['baseFactorStr_']);\n else if (valNode.childNamed('sup')) {\n attrs['baseFactor_'] = parseFloat(valNode.attr.value) ;\n }\n else {\n attrs['baseFactor_'] = parseFloat(valNode.val);\n }\n } // end if this is not a special unit\n\n // Arbitrary units are defined in the UCUM spec as \"not of any\n // specific dimension and are not commensurable with any other\n // unit\" (3.2.24). All arbitrary units in the units definition\n // XML file currently have a unit string of 1 and a base factor of 1\n // except the \"international unit\" with a code of [IU]. Its\n // unit string is the \"international unit\" with a code of [iU],\n // which is also an arbitrary unit - with a unit string of 1.\n // So I am assuming [IU] is just another code for the same unit.\n if (attrs['isArbitrary_'] === true) {\n attrs['magnitude_'] = 1;\n attrs['dim_'] = null;\n }\n\n // units with class = \"dimless\" don't have dimension arrays.\n // They're things like the number pi or the number 10 or percent.\n // Haven't figured out how to handle them yet.\n else if (attrs['class_'] === 'dimless' ||\n attrs['csCode_'] === 'mol') {\n attrs['dim_'] = null ;\n // figure the magnitude based on the unit string\n // if it's 1, the magnitude is the value specified for\n // the base factor, e.g., 3.141592653589793238462 ... for pi\n if (attrs['csUnitString_'] === '1') {\n attrs['magnitude_'] = attrs['baseFactor_'];\n }\n // else if the unit string starts with 10*, the magnitude is\n // 10 to the power specified following 10* e.g., unit = 10*-2\n // for the \"%\" unit. Except for the mole, which is that\n // multiplied by the base factor, which in this case (only,\n // I think) is not 1.\n else if (attrs['csUnitString_'].substr(0,3) == \"10*\") {\n let exp = parseInt(attrs['csUnitString_'].substr(3));\n attrs['magnitude_'] = Math.pow(10, exp) ;\n if (attrs['baseFactor_'] !== 1) {\n attrs['magnitude_'] *= attrs['baseFactor_'];\n }\n }\n // else I don't know what it is.\n else {\n attrs['defError_'] = true ;\n console.log('unexpected dimless unit definition, unit code ' +\n 'is ' + attrs['csCode_']) ;\n }\n } // end if this is a unit with class = dimless\n\n // Handle carat of gold alloys - which doesn't get a dimension\n //\n else if (attrs['csCode_'] === \"[car_Au]\") {\n attrs['magnitude_'] = 1/24 ;\n attrs['dim_'] = null ;\n }\n else {\n\n // Make sure there's a unit string to base the new unit on. There\n // should be, but I'm just checking here to make sure. And omit\n // ones with a unit string of 1. That won't do us any good.\n if (attrs['csUnitString_'] && attrs['csUnitString_'] !== '1' &&\n attrs['csUnitString_'] !== 1) {\n\n haveUnit = false;\n // Handle some special cases\n // 1. the Oersted unit, whose string is /[pi].A/m and whose\n // value is 250. Set the baseFactor to 250/[pi] and\n // the unit string to A/m\n if (attrs['csCode_'] === 'Oe') {\n attrs['baseFactor_'] = 250 / Math.PI;\n attrs['csUnitString_'] = \"A/m\"\n }\n // 2. Strings that start with '/'. Set the function to\n // the inverse function and trim the '/' off the front\n // of the string.\n else if (attrs['csUnitString_'][0] === '/') {\n attrs['cnv_'] = 'inv';\n attrs['csUnitString_'] = attrs['csUnitString_'].substr(1);\n }\n // 3. the Svedberg unit, whose string is 10*-13.s. Set the\n // base factor to 10*-13 and the unit string to s.\n else if (attrs['csCode_'] === '[S]') {\n attrs['baseFactor_'] = Math.pow(10, -13);\n attrs['csUnitString_'] = 's';\n }\n // 4. permeability of vaccuum - code [mu_0], unit given is\n // 4.[pi].10*-7.N/A2\n else if (attrs['csCode_'] === '[mu_0]') {\n attrs['baseFactor_'] = 4 * Math.PI * Math.pow(10, -7);\n attrs['csUnitString_'] = 'N/A2';\n }\n // The unit string parser will use the unit(s) named in the\n // string to create a new unit with the appropriate dimension\n // object and magnitude before it's multiplied by the one\n // specified in the input node.\n try {\n let retObj = uStrParser.parseString(attrs['csUnitString_'],\n 'validate', false);\n let ret = retObj[0];\n let retString = retObj[1];\n let retMsg = retObj[2];\n\n // Get the dimension object and magnitude (and adjust by\n // specified magnitude factor) from the unit created and\n // assign them to the attributes we'll use to create the\n // unit for this listing.\n if (ret) {\n attrs['dim_'] = ret.getProperty('dim_');\n let newMag = ret.getProperty('magnitude_');\n newMag *= attrs['baseFactor_'];\n attrs['magnitude_'] = newMag;\n haveUnit = true ;\n }\n // if there's no unit, report an error\n else {\n attrs['defError_'] = true;\n console.log(`unit definition error; code = ${attrs['csCode_']}; `+\n `msg = ${retMsg}`);\n attrs['dim_'] = null;\n attrs['magnitude_'] = null;\n }\n }\n catch(err) {\n console.log('error thrown from unit parsing code for unit name ' +\n attrs['name_'] + '\\n' + err.message);\n stopNow = true;\n }\n } // end if there is a unit string to parse\n } // end if this is not a dimless unit\n\n if (haveUnit) {\n // Now create the unit we want based on the attributes we've\n // accumulated from the xml input and from figuring the dimension\n // and magnitude. Add it to the unit tables\n let newUnit = new Unit(attrs);\n utab.addUnit(newUnit);\n\n // for now, create a list of the units created and save it to a file\n // for debugging. This is a temporary file.\n let uList = utab.printUnits();\n fs.writeFileSync('UnitsList.txt', uList,\n {encoding: 'utf8', mode: 0o666, flag: 'w'});\n } // end if have a parsed unit\n } // end for a => - to alen\n\n } // end parseUnitStrings\n\n\n /**\n * This writes out the ucumDefs data file, which contains all prefixes and\n * units (base units and others) read and parsed from the XML file.\n *\n * This creates or replace the file \"ucumDefs.json\" in the data directory.\n */\n writeJsonFile() {\n\n let licenseText = \"The following data (prefixes and units) was generated \" +\n \"by the UCUM LHC code from the UCUM data and selected \" +\n \"LOINC combinations of UCUM units. The license for \" +\n \"the UCUM LHC code (demo and library code as well as \" +\n \"the combined units) is located at \" +\n \"https://github.com/lhncbc/ucum-lhc/blob/LICENSE.md.\" ;\n let pfxTabs = PrefixTables.getInstance() ;\n let pfxArray = pfxTabs.allPrefixesByCode();\n let uTabs = UnitTables.getInstance();\n let uArray = uTabs.allUnitsByDef();\n\n let defsHash = { 'license' : licenseText,\n 'prefixes' : packArray(pfxArray),\n 'units' : packArray(uArray)};\n let dt = new Date();\n jsonfile.writeFileSync('../data/ucumDefs.json',\n defsHash,\n {spaces: 2, encoding: 'utf8', mode: 0o644, flag: 'w'});\n jsonfile.writeFileSync('../data/ucumDefs.min.json',\n defsHash,\n {encoding: 'utf8', mode: 0o644, flag: 'w'});\n } // end writeJsonFile\n\n /**\n * This writes out the ucumDefs data file, which contains all prefixes and\n * units (base units and others) read and parsed from the XML file.\n *\n * This creates the file in the data directory and appends the\n * current Date object value to \"ucumDefs\" so that this does not run\n * into problems with a previously existing file.\n */\n writeVersionText() {\n\n let rootNode = xmlInput_;\n let versionNum = rootNode.attr.version;\n let revNum = rootNode.attr.revision;\n revNum = revNum.replace('$Revision:', '');\n revNum = revNum.replace('$', '');\n revNum = revNum.trim();\n let rootString = rootNode.toString({compressed:true});\n let dateIdx = rootString.indexOf('$Date:');\n rootString = rootString.substr(dateIdx + 6);\n let nextDolIdx = rootString.indexOf('$');\n let revDate = rootString.substr(0, nextDolIdx ).replace('$','');\n revDate = revDate.trim();\n let versionText = `version ${versionNum}, revision ${revNum}, ` +\n `dated ${revDate}`;\n\n fs.writeFileSync('../data/ucumEssenceVersion.txt',\n versionText, {encoding: 'utf8', mode: 0o644, flag: 'w'});\n } // end writeVersionText\n\n} // end UcumXmlDocument\n\n\n/**\n * This function exists ONLY until the original UcumXmlDocument 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 UcumXmlDocument object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * @return the singleton UcumXmlDocument object.\n */\nUcumXmlDocument.getInstance = function(){\n return new UcumXmlDocument();\n}\n\n// Perform the first request for the document object, to get the\n// getInstance method set.\nUcumXmlDocument.getInstance();"],"file":"ucumXmlDocument.js"}
@@ -793,8 +793,8 @@ class Unit {
793
793
  * concatenated string. Basically it checks to see if the string
794
794
  * needs to be enclosed either in parentheses or square brackets.
795
795
  *
796
- * The string is enclosed if it is not a number, does not start with
797
- * a parenthesis or square bracket, and includes a period, and asterisk,
796
+ * The string is enclosed if it is not a number, is not already enclosed in a pair of
797
+ * parentheses or square brackets, and includes a period, and asterisk,
798
798
  * a slash or a blank space.
799
799
  *
800
800
  * @param str the string
@@ -810,9 +810,9 @@ class Unit {
810
810
  if (intUtils_.isNumericString(str)) {
811
811
  ret = str;
812
812
  } else {
813
- if (str.charAt(0) === '(' || str.charAt(0) === '[') {
813
+ if (str.charAt(0) === '(' && str.endsWith(')') || str.charAt(0) === '[' && str.endsWith(']')) {
814
814
  ret = str;
815
- } else if (str.includes('.') || str.includes('/') || str.includes('*') || str.includes(' ')) {
815
+ } else if (/[./* ]/.test(str)) {
816
816
  ret = startChar + str + endChar;
817
817
  } else {
818
818
  ret = str;
@@ -1 +1 @@
1
- {"version":3,"sources":["../source/unit.js"],"names":["Ucum","require","Dimension","UnitTables","isInteger","Unit","constructor","attrs","isBase_","name_","csCode_","ciCode_","property_","magnitude_","undefined","dim_","Array","printSymbol_","class_","isMetric_","variable_","cnv_","cnvPfx_","isSpecial_","isArbitrary_","moleExp_","synonyms_","source_","loincProperty_","category_","guidance_","csUnitString_","ciUnitString_","baseFactorStr_","baseFactor_","defError_","assignUnity","assignZero","assignVals","vals","key","uKey","charAt","length","hasOwnProperty","Error","clone","retUnit","Object","getOwnPropertyNames","forEach","val","assign","unit2","equals","fullEquals","thisAttr","keys","sort","u2Attr","keyLen","match","k","getProperty","propertyName","uProp","convertFrom","num","fromUnit","newNum","isMoleMassCommensurable","needMoleWeightMsg_","isNull","fromCnv","fromMag","x","fromFunc","funcs","forName","cnvFrom","toFunc","cnvTo","convertTo","toUnit","convertCoherent","f_from","mutateCoherent","i","max","getMax","elem","getElementAt","tabs","_getUnitTables","uA","getUnitsByDimension","name","convertMassToMol","amt","molUnit","molecularWeight","molAmt","avoNum","getUnitByCode","molesFactor","convertMolToMass","massUnit","massAmt","mutateRatio","multiplyThis","s","mulVal","toString","_concatStrs","multiplyThese","isZero","dimVec_","add","divide","invertString","sub","minus","invert","theString","stringRep","replace","substr","str1","operator","str2","startChar","endChar","_buildOneString","str","ret","intUtils_","isNumericString","includes","power","p","uStr","uArray","arLen","un","nun","parseInt","Math","pow","uLen","u","uChar","exp","join","mul","d","getMassDimensionIndex","commensurable","testDim","curVal","setElementAt","getInstance"],"mappings":";;;;;;;AAYA;;AAIA;;;;;;;;AAfA;;;;;;;;;AASA,IAAIA,IAAI,GAAGC,OAAO,CAA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D,CAAP,CAA2BE,UAAxC;AACF,WAAOA,UAAU,CAAC6J,WAAX,EAAP;AACD;;AAh/Be,C,CAk/BhB","sourcesContent":["\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 * 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 unitsofmeasure.org list 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 * 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 arbitrary unit ${this.name_}`));\n if (fromUnit.isArbitrary_)\n throw (new Error(`Attempt to convert to arbitrary unit ${fromUnit.name_}`));\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.isMoleMassCommensurable(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 // If the same conversion function is specified for both units, which\n // includes neither unit having a conversion function, multiply the\n // \"from\" unit's magnitude by the number passed in and then divide\n // that result by this unit's magnitude. Do this for units with\n // and without dimension vectors. PROBLEM with 2 non-commensurable\n // units with no dimension vector or function, e.g., byte to mol\n if (fromCnv === this.cnv_) {\n newNum = (num * fromMag) / this.magnitude_;\n }\n // else use a function to get the number to be returned\n else {\n let x = 0.0 ;\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 } // end if either unit has a conversion function\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 * Calculates the number of units that would result from converting a unit\n * expressed in mass/grams to a unit expressed in moles. The \"this\" unit is\n * the unit expressed in some form of mass (g, mg, mmg, kg, whatever) and the\n * target or \"to\" unit - the molUnit parameter - is a unit expressed in moles\n * - mol, umol, mmol, etc. The unit expressions surrounding the moles and\n * mass must be convertible. No validation of this requirement is performed.\n *\n * @param amt the quantity of this unit to be converted\n * @param molUnit 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 molUnit\n */\n convertMassToMol(amt, molUnit, molecularWeight) {\n // The prefix values that have been applied to this unit, which is the mass\n // (grams) unit, are reflected in the magnitude. So the number of moles\n // represented by this unit equals the number of grams -- amount * magnitude\n // divided by the molecular Weight\n let molAmt = (this.magnitude_ * amt)/molecularWeight ;\n // The molUnit's basic magnitude, before prefixes are applied,\n // is avogadro's number, get that and divide it out of the current magnitude.\n let tabs = this._getUnitTables();\n let avoNum = tabs.getUnitByCode('mol').magnitude_ ;\n let molesFactor = molUnit.magnitude_ / avoNum ;\n // return the molAmt divided by the molesFactor as the number of moles\n // for the molUnit\n return molAmt/molesFactor ;\n }\n\n /**\n * Calculates the number of units that would result from converting a unit\n * expressed in moles to a unit expressed in mass (grams). The \"this\" unit\n * is the unit expressed in some form of moles, e.g., mol, umol, mmol, etc.,\n * and the target or \"to\" unit is a unit expressed in some form of mass, e.g.,\n * g, mg, mmg, kg, etc. Any unit expressions surrounding the moles and mass\n * must be convertible. No validation of this requirement is performed.\n *\n * @param amt the quantity of this unit to be converted\n * @param massUnit 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 massUnit\n */\n convertMolToMass(amt, massUnit, molecularWeight) {\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 // Determine what prefix values (mg or mg/dL, etc.) have been applied to\n // this unit by dividing the simple mole unit magnitude out of the\n // current mole unit magnitude.\n let molesFactor = this.magnitude_ / avoNum ;\n // The number of grams (mass) is equal to the number of moles (amt)\n // times the molecular weight. We also multiply that by the prefix values\n // applied to the current unit (molesFactor) to get the grams for this\n // particular unit.\n let massAmt = (molesFactor * amt) * molecularWeight ;\n // Finally, we return the mass amount/grams for this particular unit\n // divided by any effects of prefixes applied to the \"to\" unit, which\n // is assumed to be some form of a gram unit\n return massAmt / massUnit.magnitude_ ;\n }\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.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 // 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.guidance_ = '';\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 // Update the mole exponent count by adding the count for unit2 to the\n // count for this unit.\n retUnit.moleExp_ = retUnit.moleExp_ + unit2.moleExp_ ;\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 return retUnit ;\n\n } // end multiplyThese\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.guidance_ = '';\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_ = retUnit.moleExp_ - unit2.moleExp_ ;\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 * 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\n if (this.cnv_ != null)\n throw (new Error(`Attempt to invert a non-ratio unit - ${this.name_}`));\n\n this.name_ = this.invertString(this.name_);\n this.magnitude_ = 1/this.magnitude_ ;\n this.dim_.minus();\n return this;\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 let stringRep = theString.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, does not start with\n * a parenthesis or square bracket, 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.charAt(0) === '[') {\n ret = str;\n }\n else if (str.includes('.') || str.includes('/') ||\n str.includes('*') || str.includes(' ')) {\n ret = startChar + str + endChar ;\n }\n else {\n ret = str ;\n }\n }\n return ret ;\n }\n\n\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 //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 this.csCode_ = uArray.join('');\n\n this.magnitude_ = Math.pow(this.magnitude_, p);\n if (this.dim_) {\n this.dim_.mul(p);\n }\n return this;\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 isMoleMassCommensurable(unit2) {\n let tabs = this._getUnitTables();\n let d = tabs.getMassDimensionIndex();\n let commensurable = false ;\n if (this.moleExp_ === 1 && unit2.moleExp_ === 0) {\n let testDim = this.dim_.clone();\n let curVal = testDim.getElementAt(d);\n testDim.setElementAt(d, (curVal + this.moleExp_));\n commensurable = (testDim.equals(unit2.dim_));\n }\n else if (unit2.moleExp_ === 1 && this.moleExp_ === 0) {\n let testDim = unit2.dim_.clone();\n let curVal = testDim.getElementAt(d);\n testDim.setElementAt(d, (curVal + unit2.moleExp_));\n commensurable = (testDim.equals(this.dim_));\n }\n return commensurable ;\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"],"file":"unit.js"}
1
+ {"version":3,"sources":["../source/unit.js"],"names":["Ucum","require","Dimension","UnitTables","isInteger","Unit","constructor","attrs","isBase_","name_","csCode_","ciCode_","property_","magnitude_","undefined","dim_","Array","printSymbol_","class_","isMetric_","variable_","cnv_","cnvPfx_","isSpecial_","isArbitrary_","moleExp_","synonyms_","source_","loincProperty_","category_","guidance_","csUnitString_","ciUnitString_","baseFactorStr_","baseFactor_","defError_","assignUnity","assignZero","assignVals","vals","key","uKey","charAt","length","hasOwnProperty","Error","clone","retUnit","Object","getOwnPropertyNames","forEach","val","assign","unit2","equals","fullEquals","thisAttr","keys","sort","u2Attr","keyLen","match","k","getProperty","propertyName","uProp","convertFrom","num","fromUnit","newNum","isMoleMassCommensurable","needMoleWeightMsg_","isNull","fromCnv","fromMag","x","fromFunc","funcs","forName","cnvFrom","toFunc","cnvTo","convertTo","toUnit","convertCoherent","f_from","mutateCoherent","i","max","getMax","elem","getElementAt","tabs","_getUnitTables","uA","getUnitsByDimension","name","convertMassToMol","amt","molUnit","molecularWeight","molAmt","avoNum","getUnitByCode","molesFactor","convertMolToMass","massUnit","massAmt","mutateRatio","multiplyThis","s","mulVal","toString","_concatStrs","multiplyThese","isZero","dimVec_","add","divide","invertString","sub","minus","invert","theString","stringRep","replace","substr","str1","operator","str2","startChar","endChar","_buildOneString","str","ret","intUtils_","isNumericString","endsWith","test","power","p","uStr","uArray","arLen","un","nun","parseInt","Math","pow","uLen","u","uChar","exp","join","mul","d","getMassDimensionIndex","commensurable","testDim","curVal","setElementAt","getInstance"],"mappings":";;;;;;;AAYA;;AAIA;;;;;;;;AAfA;;;;;;;;;AASA,IAAIA,IAAI,GAAGC,OAAO,CAAC,aAAD,CAAP,CAAuBD,IAAlC;;AACA,IAAIE,SAAS,GAAGD,OAAO,CAAC,gBAAD,CAAP,CAA0BC,SAA1C;;AAEA,IAAIC,UAAJ;;AAEA,IAAIC,SAAS,GAAGH,OAAO,CAAC,YAAD,CAAvB;;AAGO,MAAMI,IAAN,CAAW;AAEhB;;;;;;;;;;;;;;;AAeAC,EAAAA,WAAW,CAACC,KAAK,GAAG,EAAT,EAAa;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;;AAGA,SAAKC,OAAL,GAAeD,KAAK,CAAC,SAAD,CAAL,IAAoB,KAAnC;AAEA;;;;AAGA,SAAKE,KAAL,GAAaF,KAAK,CAAC,OAAD,CAAL,IAAkB,EAA/B;AAEA;;;;AAGA,SAAKG,OAAL,GAAeH,KAAK,CAAC,SAAD,CAAL,IAAoB,EAAnC;AAEA;;;;AAGA,SAAKI,OAAL,GAAeJ,KAAK,CAAC,SAAD,CAAL,IAAoB,EAAnC;AAEA;;;;AAGA,SAAKK,SAAL,GAAiBL,KAAK,CAAC,WAAD,CAAL,IAAsB,EAAvC;AAEA;;;;;;;;AAOA,SAAKM,UAAL,GAAkBN,KAAK,CAAC,YAAD,CAAL,IAAuB,CAAzC;AAEA;;;;AAGA,QAAIA,KAAK,CAAC,MAAD,CAAL,KAAkBO,SAAlB,IAA+BP,KAAK,CAAC,MAA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ACnE,YAAR,CAAqBgE,CAArB,CAAb;AACAG,MAAAA,OAAO,CAACE,YAAR,CAAqBL,CAArB,EAAyBI,MAAM,GAAG1G,KAAK,CAAC5B,QAAxC;AACAoI,MAAAA,aAAa,GAAIC,OAAO,CAACxG,MAAR,CAAe,KAAKvC,IAApB,CAAjB;AACD;;AACD,WAAO8I,aAAP;AACD;AAGD;;;;;;;;;;AAQAhE,EAAAA,cAAc,GAAG;AACf,QAAI,CAAC1F,UAAL,EACEA,UAAU,GAAGF,OAAO,CAAC,iBAAD,CAAP,CAA2BE,UAAxC;AACF,WAAOA,UAAU,CAAC8J,WAAX,EAAP;AACD;;AA/+Be,C,CAi/BhB","sourcesContent":["\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 * 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 unitsofmeasure.org list 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 * 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 arbitrary unit ${this.name_}`));\n if (fromUnit.isArbitrary_)\n throw (new Error(`Attempt to convert to arbitrary unit ${fromUnit.name_}`));\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.isMoleMassCommensurable(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 // If the same conversion function is specified for both units, which\n // includes neither unit having a conversion function, multiply the\n // \"from\" unit's magnitude by the number passed in and then divide\n // that result by this unit's magnitude. Do this for units with\n // and without dimension vectors. PROBLEM with 2 non-commensurable\n // units with no dimension vector or function, e.g., byte to mol\n if (fromCnv === this.cnv_) {\n newNum = (num * fromMag) / this.magnitude_;\n }\n // else use a function to get the number to be returned\n else {\n let x = 0.0 ;\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 } // end if either unit has a conversion function\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 * Calculates the number of units that would result from converting a unit\n * expressed in mass/grams to a unit expressed in moles. The \"this\" unit is\n * the unit expressed in some form of mass (g, mg, mmg, kg, whatever) and the\n * target or \"to\" unit - the molUnit parameter - is a unit expressed in moles\n * - mol, umol, mmol, etc. The unit expressions surrounding the moles and\n * mass must be convertible. No validation of this requirement is performed.\n *\n * @param amt the quantity of this unit to be converted\n * @param molUnit 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 molUnit\n */\n convertMassToMol(amt, molUnit, molecularWeight) {\n // The prefix values that have been applied to this unit, which is the mass\n // (grams) unit, are reflected in the magnitude. So the number of moles\n // represented by this unit equals the number of grams -- amount * magnitude\n // divided by the molecular Weight\n let molAmt = (this.magnitude_ * amt)/molecularWeight ;\n // The molUnit's basic magnitude, before prefixes are applied,\n // is avogadro's number, get that and divide it out of the current magnitude.\n let tabs = this._getUnitTables();\n let avoNum = tabs.getUnitByCode('mol').magnitude_ ;\n let molesFactor = molUnit.magnitude_ / avoNum ;\n // return the molAmt divided by the molesFactor as the number of moles\n // for the molUnit\n return molAmt/molesFactor ;\n }\n\n /**\n * Calculates the number of units that would result from converting a unit\n * expressed in moles to a unit expressed in mass (grams). The \"this\" unit\n * is the unit expressed in some form of moles, e.g., mol, umol, mmol, etc.,\n * and the target or \"to\" unit is a unit expressed in some form of mass, e.g.,\n * g, mg, mmg, kg, etc. Any unit expressions surrounding the moles and mass\n * must be convertible. No validation of this requirement is performed.\n *\n * @param amt the quantity of this unit to be converted\n * @param massUnit 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 massUnit\n */\n convertMolToMass(amt, massUnit, molecularWeight) {\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 // Determine what prefix values (mg or mg/dL, etc.) have been applied to\n // this unit by dividing the simple mole unit magnitude out of the\n // current mole unit magnitude.\n let molesFactor = this.magnitude_ / avoNum ;\n // The number of grams (mass) is equal to the number of moles (amt)\n // times the molecular weight. We also multiply that by the prefix values\n // applied to the current unit (molesFactor) to get the grams for this\n // particular unit.\n let massAmt = (molesFactor * amt) * molecularWeight ;\n // Finally, we return the mass amount/grams for this particular unit\n // divided by any effects of prefixes applied to the \"to\" unit, which\n // is assumed to be some form of a gram unit\n return massAmt / massUnit.magnitude_ ;\n }\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.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 // 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.guidance_ = '';\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 // Update the mole exponent count by adding the count for unit2 to the\n // count for this unit.\n retUnit.moleExp_ = retUnit.moleExp_ + unit2.moleExp_ ;\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 return retUnit ;\n\n } // end multiplyThese\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.guidance_ = '';\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_ = retUnit.moleExp_ - unit2.moleExp_ ;\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 * 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\n if (this.cnv_ != null)\n throw (new Error(`Attempt to invert a non-ratio unit - ${this.name_}`));\n\n this.name_ = this.invertString(this.name_);\n this.magnitude_ = 1/this.magnitude_ ;\n this.dim_.minus();\n return this;\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 let stringRep = theString.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 * 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 //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 this.csCode_ = uArray.join('');\n\n this.magnitude_ = Math.pow(this.magnitude_, p);\n if (this.dim_) {\n this.dim_.mul(p);\n }\n return this;\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 isMoleMassCommensurable(unit2) {\n let tabs = this._getUnitTables();\n let d = tabs.getMassDimensionIndex();\n let commensurable = false ;\n if (this.moleExp_ === 1 && unit2.moleExp_ === 0) {\n let testDim = this.dim_.clone();\n let curVal = testDim.getElementAt(d);\n testDim.setElementAt(d, (curVal + this.moleExp_));\n commensurable = (testDim.equals(unit2.dim_));\n }\n else if (unit2.moleExp_ === 1 && this.moleExp_ === 0) {\n let testDim = unit2.dim_.clone();\n let curVal = testDim.getElementAt(d);\n testDim.setElementAt(d, (curVal + unit2.moleExp_));\n commensurable = (testDim.equals(this.dim_));\n }\n return commensurable ;\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"],"file":"unit.js"}
@@ -183,7 +183,7 @@ class UnitString {
183
183
  let sUnit = null;
184
184
 
185
185
  for (sUnit in Ucum.specUnits_) {
186
- while (uStr.includes(sUnit)) uStr = uStr.replace(sUnit, Ucum.specUnits_[sUnit]);
186
+ while (uStr.indexOf(sUnit) !== -1) uStr = uStr.replace(sUnit, Ucum.specUnits_[sUnit]);
187
187
  } // Check for spaces and throw an error if any are found. The spec
188
188
  // explicitly forbids spaces except in annotations, which is why any
189
189
  // annotations are extracted before this check is made.
@@ -572,7 +572,7 @@ class UnitString {
572
572
  if (numRes && numRes.length === 3 && numRes[1] !== '' && numRes[2] !== '' && numRes[2].indexOf(this.braceFlag_) !== 0) {
573
573
  let dispVal = numRes[2];
574
574
 
575
- if (!endProcessing && numRes[2].includes(this.parensFlag_)) {
575
+ if (!endProcessing && numRes[2].indexOf(this.parensFlag_) !== -1) {
576
576
  let parensback = this._getParensUnit(numRes[2], origString);
577
577
 
578
578
  numRes[2] = parensback[0]['csCode_'];
@@ -614,7 +614,7 @@ class UnitString {
614
614
  this.retMsg_.push(`${origString} is not a valid UCUM code. ` + `It is terminated with the operator ${this.openEmph_}` + `${theOp}${this.closeEmph_}.`);
615
615
  n = u1;
616
616
  endProcessing = true;
617
- } else if (Ucum.validOps_.includes(uArray1[n])) {
617
+ } else if (Ucum.validOps_.indexOf(uArray1[n]) !== -1) {
618
618
  this.retMsg_.push(`${origString} is not a valid UCUM code. ` + `A unit code is missing between${this.openEmph_}` + `${theOp}${this.closeEmph_}and${this.openEmph_}` + `${uArray1[n]}${this.closeEmph_}in${this.openEmph_}` + `${theOp}${uArray1[n]}${this.closeEmph_}.`);
619
619
  n = u1;
620
620
  endProcessing = true;
@@ -633,7 +633,7 @@ class UnitString {
633
633
  if (numRes2 && numRes2.length === 3 && numRes2[1] !== '' && numRes2[2] !== '' && numRes2[2].indexOf(this.braceFlag_) !== 0) {
634
634
  let invalidString = numRes2[0];
635
635
 
636
- if (!endProcessing && numRes2[2].includes(this.parensFlag_)) {
636
+ if (!endProcessing && numRes2[2].indexOf(this.parensFlag_) !== -1) {
637
637
  let parensback = this._getParensUnit(numRes2[2], origString);
638
638
 
639
639
  numRes2[2] = parensback[0]['csCode_'];
@@ -1092,7 +1092,7 @@ class UnitString {
1092
1092
  let sUnit = null;
1093
1093
 
1094
1094
  for (sUnit in Ucum.specUnits_) {
1095
- if (uCode.includes(Ucum.specUnits_[sUnit])) uCode = uCode.replace(Ucum.specUnits_[sUnit], sUnit);
1095
+ if (uCode.indexOf(Ucum.specUnits_[sUnit]) !== -1) uCode = uCode.replace(Ucum.specUnits_[sUnit], sUnit);
1096
1096
  }
1097
1097
 
1098
1098
  retUnit = this.utabs_.getUnitByCode(uCode);
@@ -1276,7 +1276,7 @@ class UnitString {
1276
1276
  let befAnnoText = annoRet[1];
1277
1277
  let aftAnnoText = annoRet[2]; // Add the warning about annotations - just once.
1278
1278
 
1279
- if (this.bracesMsg_ && !this.retMsg_.includes(this.bracesMsg_)) this.retMsg_.push(this.bracesMsg_); // If there's no text before or after the annotation, it's probably
1279
+ if (this.bracesMsg_ && this.retMsg_.indexOf(this.bracesMsg_) === -1) this.retMsg_.push(this.bracesMsg_); // If there's no text before or after the annotation, it's probably
1280
1280
  // something that should be interpreted as a 1, e.g., {KCT'U}.
1281
1281
  // HOWEVER, it could also be a case where someone used braces instead
1282
1282
  // of brackets, e.g., {degF} instead of [degF]. Check for that before