@lhncbc/ucum-lhc 5.0.4 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"ucumXmlDocument.js","names":["Prefix","require","PrefixTables","Unit","UnitString","UnitTables","packArray","jsonfile","xmldoc","fs","essenceFile_","xmlInput_","UcumXmlDocument","constructor","data","readFileSync","XmlDocument","moleCodes_","holdThis","prototype","exports","Error","self","getInstance","parseXml","parsePrefixes","childrenNamed","parseBaseUnits","parseUnitStrings","writeJsonFile","writeVersionText","prefixes","plen","length","p","curPfx","attrs","attr","Code","CODE","childNamed","val","pValNode","parseFloat","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","value","slashPos","ar","split","Math","pow","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"],"sources":["../source/ucumXmlDocument.js"],"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 // Use parseFloat('1eSOMETHING') instead of Math.pow() to avoid\n // small number changes like 1.0000000000000001e-21. See LF-2830.\n // attrs[\"value_\"] = Math.pow(10, attrs[\"exp_\"]);\n attrs[\"value_\"] = parseFloat(`1e${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();\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIA,MAAM,GAAGC,OAAO,CAAC,aAAa,CAAC,CAACD,MAAM;AAC1C,IAAIE,YAAY,GAAGD,OAAO,CAAC,mBAAmB,CAAC,CAACC,YAAY;AAC5D,IAAIC,IAAI,GAAGF,OAAO,CAAC,WAAW,CAAC,CAACE,IAAI;AACpC,IAAIC,UAAU,GAAGH,OA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O,CAAC7D,IAAI,CAAC,CAAC;IACxB,IAAI8D,WAAW,GAAI,WAAUR,UAAW,cAAaE,MAAO,IAAG,GACrD,SAAQK,OAAQ,EAAC;IAE3BvH,EAAE,CAACgG,aAAa,CAAC,gCAAgC,EAC/CwB,WAAW,EAAE;MAACvB,QAAQ,EAAE,MAAM;MAAEC,IAAI,EAAE,KAAK;MAAEC,IAAI,EAAE;IAAG,CAAC,CAAC;EAC5D,CAAC,CAAC;AAEJ,CAAC,CAAC;;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAVAxF,OAAA,CAAAR,eAAA,GAAAA,eAAA;AAWAA,eAAe,CAACW,WAAW,GAAG,YAAU;EACtC,OAAO,IAAIX,eAAe,CAAC,CAAC;AAC9B,CAAC;;AAED;AACA;AACAA,eAAe,CAACW,WAAW,CAAC,CAAC"}
1
+ {"version":3,"file":"ucumXmlDocument.js","names":["Prefix","require","PrefixTables","Unit","UnitString","UnitTables","packArray","jsonfile","xmldoc","fs","essenceFile_","xmlInput_","UcumXmlDocument","constructor","data","readFileSync","XmlDocument","moleCodes_","equivCodes_","holdThis","prototype","exports","Error","self","getInstance","parseXml","parsePrefixes","childrenNamed","parseBaseUnits","parseUnitStrings","writeJsonFile","writeVersionText","prefixes","plen","length","p","curPfx","attrs","attr","Code","CODE","childNamed","val","pValNode","parseFloat","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","value","slashPos","ar","split","Math","pow","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"],"sources":["../source/ucumXmlDocument.js"],"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', 'osm', 'kat', 'U' ];\n // Works similarly to the moleCodes_ array, but for units that represents\n // equivalent units. For unit codes in the equivCodes_ array, an equivalentExp_ \n // attribute flag will be set to 1. \n this.equivCodes_ = ['eq'];\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 // Use parseFloat('1eSOMETHING') instead of Math.pow() to avoid\n // small number changes like 1.0000000000000001e-21. See LF-2830.\n // attrs[\"value_\"] = Math.pow(10, attrs[\"exp_\"]);\n attrs[\"value_\"] = parseFloat(`1e${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 // Note: This currently works as a boolean flag,\n // but it should be used to represent the dimensionality\n // of the unit as an integer instead.\n if (this.moleCodes_.indexOf(curUA.attr.Code) !== -1)\n attrs['moleExp_'] = 1;\n else\n attrs['moleExp_'] = 0;\n // Adds a flag similar to how moleExp_ works, but for units \n // that are equivalent. Note that ideally this should also\n // take values other than 1 or 0, but for now it is a boolean \n // flag.\n if (this.equivCodes_.indexOf(curUA.attr.Code) !== -1) {\n attrs['equivalentExp_'] = 1;\n }\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();\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIA,MAAM,GAAGC,OAAO,CAAC,aAAa,CAAC,CAACD,MAAM;AAC1C,IAAIE,YAAY,GAAGD,OAAO,CAAC,mBAAmB,CAAC,CAACC,YAAY;AAC5D,IAAIC,IAAI,GAAGF,OAAO,CAAC,WAAW,CAAC,CAACE,IAAI;AACpC,IAAIC,UAAU,GAAGH,OAAO,CAAC,iBAAiB,CAAC,CAACG,UAAU;AACtD,IAAIC,UAAU,GAAGJ,OAAO,CAAC,iBAAiB,CAAC,CAACI,UAAU;AACtD,IAAIC,SAAS,GAAGL,OAAO,CAAC,oBAAoB,CAAC,CAACK,SAAS;AACvD,IAAIC,QAAQ,GAAGN,OAAO,CAAC,UAAU,CAAC;AAElC,IAAIO,MAAM,GAAGP,OAAO,CAAC,QAAQ,CAAC;AAC9B,IAAIQ,EAAE,GAAGR,OAAO,CAAC,IAAI,CAAC;AAEtB,IAAIS,YAAY,GAAG,0BAA0B;;AAE7C;AACA;AACA;AACA;AACA,IAAIC,SAAS,GAAG,IAAI;AAEb,MAAMC,eAAe,CAAC;EAG3B;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAAA,EAAG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,IAAI,EAAE;IAAG,CAAC,CAAC;EAC5D,CAAC,CAAC;AAEJ,CAAC,CAAC;;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAVAxF,OAAA,CAAAT,eAAA,GAAAA,eAAA;AAWAA,eAAe,CAACY,WAAW,GAAG,YAAU;EACtC,OAAO,IAAIZ,eAAe,CAAC,CAAC;AAC9B,CAAC;;AAED;AACA;AACAA,eAAe,CAACY,WAAW,CAAC,CAAC"}
@@ -152,6 +152,11 @@ class Unit {
152
152
  */
153
153
  this.moleExp_ = attrs['moleExp_'] || 0;
154
154
 
155
+ /**
156
+ * Flag indicating whether or not this is a equivalent mole unit
157
+ */
158
+ this.equivalentExp_ = attrs['equivalentExp_'] || 0;
159
+
155
160
  /*
156
161
  * Added when added LOINC list of units
157
162
  * synonyms are used by the autocompleter to enhance lookup capabilities
@@ -480,7 +485,7 @@ class Unit {
480
485
  // return the molAmt divided by the molesFactor as the number of moles
481
486
  // for the molUnit
482
487
  return molAmt / molesFactor;
483
- }
488
+ } // end convertMassToMol
484
489
 
485
490
  /**
486
491
  * Calculates the number of units that would result from converting a unit
@@ -493,7 +498,7 @@ class Unit {
493
498
  * @param amt the quantity of this unit to be converted
494
499
  * @param massUnit the target/to unit for which the converted # is wanted
495
500
  * @param molecularWeight the molecular weight of the substance for which the
496
- * conversion is being made
501
+ * conversion is being made
497
502
  * @return the equivalent amount in massUnit
498
503
  */
499
504
  convertMolToMass(amt, massUnit, molecularWeight) {
@@ -515,7 +520,104 @@ class Unit {
515
520
  // divided by any effects of prefixes applied to the "to" unit, which
516
521
  // is assumed to be some form of a gram unit
517
522
  return massAmt / massUnit.magnitude_;
518
- }
523
+ } // end convertMolToMass
524
+
525
+ /**
526
+ * Converts equivalents to mass.
527
+ *
528
+ * @param {number} equivalents - The amount in equivalents to be converted.
529
+ * @param {object} targetUnit - The target/to unit for which the converted number is wanted.
530
+ * @param {number} molecularWeight - The molecular weight of the substance for which the conversion is being made.
531
+ * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made.
532
+ * @returns {number} - The equivalent mass in the specified mass unit.
533
+ */
534
+ convertEqToMass(equivalents, targetUnit, molecularWeight, charge) {
535
+ let standardMoleUnit = this._getUnitTables().getUnitByCode('mol');
536
+ const molAmount = this.convertEqToMol(equivalents, standardMoleUnit, charge);
537
+ return this.convertMolToMass(molAmount, targetUnit, molecularWeight);
538
+ } // end convertEqToMass
539
+
540
+ /**
541
+ * Converts mass to equivalents.
542
+ *
543
+ * @param {number} mass - The mass to be converted.
544
+ * @param {object} eqUnit - The target/to unit for which the converted number is wanted.
545
+ * @param {number} molecularWeight - The molecular weight of the substance for which the conversion is being made.
546
+ * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made.
547
+ * @returns {number} - The equivalent amount in the specified equivalent unit.
548
+ */
549
+ convertMassToEq(mass, eqUnit, molecularWeight, charge) {
550
+ // Calculate equivalent mass by dividing molecular weight by charge
551
+ let equivalentMass = molecularWeight / charge;
552
+ // Calculate equivalents by dividing mass by equivalent mass
553
+ let equivalents = mass / equivalentMass;
554
+ // Get Avogadro's number from the unit tables
555
+ let avogadroNumber = this._getUnitTables().getUnitByCode('mol').magnitude_;
556
+ // Calculate mole factor by dividing the magnitude of the equivalent unit by Avogadro's number
557
+ // eqUnit may have a prefix (e.g. meq) and we need to adjust for that
558
+ let moleFactor = eqUnit.magnitude_ / avogadroNumber;
559
+ // Adjust equivalents by dividing by the mole factor
560
+ let adjustedEquivalents = equivalents / moleFactor;
561
+ // Return the adjusted equivalents
562
+ return adjustedEquivalents;
563
+ } // end convertMassToEq
564
+
565
+ /**
566
+ * Checks if the given unit is an equivalent unit.
567
+ *
568
+ * Note: equivalent units are also be molar units, so a unit can return true for
569
+ * both isEquivalentUnit and isMolarUnit.
570
+ *
571
+ * @returns {boolean} - Returns true if the unit is an equivalent unit, false otherwise.
572
+ */
573
+ isEquivalentUnit() {
574
+ return this.equivalentExp_ !== 0;
575
+ } // end isEquivalentUnit
576
+
577
+ /**
578
+ * Checks if the given unit is a molar unit.
579
+ *
580
+ * @returns {boolean} - Returns true if the unit is a molar unit, false otherwise.
581
+ */
582
+ isMolarUnit() {
583
+ return this.moleExp_ !== 0;
584
+ } // end isMolarUnit
585
+
586
+ /**
587
+ * This function converts an equivalent amount to moles using the charge of the substance.
588
+ *
589
+ * @param {number} eqFromVal - The equivalent amount for which the conversion is being made.
590
+ * @param {object} molToUnit - The target unit for which the converted number is wanted.
591
+ * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made.
592
+ * @return {number} - The amount in moles.
593
+ */
594
+ convertEqToMol(eqFromVal, molToUnit, charge) {
595
+ // Check if molToUnit is a molar unit and eqFromVal is a eq unit
596
+ if (!molToUnit.isMolarUnit() || !this.isEquivalentUnit()) {
597
+ throw new Error("Invalid units for conversion of Eq to Mol. Please provide an equivalent and a molar unit.");
598
+ }
599
+ // The conversion from equivalents to moles is based on the principle that one equivalent is equal to 1/valencyFactor moles.
600
+ // The relative magnitude is accounted for via the current unit's magnitude (this.magnitude_) and the target unit's magnitude (molToUnit.magnitude_)
601
+ return eqFromVal * (this.magnitude_ / molToUnit.magnitude_) / charge;
602
+ } // end convertEqToMol
603
+
604
+ /**
605
+ * This function converts moles to equivalent amount using the charge of the substance.
606
+ *
607
+ * @param {number} molFromVal - The mole amount for which the conversion is being made
608
+ * @param {object} eqToUnit - The target unit for which the converted number is wanted
609
+ * @param {number} charge - The absolute value of the charge of the substance for which the conversion is being made
610
+ * @return {number} - The amount in equivalent
611
+ */
612
+ convertMolToEq(molFromVal, eqToUnit, charge) {
613
+ // Check if eqToUnit is an equivalent unit and molFromVal is a molar unit
614
+ if (!eqToUnit.isEquivalentUnit() || !this.isMolarUnit()) {
615
+ throw new Error("Invalid units for conversion of Mol to Eq. Please provide a molar and an equivalent unit.");
616
+ }
617
+ // The conversion from moles to equivalents is based on the principle that one equivalent is equal to 1/valencyFactor moles.
618
+ // The relative magnitude is accounted for via the current unit's magnitude (this.magnitude_) and the target unit's magnitude (eqToUnit.magnitude_)
619
+ return molFromVal * charge * (this.magnitude_ / eqToUnit.magnitude_);
620
+ } // end convertMolToEq
519
621
 
520
622
  /**
521
623
  * Mutates this unit into a unit on a ratio scale and converts a specified
@@ -860,6 +962,40 @@ class Unit {
860
962
  return commensurable;
861
963
  }
862
964
 
965
+ /**
966
+ * This function tests this unit against the unit passed in to see if the
967
+ * two are eq to mass commensurable. It assumes that one of the units
968
+ * is a eq-based unit and the other is a mass-based unit. It also assumes
969
+ * that the eq-based unit has a single eq unit in the numerator and that
970
+ * the mass-based unit has a single mass unit in the numerator. It does NOT
971
+ * check to validate those assumptions.
972
+ *
973
+ * The check is made by setting the dimension vector element corresponding
974
+ * to the base mass unit (gram) in the eq unit, and then comparing the
975
+ * two dimension vectors. If they match, the units are commensurable.
976
+ * Otherwise they are not.
977
+ *
978
+ * @param {Unit} unit2 the unit to be compared to this one
979
+ * @returns {boolean} boolean indicating commensurability
980
+ */
981
+ isEqMassCommensurable(unit2) {
982
+ let tabs = this._getUnitTables();
983
+ let d = tabs.getMassDimensionIndex();
984
+ let commensurable = false;
985
+ if (this.equivalentExp_ === 1 && unit2.equivalentExp_ === 0) {
986
+ let testDim = this.dim_.clone();
987
+ let curVal = testDim.getElementAt(d);
988
+ testDim.setElementAt(d, curVal + this.equivalentExp_);
989
+ commensurable = testDim.equals(unit2.dim_);
990
+ } else if (unit2.equivalentExp_ === 1 && this.equivalentExp_ === 0) {
991
+ let testDim = unit2.dim_.clone();
992
+ let curVal = testDim.getElementAt(d);
993
+ testDim.setElementAt(d, curVal + unit2.equivalentExp_);
994
+ commensurable = testDim.equals(this.dim_);
995
+ }
996
+ return commensurable;
997
+ }
998
+
863
999
  /**
864
1000
  * This returns the UnitTables singleton object. Including the require
865
1001
  * statement included here causes a circular dependency condition that