@lhncbc/ucum-lhc 4.1.7 → 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/unitTables.js"],"names":["Ucum","require","UnitTablesFactory","constructor","unitNames_","unitCodes_","codeOrder_","unitStrings_","unitDimensions_","unitSynonyms_","massDimIndex_","unitsCount","Object","keys","length","addUnit","theUnit","uName","addUnitName","addUnitCode","addUnitString","getProperty","addUnitDimension","err","push","Error","uCode","dimVec","dim_","dimVec_","d","uString","caseSensitive_","uEntry","mag","unit","uDim","buildUnitSynonyms","code","uSyns","synonyms_","synsAry","split","aLen","a","theSyn","trim","addSynonymCodes","name_","theCode","theSynonyms","words","wLen","w","word","synCodes","indexOf","getUnitByCode","retUnit","getUnitByName","undefined","sepPos","codeSep_","substr","retUnits","uLen","i","csCode_","getUnitByString","retAry","getUnitsByDimension","unitsArray","console","log","getUnitBySynonym","uSyn","retObj","foundCodes","fLen","f","message","getAllUnitNames","getUnitNamesList","nameList","codes","sort","compareCodes","getMassDimensionIndex","b","replace","toLowerCase","getAllUnitCodes","allUnitsByDef","unitsList","u","allUnitsByName","cols","sep","unitBuff","cLen","nameRecs","rec","c","Array","join","cbuf","printUnits","doLong","codeList","unitString","curUnit","curDim","csUnitString_","baseFactor_","cnv_","defError_","unitTablesInstance","UnitTables","getInstance"],"mappings":";;;;;;;AAAA;;;;;;;AAQA,IAAIA,IAAI,GAAGC,OAAO,CAAC,aAAD,CAAP,CAAuBD,IAAlC;;AAEA,MAAME,iBAAN,CAAwB;AAEtB;;;;;;;;;;;;;;;;;;;AAmBAC,EAAAA,WAAW,GAAG;AAEZ;;;;;;;;AAQA,SAAKC,UAAL,GAAkB,EAAlB;AAEA;;;;;;;;AAOA,SAAKC,UAAL,GAAkB,EAAlB;AAEA;;;;;;;AAMA,SAAKC,UAAL,GAAkB,EAAlB;AAEA;;;;;;;AAMA,SAAKC,YAAL,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WAAR,CAAoB,SAApB,CAHA,GAGiC4E,GAHjC,GAIAa,OAAO,CAACzF,WAAR,CAAoB,QAApB,CAJA,GAIgC4E,GAJhC,GAKAa,OAAO,CAACzF,WAAR,CAAoB,WAApB,CALA,GAKmC4E,GALnC,GAMAa,OAAO,CAACzF,WAAR,CAAoB,WAApB,CANA,GAMmC4E,GANnC,GAOAa,OAAO,CAACzF,WAAR,CAAoB,YAApB,CAPA,GAOoC4E,GAPpC,GAQAa,OAAO,CAACzF,WAAR,CAAoB,cAApB,CARA,GAQsC4E,GARpD;AASD;;AACD,UAAIa,OAAO,CAACK,SAAZ,EACEN,UAAU,IAAI,8CAAd;AACFD,MAAAA,QAAQ,IAAIC,UAAU,GAAG,IAAzB;AACD;;AACD,WAAOD,QAAP;AACD;;AA1rBqB,C,CA4rBtB;AAGF;AACA;;;AACA,IAAIQ,kBAAkB,GAAG,IAAIlH,iBAAJ,EAAzB;AACO,MAAMmH,UAAU,GAAG;AACxBC,EAAAA,WAAW,EAAE,YAAW;AACtB,WAAOF,kBAAP;AACD;AAHuB,CAAnB","sourcesContent":["/**\n * This class manages Hashtables that provide references to\n * defined units.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar Ucum = require('./config.js').Ucum;\n\nclass UnitTablesFactory {\n\n /**\n * Constructor. This creates the empty unit tables (hashes) once. After the\n * tables are created, it redefines this constructor to throw an error\n * stating that the constructor is no longer available and that the\n * getInstance function must be used. Here's a description of the first\n * and then all subsequent calls to this constructor.\n *\n * First call to constructor:\n * 1. creates OBJECT1\n * 2. initializes attributes of OBJECT1\n * 3. stores reference to OBJECT1.prototype in holdthis local variable\n * 4. redefines OBJECT1 as a function that throws an error\n * 5. defines the getInstance function (which is also defined outside of\n * the class definition - see below).\n *\n * All subsequent calls to constructor:\n * 1. throw error message referring to getInstance\n * 2. call getInstance, returns this - which is OBJECT1.\n */\n constructor() {\n\n /**\n * Tracks units by name\n * @type hash - key is the name;\n * value is an array of references to the Unit objects\n * with the name. More than one unit may have the same\n * name, e.g., \"second\", which is shared by the base unit\n * with the code = \"s\" and the unit with code = \"'\".\n */\n this.unitNames_ = {};\n\n /**\n * Tracks units by code using case-sensitive version.\n *\n * @type hash - key is the code;\n * value is the reference to the Unit object. Codes must\n * be unique.\n */\n this.unitCodes_ = {};\n\n /**\n * Keeps track of the order in which units are defined. The order is\n * important because unit definitions build on previous definitions.\n *\n * @type {Array}\n */\n this.codeOrder_ = [] ;\n\n /**\n * Tracks units by unit strings, e.g., cm-1\n *\n * @type hash - key is the unit string\n * value is an array of unit objects with that ciUnitString.\n */\n this.unitStrings_ = {};\n\n /**\n * Tracks units by Dimension vector\n *\n * @type hash - key is the dimension vector (not the object, just the\n * vector);\n * value is an array of references to the Unit objects\n * with that vector. More than one unit may have the same\n * unit vector, and this can be used to provide a list\n * of commensurable units.\n */\n this.unitDimensions_ = {};\n\n /**\n * Maps synonyms to units. Not built until first requested.\n *\n * @type hash - key is the synonym\n * value is an array of references to Unit objects that\n * include that synonym.\n */\n this.unitSynonyms_ = {};\n\n /*\n * Holds onto the index of the index of the dimension vector flag for\n * the base mass unit (gram). This is set when the base unit (gram) is\n * created, and is stored here so that it doesn't have to be found\n * over and over again to try to determine whether or not a unit is\n * mass-based (for mole<->mass conversions)\n *\n * @type integer\n */\n this.massDimIndex_ = 0;\n }\n\n\n /**\n * Provides the number of unit objects written to the tables, using the\n * codes table since codes must be unique.\n *\n * @returns count of the number of unit objects in the unitCodes_ table.\n */\n unitsCount() {\n return Object.keys(this.unitCodes_).length ;\n }\n\n\n /**\n * Adds a Unit object to the tables.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws passes on an error if one is thrown by the called functions for\n * a problem with the unit code or unit name\n */\n addUnit(theUnit) {\n\n let uName = theUnit['name_'] ;\n if (uName) {\n this.addUnitName(theUnit);\n }\n\n this.addUnitCode(theUnit);\n this.addUnitString(theUnit);\n\n try {\n if (theUnit['dim_'].getProperty('dimVec_'))\n this.addUnitDimension(theUnit);\n }\n catch(err){\n // do nothing - throws error if the property is null\n // and that's OK here.\n }\n\n } // end addUnit\n\n\n /**\n * Adds a Unit object to the unitNames_ table. More than one unit\n * can have the same name, e.g., the two units with the name \"second\",\n * where the code for one of them is 's' and the code for the other is\n * \"'\". Because of this, an array of unit objects is stored for the\n * name. In most cases it will be an array of one object, but this\n * clarifies that there may be more than one.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unit has no name\n */\n addUnitName(theUnit) {\n\n let uName = theUnit['name_'];\n\n if (uName) {\n if (this.unitNames_[uName])\n this.unitNames_[uName].push(theUnit);\n else\n this.unitNames_[uName] = [theUnit];\n }\n else\n throw(new Error('UnitTables.addUnitName called for a unit with no name. ' +\n `Unit code = ${theUnit['csCode_']}.`));\n\n } // end addUnitName\n\n\n /**\n * Adds a Unit object to the unitCodes_, unitUcCodes_, unitLcCodes_ and\n * codeOrder_ tables. This also sets the mass dimension index when the\n * base mass unit (gram) is read.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unitCodes_ table already contains a unit with\n * the code\n */\n addUnitCode(theUnit) {\n\n let uCode = theUnit['csCode_'];\n if (uCode) {\n\n if (this.unitCodes_[uCode])\n throw(new Error(`UnitTables.addUnitCode called, already contains entry for ` +\n `unit with code = ${uCode}`));\n else {\n this.unitCodes_[uCode] = theUnit;\n this.codeOrder_.push(uCode);\n if (uCode == 'g') {\n let dimVec = theUnit.dim_.dimVec_;\n let d = 0;\n for (; d < dimVec.length && dimVec[d] < 1; d++) ;\n this.massDimIndex_ = d;\n }\n }\n }\n else\n throw(new Error('UnitTables.addUnitCode called for unit that has ' +\n 'no code.')) ;\n\n } // end addUnitCode\n\n\n /**\n * Adds a unit object to the unitStrings_ table. More than one unit\n * can have the same string, so an array of unit objects is stored\n * for the string. The unit string is the string that creates a non-base\n * unit, e.g., a Newton has a unit code of N, a name of Newton, and a\n * unitString of kg.m/s2.\n *\n * If the unit has no string, nothing is stored and no error is reported.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n */\n addUnitString(theUnit) {\n\n let uString = null;\n if (Ucum.caseSensitive_ == true)\n uString = theUnit['csUnitString_'];\n else\n uString = theUnit['ciUnitString_'];\n\n if (uString) {\n let uEntry = {mag: theUnit['baseFactorStr_'], unit: theUnit};\n if (this.unitStrings_[uString])\n this.unitStrings_[uString].push(uEntry);\n else\n this.unitStrings_[uString] = [uEntry];\n }\n } // end addUnitString\n\n\n /**\n * Adds a Unit object to the unitDimensions_ table. More than one unit\n * can have the same dimension (commensurable units have the same dimension).\n * Because of this, an array of unit objects is stored for the\n * dimension.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unit has no dimension\n */\n addUnitDimension(theUnit) {\n\n let uDim = theUnit['dim_'].getProperty('dimVec_');\n\n if (uDim) {\n if (this.unitDimensions_[uDim])\n this.unitDimensions_[uDim].push(theUnit);\n else\n this.unitDimensions_[uDim] = [theUnit];\n }\n else\n throw(new Error('UnitTables.addUnitDimension called for a unit with no dimension. ' +\n `Unit code = ${theUnit['csCode_']}.`));\n\n } // end addUnitDimension\n\n\n /**\n * Builds the unitSynonyms_ table. This is called the first time the\n * getUnitsBySynonym method is called. The table/hash contains each word\n * (once) from each synonym as well as each word from each unit name.\n *\n * Hash keys are the words. Hash values are an array of unit codes for\n * each unit that has that word in its synonyms or name.\n *\n * @returns nothing\n */\n buildUnitSynonyms() {\n\n for (let code in this.unitCodes_) {\n let theUnit = this.unitCodes_[code];\n let uSyns = theUnit.synonyms_ ;\n\n // If the current unit has synonyms, process each synonym (often multiples)\n if (uSyns) {\n let synsAry = uSyns.split(';');\n if (synsAry[0] !== '') {\n let aLen = synsAry.length;\n for (let a = 0; a < aLen; a++) {\n let theSyn = synsAry[a].trim();\n\n // call addSynonymCodes to process each word in the\n // synonym, e.g., \"British fluid ounces\"\n this.addSynonymCodes(code, theSyn) ;\n } // end do for each synonym\n } // end if the current unit has a non-null synonym attribute\n } // end if the unit has any synonyms\n\n // Now call addSynonymCodes to process each word in the unit's name\n this.addSynonymCodes(code, theUnit.name_) ;\n } // end do for each unit\n } // end buildUnitSynonyms\n\n\n /**\n * Adds unit code entries to the synonyms table for a string containing\n * one or more words to be considered as synonyms.\n *\n * @param theCode the unit code to be connected to the synonyms\n * @param theSynonyms a string containing one or more words to be\n * considered synonyms (and thus to be added to the unitSynonyms hash).\n */\n addSynonymCodes(theCode, theSynonyms) {\n\n let words = theSynonyms.split(' ');\n let wLen = words.length;\n\n for (let w = 0; w < wLen; w++) {\n let word = words[w];\n\n // if there is already a synonyms entry for the word,\n // get the array of unit codes currently assigned to\n // the word and add the code for the current word to\n // the synonyms array if it's not already there.\n if (this.unitSynonyms_[word]) {\n let synCodes = this.unitSynonyms_[word];\n if (synCodes.indexOf(theCode) === -1) {\n this.unitSynonyms_[word].push(theCode);\n }\n }\n // else there are no synonyms entry for the word. Create a\n // synonyms array for the word, setting it to contain the unit code.\n else {\n this.unitSynonyms_[word] = [theCode];\n }\n } // end do for each word in the synonyms being processed\n\n } // end addSynonymCodes\n\n\n /**\n * Returns a unit object with a case-sensitive code matching the\n * uCode parameter, or null if no unit is found with that code.\n *\n * @param uCode the code of the unit to be returned\n * @returns the unit object or null if it is not found\n */\n getUnitByCode(uCode) {\n let retUnit = null ;\n if (uCode) {\n retUnit = this.unitCodes_[uCode];\n }\n return retUnit ;\n }\n\n\n /**\n * Returns a array of unit objects based on the unit's name. Usually this\n * will be an array of one, but there may be more, since unit names are\n * not necessarily unique.\n *\n * @param uName the name of the unit to be returned. If more than one\n * unit has the same name and you only want one specific unit, append the\n * csCode of the unit you want to the end of the name, separated by the\n * Ucum.codeSep_ value, e.g., inch - [in_i] vs. inch - [in_us].\n * @returns null if no unit was found for the specified name OR an array of\n * unit objects with the specified name. Normally this will be an array\n * of one object.\n * @throws an error if no name is provided to search on\n */\n getUnitByName(uName) {\n\n if (uName === null || uName === undefined) {\n throw (new Error('Unable to find unit by name because no name was provided.'));\n }\n let sepPos = uName.indexOf(Ucum.codeSep_);\n let uCode = null;\n if (sepPos >= 1) {\n uCode = uName.substr(sepPos + Ucum.codeSep_.length);\n uName = uName.substr(0, sepPos);\n }\n let retUnits = this.unitNames_[uName] ;\n if (retUnits) {\n let uLen = retUnits.length ;\n\n if (uCode && uLen > 1) {\n let i = 0;\n for (; retUnits[i].csCode_ !== uCode && i < uLen; i++);\n if (i < uLen)\n retUnits = [retUnits[i]];\n else {\n retUnits = null;\n }\n } // end if we need to find both a name and a code\n } // end if we got an array of units\n return retUnits ;\n\n } // end getUnitByName\n\n\n /**\n * Returns an array of unit objects with the specified unit string.\n * The array may contain one or more unit reference objects.\n * Or none, if no units have a matching unit string (which is not\n * considered an error)\n *\n * @param name the name of the unit to be returned\n * @returns the array of unit references or null if none were found\n */\n getUnitByString(uString) {\n let retAry = null ;\n if (uString) {\n retAry = this.unitStrings_[uString] ;\n if (retAry === undefined)\n retAry = null;\n }\n return retAry ;\n }\n\n\n /**\n * Returns a array of unit objects based on the unit's dimension vector.\n *\n * @param uName the dimension vector of the units to be returned.\n *\n * @returns null if no unit was found for the specified vector OR an array of\n * one or more unit objects with the specified vector.\n * @throws an error if no vector is provided to search on\n * logs an error to the console if no unit is found\n */\n getUnitsByDimension(uDim) {\n\n let unitsArray = null ;\n if (uDim === null || uDim === undefined) {\n throw (new Error('Unable to find unit by because no dimension ' +\n 'vector was provided.'));\n }\n\n unitsArray = this.unitDimensions_[uDim] ;\n if (unitsArray === undefined || unitsArray === null) {\n console.log(`Unable to find unit with dimension = ${uDim}`);\n }\n\n return unitsArray ;\n\n } // end getUnitsByDimension\n\n\n /**\n * Returns a array of unit objects that include the specified synonym.\n *\n * @param uSyn the synonym of the units to be returned.\n *\n * @returns an object with two of the following three elements:\n * 'status' will be error, failed or succeeded\n * 'msg' will be included for returns with status = error or failed and\n * will explain why the request did not return any units\n * 'units' any array of unit objects with the specified synonym will be\n * returned for requests with status = succeeded\n */\n getUnitBySynonym(uSyn) {\n\n let retObj = {} ;\n let unitsArray = [];\n\n try {\n if (uSyn === null || uSyn === undefined) {\n retObj['status'] = 'error' ;\n throw (new Error('Unable to find unit by synonym because no synonym ' +\n 'was provided.'));\n }\n // If this is the first request for a unit by synonym, build the hash map\n if (Object.keys(this.unitSynonyms_).length === 0) {\n this.buildUnitSynonyms();\n }\n let foundCodes = [];\n foundCodes = this.unitSynonyms_[uSyn];\n if (foundCodes) {\n retObj['status'] = 'succeeded';\n let fLen = foundCodes.length;\n for (let f = 0; f < fLen; f++) {\n unitsArray.push(this.unitCodes_[foundCodes[f]]);\n }\n retObj['units'] = unitsArray ;\n }\n if (unitsArray.length === 0) {\n retObj['status'] = 'failed' ;\n retObj['msg'] = `Unable to find any units with synonym = ${uSyn}`;\n }\n }\n catch(err) {\n retObj['msg'] = err.message ;\n }\n return retObj ;\n } // end getUnitBySynonym\n\n\n /**\n * Gets a list of all unit names in the Unit tables\n *\n * @returns an array of the unit names\n */\n getAllUnitNames() {\n return Object.keys(this.unitNames_);\n } // end getAllUnitNames\n\n\n /**\n * Gets a list of all unit names in the tables. Where more than one\n * unit has the same name, the unit code, in parentheses, is appended\n * to the end of the name.\n *\n * @returns {Array}\n */\n getUnitNamesList() {\n let nameList = [];\n let codes = Object.keys(this.unitCodes_);\n codes.sort(this.compareCodes) ;\n let uLen = codes.length;\n for (let i = 0; i < uLen; i++) {\n nameList[i] = codes[i] + Ucum.codeSep_ + this.unitCodes_[codes[i]].name_\n } // end do for each code\n return nameList ;\n }\n\n\n /*\n * Returns the mass dimension index\n * @returns this.massDimIndex_\n */\n getMassDimensionIndex() {\n return this.massDimIndex_ ;\n }\n\n /**\n * This provides a sort function for unit codes so that sorting ignores\n * square brackets and case.\n *\n * @param a first value\n * @param b second value\n * @returns -1 if a is should fall before b; otherwise 1.\n */\n compareCodes(a, b) {\n a = a.replace(/[\\[\\]]/g, '');\n a = a.toLowerCase();\n b = b.replace(/[\\[\\]]/g, '');\n b = b.toLowerCase();\n return (a < b) ? -1 : 1 ;\n }\n\n\n /**\n * Gets a list of all unit codes in the Unit tables\n *\n * @returns an array of the unit names\n */\n getAllUnitCodes() {\n return Object.keys(this.unitCodes_);\n } // end getAllUnitNames\n\n\n /**\n * This is used to get all unit objects. Currently it is used\n * to get the objects to write to the json ucum definitions file\n * that is used to provide prefix and unit definition objects for\n * conversions and validations.\n *\n * @returns an array containing all unit objects, ordered by definition\n * order\n */\n allUnitsByDef() {\n\n let unitsList = [];\n let uLen = this.codeOrder_.length ;\n for (let u = 0; u < uLen; u++) {\n unitsList.push(this.getUnitByCode(this.codeOrder_[u]));\n }\n return unitsList ;\n } // end allUnitsByDef\n\n\n /**\n * This is used to get all unit objects, ordered by unit name. Currently it\n * is used to create a csv list of all units.\n * @param sep separator character (or string) to be used to separate each\n * column in the output. Optional, defaults to '|' if not specified.\n * (Used to use ; but the synonyms use that extensively). Don't use a\n * comma or any other punctuation found in the output data.\n * @returns a buffer containing all unit objects, ordered by name\n * order\n */\n allUnitsByName(cols, sep) {\n if (sep === undefined || sep === null)\n sep = '|';\n let unitBuff = '';\n let unitsList = this.getAllUnitNames();\n let uLen = unitsList.length;\n let cLen = cols.length;\n for (let i = 0; i < uLen; i++) {\n let nameRecs = this.getUnitByName(unitsList[i]);\n for (let u = 0; u < nameRecs.length; u++) {\n let rec = nameRecs[u];\n for (let c = 0; c < cLen; c++) {\n if (c > 0)\n unitBuff += sep;\n if (cols[c] === 'dim_') {\n if (rec.dim_ !== null && rec.dim_ !== undefined &&\n rec.dim_.dimVec_ instanceof Array)\n unitBuff += '[' + rec.dim_.dimVec_.join(',') + ']';\n else\n unitBuff += '';\n }\n else {\n let cbuf = rec[cols[c]];\n if (typeof cbuf === 'string')\n unitBuff += cbuf.replace(/[\\n\\r]/g, ' ');\n else\n unitBuff += cbuf ;\n }\n } // end do for each column requested\n unitBuff += '\\r\\n';\n } // end do for each unit in the unit names array\n }\n return unitBuff ;\n } // end allUnitsByName\n\n\n /**\n * This creates a list of all units in the tables. It uses the byCode\n * table, and uses the codeOrder_ array to determine the order in which\n * the units are listed.\n *\n * @param doLong boolean indicating how much to output. If true, all data\n * from the unit objects is included. If false, only a few major values\n * are included.\n * @param sep separator character (or string) to be used to separate each\n * column in the output. Optional, defaults to '|' if not specified.\n * (Used to use ; but the synonyms use that extensively).\n * @returns {string} buffer containing all the listings\n */\n printUnits(doLong, sep) {\n if (doLong === undefined)\n doLong = false ;\n if (sep === undefined)\n sep = '|';\n let codeList = '';\n let uLen = this.codeOrder_.length ;\n let unitString = 'csCode' + sep ;\n if (doLong) {\n unitString += 'ciCode' + sep ;\n }\n unitString += 'name' + sep ;\n if (doLong)\n unitString += 'isBase' + sep ;\n unitString += 'magnitude' + sep + 'dimension' + sep + 'from unit(s)' + sep +\n 'value' + sep + 'function' + sep ;\n if (doLong)\n unitString += 'property' + sep + 'printSymbol' + sep + 'synonyms' + sep +\n 'source' + sep + 'class' + sep + 'isMetric' + sep +\n 'variable' + sep + 'isSpecial' + sep + 'isAbitrary' + sep ;\n unitString += 'comment';\n codeList = unitString + '\\n' ;\n\n for (let u = 0; u < uLen; u++) {\n let curUnit = this.getUnitByCode(this.codeOrder_[u]);\n unitString = this.codeOrder_[u] + sep ;\n if (doLong) {\n unitString += curUnit.getProperty('ciCode_') + sep ;\n }\n unitString += curUnit.getProperty('name_') + sep ;\n if (doLong) {\n if (curUnit.getProperty('isBase_'))\n unitString += 'true' + sep ;\n else\n unitString += 'false' + sep ;\n }\n unitString += curUnit.getProperty('magnitude_') + sep;\n let curDim = curUnit.getProperty('dim_');\n if (curDim) {\n unitString += curDim.dimVec_ + sep ;\n }\n else {\n unitString += 'null' + sep;\n }\n if (curUnit.csUnitString_)\n unitString += curUnit.csUnitString_ + sep + curUnit.baseFactor_ + sep ;\n else\n unitString += 'null' + sep + 'null' + sep;\n\n if (curUnit.cnv_)\n unitString += curUnit.cnv_ + sep ;\n else\n unitString += 'null' + sep ;\n\n if (doLong) {\n unitString += curUnit.getProperty('property_') + sep +\n curUnit.getProperty('printSymbol_') + sep +\n curUnit.getProperty('synonyms_') + sep +\n curUnit.getProperty('source_') + sep +\n curUnit.getProperty('class_') + sep +\n curUnit.getProperty('isMetric_') + sep +\n curUnit.getProperty('variable_') + sep +\n curUnit.getProperty('isSpecial_') + sep +\n curUnit.getProperty('isArbitrary_') + sep ;\n }\n if (curUnit.defError_)\n unitString += 'problem parsing this one, deferred to later.' ;\n codeList += unitString + '\\n' ;\n }\n return codeList ;\n }\n\n} // end UnitTablesFactory\n\n\n// Create a singleton instance and (to preserve the existing API) an object that\n// provides that instance via getInstance().\nvar unitTablesInstance = new UnitTablesFactory();\nexport const UnitTables = {\n getInstance: function() {\n return unitTablesInstance;\n }\n}\n"],"file":"unitTables.js"}
1
+ {"version":3,"sources":["../source/unitTables.js"],"names":["Ucum","require","UnitTablesFactory","constructor","unitNames_","unitCodes_","codeOrder_","unitStrings_","unitDimensions_","unitSynonyms_","massDimIndex_","dimVecIndexToBaseUnit_","unitsCount","Object","keys","length","addUnit","theUnit","uName","addUnitName","addUnitCode","addUnitString","getProperty","addUnitDimension","err","isBase_","dimVec","dim_","dimVec_","nonZeroIndex","i","len","undefined","csCode_","push","Error","uCode","d","uString","caseSensitive_","uEntry","mag","unit","uDim","buildUnitSynonyms","code","uSyns","synonyms_","synsAry","split","aLen","a","theSyn","trim","addSynonymCodes","name_","theCode","theSynonyms","words","wLen","w","word","synCodes","indexOf","getUnitByCode","retUnit","getUnitByName","sepPos","codeSep_","substr","retUnits","uLen","getUnitByString","retAry","getUnitsByDimension","unitsArray","console","log","getUnitBySynonym","uSyn","retObj","foundCodes","fLen","f","message","getAllUnitNames","getUnitNamesList","nameList","codes","sort","compareCodes","getMassDimensionIndex","b","replace","toLowerCase","getAllUnitCodes","allUnitsByDef","unitsList","u","allUnitsByName","cols","sep","unitBuff","cLen","nameRecs","rec","c","Array","join","cbuf","printUnits","doLong","codeList","unitString","curUnit","curDim","csUnitString_","baseFactor_","cnv_","defError_","unitTablesInstance","UnitTables","getInstance"],"mappings":";;;;;;;AAAA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,CAACK,SAAZ,EACEN,UAAU,IAAI,8CAAd;AACFD,MAAAA,QAAQ,IAAIC,UAAU,GAAG,IAAzB;AACD;;AACD,WAAOD,QAAP;AACD;;AAxsBqB,C,CA0sBtB;AAGF;AACA;;;AACA,IAAIQ,kBAAkB,GAAG,IAAItH,iBAAJ,EAAzB;AACO,MAAMuH,UAAU,GAAG;AACxBC,EAAAA,WAAW,EAAE,YAAW;AACtB,WAAOF,kBAAP;AACD;AAHuB,CAAnB","sourcesContent":["/**\n * This class manages Hashtables that provide references to\n * defined units.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar Ucum = require('./config.js').Ucum;\n\nclass UnitTablesFactory {\n\n /**\n * Constructor. This creates the empty unit tables (hashes) once. After the\n * tables are created, it redefines this constructor to throw an error\n * stating that the constructor is no longer available and that the\n * getInstance function must be used. Here's a description of the first\n * and then all subsequent calls to this constructor.\n *\n * First call to constructor:\n * 1. creates OBJECT1\n * 2. initializes attributes of OBJECT1\n * 3. stores reference to OBJECT1.prototype in holdthis local variable\n * 4. redefines OBJECT1 as a function that throws an error\n * 5. defines the getInstance function (which is also defined outside of\n * the class definition - see below).\n *\n * All subsequent calls to constructor:\n * 1. throw error message referring to getInstance\n * 2. call getInstance, returns this - which is OBJECT1.\n */\n constructor() {\n\n /**\n * Tracks units by name\n * @type hash - key is the name;\n * value is an array of references to the Unit objects\n * with the name. More than one unit may have the same\n * name, e.g., \"second\", which is shared by the base unit\n * with the code = \"s\" and the unit with code = \"'\".\n */\n this.unitNames_ = {};\n\n /**\n * Tracks units by code using case-sensitive version.\n *\n * @type hash - key is the code;\n * value is the reference to the Unit object. Codes must\n * be unique.\n */\n this.unitCodes_ = {};\n\n /**\n * Keeps track of the order in which units are defined. The order is\n * important because unit definitions build on previous definitions.\n *\n * @type {Array}\n */\n this.codeOrder_ = [] ;\n\n /**\n * Tracks units by unit strings, e.g., cm-1\n *\n * @type hash - key is the unit string\n * value is an array of unit objects with that ciUnitString.\n */\n this.unitStrings_ = {};\n\n /**\n * Tracks units by Dimension vector\n *\n * @type hash - key is the dimension vector (not the object, just the\n * vector);\n * value is an array of references to the Unit objects\n * with that vector. More than one unit may have the same\n * unit vector, and this can be used to provide a list\n * of commensurable units.\n */\n this.unitDimensions_ = {};\n\n /**\n * Maps synonyms to units. Not built until first requested.\n *\n * @type hash - key is the synonym\n * value is an array of references to Unit objects that\n * include that synonym.\n */\n this.unitSynonyms_ = {};\n\n /*\n * Holds onto the index of the index of the dimension vector flag for\n * the base mass unit (gram). This is set when the base unit (gram) is\n * created, and is stored here so that it doesn't have to be found\n * over and over again to try to determine whether or not a unit is\n * mass-based (for mole<->mass conversions)\n *\n * @type integer\n */\n this.massDimIndex_ = 0;\n\n /**\n * Map of indices in the dimension vector to base unit symbols.\n */\n this.dimVecIndexToBaseUnit_ = {};\n }\n\n\n /**\n * Provides the number of unit objects written to the tables, using the\n * codes table since codes must be unique.\n *\n * @returns count of the number of unit objects in the unitCodes_ table.\n */\n unitsCount() {\n return Object.keys(this.unitCodes_).length ;\n }\n\n\n /**\n * Adds a Unit object to the tables.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws passes on an error if one is thrown by the called functions for\n * a problem with the unit code or unit name\n */\n addUnit(theUnit) {\n\n let uName = theUnit['name_'] ;\n if (uName) {\n this.addUnitName(theUnit);\n }\n\n this.addUnitCode(theUnit);\n this.addUnitString(theUnit);\n\n try {\n if (theUnit['dim_'].getProperty('dimVec_'))\n this.addUnitDimension(theUnit);\n }\n catch(err){\n // do nothing - throws error if the property is null\n // and that's OK here.\n }\n\n if (theUnit.isBase_) {\n const dimVec = theUnit.dim_.dimVec_;\n let nonZeroIndex;\n for (let i=0, len=dimVec.length; nonZeroIndex==undefined && i<len; ++i) {\n if (dimVec[i] != 0)\n nonZeroIndex = i;\n }\n this.dimVecIndexToBaseUnit_[nonZeroIndex] = theUnit.csCode_;\n }\n } // end addUnit\n\n\n /**\n * Adds a Unit object to the unitNames_ table. More than one unit\n * can have the same name, e.g., the two units with the name \"second\",\n * where the code for one of them is 's' and the code for the other is\n * \"'\". Because of this, an array of unit objects is stored for the\n * name. In most cases it will be an array of one object, but this\n * clarifies that there may be more than one.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unit has no name\n */\n addUnitName(theUnit) {\n\n let uName = theUnit['name_'];\n\n if (uName) {\n if (this.unitNames_[uName])\n this.unitNames_[uName].push(theUnit);\n else\n this.unitNames_[uName] = [theUnit];\n }\n else\n throw(new Error('UnitTables.addUnitName called for a unit with no name. ' +\n `Unit code = ${theUnit['csCode_']}.`));\n\n } // end addUnitName\n\n\n /**\n * Adds a Unit object to the unitCodes_, unitUcCodes_, unitLcCodes_ and\n * codeOrder_ tables. This also sets the mass dimension index when the\n * base mass unit (gram) is read.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unitCodes_ table already contains a unit with\n * the code\n */\n addUnitCode(theUnit) {\n\n let uCode = theUnit['csCode_'];\n if (uCode) {\n\n if (this.unitCodes_[uCode])\n throw(new Error(`UnitTables.addUnitCode called, already contains entry for ` +\n `unit with code = ${uCode}`));\n else {\n this.unitCodes_[uCode] = theUnit;\n this.codeOrder_.push(uCode);\n if (uCode == 'g') {\n let dimVec = theUnit.dim_.dimVec_;\n let d = 0;\n for (; d < dimVec.length && dimVec[d] < 1; d++) ;\n this.massDimIndex_ = d;\n }\n }\n }\n else\n throw(new Error('UnitTables.addUnitCode called for unit that has ' +\n 'no code.')) ;\n\n } // end addUnitCode\n\n\n /**\n * Adds a unit object to the unitStrings_ table. More than one unit\n * can have the same string, so an array of unit objects is stored\n * for the string. The unit string is the string that creates a non-base\n * unit, e.g., a Newton has a unit code of N, a name of Newton, and a\n * unitString of kg.m/s2.\n *\n * If the unit has no string, nothing is stored and no error is reported.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n */\n addUnitString(theUnit) {\n\n let uString = null;\n if (Ucum.caseSensitive_ == true)\n uString = theUnit['csUnitString_'];\n else\n uString = theUnit['ciUnitString_'];\n\n if (uString) {\n let uEntry = {mag: theUnit['baseFactorStr_'], unit: theUnit};\n if (this.unitStrings_[uString])\n this.unitStrings_[uString].push(uEntry);\n else\n this.unitStrings_[uString] = [uEntry];\n }\n } // end addUnitString\n\n\n /**\n * Adds a Unit object to the unitDimensions_ table. More than one unit\n * can have the same dimension (commensurable units have the same dimension).\n * Because of this, an array of unit objects is stored for the\n * dimension.\n *\n * @param theUnit the unit to be added\n * @returns nothing\n * @throws an error if the unit has no dimension\n */\n addUnitDimension(theUnit) {\n\n let uDim = theUnit['dim_'].getProperty('dimVec_');\n\n if (uDim) {\n if (this.unitDimensions_[uDim])\n this.unitDimensions_[uDim].push(theUnit);\n else\n this.unitDimensions_[uDim] = [theUnit];\n }\n else\n throw(new Error('UnitTables.addUnitDimension called for a unit with no dimension. ' +\n `Unit code = ${theUnit['csCode_']}.`));\n\n } // end addUnitDimension\n\n\n /**\n * Builds the unitSynonyms_ table. This is called the first time the\n * getUnitsBySynonym method is called. The table/hash contains each word\n * (once) from each synonym as well as each word from each unit name.\n *\n * Hash keys are the words. Hash values are an array of unit codes for\n * each unit that has that word in its synonyms or name.\n *\n * @returns nothing\n */\n buildUnitSynonyms() {\n\n for (let code in this.unitCodes_) {\n let theUnit = this.unitCodes_[code];\n let uSyns = theUnit.synonyms_ ;\n\n // If the current unit has synonyms, process each synonym (often multiples)\n if (uSyns) {\n let synsAry = uSyns.split(';');\n if (synsAry[0] !== '') {\n let aLen = synsAry.length;\n for (let a = 0; a < aLen; a++) {\n let theSyn = synsAry[a].trim();\n\n // call addSynonymCodes to process each word in the\n // synonym, e.g., \"British fluid ounces\"\n this.addSynonymCodes(code, theSyn) ;\n } // end do for each synonym\n } // end if the current unit has a non-null synonym attribute\n } // end if the unit has any synonyms\n\n // Now call addSynonymCodes to process each word in the unit's name\n this.addSynonymCodes(code, theUnit.name_) ;\n } // end do for each unit\n } // end buildUnitSynonyms\n\n\n /**\n * Adds unit code entries to the synonyms table for a string containing\n * one or more words to be considered as synonyms.\n *\n * @param theCode the unit code to be connected to the synonyms\n * @param theSynonyms a string containing one or more words to be\n * considered synonyms (and thus to be added to the unitSynonyms hash).\n */\n addSynonymCodes(theCode, theSynonyms) {\n\n let words = theSynonyms.split(' ');\n let wLen = words.length;\n\n for (let w = 0; w < wLen; w++) {\n let word = words[w];\n\n // if there is already a synonyms entry for the word,\n // get the array of unit codes currently assigned to\n // the word and add the code for the current word to\n // the synonyms array if it's not already there.\n if (this.unitSynonyms_[word]) {\n let synCodes = this.unitSynonyms_[word];\n if (synCodes.indexOf(theCode) === -1) {\n this.unitSynonyms_[word].push(theCode);\n }\n }\n // else there are no synonyms entry for the word. Create a\n // synonyms array for the word, setting it to contain the unit code.\n else {\n this.unitSynonyms_[word] = [theCode];\n }\n } // end do for each word in the synonyms being processed\n\n } // end addSynonymCodes\n\n\n /**\n * Returns a unit object with a case-sensitive code matching the\n * uCode parameter, or null if no unit is found with that code.\n *\n * @param uCode the code of the unit to be returned\n * @returns the unit object or null if it is not found\n */\n getUnitByCode(uCode) {\n let retUnit = null ;\n if (uCode) {\n retUnit = this.unitCodes_[uCode];\n }\n return retUnit ;\n }\n\n\n /**\n * Returns a array of unit objects based on the unit's name. Usually this\n * will be an array of one, but there may be more, since unit names are\n * not necessarily unique.\n *\n * @param uName the name of the unit to be returned. If more than one\n * unit has the same name and you only want one specific unit, append the\n * csCode of the unit you want to the end of the name, separated by the\n * Ucum.codeSep_ value, e.g., inch - [in_i] vs. inch - [in_us].\n * @returns null if no unit was found for the specified name OR an array of\n * unit objects with the specified name. Normally this will be an array\n * of one object.\n * @throws an error if no name is provided to search on\n */\n getUnitByName(uName) {\n\n if (uName === null || uName === undefined) {\n throw (new Error('Unable to find unit by name because no name was provided.'));\n }\n let sepPos = uName.indexOf(Ucum.codeSep_);\n let uCode = null;\n if (sepPos >= 1) {\n uCode = uName.substr(sepPos + Ucum.codeSep_.length);\n uName = uName.substr(0, sepPos);\n }\n let retUnits = this.unitNames_[uName] ;\n if (retUnits) {\n let uLen = retUnits.length ;\n\n if (uCode && uLen > 1) {\n let i = 0;\n for (; retUnits[i].csCode_ !== uCode && i < uLen; i++);\n if (i < uLen)\n retUnits = [retUnits[i]];\n else {\n retUnits = null;\n }\n } // end if we need to find both a name and a code\n } // end if we got an array of units\n return retUnits ;\n\n } // end getUnitByName\n\n\n /**\n * Returns an array of unit objects with the specified unit string.\n * The array may contain one or more unit reference objects.\n * Or none, if no units have a matching unit string (which is not\n * considered an error)\n *\n * @param name the name of the unit to be returned\n * @returns the array of unit references or null if none were found\n */\n getUnitByString(uString) {\n let retAry = null ;\n if (uString) {\n retAry = this.unitStrings_[uString] ;\n if (retAry === undefined)\n retAry = null;\n }\n return retAry ;\n }\n\n\n /**\n * Returns a array of unit objects based on the unit's dimension vector.\n *\n * @param uName the dimension vector of the units to be returned.\n *\n * @returns null if no unit was found for the specified vector OR an array of\n * one or more unit objects with the specified vector.\n * @throws an error if no vector is provided to search on\n * logs an error to the console if no unit is found\n */\n getUnitsByDimension(uDim) {\n\n let unitsArray = null ;\n if (uDim === null || uDim === undefined) {\n throw (new Error('Unable to find unit by because no dimension ' +\n 'vector was provided.'));\n }\n\n unitsArray = this.unitDimensions_[uDim] ;\n if (unitsArray === undefined || unitsArray === null) {\n console.log(`Unable to find unit with dimension = ${uDim}`);\n }\n\n return unitsArray ;\n\n } // end getUnitsByDimension\n\n\n /**\n * Returns a array of unit objects that include the specified synonym.\n *\n * @param uSyn the synonym of the units to be returned.\n *\n * @returns an object with two of the following three elements:\n * 'status' will be error, failed or succeeded\n * 'msg' will be included for returns with status = error or failed and\n * will explain why the request did not return any units\n * 'units' any array of unit objects with the specified synonym will be\n * returned for requests with status = succeeded\n */\n getUnitBySynonym(uSyn) {\n\n let retObj = {} ;\n let unitsArray = [];\n\n try {\n if (uSyn === null || uSyn === undefined) {\n retObj['status'] = 'error' ;\n throw (new Error('Unable to find unit by synonym because no synonym ' +\n 'was provided.'));\n }\n // If this is the first request for a unit by synonym, build the hash map\n if (Object.keys(this.unitSynonyms_).length === 0) {\n this.buildUnitSynonyms();\n }\n let foundCodes = [];\n foundCodes = this.unitSynonyms_[uSyn];\n if (foundCodes) {\n retObj['status'] = 'succeeded';\n let fLen = foundCodes.length;\n for (let f = 0; f < fLen; f++) {\n unitsArray.push(this.unitCodes_[foundCodes[f]]);\n }\n retObj['units'] = unitsArray ;\n }\n if (unitsArray.length === 0) {\n retObj['status'] = 'failed' ;\n retObj['msg'] = `Unable to find any units with synonym = ${uSyn}`;\n }\n }\n catch(err) {\n retObj['msg'] = err.message ;\n }\n return retObj ;\n } // end getUnitBySynonym\n\n\n /**\n * Gets a list of all unit names in the Unit tables\n *\n * @returns an array of the unit names\n */\n getAllUnitNames() {\n return Object.keys(this.unitNames_);\n } // end getAllUnitNames\n\n\n /**\n * Gets a list of all unit names in the tables. Where more than one\n * unit has the same name, the unit code, in parentheses, is appended\n * to the end of the name.\n *\n * @returns {Array}\n */\n getUnitNamesList() {\n let nameList = [];\n let codes = Object.keys(this.unitCodes_);\n codes.sort(this.compareCodes) ;\n let uLen = codes.length;\n for (let i = 0; i < uLen; i++) {\n nameList[i] = codes[i] + Ucum.codeSep_ + this.unitCodes_[codes[i]].name_\n } // end do for each code\n return nameList ;\n }\n\n\n /*\n * Returns the mass dimension index\n * @returns this.massDimIndex_\n */\n getMassDimensionIndex() {\n return this.massDimIndex_ ;\n }\n\n /**\n * This provides a sort function for unit codes so that sorting ignores\n * square brackets and case.\n *\n * @param a first value\n * @param b second value\n * @returns -1 if a is should fall before b; otherwise 1.\n */\n compareCodes(a, b) {\n a = a.replace(/[\\[\\]]/g, '');\n a = a.toLowerCase();\n b = b.replace(/[\\[\\]]/g, '');\n b = b.toLowerCase();\n return (a < b) ? -1 : 1 ;\n }\n\n\n /**\n * Gets a list of all unit codes in the Unit tables\n *\n * @returns an array of the unit names\n */\n getAllUnitCodes() {\n return Object.keys(this.unitCodes_);\n } // end getAllUnitNames\n\n\n /**\n * This is used to get all unit objects. Currently it is used\n * to get the objects to write to the json ucum definitions file\n * that is used to provide prefix and unit definition objects for\n * conversions and validations.\n *\n * @returns an array containing all unit objects, ordered by definition\n * order\n */\n allUnitsByDef() {\n\n let unitsList = [];\n let uLen = this.codeOrder_.length ;\n for (let u = 0; u < uLen; u++) {\n unitsList.push(this.getUnitByCode(this.codeOrder_[u]));\n }\n return unitsList ;\n } // end allUnitsByDef\n\n\n /**\n * This is used to get all unit objects, ordered by unit name. Currently it\n * is used to create a csv list of all units.\n * @param sep separator character (or string) to be used to separate each\n * column in the output. Optional, defaults to '|' if not specified.\n * (Used to use ; but the synonyms use that extensively). Don't use a\n * comma or any other punctuation found in the output data.\n * @returns a buffer containing all unit objects, ordered by name\n * order\n */\n allUnitsByName(cols, sep) {\n if (sep === undefined || sep === null)\n sep = '|';\n let unitBuff = '';\n let unitsList = this.getAllUnitNames();\n let uLen = unitsList.length;\n let cLen = cols.length;\n for (let i = 0; i < uLen; i++) {\n let nameRecs = this.getUnitByName(unitsList[i]);\n for (let u = 0; u < nameRecs.length; u++) {\n let rec = nameRecs[u];\n for (let c = 0; c < cLen; c++) {\n if (c > 0)\n unitBuff += sep;\n if (cols[c] === 'dim_') {\n if (rec.dim_ !== null && rec.dim_ !== undefined &&\n rec.dim_.dimVec_ instanceof Array)\n unitBuff += '[' + rec.dim_.dimVec_.join(',') + ']';\n else\n unitBuff += '';\n }\n else {\n let cbuf = rec[cols[c]];\n if (typeof cbuf === 'string')\n unitBuff += cbuf.replace(/[\\n\\r]/g, ' ');\n else\n unitBuff += cbuf ;\n }\n } // end do for each column requested\n unitBuff += '\\r\\n';\n } // end do for each unit in the unit names array\n }\n return unitBuff ;\n } // end allUnitsByName\n\n\n /**\n * This creates a list of all units in the tables. It uses the byCode\n * table, and uses the codeOrder_ array to determine the order in which\n * the units are listed.\n *\n * @param doLong boolean indicating how much to output. If true, all data\n * from the unit objects is included. If false, only a few major values\n * are included.\n * @param sep separator character (or string) to be used to separate each\n * column in the output. Optional, defaults to '|' if not specified.\n * (Used to use ; but the synonyms use that extensively).\n * @returns {string} buffer containing all the listings\n */\n printUnits(doLong, sep) {\n if (doLong === undefined)\n doLong = false ;\n if (sep === undefined)\n sep = '|';\n let codeList = '';\n let uLen = this.codeOrder_.length ;\n let unitString = 'csCode' + sep ;\n if (doLong) {\n unitString += 'ciCode' + sep ;\n }\n unitString += 'name' + sep ;\n if (doLong)\n unitString += 'isBase' + sep ;\n unitString += 'magnitude' + sep + 'dimension' + sep + 'from unit(s)' + sep +\n 'value' + sep + 'function' + sep ;\n if (doLong)\n unitString += 'property' + sep + 'printSymbol' + sep + 'synonyms' + sep +\n 'source' + sep + 'class' + sep + 'isMetric' + sep +\n 'variable' + sep + 'isSpecial' + sep + 'isAbitrary' + sep ;\n unitString += 'comment';\n codeList = unitString + '\\n' ;\n\n for (let u = 0; u < uLen; u++) {\n let curUnit = this.getUnitByCode(this.codeOrder_[u]);\n unitString = this.codeOrder_[u] + sep ;\n if (doLong) {\n unitString += curUnit.getProperty('ciCode_') + sep ;\n }\n unitString += curUnit.getProperty('name_') + sep ;\n if (doLong) {\n if (curUnit.getProperty('isBase_'))\n unitString += 'true' + sep ;\n else\n unitString += 'false' + sep ;\n }\n unitString += curUnit.getProperty('magnitude_') + sep;\n let curDim = curUnit.getProperty('dim_');\n if (curDim) {\n unitString += curDim.dimVec_ + sep ;\n }\n else {\n unitString += 'null' + sep;\n }\n if (curUnit.csUnitString_)\n unitString += curUnit.csUnitString_ + sep + curUnit.baseFactor_ + sep ;\n else\n unitString += 'null' + sep + 'null' + sep;\n\n if (curUnit.cnv_)\n unitString += curUnit.cnv_ + sep ;\n else\n unitString += 'null' + sep ;\n\n if (doLong) {\n unitString += curUnit.getProperty('property_') + sep +\n curUnit.getProperty('printSymbol_') + sep +\n curUnit.getProperty('synonyms_') + sep +\n curUnit.getProperty('source_') + sep +\n curUnit.getProperty('class_') + sep +\n curUnit.getProperty('isMetric_') + sep +\n curUnit.getProperty('variable_') + sep +\n curUnit.getProperty('isSpecial_') + sep +\n curUnit.getProperty('isArbitrary_') + sep ;\n }\n if (curUnit.defError_)\n unitString += 'problem parsing this one, deferred to later.' ;\n codeList += unitString + '\\n' ;\n }\n return codeList ;\n }\n\n} // end UnitTablesFactory\n\n\n// Create a singleton instance and (to preserve the existing API) an object that\n// provides that instance via getInstance().\nvar unitTablesInstance = new UnitTablesFactory();\nexport const UnitTables = {\n getInstance: function() {\n return unitTablesInstance;\n }\n}\n"],"file":"unitTables.js"}
package/CHANGELOG.md DELETED
@@ -1,329 +0,0 @@
1
- # Change Log
2
- All notable changes to this project will be documented in this file.
3
-
4
- The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
- and this project adheres to [Semantic Versioning](http://semver.org/).
6
-
7
- ## [4.1.7] 2022-12-21
8
- ### Fixed
9
- - Units from the data/ucum.csv file, which contains many unit strings with
10
- prefixes, were previously permitted to take an additional prefix.
11
- - Units derived from other units were previously being labeled as "base units",
12
- though apparently without ill effect on the current public APIs.
13
-
14
- ## [4.1.6] 2022-09-13
15
- ### Changed
16
- - Update version to 4.1.6 for tagging the last merge, which was to update
17
- generated files but was not given a new version number and not tagged.
18
-
19
- ## [4.1.5] 2021-05-20
20
- ### Fixed
21
- - Fixed generated name issue for complex units, https://github.com/lhncbc/ucum-lhc/issues/29
22
-
23
- ## [4.1.4] 2021-01-05
24
- ### Fixed
25
- - Moved grunt-extract-sourcemap to devDependencies.
26
- - Updated dependencies to avoid issues raised by npm audit (except one
27
- on a devDependency).
28
-
29
- ## [4.1.3] 2020-04-20
30
- ### Fixed
31
- - Fixed to work in IE 11.
32
-
33
- ## [4.1.2] 2020-04-03
34
- ### Changes
35
- - Updated dependencies to get patches for security vulnerabilities.
36
-
37
- ## [4.1.1] 2020-03-09
38
- ### Changes
39
- - removed unnecessary index.html
40
-
41
- ## [4.1.0] 2020-03-05
42
- ### Changes
43
- - the sizes of ucumDefs.json and related files reduced
44
-
45
- ## [4.0.2] 2020-03-02
46
- ### Fixed
47
- - ucumDefs.json generation: baseFactor_ and magnitude_ should be numbers
48
- ### Added
49
- - added impexp/README.md about generating ucumDef.json
50
-
51
- ## [4.0.1] 2020-02-14
52
- ### Fixed
53
- - 4.0.0 was just published today, and is missing a data file in the npm package.
54
- This version fixes that.
55
-
56
- ## [4.0.0] 2020-01-27
57
- ### Changed
58
- - This main file of the npm package is now a file that uses CommonJS modules
59
- (i.e., NodeJs-compatible) instead of a browserified bundle. The problem with
60
- serving a browserfied bundle via npm was that if you pulled it in and then
61
- tried to browserify it along with application code, an exception would be thrown
62
- because browserify has already run on part of the code. The change should be
63
- transparent to the user of the package, but just in case there is some
64
- unforeseen consequence, I am incrementing the major version. If your
65
- application needs the browserified version, that is still available in the
66
- browser-dist directory.
67
-
68
- ## [3.0.1] 2020-01-07
69
- ### Fixed
70
- - Corrected processing so that strings like "1e2" are no longer considered valid
71
- units.
72
-
73
- ## [3.0.0] - 2019-09-26
74
- ### Fixed
75
- - Updated dependencies to get patches for security vulnerabilities.
76
- - Minor corrections to the UCUM data (mostly with regard to extra properties we
77
- added like "guidance").
78
- ### Changed
79
- - As result of the dependency update, the build process needed to be revised,
80
- and the individual transpiled files were removed. The package.json "main"
81
- file has changed. This is not expected to cause a problem for normal usage of
82
- the package (relying on the "main" file), and the API has not changed, but due
83
- to the upheaval, a semver-major change seemed warranted.
84
-
85
- ## [2.6.4] - 2019-06-05
86
- ### Fixed
87
- - Updated dependencies to get patches for security vulnerabilities.
88
-
89
- ## [2.6.3] - 2019-04-29
90
- ### Fixed
91
- - Demo page: The validation message on the Validator tab was displayed
92
- vertically when the unit was valid.
93
-
94
- ## [2.6.2] - 2019-03-29
95
- ### Fixed
96
- - Demo page changes: fixed processing flow problem that allowed an attempt to
97
- convert an invalid unit; tweaked flow on initial display of converter tab;
98
- added meta data to the page to increase visibility to search engines.
99
-
100
- ## [2.6.1] - 2019-03-22
101
- ### Added
102
- - Added mass<-> moles conversion to the UCUM Demo page, with a request to the
103
- user to supply a molecular weight when such a conversion is requested.
104
-
105
- ## [2.6.0] - 2019-03-08
106
- ### Added
107
- - Added capability to existing convertUnitTo library function to convert mass
108
- to moles expression.
109
-
110
- ## [2.5.5] - 2019-02-28
111
- ### Fixed
112
- - Fixed mismatches with version numbers as well as problem with library
113
- distribution on 2.5.2.
114
-
115
- ## [2.5.2] - 2019-02-05
116
- ### Fixed
117
- - Fixed problem with 2.5.0 where not all files were being included in the
118
- source-es5/ucumPkg.js package.
119
-
120
- ## [2.5.0] - 2019-01-07
121
- ### Changed
122
- - The changes made by browserify have been removed from the ucum-lhc package
123
- available to node.js users, necessitating the creation of separate distributions.
124
- The distribution of the library code starts at the source-es5/ucumPkg.js file.
125
- The distribution in the browser-dist directory contains server side code that
126
- includes browser related code. The distribution in the demo-dist directory
127
- continues to contain the code related to the UCUM-LHC demo page.
128
-
129
- ## [2.4.4] - 2018-12-13
130
- ### Fixed
131
- - fixed bug where validation of a unit string that contains an operator, such
132
- as B[10.nV] is a valid string and validates correctly as a single valid UCUM
133
- code, but did not validate correctly when preceded by a prefix, e.g., dB[10.nV].
134
-
135
- ## [2.4.3] - 2018-11-06
136
- ### Fixed
137
- - fixed bug where validation of a unit string terminated with an operator
138
- returned an incorrect response. It correctly flagged the string as an
139
- invalid unit expression but included a coding error message that should
140
- not have been included.
141
-
142
- ## [2.4.2] - 2018-11-05
143
- ### Fixed
144
- - blocked division and multiplication operations as well as conversion
145
- operations on arbitrary units
146
-
147
- ## [2.4.1] - 2018-10-25
148
- ### Added
149
- - Added capability to open directly to converter page using url
150
- https://ucum.nlm.nih.gov/ucum-lhc/demo.html#converter
151
-
152
- ## [2.4.0] - 2018-10-10
153
- ### Changed
154
- - redesigned validator tab on Demo page to move messages closer to the
155
- unit expression input field
156
- - redesigned converter tab on Demo page to resemble an equation for the
157
- conversion
158
-
159
- ## [2.3.4] - 2018-08-15
160
- ### Fixed
161
- - Updated npm packages growl and semver to avoid critical security
162
- vulnerabilities flagged by GitHub
163
-
164
- ## [2.3.3] - 2018-08-15
165
- ### Fixed
166
- - Updated conversion code to properly handle conversion of unitless
167
- measurements, such as moles.
168
- - Updated code to make text for combined units, e.g., 2.(mmol/L), more
169
- explicit in regards to evaluation order.
170
-
171
- ## [2.3.2] - 2018-06-27
172
- ### Fixed
173
- - fixed appearance of the demo page converter tab so that when the page is
174
- widened in the browser the text all anchors on the left. One portion
175
- of the text was anchored to the right, which made a widened version look
176
- wrong.
177
-
178
- ## [2.3.1] - 2018-06-13
179
- ### Fixed
180
- - modifications to ensure that plain numbers, e.g., 7, are reported correctly.
181
- ### Added
182
- - added unit name to demo output messages, where available, to make sure user
183
- knows what unit is being reported as valid.
184
-
185
- ## [2.3.0] - 2018-05-23
186
- ### Added
187
- - added information related to version number of the ucum-essence.xml
188
- file used as well as changes made to it
189
-
190
- ## [2.2.1] - 2018-05-22
191
- ### Changed
192
- - reformatted display of suggestions lists for the demo site to use a bulleted
193
- list of suggestions rather than a plain text list.
194
- ## Fixed
195
- - fixed a bug that prevented suggestion lists from being created for more than
196
- one unit.
197
-
198
- ## [2.2.0] - 2018-05-02
199
- ### Changed
200
- - added list selection listener to unit expression field on validation
201
- tab of the demo page
202
- ### Fixed
203
- - fixed autofill problem on Edge browser.
204
-
205
- ## [2.3.4] - 2018-05-?
206
- - fixed positioning of text on converter tab of the demo page so that
207
- it is consistent in how it lines up when the page is widened.
208
-
209
- ## [2.1.12] - 2018-04-26
210
- ### Changed
211
- - changed unit name (not code) creation for constructed units to enclose
212
- the name in square brackets and use an asterisk (*) for multiplication
213
- instead of a period.
214
-
215
- ## [2.1.11] - 2018-04-23
216
- ### Fixed
217
- - fix for overwritten units during data update process
218
-
219
- ## [2.1.10] - 2018-04-12
220
- ### Changed
221
- - updates to register bower package
222
-
223
- ## [2.1.9] - 2018-04-03
224
- ### Changed
225
- - updates to third party and UCUM LHC license information
226
-
227
- ## [2.1.8] - 2018-03-28
228
- ### Fixed
229
- - fixes to csv file validator
230
-
231
- ## [2.1.7] - 2018-03-12
232
- ### Changed
233
- - cosmetic updates to overview and demo pages related to banner, titles
234
-
235
- ## [2.1.6] - 2018-03-07
236
- ### Changed
237
- - created npm package
238
-
239
- ## [2.1.5] - 2018-02-21
240
- ### Changed
241
- - shifts module tests to use distribution package
242
- - moves ucumFileValidator to demo directory
243
- - updates README
244
-
245
- ## [2.1.4] - 2018-02-16
246
- ### Changed
247
- - removes guidance text for constructed units, e.g., units that are created
248
- on the fly, as they are specified for validation or conversion. For example,
249
- m\[H2O\]/cm is constructed from m\[H2O\] (meter of water column) divided by
250
- cm (centimeter). No guidance data is provided for this constructed unit.
251
-
252
- ## [2.1.3] - 2018-02-15
253
- ### Changed
254
- - added disclaimer concerning conversion results to demo page convert
255
- tab and to README.md page
256
-
257
- ## [2.1.2] - 2018-02-15
258
- ### Fixed
259
- - completed bug fix for zero and negative number of units for conversions.
260
-
261
- ## [2.1.1] - 2018-01-25
262
- ### Changed
263
- - updated link at the top of the demo page to refer back to the
264
- overview page - and the link at the top of the overview page to
265
- refer back to itself.
266
- - added text to the demo file validation to clarify that only
267
- units are validated. Prefixes on their own are not validated.
268
- - updated the ucumDefs.json with version 2.1 (November 21, 2017) of the
269
- ucum-essence.xml file from unitsofmeasure.org
270
- ### Fixed
271
- - started fixes on a bug where a zero or negative number of units was considered an error.
272
-
273
-
274
- ## [2.1.0] - 2017-12-21
275
- ### Changed
276
- - Upgraded the validation processing for conversion request on the
277
- demo page; validation is now performed on the fly as each element
278
- is entered. This is a change only to the demo page.
279
-
280
- ## [2.0.0] - 2017-12-01
281
- ### Added
282
- - Added ability to get suggestions for invalid unit expressions.
283
-
284
- ## [1.2.0] - 2017-10-06
285
- ### Fixed
286
- - Enhanced unit string validation to accommodate/correct:
287
- - missing multiplication operators, e.g., **2mg** instead of **2.mg**;
288
- - unit name specified instead of ucum code, e.g., **day** instead of **d**;
289
- - misplaced annotations, e.g., **{creatine}**mol** instead of mol**{creatine}**;
290
- - missing square brackets, e.g., **in_i** instead of **[in_i]**; and
291
- - braces instead of brackets, e.g., **{degF}** instead of **[degF]**.
292
-
293
- ## [1.1.2] - 2017-08-07
294
- ### Changed
295
- - Updated unit creation process to include updates to case-insensitve codes
296
- and print symbol values when creating a unit from multiple units.
297
- - Updated treatment of prefixes for special units that use conversion
298
- functions to record prefix values in the separate conversion prefix field.
299
-
300
- ## [1.1.1] - 2017-07-13
301
- ### Changed
302
- - Data file has been updated with enhanced synonyms and is also now written
303
- in a a readable JSON format.
304
-
305
- ## [1.1.0] - 2017-07-06
306
- ### Changed
307
- - Autocompleters no longer return multiple-unit strings, e.g., kg/cm.
308
- Multiple-unit strings are still (very) valid, but the autocompleters just
309
- return one list single-unit strings at a time.
310
- - The commensurables list on the conversion tab's "convert to" field has been
311
- changed to just use the same autocompleter as used for the "convert from" field.
312
- The list will now include units that cannot be converted.
313
-
314
- ## [1.0.2] - 2017-06-23
315
- ### Fixed
316
- - Allowed conversion of units with no dimensions
317
- - added testing for the Unit.convertFrom and Unit.convertTo functions
318
-
319
- ## [1.0.1] - 2017-05-30
320
- ### Added
321
- - This change log.
322
- ### Changed
323
- - Streamlined divString function in Unit.js
324
- - Moved parenthesized unit string processing to separate function
325
- in UnitString.js (processParens).
326
- - Added testing for the processParens function in testUnitString.spec.js
327
- ### Fixed
328
- - Updated UcumFileValidator.js with previously changed function name
329
- (validUnitString -> validateUnitString in UcumLhcUtils.js).