@lhncbc/ucum-lhc 4.1.8 → 4.2.0

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/ucumLhcUtils.js"],"names":["Ucum","require","UnitTables","UnitString","UcumLhcUtils","constructor","getInstance","unitsCount","ucumJsonDefs","loadJsonDefs","uStrParser_","useHTMLInMessages","use","undefined","useBraceMsgForEachString","validateUnitString","uStr","suggest","valConv","resp","getSpecifiedUnit","theUnit","retObj","csCode_","name_","guidance_","convertUnitTo","fromUnitCode","fromVal","toUnitCode","molecularWeight","returnObj","trim","push","isNaN","intUtils_","isNumericString","fromUnit","parseResp","concat","toUnit","convertFrom","moleExp_","Error","isMoleMassCommensurable","convertMolToMass","convertMassToMol","err","message","needMoleWeightMsg_","checkSynonyms","theSyn","getSynonyms","uName","utab","getUnitByCode","parseString","console","log","unshift","commensurablesList","fromName","retMsg","commUnits","length","dimVec","fromDim","getProperty","getUnitsByDimension"],"mappings":";;;;;;;AAOA;;AAIA;;;;;;AAXA;;;;;;AAMA,IAAIA,IAAI,GAAGC,OAAO,CAAC,aAAD,CAAP,CAAuBD,IAAlC;;AAEA,IAAIE,UAAU,GAAGD,OAAO,CAAC,iBAAD,CAAP,CAA2BC,UAA5C;;AACA,IAAIC,UAAU,GAAGF,OAAO,CAAC,iBAAD,CAAP,CAA2BE,UAA5C;;AAIA;;;AAGO,MAAMC,YAAN,CAAmB;AAExB;;;;;AAKAC,EAAAA,WAAW,GAAG;AAEV,QAAIH,UAAU,CAACI,WAAX,GAAyBC,UAAzB,OAA0C,CAA9C,EAAiD;AAE/C;AACAC,iCAAaC,YAAb;AACD,KANS,CAQV;AACA;;;AACA,SAAKC,WAAL,GAAmBP,UAAU,CAACG,WAAX,EAAnB;AAEH,GAnBuB,CAmBtB;;AAGF;;;;;;;;;;AAQAK,EAAAA,iBAAiB,CAACC,GAAD,EAAM;AACrB,QAAIA,GAAG,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AAhB;AACA,cAAID,GAAG,CAACC,OAAJ,KACF,qDADF,EAEEiB,MAAM,GAAG,IAAT;AACH;;AACD,YAAIA,MAAJ,EAAY;AACV,cAAIX,IAAI,GAAGpD,UAAU,CAACI,WAAX,EAAX;AACAyD,UAAAA,SAAS,GAAGT,IAAI,CAACc,mBAAL,CAAyBH,MAAzB,CAAZ;AACD;AACF,OApBE,CAoBD;;AACH,KAhC0B,CAgCzB;;;AACF,WAAO,CAACF,SAAD,EAAaD,MAAb,CAAP;AACD,GA5duB,CA4dtB;;;AA5dsB,C,CA8dxB;;AAGF;;;;;;;;;;;;;;;;;;AAcA1D,YAAY,CAACE,WAAb,GAA2B,YAAU;AACnC,SAAO,IAAIF,YAAJ,EAAP;AACD,CAFD","sourcesContent":["/**\n * This class provides a single point of access to the LHC UCUM utilities\n *\n * @author Lee Mericle\n *\n */\nvar Ucum = require('./config.js').Ucum;\nimport {ucumJsonDefs} from './ucumJsonDefs.js';\nvar UnitTables = require('./unitTables.js').UnitTables;\nvar UnitString = require('./unitString.js').UnitString;\n\nimport * as intUtils_ from \"./ucumInternalUtils.js\";\n\n/**\n * UCUM external utilities class\n */\nexport class UcumLhcUtils {\n\n /**\n * Constructor. This loads the json prefix and unit definitions if\n * they haven't been loaded already and creates itself as a singleton object.\n *\n */\n constructor() {\n\n if (UnitTables.getInstance().unitsCount() === 0) {\n\n // Load the prefix and unit objects\n ucumJsonDefs.loadJsonDefs();\n }\n\n // Get the UnitString parser that will be used with this instance\n // of the LHC Utilities\n this.uStrParser_ = UnitString.getInstance();\n\n } // end constructor\n\n\n /**\n * This method calls the useHTMLInMessages method on the UnitString\n * object. It should be called by web applications that use\n * these utilities.\n *\n * @param use flag indicating whether or not to use the braces message;\n * defaults to true\n */\n useHTMLInMessages(use) {\n if (use === undefined)\n use = true ;\n this.uStrParser_.useHTMLInMessages(use);\n }\n\n\n /**\n * This method calls the useBraceMsgForEachString method on the UnitString\n * object. It should be called by web applications where unit\n * strings are validated individually (as opposed to validating a whole\n * file of unit strings).\n *\n * @param use flag indicating whether or not to use the braces message;\n * defaults to true\n */\n useBraceMsgForEachString(use) {\n if (use === undefined)\n use = true ;\n this.uStrParser_.useBraceMsgForEachString(use);\n }\n\n\n /**\n * This method validates a unit string. It first checks to see if the\n * string passed in is a unit code that is found in the unit codes table.\n * If it is not found it parses the string to see if it resolves to a\n * valid unit string.\n *\n * If a valid unit cannot be found, the string is tested for some common\n * errors, such as missing brackets or a missing multiplication operator.\n * If found, the error is reported in the messages array that is returned.\n *\n * If a valid unit cannot be found and an error cannot be discerned, this\n * may return, if requested, a list of suggested units in the messages\n * array that is returned. Suggestions are based on matching the expression\n * with unit names and synonyms.\n *\n * @param uStr the string to be validated\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @param valConv a string indicating if this validation request was initiated\n * by a validation task ('validate') or a conversion task ('convert'),\n * used only for the demo code, and the default is 'Validator' if the\n * parameter is not specified;\n * @returns an object with five properties:\n * 'status' will be 'valid' (the uStr is a valid UCUM code), 'invalid'\n * (the uStr is not a valid UCUM code, and substitutions or\n * suggestions may or may not be returned, depending on what was\n * requested and found); or 'error' (an input or programming error\n * occurred);\n * 'ucumCode' the valid ucum code, which may differ from what was passed\n * in (e.g., if 'Gauss' is passed in, this will contain 'G') OR null if\n * the string was flagged as invalid or an error occurred;\n * 'msg' is an array of one or more messages, if the string is invalid or\n * an error occurred, indicating the problem, or an explanation of a\n * substitution such as the substitution of 'G' for 'Gauss', or\n * an empty array if no messages were generated;\n * 'unit' which is null if no unit is found, or a hash for a unit found:\n * 'code' is the unit's ucum code (G in the above example;\n * 'name' is the unit's name (Gauss in the above example); and\n * 'guidance' is the unit's guidance/description data; and\n * 'suggestions' if suggestions were requested and found, this is an array\n * of one or more hash objects. Each hash contains three elements:\n * 'msg' which is a message indicating what part of the uStr input\n * parameter the suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions are\n * for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were requested and found, this property is not\n * returned.\n */\n validateUnitString(uStr, suggest, valConv) {\n\n if (suggest === undefined)\n suggest = false ;\n\n if (valConv === undefined)\n valConv = 'validate' ;\n\n let resp = this.getSpecifiedUnit(uStr, valConv, suggest);\n let theUnit = resp['unit'];\n let retObj = {};\n if (!theUnit) {\n retObj = {'status': (!resp['origString'] || resp['origString'] === null) ?\n 'error' : 'invalid',\n 'ucumCode': null};\n }\n else {\n retObj = {'status': resp['origString'] === uStr ? 'valid': 'invalid',\n 'ucumCode': resp['origString'],\n 'unit': {'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_ }};\n }\n if (resp['suggestions']) {\n retObj['suggestions'] = resp['suggestions'];\n }\n retObj['msg'] = resp['retMsg'];\n return retObj;\n\n } // end validateUnitString\n\n\n /**\n * This method converts one unit to another\n *\n * @param fromUnitCode the unit code/expression/string of the unit to be converted\n * @param fromVal the number of \"from\" units to be converted to \"to\" units\n * @param toUnitCode the unit code/expression/string of the unit that the from\n * field is to be converted to\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @param molecularWeight the molecular weight of the substance in question\n * when a conversion is being requested from mass to moles and vice versa.\n * This is required when one of the units represents a value in moles. It is\n * ignored if neither unit includes a measurement in moles.\n * @returns a hash with six elements:\n * 'status' that will be: 'succeeded' if the conversion was successfully\n * calculated; 'failed' if the conversion could not be made, e.g., if\n * the units are not commensurable; or 'error' if an error occurred;\n * 'toVal' the numeric value indicating the conversion amount, or null\n * if the conversion failed (e.g., if the units are not commensurable);\n * 'msg' is an array message, if the string is invalid or an error occurred,\n * indicating the problem, or an explanation of a substitution such as\n * the substitution of 'G' for 'Gauss', or an empty array if no\n * messages were generated;\n * 'suggestions' if suggestions were requested and found, this is a hash\n * that contains at most two elements:\n * 'from' which, if the fromUnitCode input parameter or one or more of\n * its components could not be found, is an array one or more hash\n * objects. Each hash contains three elements:\n * 'msg' which is a message indicating what unit expression the\n * suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions\n * are for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were found for the fromUnitCode this element\n * will not be included.\n * 'to' which, if the \"to\" unit expression or one or more of its\n * components could not be found, is an array one or more hash objects. Each hash\n * contains three elements:\n * 'msg' which is a message indicating what toUnitCode input\n * parameter the suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions\n * are for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were found for the toUnitCode this element\n * will not be included.\n * No 'suggestions' element will be included in the returned hash\n * object if none were found, whether or not they were requested.\n * 'fromUnit' the unit object for the fromUnitCode passed in; returned\n * in case it's needed for additional data from the object; and\n * 'toUnit' the unit object for the toUnitCode passed in; returned\n * in case it's needed for additional data from the object.\n */\n convertUnitTo(fromUnitCode, fromVal, toUnitCode, suggest, molecularWeight) {\n if (suggest === undefined)\n suggest = false ;\n\n if (molecularWeight === undefined)\n molecularWeight = null ;\n\n let returnObj = {'status' : 'failed',\n 'toVal' : null,\n 'msg' : []} ;\n\n if (fromUnitCode) {\n fromUnitCode = fromUnitCode.trim();\n }\n if (!fromUnitCode || fromUnitCode == '') {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"from\" unit expression specified.');\n }\n if (fromVal === null || isNaN(fromVal) || (typeof fromVal !== 'number' &&\n !intUtils_.isNumericString(fromVal))) {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"from\" value, or an invalid \"from\" value, ' +\n 'was specified.');\n }\n if (toUnitCode) {\n toUnitCode = toUnitCode.trim();\n }\n if (!toUnitCode || toUnitCode == '') {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"to\" unit expression specified.');\n }\n if (returnObj['status'] !== 'error') {\n try {\n let fromUnit = null;\n\n let parseResp = this.getSpecifiedUnit(fromUnitCode, 'convert', suggest);\n fromUnit = parseResp['unit'];\n if (parseResp['retMsg'])\n returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);\n if (parseResp['suggestions']) {\n returnObj['suggestions'] = {};\n returnObj['suggestions']['from'] = parseResp['suggestions'];\n }\n if (!fromUnit) {\n returnObj['msg'].push(`Unable to find a unit for ${fromUnitCode}, ` +\n `so no conversion could be performed.`);\n }\n\n let toUnit = null;\n parseResp = this.getSpecifiedUnit(toUnitCode, 'convert', suggest);\n toUnit = parseResp['unit'];\n if (parseResp['retMsg'])\n returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);\n if (parseResp['suggestions']) {\n if (!returnObj['suggestions'])\n returnObj['suggestions'] = {} ;\n returnObj['suggestions']['to'] = parseResp['suggestions'];\n }\n if (!toUnit) {\n returnObj['msg'].push(`Unable to find a unit for ${toUnitCode}, ` +\n `so no conversion could be performed.`);\n }\n\n if (fromUnit && toUnit) {\n try {\n // if no molecular weight was specified perform a normal conversion\n if (!molecularWeight) {\n returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);\n }\n else {\n if (fromUnit.moleExp_ !== 0 && toUnit.moleExp_ !== 0) {\n throw(new Error('A molecular weight was specified ' +\n 'but a mass <-> mole conversion cannot be executed for two ' +\n 'mole-based units. No conversion was attempted.'));\n }\n if (fromUnit.moleExp_ === 0 && toUnit.moleExp_ === 0) {\n throw(new Error('A molecular weight was specified ' +\n 'but a mass <-> mole conversion cannot be executed when ' +\n 'neither unit is mole-based. No conversion was attempted.'));\n }\n if (!fromUnit.isMoleMassCommensurable(toUnit)) {\n throw(new Error(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`));\n }\n\n // if the \"from\" unit is a mole-based unit, assume a mole to mass\n // request\n if (fromUnit.moleExp_ !== 0) {\n returnObj['toVal'] =\n fromUnit.convertMolToMass(fromVal, toUnit, molecularWeight);\n }\n // else the \"to\" unit must be the mole-based unit, so assume a\n // mass to mole request\n else {\n returnObj['toVal'] =\n fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight);\n }\n } // end if a molecular weight was specified\n\n // if an error hasn't been thrown - either from convertFrom or here,\n // set the return object to show success\n returnObj['status'] = 'succeeded';\n returnObj['fromUnit'] = fromUnit;\n returnObj['toUnit'] = toUnit;\n }\n catch (err) {\n returnObj['status'] = 'failed';\n returnObj['msg'].push(err.message);\n }\n\n\n } // end if we have the from and to units\n }\n catch (err) {\n if (err.message == Ucum.needMoleWeightMsg_)\n returnObj['status'] = 'failed';\n else\n returnObj['status'] = 'error';\n returnObj['msg'].push(err.message);\n }\n }\n\n return returnObj ;\n\n } // end convertUnitTo\n\n\n /**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for\n * @returns a hash with up to three elements:\n * 'status' contains the status of the request, which can be 'error',\n * 'failed' or succeeded';\n * 'msg' which contains a message for an error or if no units were found; and\n * 'units' which is an array that contains one hash for each unit found:\n * 'code' is the unit's csCode_\n * 'name' is the unit's name_\n * 'guidance' is the unit's guidance_\n *\n */\n checkSynonyms(theSyn) {\n let retObj = {} ;\n if (theSyn === undefined || theSyn === null) {\n retObj['status'] = 'error';\n retObj['msg'] = 'No term specified for synonym search.'\n }\n else {\n retObj = intUtils_.getSynonyms(theSyn);\n } // end if a search synonym was supplied\n\n return retObj ;\n\n } // end checkSynonyms\n\n\n /**\n * This method parses a unit string to get (or try to get) the unit\n * represented by the string. It returns an error message if no string was specified\n * or if any errors were encountered trying to get the unit.\n *\n * @param uName the expression/string representing the unit\n * @param valConv indicates what type of request this is for - a request to\n * validate (pass in 'validate') or a request to convert (pass in 'convert')\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @returns a hash containing:\n * 'unit' the unit object (or null if there were problems creating the\n * unit);\n * 'origString' the possibly updated unit string passed in;\n * 'retMsg' an array of user messages (informational, error or warning) if\n * any were generated (IF any were generated, otherwise will be an\n * empty array); and\n * 'suggestions' is an array of 1 or more hash objects. Each hash\n * contains three elements:\n * 'msg' which is a message indicating what unit expression the\n * suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions are\n * for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * The return hash will not contain a suggestions array if a valid unit\n * was found or if suggestions were not requested and found.\n */\n getSpecifiedUnit(uName, valConv, suggest) {\n\n if (suggest === undefined)\n suggest = false ;\n\n let retObj = {};\n retObj['retMsg'] = [];\n\n if (!uName) {\n retObj['retMsg'].push('No unit string specified.');\n }\n else {\n let utab = UnitTables.getInstance();\n uName = uName.trim();\n\n // go ahead and just try using the name as the code. This may or may not\n // work, but if it does, it cuts out a lot of parsing.\n let theUnit = utab.getUnitByCode(uName);\n\n // If we found it, set the returned unit string to what was passed in;\n // otherwise try parsing as a unit string\n if (theUnit) {\n retObj['unit'] = theUnit ;\n retObj['origString'] = uName;\n }\n else {\n try {\n let resp = this.uStrParser_.parseString(uName, valConv, suggest);\n retObj['unit'] = resp[0];\n retObj['origString'] = resp[1];\n if (resp[2])\n retObj['retMsg'] = resp[2];\n retObj['suggestions'] = resp[3];\n }\n catch (err) {\n console.log(`Unit requested for unit string ${uName}.` +\n 'request unsuccessful; error thrown = ' + err.message);\n retObj['retMsg'].unshift(`${uName} is not a valid unit. ` +\n `${err.message}`);\n }\n } // end if the unit was not found as a unit name\n } // end if a unit expression was specified\n\n return retObj;\n\n } // end getSpecifiedUnit\n\n\n /**\n * This method retrieves a list of units commensurable, i.e., that can be\n * converted from and to, a specified unit. Returns an error if the \"from\"\n * unit cannot be found.\n *\n * @param fromName the name/unit string of the \"from\" unit\n * @returns an array containing two elements;\n * first element is the list of commensurable units if any were found\n * second element is an error message if the \"from\" unit is not found\n */\n commensurablesList(fromName) {\n\n let retMsg = [];\n let commUnits = null ;\n let parseResp = this.getSpecifiedUnit(fromName, 'validate', false);\n let fromUnit = parseResp['unit'];\n if (parseResp['retMsg'].length > 0)\n retMsg = parseResp['retMsg'] ;\n if (!fromUnit) {\n retMsg.push(`Could not find unit ${fromName}.`);\n }\n else {\n let dimVec = null ;\n let fromDim = fromUnit.getProperty('dim_');\n if (!fromDim) {\n retMsg.push('No commensurable units were found for ' + fromName) ;\n }\n else {\n try {\n dimVec = fromDim.getProperty('dimVec_');\n }\n catch (err) {\n retMsg.push(err.message);\n if (err.message ===\n \"Dimension does not have requested property(dimVec_)\")\n dimVec = null;\n }\n if (dimVec) {\n let utab = UnitTables.getInstance();\n commUnits = utab.getUnitsByDimension(dimVec);\n }\n } // end if the from unit has a dimension vector\n } // end if we found a \"from\" unit\n return [commUnits , retMsg];\n } // end commensurablesList\n\n} // end UcumLhcUtils class\n\n\n/**\n * This function exists ONLY until the original UcumLhcUtils constructor\n * is called for the first time. It's defined here in case getInstance\n * is called before the constructor. This calls the constructor.\n *\n * The constructor redefines the getInstance function to return the\n * singleton UcumLhcUtils object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * NO LONGER TRUE - not implemented as a singleton. This method retained to\n * avoid problems with calls to it that exist throughout the code.\n *\n * @return the (formerly singleton) UcumLhcUtils object.\n */\nUcumLhcUtils.getInstance = function(){\n return new UcumLhcUtils();\n} ;\n\n\n\n\n"],"file":"ucumLhcUtils.js"}
1
+ {"version":3,"sources":["../source/ucumLhcUtils.js"],"names":["Ucum","require","UnitTables","UnitString","UcumLhcUtils","constructor","getInstance","unitsCount","ucumJsonDefs","loadJsonDefs","uStrParser_","useHTMLInMessages","use","undefined","useBraceMsgForEachString","validateUnitString","uStr","suggest","valConv","resp","getSpecifiedUnit","theUnit","retObj","csCode_","name_","guidance_","convertUnitTo","fromUnitCode","fromVal","toUnitCode","molecularWeight","returnObj","trim","push","isNaN","intUtils_","isNumericString","fromUnit","parseResp","concat","toUnit","convertFrom","moleExp_","Error","isMoleMassCommensurable","convertMolToMass","convertMassToMol","err","message","needMoleWeightMsg_","convertToBaseUnits","inputUnitLookup","unit","msg","retMsg","length","isArbitrary_","unitToExp","dimVec","dim_","dimVec_","baseUnitString","dimVecIndexToBaseUnit","dimVecIndexToBaseUnit_","i","len","exp","retUnitLookup","retUnit","magnitude","e","toString","fromUnitIsSpecial","isSpecial_","checkSynonyms","theSyn","getSynonyms","uName","utab","getUnitByCode","parseString","console","log","unshift","commensurablesList","fromName","commUnits","fromDim","getProperty","getUnitsByDimension"],"mappings":";;;;;;;AAOA;;AAIA;;;;;;AAXA;;;;;;AAMA,IAAIA,IAAI,GAAGC,OAAO,CAAC,aAAD,CAAP,CAAuBD,IAAlC;;AAEA,IAAIE,UAAU,GAAGD,OAAO,CAAC,iBAAD,CAAP,CAA2BC,UAA5C;;AACA,IAAIC,UAAU,GAAGF,OAAO,CAAC,iBAAD,CAAP,CAA2BE,UAA5C;;AAIA;;;AAGO,MAAMC,YAAN,CAAmB;AAExB;;;;;AAKAC,EAAAA,WAAW,GAAG;AAEV,QAAIH,UAAU,CAACI,WAAX,GAAyBC,UAAzB,OAA0C,CAA9C,EAAiD;AAE/C;AACAC,iCAAaC,YAAb;AACD,KANS,CAQV;AACA;;;AACA,SAAKC,WAAL,GAAmBP,UAAU,CAACG,WAAX,EAAnB;AAEH,GAnBuB,CAmBtB;;AAGF;;;;;;;;;;AAQAK,EAAAA,iBAAiB,CAACC,GAAD,EAAM;AACrB,QAAIA,GAAG,KAAKC,SAAZ,EACED,GAAG,GAAG,IAAN;AACF,SAAKF,WAAL,CAAiBC,iBAAjB,CAAmCC,GAAnC;AACD;AAGD;;;;;;;;;;;AASAE,EAAAA,wBAAwB,CAACF,GAAD,EAAM;AAC5B,QAAIA,GAAG,KAAKC,SAAZ,EACED,GAAG,GAAG,IAAN;AACF,SAAKF,WAAL,CAAiBI,wBAAjB,CA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QAAD,CAAT,CAAoBiB,MAApB,GAA6B,CAAjC,EACED,MAAM,GAAGhB,SAAS,CAAC,QAAD,CAAlB;;AACF,QAAI,CAACD,QAAL,EAAe;AACbiB,MAAAA,MAAM,CAACrB,IAAP,CAAa,uBAAsBoD,QAAS,GAA5C;AACD,KAFD,MAGK;AACH,UAAI3B,MAAM,GAAG,IAAb;AACA,UAAI6B,OAAO,GAAGlD,QAAQ,CAACmD,WAAT,CAAqB,MAArB,CAAd;;AACA,UAAI,CAACD,OAAL,EAAc;AACZjC,QAAAA,MAAM,CAACrB,IAAP,CAAY,2CAA2CoD,QAAvD;AACD,OAFD,MAGK;AACH,YAAI;AACF3B,UAAAA,MAAM,GAAG6B,OAAO,CAACC,WAAR,CAAoB,SAApB,CAAT;AACD,SAFD,CAGA,OAAOzC,GAAP,EAAY;AACVO,UAAAA,MAAM,CAACrB,IAAP,CAAYc,GAAG,CAACC,OAAhB;AACA,cAAID,GAAG,CAACC,OAAJ,KACF,qDADF,EAEEU,MAAM,GAAG,IAAT;AACH;;AACD,YAAIA,MAAJ,EAAY;AACV,cAAIoB,IAAI,GAAG5E,UAAU,CAACI,WAAX,EAAX;AACAgF,UAAAA,SAAS,GAAGR,IAAI,CAACW,mBAAL,CAAyB/B,MAAzB,CAAZ;AACD;AACF,OApBE,CAoBD;;AACH,KAhC0B,CAgCzB;;;AACF,WAAO,CAAC4B,SAAD,EAAahC,MAAb,CAAP;AACD,GAliBuB,CAkiBtB;;;AAliBsB,C,CAoiBxB;;AAGF;;;;;;;;;;;;;;;;;;AAcAlD,YAAY,CAACE,WAAb,GAA2B,YAAU;AACnC,SAAO,IAAIF,YAAJ,EAAP;AACD,CAFD","sourcesContent":["/**\n * This class provides a single point of access to the LHC UCUM utilities\n *\n * @author Lee Mericle\n *\n */\nvar Ucum = require('./config.js').Ucum;\nimport {ucumJsonDefs} from './ucumJsonDefs.js';\nvar UnitTables = require('./unitTables.js').UnitTables;\nvar UnitString = require('./unitString.js').UnitString;\n\nimport * as intUtils_ from \"./ucumInternalUtils.js\";\n\n/**\n * UCUM external utilities class\n */\nexport class UcumLhcUtils {\n\n /**\n * Constructor. This loads the json prefix and unit definitions if\n * they haven't been loaded already and creates itself as a singleton object.\n *\n */\n constructor() {\n\n if (UnitTables.getInstance().unitsCount() === 0) {\n\n // Load the prefix and unit objects\n ucumJsonDefs.loadJsonDefs();\n }\n\n // Get the UnitString parser that will be used with this instance\n // of the LHC Utilities\n this.uStrParser_ = UnitString.getInstance();\n\n } // end constructor\n\n\n /**\n * This method calls the useHTMLInMessages method on the UnitString\n * object. It should be called by web applications that use\n * these utilities.\n *\n * @param use flag indicating whether or not to use the braces message;\n * defaults to true\n */\n useHTMLInMessages(use) {\n if (use === undefined)\n use = true ;\n this.uStrParser_.useHTMLInMessages(use);\n }\n\n\n /**\n * This method calls the useBraceMsgForEachString method on the UnitString\n * object. It should be called by web applications where unit\n * strings are validated individually (as opposed to validating a whole\n * file of unit strings).\n *\n * @param use flag indicating whether or not to use the braces message;\n * defaults to true\n */\n useBraceMsgForEachString(use) {\n if (use === undefined)\n use = true ;\n this.uStrParser_.useBraceMsgForEachString(use);\n }\n\n\n /**\n * This method validates a unit string. It first checks to see if the\n * string passed in is a unit code that is found in the unit codes table.\n * If it is not found it parses the string to see if it resolves to a\n * valid unit string.\n *\n * If a valid unit cannot be found, the string is tested for some common\n * errors, such as missing brackets or a missing multiplication operator.\n * If found, the error is reported in the messages array that is returned.\n *\n * If a valid unit cannot be found and an error cannot be discerned, this\n * may return, if requested, a list of suggested units in the messages\n * array that is returned. Suggestions are based on matching the expression\n * with unit names and synonyms.\n *\n * @param uStr the string to be validated\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @param valConv a string indicating if this validation request was initiated\n * by a validation task ('validate') or a conversion task ('convert'),\n * used only for the demo code, and the default is 'Validator' if the\n * parameter is not specified;\n * @returns an object with five properties:\n * 'status' will be 'valid' (the uStr is a valid UCUM code), 'invalid'\n * (the uStr is not a valid UCUM code, and substitutions or\n * suggestions may or may not be returned, depending on what was\n * requested and found); or 'error' (an input or programming error\n * occurred);\n * 'ucumCode' the valid ucum code, which may differ from what was passed\n * in (e.g., if 'Gauss' is passed in, this will contain 'G') OR null if\n * the string was flagged as invalid or an error occurred;\n * 'msg' is an array of one or more messages, if the string is invalid or\n * an error occurred, indicating the problem, or an explanation of a\n * substitution such as the substitution of 'G' for 'Gauss', or\n * an empty array if no messages were generated;\n * 'unit' which is null if no unit is found, or a hash for a unit found:\n * 'code' is the unit's ucum code (G in the above example;\n * 'name' is the unit's name (Gauss in the above example); and\n * 'guidance' is the unit's guidance/description data; and\n * 'suggestions' if suggestions were requested and found, this is an array\n * of one or more hash objects. Each hash contains three elements:\n * 'msg' which is a message indicating what part of the uStr input\n * parameter the suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions are\n * for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were requested and found, this property is not\n * returned.\n */\n validateUnitString(uStr, suggest, valConv) {\n\n if (suggest === undefined)\n suggest = false ;\n\n if (valConv === undefined)\n valConv = 'validate' ;\n\n let resp = this.getSpecifiedUnit(uStr, valConv, suggest);\n let theUnit = resp['unit'];\n let retObj = {};\n if (!theUnit) {\n retObj = {'status': (!resp['origString'] || resp['origString'] === null) ?\n 'error' : 'invalid',\n 'ucumCode': null};\n }\n else {\n retObj = {'status': resp['origString'] === uStr ? 'valid': 'invalid',\n 'ucumCode': resp['origString'],\n 'unit': {'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_ }};\n }\n if (resp['suggestions']) {\n retObj['suggestions'] = resp['suggestions'];\n }\n retObj['msg'] = resp['retMsg'];\n return retObj;\n\n } // end validateUnitString\n\n\n /**\n * This method converts one unit to another\n *\n * @param fromUnitCode the unit code/expression/string of the unit to be converted\n * @param fromVal the number of \"from\" units to be converted to \"to\" units\n * @param toUnitCode the unit code/expression/string of the unit that the from\n * field is to be converted to\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @param molecularWeight the molecular weight of the substance in question\n * when a conversion is being requested from mass to moles and vice versa.\n * This is required when one of the units represents a value in moles. It is\n * ignored if neither unit includes a measurement in moles.\n * @returns a hash with six elements:\n * 'status' that will be: 'succeeded' if the conversion was successfully\n * calculated; 'failed' if the conversion could not be made, e.g., if\n * the units are not commensurable; or 'error' if an error occurred;\n * 'toVal' the numeric value indicating the conversion amount, or null\n * if the conversion failed (e.g., if the units are not commensurable);\n * 'msg' is an array message, if the string is invalid or an error occurred,\n * indicating the problem, or an explanation of a substitution such as\n * the substitution of 'G' for 'Gauss', or an empty array if no\n * messages were generated;\n * 'suggestions' if suggestions were requested and found, this is a hash\n * that contains at most two elements:\n * 'from' which, if the fromUnitCode input parameter or one or more of\n * its components could not be found, is an array one or more hash\n * objects. Each hash contains three elements:\n * 'msg' which is a message indicating what unit expression the\n * suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions\n * are for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were found for the fromUnitCode this element\n * will not be included.\n * 'to' which, if the \"to\" unit expression or one or more of its\n * components could not be found, is an array one or more hash objects. Each hash\n * contains three elements:\n * 'msg' which is a message indicating what toUnitCode input\n * parameter the suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions\n * are for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * If no suggestions were found for the toUnitCode this element\n * will not be included.\n * No 'suggestions' element will be included in the returned hash\n * object if none were found, whether or not they were requested.\n * 'fromUnit' the unit object for the fromUnitCode passed in; returned\n * in case it's needed for additional data from the object; and\n * 'toUnit' the unit object for the toUnitCode passed in; returned\n * in case it's needed for additional data from the object.\n */\n convertUnitTo(fromUnitCode, fromVal, toUnitCode, suggest, molecularWeight) {\n if (suggest === undefined)\n suggest = false ;\n\n if (molecularWeight === undefined)\n molecularWeight = null ;\n\n let returnObj = {'status' : 'failed',\n 'toVal' : null,\n 'msg' : []} ;\n\n if (fromUnitCode) {\n fromUnitCode = fromUnitCode.trim();\n }\n if (!fromUnitCode || fromUnitCode == '') {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"from\" unit expression specified.');\n }\n if (fromVal === null || isNaN(fromVal) || (typeof fromVal !== 'number' &&\n !intUtils_.isNumericString(fromVal))) {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"from\" value, or an invalid \"from\" value, ' +\n 'was specified.');\n }\n if (toUnitCode) {\n toUnitCode = toUnitCode.trim();\n }\n if (!toUnitCode || toUnitCode == '') {\n returnObj['status'] = 'error';\n returnObj['msg'].push('No \"to\" unit expression specified.');\n }\n if (returnObj['status'] !== 'error') {\n try {\n let fromUnit = null;\n\n let parseResp = this.getSpecifiedUnit(fromUnitCode, 'convert', suggest);\n fromUnit = parseResp['unit'];\n if (parseResp['retMsg'])\n returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);\n if (parseResp['suggestions']) {\n returnObj['suggestions'] = {};\n returnObj['suggestions']['from'] = parseResp['suggestions'];\n }\n if (!fromUnit) {\n returnObj['msg'].push(`Unable to find a unit for ${fromUnitCode}, ` +\n `so no conversion could be performed.`);\n }\n\n let toUnit = null;\n parseResp = this.getSpecifiedUnit(toUnitCode, 'convert', suggest);\n toUnit = parseResp['unit'];\n if (parseResp['retMsg'])\n returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);\n if (parseResp['suggestions']) {\n if (!returnObj['suggestions'])\n returnObj['suggestions'] = {} ;\n returnObj['suggestions']['to'] = parseResp['suggestions'];\n }\n if (!toUnit) {\n returnObj['msg'].push(`Unable to find a unit for ${toUnitCode}, ` +\n `so no conversion could be performed.`);\n }\n\n if (fromUnit && toUnit) {\n try {\n // if no molecular weight was specified perform a normal conversion\n if (!molecularWeight) {\n returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);\n }\n else {\n if (fromUnit.moleExp_ !== 0 && toUnit.moleExp_ !== 0) {\n throw(new Error('A molecular weight was specified ' +\n 'but a mass <-> mole conversion cannot be executed for two ' +\n 'mole-based units. No conversion was attempted.'));\n }\n if (fromUnit.moleExp_ === 0 && toUnit.moleExp_ === 0) {\n throw(new Error('A molecular weight was specified ' +\n 'but a mass <-> mole conversion cannot be executed when ' +\n 'neither unit is mole-based. No conversion was attempted.'));\n }\n if (!fromUnit.isMoleMassCommensurable(toUnit)) {\n throw(new Error(`Sorry. ${fromUnitCode} cannot be ` +\n `converted to ${toUnitCode}.`));\n }\n\n // if the \"from\" unit is a mole-based unit, assume a mole to mass\n // request\n if (fromUnit.moleExp_ !== 0) {\n returnObj['toVal'] =\n fromUnit.convertMolToMass(fromVal, toUnit, molecularWeight);\n }\n // else the \"to\" unit must be the mole-based unit, so assume a\n // mass to mole request\n else {\n returnObj['toVal'] =\n fromUnit.convertMassToMol(fromVal, toUnit, molecularWeight);\n }\n } // end if a molecular weight was specified\n\n // if an error hasn't been thrown - either from convertFrom or here,\n // set the return object to show success\n returnObj['status'] = 'succeeded';\n returnObj['fromUnit'] = fromUnit;\n returnObj['toUnit'] = toUnit;\n }\n catch (err) {\n returnObj['status'] = 'failed';\n returnObj['msg'].push(err.message);\n }\n\n\n } // end if we have the from and to units\n }\n catch (err) {\n if (err.message == Ucum.needMoleWeightMsg_)\n returnObj['status'] = 'failed';\n else\n returnObj['status'] = 'error';\n returnObj['msg'].push(err.message);\n }\n }\n\n return returnObj ;\n\n } // end convertUnitTo\n\n\n /**\n * Converts the given unit string into its base units, their exponents, and\n * a magnitude, and returns that data.\n * @param fromUnit the unit string to be converted to base units information\n * @param fromVal the number of \"from\" units to be converted\n * @returns an object with the properties:\n * 'msg': an array of one or more messages, if the string is invalid or\n * an error occurred, indicating the problem, or a suggestion of a\n * substitution such as the substitution of 'G' for 'Gauss', or\n * an empty array if no messages were generated. If this is not empty,\n * no other information will be returned.\n * 'magnitude': the new value when fromVal units of fromUnits is expressed in the base units.\n * 'fromUnitIsSpecial': whether the input unit fromUnit is a \"special unit\"\n * as defined in UCUM. This means there is some function applied to convert\n * between fromUnit and the base units, so the returned magnitude is likely not\n * useful as a scale factor for other conversions (i.e., it only has validity\n * and usefulness for the input values that produced it).\n * 'unitToExp': a map of base units in uStr to their exponent\n */\n convertToBaseUnits(fromUnit, fromVal) {\n let inputUnitLookup = this.getSpecifiedUnit(fromUnit, 'validate');\n let retObj = {};\n let unit = inputUnitLookup.unit;\n retObj.msg = inputUnitLookup.retMsg || [];\n if (!unit) {\n if (inputUnitLookup.retMsg?.length == 0)\n retObj.msg.push('Could not find unit information for '+fromUnit);\n }\n else if (unit.isArbitrary_) {\n retObj.msg.push('Arbitrary units cannot be converted to base units or other units.');\n }\n else if (retObj.msg.length == 0) {\n let unitToExp = {};\n let dimVec = unit.dim_?.dimVec_\n let baseUnitString = '1';\n if (dimVec) {\n let dimVecIndexToBaseUnit = UnitTables.getInstance().dimVecIndexToBaseUnit_;\n for (let i=0, len=dimVec.length; i<len; ++i) {\n let exp = dimVec[i];\n if (exp) {\n unitToExp[dimVecIndexToBaseUnit[i]] = exp;\n baseUnitString += '.' + dimVecIndexToBaseUnit[i] + exp;\n }\n }\n }\n\n // The unit might have a conversion function, which has to be applied; we\n // cannot just assume unit_.magnitude_ is the magnitude in base units.\n let retUnitLookup = this.getSpecifiedUnit(baseUnitString, 'validate');\n // There should not be any error in retUnitLookup, unless there is a bug.\n let retUnit = retUnitLookup.unit;\n if (!retUnit && retUnitLookup.retMsg?.length == 0)\n retObj.msg.push('Unable construct base unit string; tried '+baseUnitString);\n else {\n try {\n retObj.magnitude = retUnit.convertFrom(fromVal, unit);\n }\n catch (e) {\n retObj.msg.push(e.toString());\n }\n if (retObj.msg.length == 0) {\n retObj.unitToExp = unitToExp;\n retObj.fromUnitIsSpecial = unit.isSpecial_;\n }\n }\n }\n return retObj;\n }\n\n\n /**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for\n * @returns a hash with up to three elements:\n * 'status' contains the status of the request, which can be 'error',\n * 'failed' or succeeded';\n * 'msg' which contains a message for an error or if no units were found; and\n * 'units' which is an array that contains one hash for each unit found:\n * 'code' is the unit's csCode_\n * 'name' is the unit's name_\n * 'guidance' is the unit's guidance_\n *\n */\n checkSynonyms(theSyn) {\n let retObj = {} ;\n if (theSyn === undefined || theSyn === null) {\n retObj['status'] = 'error';\n retObj['msg'] = 'No term specified for synonym search.'\n }\n else {\n retObj = intUtils_.getSynonyms(theSyn);\n } // end if a search synonym was supplied\n\n return retObj ;\n\n } // end checkSynonyms\n\n\n /**\n * This method parses a unit string to get (or try to get) the unit\n * represented by the string. It returns an error message if no string was specified\n * or if any errors were encountered trying to get the unit.\n *\n * @param uName the expression/string representing the unit\n * @param valConv indicates what type of request this is for - a request to\n * validate (pass in 'validate') or a request to convert (pass in 'convert')\n * @param suggest a boolean to indicate whether or not suggestions are\n * requested for a string that cannot be resolved to a valid unit;\n * true indicates suggestions are wanted; false indicates they are not,\n * and is the default if the parameter is not specified;\n * @returns a hash containing:\n * 'unit' the unit object (or null if there were problems creating the\n * unit);\n * 'origString' the possibly updated unit string passed in;\n * 'retMsg' an array of user messages (informational, error or warning) if\n * any were generated (IF any were generated, otherwise will be an\n * empty array); and\n * 'suggestions' is an array of 1 or more hash objects. Each hash\n * contains three elements:\n * 'msg' which is a message indicating what unit expression the\n * suggestions are for;\n * 'invalidUnit' which is the unit expression the suggestions are\n * for; and\n * 'units' which is an array of data for each suggested unit found.\n * Each array will contain the unit code, the unit name and the\n * unit guidance (if any).\n * The return hash will not contain a suggestions array if a valid unit\n * was found or if suggestions were not requested and found.\n */\n getSpecifiedUnit(uName, valConv, suggest) {\n\n if (suggest === undefined)\n suggest = false ;\n\n let retObj = {};\n retObj['retMsg'] = [];\n\n if (!uName) {\n retObj['retMsg'].push('No unit string specified.');\n }\n else {\n let utab = UnitTables.getInstance();\n uName = uName.trim();\n\n // go ahead and just try using the name as the code. This may or may not\n // work, but if it does, it cuts out a lot of parsing.\n let theUnit = utab.getUnitByCode(uName);\n\n // If we found it, set the returned unit string to what was passed in;\n // otherwise try parsing as a unit string\n if (theUnit) {\n retObj['unit'] = theUnit ;\n retObj['origString'] = uName;\n }\n else {\n try {\n let resp = this.uStrParser_.parseString(uName, valConv, suggest);\n retObj['unit'] = resp[0];\n retObj['origString'] = resp[1];\n if (resp[2])\n retObj['retMsg'] = resp[2];\n retObj['suggestions'] = resp[3];\n }\n catch (err) {\n console.log(`Unit requested for unit string ${uName}.` +\n 'request unsuccessful; error thrown = ' + err.message);\n retObj['retMsg'].unshift(`${uName} is not a valid unit. ` +\n `${err.message}`);\n }\n } // end if the unit was not found as a unit name\n } // end if a unit expression was specified\n\n return retObj;\n\n } // end getSpecifiedUnit\n\n\n /**\n * This method retrieves a list of units commensurable, i.e., that can be\n * converted from and to, a specified unit. Returns an error if the \"from\"\n * unit cannot be found.\n *\n * @param fromName the name/unit string of the \"from\" unit\n * @returns an array containing two elements;\n * first element is the list of commensurable units if any were found\n * second element is an error message if the \"from\" unit is not found\n */\n commensurablesList(fromName) {\n\n let retMsg = [];\n let commUnits = null ;\n let parseResp = this.getSpecifiedUnit(fromName, 'validate', false);\n let fromUnit = parseResp['unit'];\n if (parseResp['retMsg'].length > 0)\n retMsg = parseResp['retMsg'] ;\n if (!fromUnit) {\n retMsg.push(`Could not find unit ${fromName}.`);\n }\n else {\n let dimVec = null ;\n let fromDim = fromUnit.getProperty('dim_');\n if (!fromDim) {\n retMsg.push('No commensurable units were found for ' + fromName) ;\n }\n else {\n try {\n dimVec = fromDim.getProperty('dimVec_');\n }\n catch (err) {\n retMsg.push(err.message);\n if (err.message ===\n \"Dimension does not have requested property(dimVec_)\")\n dimVec = null;\n }\n if (dimVec) {\n let utab = UnitTables.getInstance();\n commUnits = utab.getUnitsByDimension(dimVec);\n }\n } // end if the from unit has a dimension vector\n } // end if we found a \"from\" unit\n return [commUnits , retMsg];\n } // end commensurablesList\n\n} // end UcumLhcUtils class\n\n\n/**\n * This function exists ONLY until the original UcumLhcUtils constructor\n * is called for the first time. It's defined here in case getInstance\n * is called before the constructor. This calls the constructor.\n *\n * The constructor redefines the getInstance function to return the\n * singleton UcumLhcUtils object. This is based on the UnitTables singleton\n * implementation; see more detail in the UnitTables constructor description.\n *\n * NO LONGER TRUE - not implemented as a singleton. This method retained to\n * avoid problems with calls to it that exist throughout the code.\n *\n * @return the (formerly singleton) UcumLhcUtils object.\n */\nUcumLhcUtils.getInstance = function(){\n return new UcumLhcUtils();\n} ;\n\n\n\n\n"],"file":"ucumLhcUtils.js"}
@@ -370,8 +370,8 @@ class Unit {
370
370
 
371
371
  convertFrom(num, fromUnit) {
372
372
  let newNum = 0.0;
373
- if (this.isArbitrary_) throw new Error(`Attempt to convert arbitrary unit ${this.name_}`);
374
- if (fromUnit.isArbitrary_) throw new Error(`Attempt to convert to arbitrary unit ${fromUnit.name_}`); // reject request if both units have dimensions that are not equal
373
+ if (this.isArbitrary_) throw new Error(`Attempt to convert to arbitrary unit "${this.csCode_}"`);
374
+ if (fromUnit.isArbitrary_) throw new Error(`Attempt to convert arbitrary unit "${fromUnit.csCode_}"`); // reject request if both units have dimensions that are not equal
375
375
 
376
376
  if (fromUnit.dim_ && this.dim_ && !fromUnit.dim_.equals(this.dim_)) {
377
377
  // check first to see if a mole<->mass conversion is appropriate
@@ -393,40 +393,28 @@ class Unit {
393
393
  }
394
394
 
395
395
  let fromCnv = fromUnit.cnv_;
396
- let fromMag = fromUnit.magnitude_; // If the same conversion function is specified for both units, which
397
- // includes neither unit having a conversion function, multiply the
398
- // "from" unit's magnitude by the number passed in and then divide
399
- // that result by this unit's magnitude. Do this for units with
400
- // and without dimension vectors. PROBLEM with 2 non-commensurable
401
- // units with no dimension vector or function, e.g., byte to mol
402
-
403
- if (fromCnv === this.cnv_) {
404
- newNum = num * fromMag / this.magnitude_;
405
- } // else use a function to get the number to be returned
406
- else {
407
- let x = 0.0;
408
-
409
- if (fromCnv != null) {
410
- // turn num * fromUnit.magnitude into its ratio scale equivalent,
411
- // e.g., convert Celsius to Kelvin
412
- let fromFunc = _ucumFunctions.default.forName(fromCnv);
413
-
414
- x = fromFunc.cnvFrom(num * fromUnit.cnvPfx_) * fromMag; //x = fromFunc.cnvFrom(num * fromMag) * fromUnit.cnvPfx_;
415
- } else {
416
- x = num * fromMag;
417
- }
418
-
419
- if (this.cnv_ != null) {
420
- // turn mag * origUnit on ratio scale into a non-ratio unit,
421
- // e.g. convert Kelvin to Fahrenheit
422
- let toFunc = _ucumFunctions.default.forName(this.cnv_);
423
-
424
- newNum = toFunc.cnvTo(x / this.magnitude_) / this.cnvPfx_;
425
- } else {
426
- newNum = x / this.magnitude_;
427
- }
428
- } // end if either unit has a conversion function
396
+ let fromMag = fromUnit.magnitude_;
397
+ let x;
429
398
 
399
+ if (fromCnv != null) {
400
+ // turn num * fromUnit.magnitude into its ratio scale equivalent,
401
+ // e.g., convert Celsius to Kelvin
402
+ let fromFunc = _ucumFunctions.default.forName(fromCnv);
403
+
404
+ x = fromFunc.cnvFrom(num * fromUnit.cnvPfx_) * fromMag; //x = fromFunc.cnvFrom(num * fromMag) * fromUnit.cnvPfx_;
405
+ } else {
406
+ x = num * fromMag;
407
+ }
408
+
409
+ if (this.cnv_ != null) {
410
+ // turn mag * origUnit on ratio scale into a non-ratio unit,
411
+ // e.g. convert Kelvin to Fahrenheit
412
+ let toFunc = _ucumFunctions.default.forName(this.cnv_);
413
+
414
+ newNum = toFunc.cnvTo(x / this.magnitude_) / this.cnvPfx_;
415
+ } else {
416
+ newNum = x / this.magnitude_;
417
+ }
430
418
 
431
419
  return newNum;
432
420
  } // end convertFrom
@@ -633,6 +621,7 @@ class Unit {
633
621
  else if (unit2.cnv_ != null) {
634
622
  if (!retUnit.dim_ || retUnit.dim_.isZero()) {
635
623
  retUnit.cnvPfx_ = unit2.cnvPfx_ * retUnit.magnitude_;
624
+ retUnit.magnitude_ = unit2.magnitude_;
636
625
  retUnit.cnv_ = unit2.cnv_;
637
626
  } else throw new Error(`Attempt to multiply non-ratio unit ${unit2.name_}`);
638
627
  } // end if unit2 has a conversion function
@@ -666,7 +655,9 @@ class Unit {
666
655
  // if (!retUnit.isMole_)
667
656
  // retUnit.isMole_ = unit2.isMole_ ;
668
657
 
669
- if (!retUnit.isArbitrary_) retUnit.isArbitrary_ = unit2.isArbitrary_;
658
+ if (!retUnit.isArbitrary_) retUnit.isArbitrary_ = unit2.isArbitrary_; // Likewise for special units
659
+
660
+ if (!retUnit.isSpecial_) retUnit.isSpecial_ = unit2.isSpecial_;
670
661
  return retUnit;
671
662
  } // end multiplyThese
672
663
 
@@ -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","resetFieldsForDerivedUnit","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,C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AAKA,QAAL,KAAkB,CAA9C,EAAiD;AACpD,UAAIsI,OAAO,GAAG1G,KAAK,CAACtC,IAAN,CAAW+B,KAAX,EAAd;AACA,UAAIkH,MAAM,GAAGD,OAAO,CAACpE,YAAR,CAAqBiE,CAArB,CAAb;AACAG,MAAAA,OAAO,CAACE,YAAR,CAAqBL,CAArB,EAAyBI,MAAM,GAAG3G,KAAK,CAAC5B,QAAxC;AACAqI,MAAAA,aAAa,GAAIC,OAAO,CAACzG,MAAR,CAAe,KAAKvC,IAApB,CAAjB;AACD;;AACD,WAAO+I,aAAP;AACD;AAGD;;;;;;;;;;AAQAjE,EAAAA,cAAc,GAAG;AACf,QAAI,CAAC1F,UAAL,EACEA,UAAU,GAAGF,OAAO,CAAC,iBAAD,CAAP,CAA2BE,UAAxC;AACF,WAAOA,UAAU,CAAC+J,WAAX,EAAP;AACD;;AA1/Be,C,CA4/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.resetFieldsForDerivedUnit();\n if (retUnit.printSymbol_ && unit2.printSymbol_)\n retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '.',\n unit2.printSymbol_, '(', ')');\n else if (unit2.printSymbol_)\n retUnit.printSymbol_ = unit2.printSymbol_;\n\n // 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 * Clears fields like isBase_, synonyms_, etc. when a unit has been cloned\n * from a known unit but it being used to construct a derived unit.\n */\n resetFieldsForDerivedUnit() {\n this.guidance_ = '';\n this.synonyms_ = null;\n this.isBase_ = false;\n }\n\n\n /**\n * Divides this unit by another unit. If this unit is not on a ratio\n * scale an exception is raised. Mutating to a ratio scale unit\n * is not possible for a unit, only for a measurement.\n *\n * This unit is NOT modified by this function.\n * @param unit2 the unit by which to divide this one\n * @return this unit after it is divided by unit2\n * @throws an error if either of the units is not on a ratio scale.\n * */\n divide(unit2) {\n\n var retUnit = this.clone();\n\n if (retUnit.cnv_ != null)\n throw (new Error(`Attempt to divide non-ratio unit ${retUnit.name_}`));\n if (unit2.cnv_ != null)\n throw (new Error(`Attempt to divide by non-ratio unit ${unit2.name_}`));\n\n if (retUnit.name_ && unit2.name_)\n retUnit.name_ = this._concatStrs(retUnit.name_, '/', unit2.name_, '[', ']');\n else if (unit2.name_)\n retUnit.name_ = unit2.invertString(unit2.name_);\n\n retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '/', unit2.csCode_,\n '(', ')');\n\n if (retUnit.ciCode_ && unit2.ciCode_)\n retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '/', unit2.ciCode_,\n '(', ')');\n else if (unit2.ciCode_)\n retUnit.ciCode_ = unit2.invertString(unit2.ciCode_) ;\n\n retUnit.resetFieldsForDerivedUnit();\n\n retUnit.magnitude_ /= unit2.magnitude_;\n\n if (retUnit.printSymbol_ && unit2.printSymbol_)\n retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '/',\n unit2.printSymbol_, '(', ')');\n else if (unit2.printSymbol_)\n retUnit.printSymbol_ = unit2.invertString(unit2.printSymbol_);\n\n // Continue if unit2 has a dimension object.\n // If this object has a dimension object, subtract unit2's dim_ object from\n // this one. The sub method will take care of cases where the dimVec_ arrays\n // are missing on one or both dim_ objects.\n if (unit2.dim_) {\n if (retUnit.dim_) {\n if (retUnit.dim_.isNull())\n retUnit.dim_.assignZero();\n retUnit.dim_ = retUnit.dim_.sub(unit2.dim_);\n } // end if this.dim_ exists\n\n // Else if this dim_ object is missing, clone unit2's dim_ object\n // and give the inverted clone to this unit.\n else\n retUnit.dim_ = unit2.dim_.clone().minus();\n } // end if unit2 has a dimension object\n\n // Update the mole exponent count by subtracting the count for unit2 from\n // the // count for this unit.\n retUnit.moleExp_ = 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"}
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","resetFieldsForDerivedUnit","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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CAACjB,KAAD,EAAQ;AAC7B,QAAIuC,IAAI,GAAG,KAAKC,cAAL,EAAX;;AACA,QAAI+D,CAAC,GAAGhE,IAAI,CAACiE,qBAAL,EAAR;AACA,QAAIC,aAAa,GAAG,KAApB;;AACA,QAAI,KAAKrI,QAAL,KAAkB,CAAlB,IAAuB4B,KAAK,CAAC5B,QAAN,KAAmB,CAA9C,EAAiD;AAC/C,UAAIsI,OAAO,GAAG,KAAKhJ,IAAL,CAAU+B,KAAV,EAAd;AACA,UAAIkH,MAAM,GAAGD,OAAO,CAACpE,YAAR,CAAqBiE,CAArB,CAAb;AACAG,MAAAA,OAAO,CAACE,YAAR,CAAqBL,CAArB,EAAyBI,MAAM,GAAG,KAAKvI,QAAvC;AACAqI,MAAAA,aAAa,GAAIC,OAAO,CAACzG,MAAR,CAAeD,KAAK,CAACtC,IAArB,CAAjB;AACD,KALD,MAMK,IAAIsC,KAAK,CAAC5B,QAAN,KAAmB,CAAnB,IAAwB,KAAKA,QAAL,KAAkB,CAA9C,EAAiD;AACpD,UAAIsI,OAAO,GAAG1G,KAAK,CAACtC,IAAN,CAAW+B,KAAX,EAAd;AACA,UAAIkH,MAAM,GAAGD,OAAO,CAACpE,YAAR,CAAqBiE,CAArB,CAAb;AACAG,MAAAA,OAAO,CAACE,YAAR,CAAqBL,CAArB,EAAyBI,MAAM,GAAG3G,KAAK,CAAC5B,QAAxC;AACAqI,MAAAA,aAAa,GAAIC,OAAO,CAACzG,MAAR,CAAe,KAAKvC,IAApB,CAAjB;AACD;;AACD,WAAO+I,aAAP;AACD;AAGD;;;;;;;;;;AAQAjE,EAAAA,cAAc,GAAG;AACf,QAAI,CAAC1F,UAAL,EACEA,UAAU,GAAGF,OAAO,CAAC,iBAAD,CAAP,CAA2BE,UAAxC;AACF,WAAOA,UAAU,CAAC+J,WAAX,EAAP;AACD;;AAp/Be,C,CAs/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 /**\n * This returns the value of the property named by the parameter\n * passed in.\n *\n * @param propertyName name of the property to be returned, with\n * or without the trailing underscore.\n * @return the requested property, if found for this unit\n * @throws an error if the property is not found for this unit\n */\n getProperty(propertyName) {\n let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName :\n propertyName + '_' ;\n return this[uProp] ;\n\n } // end getProperty\n\n\n /**\n * Takes a measurement consisting of a number of units and a unit and returns\n * the equivalent number of this unit. So, 15 mL would translate\n * to 1 tablespoon if this object is a tablespoon.\n *\n * Note that the number returned may not be what is normally expected.\n * For example, converting 10 Celsius units to Fahrenheit would \"normally\"\n * return a value of 50. But in this case you'll get back something like\n * 49.99999999999994.\n *\n * If either unit is an arbitrary unit an exception is raised.\n *\n * @param num the magnitude for the unit to be translated (e.g. 15 for 15 mL)\n * @param fromUnit the unit to be translated to one of this type (e.g. a mL unit)\n *\n * @return the number of converted units (e.g. 1 for 1 tablespoon)\n * @throws an error if the dimension of the fromUnit differs from this unit's\n * dimension\n */\n convertFrom(num, fromUnit) {\n let newNum = 0.0 ;\n\n if (this.isArbitrary_)\n throw (new Error(`Attempt to convert to arbitrary unit \"${this.csCode_}\"`));\n if (fromUnit.isArbitrary_)\n throw (new Error(`Attempt to convert arbitrary unit \"${fromUnit.csCode_}\"`));\n\n // reject request if both units have dimensions that are not equal\n if (fromUnit.dim_ && this.dim_ && !(fromUnit.dim_.equals(this.dim_))) {\n // check first to see if a mole<->mass conversion is appropriate\n if (this.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 let x;\n if (fromCnv != null) {\n // turn num * fromUnit.magnitude into its ratio scale equivalent,\n // e.g., convert Celsius to Kelvin\n let fromFunc = funcs.forName(fromCnv);\n x = fromFunc.cnvFrom(num * fromUnit.cnvPfx_) * fromMag;\n //x = fromFunc.cnvFrom(num * fromMag) * fromUnit.cnvPfx_;\n }\n else {\n x = num * fromMag;\n }\n\n if (this.cnv_ != null) {\n // turn mag * origUnit on ratio scale into a non-ratio unit,\n // e.g. convert Kelvin to Fahrenheit\n let toFunc = funcs.forName(this.cnv_);\n newNum = toFunc.cnvTo(x / this.magnitude_) / this.cnvPfx_;\n }\n else {\n newNum = x / this.magnitude_;\n }\n\n return newNum;\n\n } // end convertFrom\n\n\n /**\n * Takes a number and a target unit and returns the number for a measurement\n * of this unit that corresponds to the number of the target unit passed in.\n * So, 1 tablespoon (where this unit represents a tablespoon) would translate\n * to 15 mL.\n *\n * See the note on convertFrom about return values.\n *\n * @param mag the magnitude for this unit (e.g. 1 for 1 tablespoon)\n * @param toUnit the unit to which this unit is to be translated\n * (e.g. an mL unit)\n *\n * @return the converted number value (e.g. 15 mL)\n * @throws an error if the dimension of the toUnit differs from this unit's\n * dimension\n */\n convertTo(num, toUnit) {\n\n return toUnit.convertFrom(num, this) ;\n\n } // end convertTo\n\n\n /**\n * Takes a given number of this unit returns the number of this unit\n * if it is converted into a coherent unit. Does not change this unit.\n *\n * If this is a coherent unit already, just gives back the number\n * passed in.\n *\n * @param num the number for the coherent version of this unit\n * @return the number for the coherent version of this unit\n */\n convertCoherent(num) {\n\n // convert mag' * u' into canonical number * u on ratio scale\n if(this.cnv_ !== null)\n num = this.cnv_.f_from(num / this.cnvPfx_) * this.magnitude_;\n\n return num;\n\n } // end convertCoherent\n\n\n /**\n * Mutates this unit into a coherent unit and converts a given number of\n * units to the appropriate value for this unit as a coherent unit\n *\n * @param num the number for this unit before conversion\n * @return the number of this unit after conversion\n * @throws an error if the dimensions differ\n */\n mutateCoherent(num) {\n\n // convert mu' * u' into canonical mu * u on ratio scale\n num = this.convertCoherent(num) ;\n\n // mutate to coherent unit\n this.magnitude_ = 1;\n this.cnv_ = null;\n this.cnvPfx_ = 1;\n this.name_ = \"\";\n\n // build a name as a term of coherent base units\n // This is probably ALL WRONG and a HORRIBLE MISTAKE\n // but until we figure out what the heck the name being\n // built here really is, it will have to stay.\n for (let i = 0, max = Dimension.getMax(); i < max; i++) {\n let elem = this.dim_.getElementAt(i);\n let tabs = this._getUnitTables();\n let uA = tabs.getUnitsByDimension(new Dimension(i));\n if(uA == null)\n throw(new Error(`Can't find base unit for dimension ${i}`));\n this.name_ = uA.name + elem;\n }\n return num;\n\n } // end mutateCoherent\n\n\n /**\n * 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.magnitude_ = unit2.magnitude_;\n retUnit.cnv_ = unit2.cnv_ ;\n }\n else\n throw (new Error(`Attempt to multiply non-ratio unit ${unit2.name_}`));\n } // end if unit2 has a conversion function\n\n // else neither unit has a conversion function\n else {\n retUnit.magnitude_ *= unit2.magnitude_;\n } // end if unit2 does not have a conversion function\n\n // If this.dim_ isn't there, clone the dimension in unit2 - if dimVec_\n // is a dimension in unit2.dim_; else just transfer it to this dimension\n if (!retUnit.dim_ || (retUnit.dim_ && !retUnit.dim_.dimVec_)) {\n if (unit2.dim_)\n retUnit.dim_ = unit2.dim_.clone();\n else\n retUnit.dim_ = unit2.dim_;\n }\n // Else this.dim_ is there. If there is a dimension for unit2,\n // add it to this one.\n else if (unit2.dim_ && unit2.dim_ instanceof Dimension) {\n retUnit.dim_.add(unit2.dim_);\n }\n\n // Concatenate the unit info (name, code, etc) for all cases\n // where the multiplication was performed (an error wasn't thrown)\n retUnit.name_ = this._concatStrs(retUnit.name_, '*', unit2.name_, '[', ']');\n retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '.', unit2.csCode_,\n '(', ')');\n if (retUnit.ciCode_ && unit2.ciCode_)\n retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '.', unit2.ciCode_,\n '(', ')');\n else if (unit2.ciCode_)\n retUnit.ciCode_ = unit2.ciCode_;\n retUnit.resetFieldsForDerivedUnit();\n if (retUnit.printSymbol_ && unit2.printSymbol_)\n retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '.',\n unit2.printSymbol_, '(', ')');\n else if (unit2.printSymbol_)\n retUnit.printSymbol_ = unit2.printSymbol_;\n\n // 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 // Likewise for special units\n if (!retUnit.isSpecial_)\n retUnit.isSpecial_ = unit2.isSpecial_;\n\n return retUnit ;\n\n } // end multiplyThese\n\n\n /**\n * Clears fields like isBase_, synonyms_, etc. when a unit has been cloned\n * from a known unit but it being used to construct a derived unit.\n */\n resetFieldsForDerivedUnit() {\n this.guidance_ = '';\n this.synonyms_ = null;\n this.isBase_ = false;\n }\n\n\n /**\n * Divides this unit by another unit. If this unit is not on a ratio\n * scale an exception is raised. Mutating to a ratio scale unit\n * is not possible for a unit, only for a measurement.\n *\n * This unit is NOT modified by this function.\n * @param unit2 the unit by which to divide this one\n * @return this unit after it is divided by unit2\n * @throws an error if either of the units is not on a ratio scale.\n * */\n divide(unit2) {\n\n var retUnit = this.clone();\n\n if (retUnit.cnv_ != null)\n throw (new Error(`Attempt to divide non-ratio unit ${retUnit.name_}`));\n if (unit2.cnv_ != null)\n throw (new Error(`Attempt to divide by non-ratio unit ${unit2.name_}`));\n\n if (retUnit.name_ && unit2.name_)\n retUnit.name_ = this._concatStrs(retUnit.name_, '/', unit2.name_, '[', ']');\n else if (unit2.name_)\n retUnit.name_ = unit2.invertString(unit2.name_);\n\n retUnit.csCode_ = this._concatStrs(retUnit.csCode_, '/', unit2.csCode_,\n '(', ')');\n\n if (retUnit.ciCode_ && unit2.ciCode_)\n retUnit.ciCode_ = this._concatStrs(retUnit.ciCode_, '/', unit2.ciCode_,\n '(', ')');\n else if (unit2.ciCode_)\n retUnit.ciCode_ = unit2.invertString(unit2.ciCode_) ;\n\n retUnit.resetFieldsForDerivedUnit();\n\n retUnit.magnitude_ /= unit2.magnitude_;\n\n if (retUnit.printSymbol_ && unit2.printSymbol_)\n retUnit.printSymbol_ = this._concatStrs(retUnit.printSymbol_, '/',\n unit2.printSymbol_, '(', ')');\n else if (unit2.printSymbol_)\n retUnit.printSymbol_ = unit2.invertString(unit2.printSymbol_);\n\n // Continue if unit2 has a dimension object.\n // If this object has a dimension object, subtract unit2's dim_ object from\n // this one. The sub method will take care of cases where the dimVec_ arrays\n // are missing on one or both dim_ objects.\n if (unit2.dim_) {\n if (retUnit.dim_) {\n if (retUnit.dim_.isNull())\n retUnit.dim_.assignZero();\n retUnit.dim_ = retUnit.dim_.sub(unit2.dim_);\n } // end if this.dim_ exists\n\n // Else if this dim_ object is missing, clone unit2's dim_ object\n // and give the inverted clone to this unit.\n else\n retUnit.dim_ = unit2.dim_.clone().minus();\n } // end if unit2 has a dimension object\n\n // Update the mole exponent count by subtracting the count for unit2 from\n // the // count for this unit.\n retUnit.moleExp_ = 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"}
@@ -209,6 +209,7 @@ class UnitString {
209
209
  if (intUtils_.isIntegerUnit(finalUnit) || typeof finalUnit === 'number') {
210
210
  finalUnit = new Unit({
211
211
  'csCode_': origString,
212
+ 'ciCode_': origString,
212
213
  'magnitude_': finalUnit,
213
214
  'name_': origString
214
215
  });
@@ -1410,6 +1411,7 @@ class UnitString {
1410
1411
  if (intUtils_.isIntegerUnit(finalUnit)) {
1411
1412
  finalUnit = new Unit({
1412
1413
  'csCode_': finalUnit,
1414
+ 'ciCode_': finalUnit,
1413
1415
  'magnitude_': Number(finalUnit),
1414
1416
  'name_': finalUnit
1415
1417
  });
@@ -1425,6 +1427,7 @@ class UnitString {
1425
1427
  if (intUtils_.isIntegerUnit(nextUnit)) {
1426
1428
  nextUnit = new Unit({
1427
1429
  'csCode_': nextUnit,
1430
+ 'ciCode_': nextUnit,
1428
1431
  'magnitude_': Number(nextUnit),
1429
1432
  'name_': nextUnit
1430
1433
  });