@lhncbc/ucum-lhc 7.1.0 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lhncbc/ucum-lhc",
3
- "version": "7.1.0",
3
+ "version": "7.1.1",
4
4
  "description": "Implements Unified Code for Units of Measure (UCUM) functions in a javascript library",
5
5
  "main": "source-cjs/ucumPkg.js",
6
6
  "homepage": "https://lhncbc.github.io/ucum-lhc/",
@@ -293,12 +293,14 @@ export class UcumLhcUtils {
293
293
  * in case it's needed for additional data from the object.
294
294
  */
295
295
  convertUnitTo(fromUnitCode, fromVal, toUnitCode, options = {}) {
296
- let { suggest = false, molecularWeight = null, charge = null } = options;
296
+ let {suggest = false, molecularWeight = null, charge = null} = options;
297
297
 
298
298
  /** @type {ConvertUnitResult} */
299
- let returnObj = {'status' : 'failed',
300
- 'toVal' : null,
301
- 'msg' : []} ;
299
+ let returnObj = {
300
+ 'status': 'failed',
301
+ 'toVal': null,
302
+ 'msg': []
303
+ };
302
304
 
303
305
  if (fromUnitCode) {
304
306
  fromUnitCode = fromUnitCode.trim();
@@ -316,116 +318,120 @@ export class UcumLhcUtils {
316
318
  returnObj['msg'].push('No "to" unit expression specified.');
317
319
  }
318
320
  if (returnObj['status'] !== 'error') {
319
- try {
320
- let fromUnit = null;
321
-
322
- let parseResp = this.getSpecifiedUnit(fromUnitCode, 'convert', suggest);
323
- fromUnit = parseResp['unit'];
324
- if (parseResp['retMsg'])
325
- returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);
326
- if (parseResp['suggestions']) {
327
- returnObj['suggestions'] = {};
328
- returnObj['suggestions']['from'] = parseResp['suggestions'];
329
- }
330
- if (!fromUnit) {
331
- returnObj['msg'].push(`Unable to find a unit for ${fromUnitCode}, ` +
332
- `so no conversion could be performed.`);
333
- }
321
+ let fromUnit = null;
322
+
323
+ let parseResp = this.getSpecifiedUnit(fromUnitCode, 'convert', suggest);
324
+ fromUnit = parseResp['unit'];
325
+ if (parseResp['retMsg'])
326
+ returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);
327
+ if (parseResp['suggestions']) {
328
+ returnObj['suggestions'] = {};
329
+ returnObj['suggestions']['from'] = parseResp['suggestions'];
330
+ }
331
+ if (!fromUnit) {
332
+ returnObj['msg'].push(`Unable to find a unit for ${fromUnitCode}, ` +
333
+ `so no conversion could be performed.`);
334
+ }
334
335
 
335
- let toUnit = null;
336
- parseResp = this.getSpecifiedUnit(toUnitCode, 'convert', suggest);
337
- toUnit = parseResp['unit'];
338
- if (parseResp['retMsg'])
339
- returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);
340
- if (parseResp['suggestions']) {
341
- if (!returnObj['suggestions'])
342
- returnObj['suggestions'] = {} ;
343
- returnObj['suggestions']['to'] = parseResp['suggestions'];
344
- }
345
- if (!toUnit) {
346
- returnObj['msg'].push(`Unable to find a unit for ${toUnitCode}, ` +
347
- `so no conversion could be performed.`);
348
- }
336
+ let toUnit = null;
337
+ parseResp = this.getSpecifiedUnit(toUnitCode, 'convert', suggest);
338
+ toUnit = parseResp['unit'];
339
+ if (parseResp['retMsg'])
340
+ returnObj['msg'] = returnObj['msg'].concat(parseResp['retMsg']);
341
+ if (parseResp['suggestions']) {
342
+ if (!returnObj['suggestions'])
343
+ returnObj['suggestions'] = {};
344
+ returnObj['suggestions']['to'] = parseResp['suggestions'];
345
+ }
346
+ if (!toUnit) {
347
+ returnObj['msg'].push(`Unable to find a unit for ${toUnitCode}, ` +
348
+ `so no conversion could be performed.`);
349
+ }
349
350
 
350
- if (fromUnit && toUnit) {
351
- try {
352
- const convertType = this.detectConversionType(fromUnit, toUnit);
353
-
354
- switch (convertType) {
355
- case 'normal':
356
- returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);
357
- break;
358
- case 'mol|mass':
359
- if (!molecularWeight) {
360
- throw new Error(Ucum.needMoleWeightMsg_);
361
- }
362
- if (!fromUnit.isMolMassCommensurable(toUnit)) {
363
- throw new Error(`Sorry. ${fromUnitCode} cannot be ` +
364
- `converted to ${toUnitCode}.`);
365
- }
366
- returnObj['toVal'] = fromUnit.convertMolMass(fromVal, toUnit, molecularWeight);
367
- break;
368
- case 'eq|mass':
369
- if (!molecularWeight) {
370
- throw new Error(Ucum.needEqWeightMsg_);
371
- }
372
- if (!charge) {
373
- throw new Error(Ucum.needEqChargeMsg_);
374
- }
375
- if (!fromUnit.isEqMassCommensurable(toUnit)) {
376
- throw new Error(`Sorry. ${fromUnitCode} cannot be ` +
377
- `converted to ${toUnitCode}.`);
378
- }
379
- returnObj['toVal'] = fromUnit.convertEqMass(fromVal, toUnit, molecularWeight, charge);
380
- break;
381
- case 'eq|mol':
382
- if (!fromUnit.isEqMolCommensurable(toUnit)) {
383
- throw new Error(`Sorry. ${fromUnitCode} cannot be ` +
384
- `converted to ${toUnitCode}.`);
385
- }
386
- if (!charge) {
387
- throw new Error(Ucum.needEqChargeMsg_);
388
- }
389
- returnObj['toVal'] = fromUnit.convertEqMol(fromVal, toUnit, charge);
390
- break;
391
- case 'eq|mol|mass':
392
- if (!molecularWeight) {
393
- throw new Error(Ucum.needEqWeightMsg_);
394
- }
395
- if (!charge) {
396
- throw new Error(Ucum.needEqChargeMsg_);
397
- }
398
- if (!fromUnit.isEqMolMassCommensurable(toUnit)) {
399
- throw new Error(`Sorry. ${fromUnitCode} cannot be ` +
400
- `converted to ${toUnitCode}.`);
401
- }
402
- returnObj['toVal'] = fromUnit.convertEqMolMass(fromVal, toUnit, molecularWeight, charge);
403
- break;
404
- default:
405
- throw new Error("Unknown conversion type. No conversion was attempted.");
351
+ if (fromUnit && toUnit) {
352
+ const convertType = this.detectConversionType(fromUnit, toUnit);
353
+ const msgCountBeforeConvert = returnObj['msg'].length;
354
+ switch (convertType) {
355
+ case 'normal':
356
+ try {
357
+ returnObj['toVal'] = toUnit.convertFrom(fromVal, fromUnit);
358
+ } catch (err) {
359
+ returnObj['msg'].push(err.message);
406
360
  }
407
- // if an error hasn't been thrown - either from convertFrom or here,
408
- // set the return object to show success
409
- returnObj['status'] = 'succeeded';
410
- returnObj['fromUnit'] = fromUnit;
411
- returnObj['toUnit'] = toUnit;
412
- }
413
- catch (err) {
414
- returnObj['status'] = 'failed';
415
- returnObj['msg'].push(err.message);
416
- }
417
- } // end if we have the from and to units
418
- }
419
- catch (err) {
420
- if (err.message == Ucum.needMoleWeightMsg_)
361
+ break;
362
+ case 'mol|mass':
363
+ if (!fromUnit.isMolMassCommensurable(toUnit)) {
364
+ returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +
365
+ `converted to ${toUnitCode}.`);
366
+ break;
367
+ }
368
+ if (!molecularWeight) {
369
+ returnObj['msg'].push(Ucum.needMoleWeightMsg_);
370
+ break;
371
+ }
372
+ returnObj['toVal'] = fromUnit.convertMolMass(fromVal, toUnit, molecularWeight);
373
+ break;
374
+ case 'eq|mass':
375
+ if (!fromUnit.isEqMassCommensurable(toUnit)) {
376
+ returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +
377
+ `converted to ${toUnitCode}.`);
378
+ break;
379
+ }
380
+ if (!molecularWeight) {
381
+ returnObj['msg'].push(Ucum.needEqWeightMsg_);
382
+ }
383
+ if (!charge) {
384
+ returnObj['msg'].push(Ucum.needEqChargeMsg_);
385
+ }
386
+ if (!returnObj['msg'].length) {
387
+ returnObj['toVal'] = fromUnit.convertEqMass(fromVal, toUnit, molecularWeight, charge);
388
+ }
389
+ break;
390
+ case 'eq|mol':
391
+ if (!fromUnit.isEqMolCommensurable(toUnit)) {
392
+ returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +
393
+ `converted to ${toUnitCode}.`);
394
+ break;
395
+ }
396
+ if (!charge) {
397
+ returnObj['msg'].push(Ucum.needEqChargeMsg_);
398
+ break;
399
+ }
400
+ returnObj['toVal'] = fromUnit.convertEqMol(fromVal, toUnit, charge);
401
+ break;
402
+ case 'eq|mol|mass':
403
+ if (!fromUnit.isEqMolMassCommensurable(toUnit)) {
404
+ returnObj['msg'].push(`Sorry. ${fromUnitCode} cannot be ` +
405
+ `converted to ${toUnitCode}.`);
406
+ break;
407
+ }
408
+ if (!molecularWeight) {
409
+ returnObj['msg'].push(Ucum.needEqWeightMsg_);
410
+ }
411
+ if (!charge) {
412
+ returnObj['msg'].push(Ucum.needEqChargeMsg_);
413
+ }
414
+ if (!returnObj['msg'].length) {
415
+ returnObj['toVal'] = fromUnit.convertEqMolMass(fromVal, toUnit, molecularWeight, charge);
416
+ }
417
+ break;
418
+ default:
419
+ returnObj['msg'].push("Unknown conversion type. No conversion was attempted.");
420
+ }
421
+ if (returnObj['msg'].length > msgCountBeforeConvert) {
422
+ // If one or more failure messages are pushed into returnObj['msg']
423
+ // in the switch statement, mark the status as 'failed'.
421
424
  returnObj['status'] = 'failed';
422
- else
423
- returnObj['status'] = 'error';
424
- returnObj['msg'].push(err.message);
425
- }
425
+ } else {
426
+ // Set the return object to show success.
427
+ returnObj['status'] = 'succeeded';
428
+ returnObj['fromUnit'] = fromUnit;
429
+ returnObj['toUnit'] = toUnit;
430
+ }
431
+ } // end if we have the from and to units
426
432
  }
427
433
 
428
- return returnObj ;
434
+ return returnObj;
429
435
 
430
436
  } // end convertUnitTo
431
437
 
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","names":["Ucum","dimLen_","validOps_","codeSep_","valMsgStart_","valMsgEnd_","cnvMsgStart_","cnvMsgEnd_","openEmph_","closeEmph_","openEmphHTML_","closeEmphHTML_","bracesMsg_","needMoleWeightMsg_","needEqWeightMsg_","needEqChargeMsg_","csvCols_","inputKey_","specUnits_","exports"],"sources":["../source/config.js"],"sourcesContent":["/*\n * This defines the namespace for the UCUM classes and provides\n * a place for the definition of global variables and constants.\n *\n * The javascript for this UCUM implementation uses syntax as\n * defined by the ECMAScript 6 standard\n */\n\nexport var Ucum = {\n\n /**\n * Flag indicating whether or not we're using case sensitive labels\n * I don't think we need this. I think we're just going with\n * case sensitive, per Clem. Gunther's code has this flag, but I\n * am removing it, at least for now. lm, 6/2016\n */\n //caseSensitive_: true ,\n\n /**\n * The number of elements in a Dimension array. Currently this\n * is set as a configuration variable, but when we get to the point\n * of loading the unit definitions from a file, this value will be\n * set from that.\n */\n dimLen_: 7,\n\n\n /**\n * The characters used as valid operators in a UCUM unit expression,\n * where '.' is for multiplication and '/' is for division.\n */\n validOps_: ['.', '/'],\n\n\n /**\n * The string used to separate a unit code and unit name when they\n * are displayed together\n */\n codeSep_ : ': ',\n\n // Message text variations for validation methods and conversion methods\n valMsgStart_ : 'Did you mean ',\n valMsgEnd_ : '?' ,\n cnvMsgStart_ : 'We assumed you meant ',\n cnvMsgEnd_ : '.',\n\n\n/**\n * Default opening string used to emphasize portions of error messages.\n * Used when NOT displaying messages on a web site, i.e., for output\n * from the library methods or to a file.\n */\n openEmph_ : ' ->',\n\n /**\n * Default closing string used to emphasize portions of error messages.\n * Used when NOT displaying messages on a web site, i.e., for output\n * from the library methods or to a file.\n */\n closeEmph_ : '<- ' ,\n\n /**\n * Opening HTML used to emphasize portions of error messages. Used when\n * displaying messages on a web site; should be blank when output is\n * to a file.\n */\n openEmphHTML_ : ' <span class=\"emphSpan\">',\n\n /**\n * Closing HTML used to emphasize portions of error messages. Used when\n * displaying messages on a web site; should be blank when output is\n * to a file.\n */\n closeEmphHTML_ : '</span> ' ,\n\n /**\n * Message that is displayed when annotations are included in a unit\n * string, to let the user know how they are interpreted.\n */\n bracesMsg_ : 'FYI - annotations (text in curly braces {}) are ignored, ' +\n 'except that an annotation without a leading symbol implies ' +\n 'the default unit 1 (the unity).',\n\n /**\n * Message that is displayed or returned when a conversion is requested\n * for two units where (only) a mass<->moles conversion is appropriate\n * but no molecular weight was specified.\n */\n needMoleWeightMsg_ : 'Did you wish to convert between mass and moles? The ' +\n 'molecular weight of the substance represented by the ' +\n 'units is required to perform the conversion.',\n\n /**\n * Message that is returned when a mass<->eq conversion is requested \n * (which requires a molecular weight to calculate), but no molecular \n * weight was provided by the user.\n */ \n needEqWeightMsg_ : 'Did you wish to convert with equivalents? The ' +\n 'molecular weight of the substance is required to perform ' + \n 'the conversion.', \n\n /**\n * Message that is returned when a mass<->eq or a mol<->eq conversion \n * is requested (which requires a charge to calculate), but no charge\n * was provided by the user.\n */\n needEqChargeMsg_ : 'Did you wish to convert with equivalents? The ' +\n 'charge of the substance is required to perform ' + \n 'the conversion.', \n\n /**\n * Hash that matches unit column names to names used in the csv file\n * that is submitted to the data updater.\n */\n csvCols_ : {\n 'case-sensitive code' : 'csCode_',\n 'LOINC property' : 'loincProperty_',\n 'name (display)' : 'name_',\n 'synonyms' : 'synonyms_',\n 'source' : 'source_',\n 'category' : 'category_',\n 'Guidance' : 'guidance_'\n } ,\n\n /**\n * Name of the column in the csv file that serves as the key\n */\n inputKey_ : 'case-sensitive code' ,\n\n /**\n * Special codes that contain operators within brackets. The operator\n * within these codes causes them to parse incorrectly if they are preceded\n * by a prefix, because the parsing algorithm splits them up on the operator.\n * So we use this object to identify them and substitute placeholders to\n * avoid that.\n */\n specUnits_ : { 'B[10.nV]' : 'specialUnitOne',\n '[m/s2/Hz^(1/2)]' : 'specialUnitTwo'}\n} ;\n\n\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,IAAIA,IAAI,GAAG;EAEhB;AACF;AACA;AACA;AACA;AACA;EACE;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEC,OAAO,EAAE,CAAC;EAGV;AACF;AACA;AACA;EACEC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;EAGrB;AACF;AACA;AACA;EACEC,QAAQ,EAAG,IAAI;EAEf;EACAC,YAAY,EAAG,eAAe;EAC9BC,UAAU,EAAG,GAAG;EAChBC,YAAY,EAAG,uBAAuB;EACtCC,UAAU,EAAG,GAAG;EAGlB;AACA;AACA;AACA;AACA;EACEC,SAAS,EAAG,KAAK;EAEjB;AACF;AACA;AACA;AACA;EACEC,UAAU,EAAG,KAAK;EAElB;AACF;AACA;AACA;AACA;EACEC,aAAa,EAAG,0BAA0B;EAE1C;AACF;AACA;AACA;AACA;EACEC,cAAc,EAAG,UAAU;EAE3B;AACF;AACA;AACA;EACEC,UAAU,EAAG,2DAA2D,GAC3D,6DAA6D,GAC7D,iCAAiC;EAE9C;AACF;AACA;AACA;AACA;EACEC,kBAAkB,EAAG,uDAAuD,GACvD,uDAAuD,GACvD,8CAA8C;EAEnE;AACF;AACA;AACA;AACA;EACEC,gBAAgB,EAAG,iDAAiD,GAChD,2DAA2D,GAC3D,iBAAiB;EAErC;AACF;AACA;AACA;AACA;EACEC,gBAAgB,EAAG,iDAAiD,GAChD,iDAAiD,GACjD,iBAAiB;EAErC;AACF;AACA;AACA;EACEC,QAAQ,EAAG;IACT,qBAAqB,EAAG,SAAS;IACjC,gBAAgB,EAAG,gBAAgB;IACnC,gBAAgB,EAAG,OAAO;IAC1B,UAAU,EAAG,WAAW;IACxB,QAAQ,EAAG,SAAS;IACpB,UAAU,EAAG,WAAW;IACxB,UAAU,EAAG;EACf,CAAC;EAED;AACF;AACA;EACEC,SAAS,EAAG,qBAAqB;EAEjC;AACF;AACA;AACA;AACA;AACA;AACA;EACGC,UAAU,EAAG;IAAE,UAAU,EAAG,gBAAgB;IAC7B,iBAAiB,EAAG;EAAgB;AACtD,CAAC;AAAEC,OAAA,CAAAnB,IAAA,GAAAA,IAAA"}
1
+ {"version":3,"file":"config.js","names":["Ucum","dimLen_","validOps_","codeSep_","valMsgStart_","valMsgEnd_","cnvMsgStart_","cnvMsgEnd_","openEmph_","closeEmph_","openEmphHTML_","closeEmphHTML_","bracesMsg_","needMoleWeightMsg_","needEqWeightMsg_","needEqChargeMsg_","csvCols_","inputKey_","specUnits_","exports"],"sources":["../source/config.js"],"sourcesContent":["/*\n * This defines the namespace for the UCUM classes and provides\n * a place for the definition of global variables and constants.\n *\n * The javascript for this UCUM implementation uses syntax as\n * defined by the ECMAScript 6 standard\n */\n\nexport var Ucum = {\n\n /**\n * Flag indicating whether or not we're using case sensitive labels\n * I don't think we need this. I think we're just going with\n * case sensitive, per Clem. Gunther's code has this flag, but I\n * am removing it, at least for now. lm, 6/2016\n */\n //caseSensitive_: true ,\n\n /**\n * The number of elements in a Dimension array. Currently this\n * is set as a configuration variable, but when we get to the point\n * of loading the unit definitions from a file, this value will be\n * set from that.\n */\n dimLen_: 7,\n\n\n /**\n * The characters used as valid operators in a UCUM unit expression,\n * where '.' is for multiplication and '/' is for division.\n */\n validOps_: ['.', '/'],\n\n\n /**\n * The string used to separate a unit code and unit name when they\n * are displayed together\n */\n codeSep_ : ': ',\n\n // Message text variations for validation methods and conversion methods\n valMsgStart_ : 'Did you mean ',\n valMsgEnd_ : '?' ,\n cnvMsgStart_ : 'We assumed you meant ',\n cnvMsgEnd_ : '.',\n\n\n/**\n * Default opening string used to emphasize portions of error messages.\n * Used when NOT displaying messages on a web site, i.e., for output\n * from the library methods or to a file.\n */\n openEmph_ : ' ->',\n\n /**\n * Default closing string used to emphasize portions of error messages.\n * Used when NOT displaying messages on a web site, i.e., for output\n * from the library methods or to a file.\n */\n closeEmph_ : '<- ' ,\n\n /**\n * Opening HTML used to emphasize portions of error messages. Used when\n * displaying messages on a web site; should be blank when output is\n * to a file.\n */\n openEmphHTML_ : ' <span class=\"emphSpan\">',\n\n /**\n * Closing HTML used to emphasize portions of error messages. Used when\n * displaying messages on a web site; should be blank when output is\n * to a file.\n */\n closeEmphHTML_ : '</span> ' ,\n\n /**\n * Message that is displayed when annotations are included in a unit\n * string, to let the user know how they are interpreted.\n */\n bracesMsg_ : 'FYI - annotations (text in curly braces {}) are ignored, ' +\n 'except that an annotation without a leading symbol implies ' +\n 'the default unit 1 (the unity).',\n\n /**\n * Message that is displayed or returned when a conversion is requested\n * for two units where (only) a mass<->moles conversion is appropriate\n * but no molecular weight was specified.\n */\n needMoleWeightMsg_ : 'Did you wish to convert between mass and moles? The ' +\n 'molecular weight of the substance represented by the ' +\n 'units is required to perform the conversion.',\n\n /**\n * Message that is returned when a mass<->eq conversion is requested \n * (which requires a molecular weight to calculate), but no molecular \n * weight was provided by the user.\n */ \n needEqWeightMsg_ : 'Did you wish to convert with equivalents? The ' +\n 'molecular weight of the substance is required to perform ' + \n 'the conversion.', \n\n /**\n * Message that is returned when a mass<->eq or a mol<->eq conversion \n * is requested (which requires a charge to calculate), but no charge\n * was provided by the user.\n */\n needEqChargeMsg_ : 'Did you wish to convert with equivalents? The ' +\n 'charge of the substance is required to perform ' + \n 'the conversion.', \n\n /**\n * Hash that matches unit column names to names used in the csv file\n * that is submitted to the data updater.\n */\n csvCols_ : {\n 'case-sensitive code' : 'csCode_',\n 'LOINC property' : 'loincProperty_',\n 'name (display)' : 'name_',\n 'synonyms' : 'synonyms_',\n 'source' : 'source_',\n 'category' : 'category_',\n 'Guidance' : 'guidance_'\n } ,\n\n /**\n * Name of the column in the csv file that serves as the key\n */\n inputKey_ : 'case-sensitive code' ,\n\n /**\n * Special codes that contain operators within brackets. The operator\n * within these codes causes them to parse incorrectly if they are preceded\n * by a prefix, because the parsing algorithm splits them up on the operator.\n * So we use this object to identify them and substitute placeholders to\n * avoid that.\n */\n specUnits_ : { 'B[10.nV]' : 'specialUnitOne',\n '[m/s2/Hz^(1/2)]' : 'specialUnitTwo'}\n} ;\n\n\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,IAAIA,IAAI,GAAG;EAEhB;AACF;AACA;AACA;AACA;AACA;EACE;;EAEA;AACF;AACA;AACA;AACA;AACA;EACEC,OAAO,EAAE,CAAC;EAGV;AACF;AACA;AACA;EACEC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;EAGrB;AACF;AACA;AACA;EACEC,QAAQ,EAAG,IAAI;EAEf;EACAC,YAAY,EAAG,eAAe;EAC9BC,UAAU,EAAG,GAAG;EAChBC,YAAY,EAAG,uBAAuB;EACtCC,UAAU,EAAG,GAAG;EAGlB;AACA;AACA;AACA;AACA;EACEC,SAAS,EAAG,KAAK;EAEjB;AACF;AACA;AACA;AACA;EACEC,UAAU,EAAG,KAAK;EAElB;AACF;AACA;AACA;AACA;EACEC,aAAa,EAAG,0BAA0B;EAE1C;AACF;AACA;AACA;AACA;EACEC,cAAc,EAAG,UAAU;EAE3B;AACF;AACA;AACA;EACEC,UAAU,EAAG,2DAA2D,GAC3D,6DAA6D,GAC7D,iCAAiC;EAE9C;AACF;AACA;AACA;AACA;EACEC,kBAAkB,EAAG,uDAAuD,GACvD,uDAAuD,GACvD,8CAA8C;EAEnE;AACF;AACA;AACA;AACA;EACEC,gBAAgB,EAAG,iDAAiD,GAChD,2DAA2D,GAC3D,iBAAiB;EAErC;AACF;AACA;AACA;AACA;EACEC,gBAAgB,EAAG,iDAAiD,GAChD,iDAAiD,GACjD,iBAAiB;EAErC;AACF;AACA;AACA;EACEC,QAAQ,EAAG;IACT,qBAAqB,EAAG,SAAS;IACjC,gBAAgB,EAAG,gBAAgB;IACnC,gBAAgB,EAAG,OAAO;IAC1B,UAAU,EAAG,WAAW;IACxB,QAAQ,EAAG,SAAS;IACpB,UAAU,EAAG,WAAW;IACxB,UAAU,EAAG;EACf,CAAC;EAED;AACF;AACA;EACEC,SAAS,EAAG,qBAAqB;EAEjC;AACF;AACA;AACA;AACA;AACA;AACA;EACGC,UAAU,EAAG;IAAE,UAAU,EAAG,gBAAgB;IAC7B,iBAAiB,EAAG;EAAgB;AACtD,CAAC;AAAEC,OAAA,CAAAnB,IAAA,GAAAA,IAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"dimension.js","names":["UC","require","isInteger","Dimension","constructor","dimSetting","Ucum","dimLen_","Error","undefined","assignZero","Array","length","JSON","stringify","dimVec_","d","push","setElementAt","indexPos","value","getElementAt","ret","getProperty","propertyName","uProp","charAt","toString","join","add","dim2","i","sub","minus","mul","s","equals","isEqual","dimVec2","assignDim","isZero","allZero","isNull","clone","that","exports"],"sources":["../source/dimension.js"],"sourcesContent":["/**\n * This class implements an object containing the vector of exponents for\n * a unit and its operations for addition, subtraction, and multiplication\n * with a scalar.\n *\n * This object should exist for each unit that can be expressed as a\n * vector of numbers. This excludes arbitrary units, e.g., (10*23), and\n * units that are not numbers but are an expression based solely on numbers,\n * e.g., mol (mole) which is based on 10*23.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n */\nvar UC = require('./config.js');\nvar isInteger = require(\"is-integer\");\nexport class Dimension {\n\n /**\n * Constructor.\n *\n * @param dimSetting an optional parameter that may be:\n * null, which means that the dimVec_ attribute for this object will be null; or\n * an array, which must be the length defined by Ucum.dimLen_, and\n * whose contents will be copied to this new object's vector; or\n * an integer, which must be between 0 and 1 less than the vector length\n * defined by Ucum.dimLen_. This new object's vector will be\n * initialized to zero for all elements except the one whose index\n * matches the number passed in. That element will be set to one.\n\n * @throws an error if the dimSetting parameter does not meet the types\n * listed above.\n * An error will also be thrown if Ucum.dimLen_ has not been set yet,\n * i.e., is still zero. Currently that won't happen, because the\n * value is set in the config.js file. But further down the road\n * the setting will come from a definitions input file, so we check\n * here anyway.\n *\n */\n constructor(dimSetting) {\n\n if (UC.Ucum.dimLen_ === 0) {\n throw(new Error('Dimension.setDimensionLen must be called before ' +\n 'Dimension constructor'));\n }\n if (dimSetting === undefined || dimSetting === null) {\n this.assignZero() ;\n }\n else if (dimSetting instanceof Array) {\n if (dimSetting.length !== UC.Ucum.dimLen_) {\n throw(new Error('Parameter error, incorrect length of vector passed to ' +\n `Dimension constructor, vector = ${JSON.stringify(dimSetting)}`));\n }\n this.dimVec_ = [];\n for (let d = 0; d < UC.Ucum.dimLen_; d++)\n this.dimVec_.push(dimSetting[d]);\n }\n\n // In es6 this should be Number.isInteger(dimSetting). But Babel\n // doesn't transpile that correctly, so we need to use the isInteger\n // module. :0\n else if (isInteger(dimSetting)) {\n if (dimSetting < 0 || dimSetting >= UC.Ucum.dimLen_) {\n throw(new Error('Parameter error, invalid element number specified for ' +\n 'Dimension constructor'));\n }\n this.assignZero() ;\n this.dimVec_[dimSetting] = 1;\n }\n } // end constructor\n\n\n /**\n * Sets the element at the specified position to a specified value. The\n * default value is 1. If the dimension vector is null when this is called\n * a zero-filled vector is created and then the indicated position is set.\n *\n * @param indexPos the index of the element to be set\n * @param value the value to assign to the specified element; optional,\n * default value is 1\n * @throws an exception if the specified position is invalid, i.e., not a\n * number or is less than 0 or greater than Ucum.dimLen_\n **/\n setElementAt(indexPos, value) {\n\n if (!isInteger(indexPos) ||\n indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {\n throw(new Error(`Dimension.setElementAt called with an invalid index ` +\n `position (${indexPos})`));\n }\n\n if (!this.dimVec_) {\n this.assignZero();\n }\n if (value === undefined || value === null)\n value = 1 ;\n\n this.dimVec_[indexPos] = value;\n }\n\n\n /**\n * Gets the value of the element at the specified position\n *\n * @param indexPos the index of the element whose value is to be returned\n * @return the value of the element at indexPos, or null if the dimension\n * vector is null\n * @throws an exception if the specified position is invalid, i.e., not a\n * number or is less than 0 or greater than Ucum.dimLen_\n **/\n getElementAt(indexPos) {\n if (!isInteger(indexPos) ||\n indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {\n throw(new Error(`Dimension.getElementAt called with an invalid index ` +\n `position (${indexPos})`));\n }\n let ret = null;\n if (this.dimVec_)\n ret = this.dimVec_[indexPos];\n return ret;\n }\n\n\n /**\n * This returns the value of the property named by the parameter\n * passed in. Although we currently only have one property, dimVec_,\n * that this will get, it's possible that we'll have additional\n * properties. If we don't this could just be replaced by a\n * getVector function.\n *\n * @param propertyName name of the property to be returned, with\n * or without the trailing underscore.\n * @return the requested property, if found for this Dimension\n * @throws an error if the property is not found for this Dimension\n */\n getProperty(propertyName) {\n let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName : propertyName + '_';\n\n return this[uProp] ;\n\n } // end getProperty\n\n\n /**\n * Return a string that represents the dimension vector. Returns null if\n * the dimension vector is null.\n *\n * @return the string that represents the dimension vector. The\n * values are enclosed in square brackets, each separated\n * by a comma and a space\n **/\n toString() {\n let ret = null ;\n if (this.dimVec_)\n ret = '[' + this.dimVec_.join(', ') + ']';\n return ret ;\n }\n\n\n /**\n * Adds the vector of the dimension object passed in to this\n * dimension object's vector. This object's vector is changed.\n * If either dimension vector is null, no changes are made to this object.\n *\n *\n * @param dim2 the dimension whose vector is to be added to this one\n * @return this object\n * @throws an exception if dim2 is not a Dimension object\n **/\n add(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.add called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (this.dimVec_ && dim2.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] += dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Subtracts the vector of the dimension object passed in from this\n * dimension object's vector. This object's vector is changed.\n * If either dimension vector is null, no changes are made to this object.\n *\n * @param dim2 the dimension whose vector is to be subtracted from this one\n * @return this object\n * @throws an exception if dim2 is not a Dimension object\n **/\n sub(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.sub called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (this.dimVec_ && dim2.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] -= dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Inverts this dimension object's vector (by multiplying each element\n * by negative 1). This object's vector is changed - unless it is null,\n * in which case it stays that way.\n *\n * @return this object\n **/\n minus() {\n if (this.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] = -this.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Multiplies this dimension object's vector with a scalar. This is used\n * when a unit is raised to a power. This object's vector is changed unless\n * the vector is null, in which case it stays that way.\n *\n * @param s the scalar to use\n * @return this object\n * @throws an exception if s is not a number\n */\n mul(s) {\n if (!isInteger(s)) {\n throw(new Error(`Dimension.sub called with an invalid parameter - ` +\n `${typeof dim2} instead of a number`));\n }\n if (this.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] *= s;\n }\n return this;\n }\n\n\n /**\n * Tests for equality of this dimension object's vector and that of\n * the dimension object passed in. If the dimension vector for one of\n * the objects is null, the dimension vector for the other object must\n * also be null for the two to be equal. (I know - duh. still)\n *\n * @param dim2 the dimension object whose vector is to be compared to this one\n * @return true if the two vectors are equal; false otherwise.\n * @throws an exception if dim2 is not a Dimension object\n */\n equals(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.equals called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n let isEqual = true ;\n let dimVec2 = dim2.dimVec_;\n if (this.dimVec_ && dimVec2) {\n for (let i = 0; isEqual && i < UC.Ucum.dimLen_; i++)\n isEqual = (this.dimVec_[i] === dimVec2[i]);\n }\n else {\n isEqual = (this.dimVec_ === null && dimVec2 === null);\n }\n return isEqual;\n }\n\n\n /**\n * Assigns the contents of the vector belonging to the dimension object\n * passed in to this dimension's vector. If this dimension vector is null\n * and the other is not, this one will get the contents of the other. If\n * this dimension vector is not null but the one passed in is null, this\n * one will be set to null.\n *\n * @param dim2 the dimension object with the vector whose contents are\n * to be assigned to this dimension's vector\n * @return this object (not sure why)\n * @throws an exception if dim2 is not a Dimension object\n */\n assignDim(dim2) {\n\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.assignDim called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (dim2.dimVec_ === null)\n this.dimVec_ = null;\n else {\n if (this.dimVec_ === null) {\n this.dimVec_ = [] ;\n }\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] = dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Sets all elements of this dimension object's vector to zero.\n * If this object's vector is null, it is created as a zero-filled vector.\n *\n * @return this object (not sure why)\n */\n assignZero() {\n if (this.dimVec_ === null || this.dimVec_ === undefined)\n this.dimVec_ = [];\n\n for (let i = 0; i < UC.Ucum.dimLen_; i++) {\n this.dimVec_.push(0);\n }\n return this;\n }\n\n\n /**\n * Tests for a dimension vector set to all zeroes.\n *\n * @return true if exponents (elements) of this dimension's vector are all\n * zero; false otherwise (including if the current vector is null).\n *\n */\n isZero() {\n let allZero = this.dimVec_ !== null ;\n if (this.dimVec_) {\n for (let i = 0; allZero && i < UC.Ucum.dimLen_; i++)\n allZero = this.dimVec_[i] === 0;\n }\n return allZero;\n }\n\n\n /**\n * Tests for a Dimension object with no dimension vector (dimVec_ is null).\n *\n * @return true the dimension vector is null; false if it is not\n *\n */\n isNull() {\n return (this.dimVec_ === null);\n }\n\n\n /**\n * Creates and returns a clone of this Dimension object\n *\n * @return the clone\n */\n clone() {\n let that = new Dimension();\n that.assignDim(this);\n return that;\n }\n\n} // end Dimension class\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIA,EAAE,GAAGC,OAAO,CAAC,aAAa,CAAC;AAC/B,IAAIC,SAAS,GAAGD,OAAO,CAAC,YAAY,CAAC;AAC9B,MAAME,SAAS,CAAC;EAErB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EAEEC,WAAWA,CAACC,UAAU,EAAE;IAEtB,IAAIL,EAAE,CAACM,IAAI,CAACC,OAAO,KAAK,CAAC,EAAE;MACzB,MAAM,IAAIC,KAAK,CAAC,kDAAkD,GAClE,uBAAuB,CAAC;IAC1B;IACA,IAAIH,UAAU,KAAKI,SAAS,IAAIJ,UAAU,KAAK,IAAI,EAAE;MACnD,IAAI,CAACK,UAAU,CAAC,CAAC;IACnB,CAAC,MACI,IAAIL,UAAU,YAAYM,KAAK,EAAE;MACpC,IAAIN,UAAU,CAACO,MAAM,KAAKZ,EAAE,CAACM,IAAI,CAACC,OAAO,EAAE;QACzC,MAAM,IAAIC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,SAAS,CAAC,CAAC;IAC1ByC,IAAI,CAACL,SAAS,CAAC,IAAI,CAAC;IACpB,OAAOK,IAAI;EACb;AAEF,CAAC,CAAC;AAAAC,OAAA,CAAA1C,SAAA,GAAAA,SAAA"}
1
+ {"version":3,"file":"dimension.js","names":["UC","require","isInteger","Dimension","constructor","dimSetting","Ucum","dimLen_","Error","undefined","assignZero","Array","length","JSON","stringify","dimVec_","d","push","setElementAt","indexPos","value","getElementAt","ret","getProperty","propertyName","uProp","charAt","toString","join","add","dim2","i","sub","minus","mul","s","equals","isEqual","dimVec2","assignDim","isZero","allZero","isNull","clone","that","exports"],"sources":["../source/dimension.js"],"sourcesContent":["/**\n * This class implements an object containing the vector of exponents for\n * a unit and its operations for addition, subtraction, and multiplication\n * with a scalar.\n *\n * This object should exist for each unit that can be expressed as a\n * vector of numbers. This excludes arbitrary units, e.g., (10*23), and\n * units that are not numbers but are an expression based solely on numbers,\n * e.g., mol (mole) which is based on 10*23.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n */\nvar UC = require('./config.js');\nvar isInteger = require(\"is-integer\");\nexport class Dimension {\n\n /**\n * Constructor.\n *\n * @param dimSetting an optional parameter that may be:\n * null, which means that the dimVec_ attribute for this object will be null; or\n * an array, which must be the length defined by Ucum.dimLen_, and\n * whose contents will be copied to this new object's vector; or\n * an integer, which must be between 0 and 1 less than the vector length\n * defined by Ucum.dimLen_. This new object's vector will be\n * initialized to zero for all elements except the one whose index\n * matches the number passed in. That element will be set to one.\n\n * @throws an error if the dimSetting parameter does not meet the types\n * listed above.\n * An error will also be thrown if Ucum.dimLen_ has not been set yet,\n * i.e., is still zero. Currently that won't happen, because the\n * value is set in the config.js file. But further down the road\n * the setting will come from a definitions input file, so we check\n * here anyway.\n *\n */\n constructor(dimSetting) {\n\n if (UC.Ucum.dimLen_ === 0) {\n throw(new Error('Dimension.setDimensionLen must be called before ' +\n 'Dimension constructor'));\n }\n if (dimSetting === undefined || dimSetting === null) {\n this.assignZero() ;\n }\n else if (dimSetting instanceof Array) {\n if (dimSetting.length !== UC.Ucum.dimLen_) {\n throw(new Error('Parameter error, incorrect length of vector passed to ' +\n `Dimension constructor, vector = ${JSON.stringify(dimSetting)}`));\n }\n this.dimVec_ = [];\n for (let d = 0; d < UC.Ucum.dimLen_; d++)\n this.dimVec_.push(dimSetting[d]);\n }\n\n // In es6 this should be Number.isInteger(dimSetting). But Babel\n // doesn't transpile that correctly, so we need to use the isInteger\n // module. :0\n else if (isInteger(dimSetting)) {\n if (dimSetting < 0 || dimSetting >= UC.Ucum.dimLen_) {\n throw(new Error('Parameter error, invalid element number specified for ' +\n 'Dimension constructor'));\n }\n this.assignZero() ;\n this.dimVec_[dimSetting] = 1;\n }\n } // end constructor\n\n\n /**\n * Sets the element at the specified position to a specified value. The\n * default value is 1. If the dimension vector is null when this is called\n * a zero-filled vector is created and then the indicated position is set.\n *\n * @param indexPos the index of the element to be set\n * @param value the value to assign to the specified element; optional,\n * default value is 1\n * @throws an exception if the specified position is invalid, i.e., not a\n * number or is less than 0 or greater than Ucum.dimLen_\n **/\n setElementAt(indexPos, value) {\n\n if (!isInteger(indexPos) ||\n indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {\n throw(new Error(`Dimension.setElementAt called with an invalid index ` +\n `position (${indexPos})`));\n }\n\n if (!this.dimVec_) {\n this.assignZero();\n }\n if (value === undefined || value === null)\n value = 1 ;\n\n this.dimVec_[indexPos] = value;\n }\n\n\n /**\n * Gets the value of the element at the specified position\n *\n * @param indexPos the index of the element whose value is to be returned\n * @return the value of the element at indexPos, or null if the dimension\n * vector is null\n * @throws an exception if the specified position is invalid, i.e., not a\n * number or is less than 0 or greater than Ucum.dimLen_\n **/\n getElementAt(indexPos) {\n if (!isInteger(indexPos) ||\n indexPos < 0 || indexPos >= UC.Ucum.dimLen_) {\n throw(new Error(`Dimension.getElementAt called with an invalid index ` +\n `position (${indexPos})`));\n }\n let ret = null;\n if (this.dimVec_)\n ret = this.dimVec_[indexPos];\n return ret;\n }\n\n\n /**\n * This returns the value of the property named by the parameter\n * passed in. Although we currently only have one property, dimVec_,\n * that this will get, it's possible that we'll have additional\n * properties. If we don't this could just be replaced by a\n * getVector function.\n *\n * @param propertyName name of the property to be returned, with\n * or without the trailing underscore.\n * @return the requested property, if found for this Dimension\n * @throws an error if the property is not found for this Dimension\n */\n getProperty(propertyName) {\n let uProp = propertyName.charAt(propertyName.length - 1) === '_' ? propertyName : propertyName + '_';\n\n return this[uProp] ;\n\n } // end getProperty\n\n\n /**\n * Return a string that represents the dimension vector. Returns null if\n * the dimension vector is null.\n *\n * @return the string that represents the dimension vector. The\n * values are enclosed in square brackets, each separated\n * by a comma and a space\n **/\n toString() {\n let ret = null ;\n if (this.dimVec_)\n ret = '[' + this.dimVec_.join(', ') + ']';\n return ret ;\n }\n\n\n /**\n * Adds the vector of the dimension object passed in to this\n * dimension object's vector. This object's vector is changed.\n * If either dimension vector is null, no changes are made to this object.\n *\n *\n * @param dim2 the dimension whose vector is to be added to this one\n * @return this object\n * @throws an exception if dim2 is not a Dimension object\n **/\n add(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.add called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (this.dimVec_ && dim2.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] += dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Subtracts the vector of the dimension object passed in from this\n * dimension object's vector. This object's vector is changed.\n * If either dimension vector is null, no changes are made to this object.\n *\n * @param dim2 the dimension whose vector is to be subtracted from this one\n * @return this object\n * @throws an exception if dim2 is not a Dimension object\n **/\n sub(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.sub called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (this.dimVec_ && dim2.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] -= dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Inverts this dimension object's vector (by multiplying each element\n * by negative 1). This object's vector is changed - unless it is null,\n * in which case it stays that way.\n *\n * @return this object\n **/\n minus() {\n if (this.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] = -this.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Multiplies this dimension object's vector with a scalar. This is used\n * when a unit is raised to a power. This object's vector is changed unless\n * the vector is null, in which case it stays that way.\n *\n * @param s the scalar to use\n * @return this object\n * @throws an exception if s is not a number\n */\n mul(s) {\n if (!isInteger(s)) {\n throw(new Error(`Dimension.sub called with an invalid parameter - ` +\n `${typeof dim2} instead of a number`));\n }\n if (this.dimVec_) {\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] *= s;\n }\n return this;\n }\n\n\n /**\n * Tests for equality of this dimension object's vector and that of\n * the dimension object passed in. If the dimension vector for one of\n * the objects is null, the dimension vector for the other object must\n * also be null for the two to be equal. (I know - duh. still)\n *\n * @param dim2 the dimension object whose vector is to be compared to this one\n * @return true if the two vectors are equal; false otherwise.\n * @throws an exception if dim2 is not a Dimension object\n */\n equals(dim2) {\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.equals called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n let isEqual = true ;\n let dimVec2 = dim2.dimVec_;\n if (this.dimVec_ && dimVec2) {\n for (let i = 0; isEqual && i < UC.Ucum.dimLen_; i++)\n isEqual = (this.dimVec_[i] === dimVec2[i]);\n }\n else {\n isEqual = (this.dimVec_ === null && dimVec2 === null);\n }\n return isEqual;\n }\n\n\n /**\n * Assigns the contents of the vector belonging to the dimension object\n * passed in to this dimension's vector. If this dimension vector is null\n * and the other is not, this one will get the contents of the other. If\n * this dimension vector is not null but the one passed in is null, this\n * one will be set to null.\n *\n * @param dim2 the dimension object with the vector whose contents are\n * to be assigned to this dimension's vector\n * @return this object (not sure why)\n * @throws an exception if dim2 is not a Dimension object\n */\n assignDim(dim2) {\n\n if (!dim2 instanceof Dimension) {\n throw(new Error(`Dimension.assignDim called with an invalid parameter - ` +\n `${typeof dim2} instead of a Dimension object`));\n }\n if (dim2.dimVec_ === null)\n this.dimVec_ = null;\n else {\n if (this.dimVec_ === null) {\n this.dimVec_ = [] ;\n }\n for (let i = 0; i < UC.Ucum.dimLen_; i++)\n this.dimVec_[i] = dim2.dimVec_[i];\n }\n return this;\n }\n\n\n /**\n * Sets all elements of this dimension object's vector to zero.\n * If this object's vector is null, it is created as a zero-filled vector.\n *\n * @return this object (not sure why)\n */\n assignZero() {\n if (this.dimVec_ === null || this.dimVec_ === undefined)\n this.dimVec_ = [];\n\n for (let i = 0; i < UC.Ucum.dimLen_; i++) {\n this.dimVec_.push(0);\n }\n return this;\n }\n\n\n /**\n * Tests for a dimension vector set to all zeroes.\n *\n * @return true if exponents (elements) of this dimension's vector are all\n * zero; false otherwise (including if the current vector is null).\n *\n */\n isZero() {\n let allZero = this.dimVec_ !== null ;\n if (this.dimVec_) {\n for (let i = 0; allZero && i < UC.Ucum.dimLen_; i++)\n allZero = this.dimVec_[i] === 0;\n }\n return allZero;\n }\n\n\n /**\n * Tests for a Dimension object with no dimension vector (dimVec_ is null).\n *\n * @return true the dimension vector is null; false if it is not\n *\n */\n isNull() {\n return (this.dimVec_ === null);\n }\n\n\n /**\n * Creates and returns a clone of this Dimension object\n *\n * @return the clone\n */\n clone() {\n let that = new Dimension();\n that.assignDim(this);\n return that;\n }\n\n} // end Dimension class\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIA,EAAE,GAAGC,OAAO,CAAC,aAAa,CAAC;AAC/B,IAAIC,SAAS,GAAGD,OAAO,CAAC,YAAY,CAAC;AAC9B,MAAME,SAAS,CAAC;EAErB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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,KAAK,IAAIgB,CAAC,GAAG,CAAC,EAAEU,OAAO,IAAIV,CAAC,GAAG/B,EAAE,CAACM,IAAI,CAACC,OAAO,EAAEwB,CAAC,EAAE,EACjDU,OAAO,GAAG,IAAI,CAAC1B,OAAO,CAACgB,CAAC,CAAC,KAAK,CAAC;IACnC;IACA,OAAOU,OAAO;EAChB;;EAGA;AACF;AACA;AACA;AACA;AACA;EACEC,MAAMA,CAAA,EAAG;IACP,OAAQ,IAAI,CAAC3B,OAAO,KAAK,IAAI;EAC/B;;EAGA;AACF;AACA;AACA;AACA;EACE4B,KAAKA,CAAA,EAAG;IACN,IAAIC,IAAI,GAAG,IAAIzC,SAAS,CAAC,CAAC;IAC1ByC,IAAI,CAACL,SAAS,CAAC,IAAI,CAAC;IACpB,OAAOK,IAAI;EACb;AAEF,CAAC,CAAC;AAAAC,OAAA,CAAA1C,SAAA,GAAAA,SAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"jsonArrayPack.js","names":["pushFn","Array","prototype","push","isObject","value","Object","toString","call","createConfig","refObj","keys","reduce","config","key","apply","map","keyTail","concat","prepareConfig","isArray","packItem","item","join","Error","keyArr","place","forEach","undefined","unpackItem","result","i","length","packArray","arr","_config","data","bind","unpackArray","obj"],"sources":["../source/jsonArrayPack.js"],"sourcesContent":["/**\n * This file provides functions to reduce the size of an array of objects of the same structure in JSON.\n */\nconst pushFn = Array.prototype.push;\n\nfunction isObject(value) {\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\n/**\n * Makes human readable config used to pack/unpack array of objects of the same structure to store with packed data.\n * @param {Object} refObj - reference item of array of objects of the same structure\n * @returns {Array}\n */\nfunction createConfig(refObj) {\n return Object.keys(refObj).reduce((config, key) => {\n if (isObject(refObj[key])) {\n pushFn.apply(config, createConfig(refObj[key]).map(keyTail => [key, ...[].concat(keyTail)]));\n } else {\n config.push(key);\n }\n return config;\n }, [])\n}\n\n/**\n * Prepares config created with createConfig function to use in packItem/unpackItem functions.\n * @param {Array} config\n * @returns {Array}\n */\nfunction prepareConfig(config) {\n return config.map(key => Array.isArray(key) ? key : [key]);\n}\n\n/**\n * Converts an object to an array of values in the order of keys from configuration array.\n * @param {Array} config - configuration array\n * @param {Object} item - input object\n * @returns {Array}\n */\nfunction packItem(config, item) {\n if (config.join() !== prepareConfig(createConfig(item)).join()) {\n throw new Error('Object of unusual structure')\n }\n\n return config.map(keyArr => {\n let place = item;\n keyArr.forEach(key => {\n place = place[key];\n if (place === undefined) {\n throw new Error('Object of unusual structure')\n }\n });\n return place;\n });\n}\n\n/**\n * Performs the reverse of packItem function.\n * @param {Array} config - configuration array\n * @param {Array} item - input object\n * @returns {Object}\n */\nfunction unpackItem(config, item) {\n let result = {};\n\n config.forEach((keyArr, i) => {\n let place = result;\n for (let i = 0; i < keyArr.length - 1; i++) {\n place = place[keyArr[i]] = place[keyArr[i]] || {};\n }\n place[keyArr[keyArr.length - 1]] = item[i];\n });\n\n return result;\n}\n\n/**\n * Reduces size of an array of objects of the same structure before serialize it to JSON\n * @param {Array} arr\n * @returns {Object}\n */\nexport function packArray(arr) {\n if (arr && arr.length) {\n const config = createConfig(arr[0]),\n _config = prepareConfig(config);\n\n if (config.length) {\n return {\n config: config,\n data: arr.map(packItem.bind(null, _config))\n };\n }\n }\n\n return {\n config: [],\n data: arr\n };\n}\n\n/**\n * Restores an array of objects of the same structure after deserializing this object from JSON\n * @param {Object} obj\n * @returns {Array}\n */\nexport function unpackArray(obj) {\n const config = obj && obj.config;\n\n if (config) {\n if (config.length && obj.data) {\n const _config = prepareConfig(config);\n\n return obj.data.map(unpackItem.bind(null, _config));\n } else {\n return obj.data;\n }\n }\n\n return obj;\n}"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA,MAAMA,MAAM,GAAGC,KAAK,CAACC,SAAS,CAACC,IAAI;AAEnC,SAASC,QAAQA,CAACC,KAAK,EAAE;EACvB,OAAOC,MAAM,CAACJ,SAAS,CAACK,QAAQ,CAACC,IAAI,CAACH,KA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AACH;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASI,WAAWA,CAACC,GAAG,EAAE;EAC/B,MAAM1B,MAAM,GAAG0B,GAAG,IAAIA,GAAG,CAAC1B,MAAM;EAEhC,IAAIA,MAAM,EAAE;IACV,IAAIA,MAAM,CAACmB,MAAM,IAAIO,GAAG,CAACH,IAAI,EAAE;MAC7B,MAAMD,OAAO,GAAGhB,aAAa,CAACN,MAAM,CAAC;MAErC,OAAO0B,GAAG,CAACH,IAAI,CAACpB,GAAG,CAACa,UAAU,CAACQ,IAAI,CAAC,IAAI,EAAEF,OAAO,CAAC,CAAC;IACrD,CAAC,MAAM;MACL,OAAOI,GAAG,CAACH,IAAI;IACjB;EACF;EAEA,OAAOG,GAAG;AACZ"}
1
+ {"version":3,"file":"jsonArrayPack.js","names":["pushFn","Array","prototype","push","isObject","value","Object","toString","call","createConfig","refObj","keys","reduce","config","key","apply","map","keyTail","concat","prepareConfig","isArray","packItem","item","join","Error","keyArr","place","forEach","undefined","unpackItem","result","i","length","packArray","arr","_config","data","bind","unpackArray","obj"],"sources":["../source/jsonArrayPack.js"],"sourcesContent":["/**\n * This file provides functions to reduce the size of an array of objects of the same structure in JSON.\n */\nconst pushFn = Array.prototype.push;\n\nfunction isObject(value) {\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\n/**\n * Makes human readable config used to pack/unpack array of objects of the same structure to store with packed data.\n * @param {Object} refObj - reference item of array of objects of the same structure\n * @returns {Array}\n */\nfunction createConfig(refObj) {\n return Object.keys(refObj).reduce((config, key) => {\n if (isObject(refObj[key])) {\n pushFn.apply(config, createConfig(refObj[key]).map(keyTail => [key, ...[].concat(keyTail)]));\n } else {\n config.push(key);\n }\n return config;\n }, [])\n}\n\n/**\n * Prepares config created with createConfig function to use in packItem/unpackItem functions.\n * @param {Array} config\n * @returns {Array}\n */\nfunction prepareConfig(config) {\n return config.map(key => Array.isArray(key) ? key : [key]);\n}\n\n/**\n * Converts an object to an array of values in the order of keys from configuration array.\n * @param {Array} config - configuration array\n * @param {Object} item - input object\n * @returns {Array}\n */\nfunction packItem(config, item) {\n if (config.join() !== prepareConfig(createConfig(item)).join()) {\n throw new Error('Object of unusual structure')\n }\n\n return config.map(keyArr => {\n let place = item;\n keyArr.forEach(key => {\n place = place[key];\n if (place === undefined) {\n throw new Error('Object of unusual structure')\n }\n });\n return place;\n });\n}\n\n/**\n * Performs the reverse of packItem function.\n * @param {Array} config - configuration array\n * @param {Array} item - input object\n * @returns {Object}\n */\nfunction unpackItem(config, item) {\n let result = {};\n\n config.forEach((keyArr, i) => {\n let place = result;\n for (let i = 0; i < keyArr.length - 1; i++) {\n place = place[keyArr[i]] = place[keyArr[i]] || {};\n }\n place[keyArr[keyArr.length - 1]] = item[i];\n });\n\n return result;\n}\n\n/**\n * Reduces size of an array of objects of the same structure before serialize it to JSON\n * @param {Array} arr\n * @returns {Object}\n */\nexport function packArray(arr) {\n if (arr && arr.length) {\n const config = createConfig(arr[0]),\n _config = prepareConfig(config);\n\n if (config.length) {\n return {\n config: config,\n data: arr.map(packItem.bind(null, _config))\n };\n }\n }\n\n return {\n config: [],\n data: arr\n };\n}\n\n/**\n * Restores an array of objects of the same structure after deserializing this object from JSON\n * @param {Object} obj\n * @returns {Array}\n */\nexport function unpackArray(obj) {\n const config = obj && obj.config;\n\n if (config) {\n if (config.length && obj.data) {\n const _config = prepareConfig(config);\n\n return obj.data.map(unpackItem.bind(null, _config));\n } else {\n return obj.data;\n }\n }\n\n return obj;\n}"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA,MAAMA,MAAM,GAAGC,KAAK,CAACC,SAAS,CAACC,IAAI;AAEnC,SAASC,QAAQA,CAACC,KAAK,EAAE;EACvB,OAAOC,MAAM,CAACJ,SAAS,CAACK,QAAQ,CAACC,IAAI,CAACH,KAAK,CAAC,KAAK,iBAAiB;AACpE;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASI,YAAYA,CAACC,MAAM,EAAE;EAC5B,OAAOJ,MAAM,CAAC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AAC1B,MAAM;EAEhC,IAAIA,MAAM,EAAE;IACV,IAAIA,MAAM,CAACmB,MAAM,IAAIO,GAAG,CAACH,IAAI,EAAE;MAC7B,MAAMD,OAAO,GAAGhB,aAAa,CAACN,MAAM,CAAC;MAErC,OAAO0B,GAAG,CAACH,IAAI,CAACpB,GAAG,CAACa,UAAU,CAACQ,IAAI,CAAC,IAAI,EAAEF,OAAO,CAAC,CAAC;IACrD,CAAC,MAAM;MACL,OAAOI,GAAG,CAACH,IAAI;IACjB;EACF;EAEA,OAAOG,GAAG;AACZ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"prefix.js","names":["Ucum","require","Prefix","constructor","attrs","undefined","Error","code_","ciCode_","name_","printSymbol_","value_","parseFloat","exp_","getValue","getCode","getCiCode","getName","getPrintSymbol","getExp","equals","prefix2","exports"],"sources":["../source/prefix.js"],"sourcesContent":["/**\n * Prefix objects are defined in this file.\n */\n\n/**\n * This class implements the prefix object. Prefixes are used as multipliers\n * for units, e.g., km for kilometers\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nvar Ucum = require('./config.js');\n\nexport class Prefix {\n\n /**\n * Creates a single prefix object.\n *\n * @param attrs a hash of the values to use in creating the prefix object.\n * They should be:\n * code_ - which is the case-sensitive code used for the prefix,\n * e.g., k for kilo\n * ciCode_ - which is the case-insensitive code used for the prefix,\n * e.g., K for kilo\n * name_ - which is the name of the prefix, e.g., kilo\n * printSymbol_ - which is the print symbol for the prefix, e.g., k for kilo\n * value_ - which is teh value to use in multiplying the magnitude of\n * a unit, e.g., for a prefix of c the value will be .01.\n * exp_ - which is the exponent used to get the value. For decimal based\n * prefixes the base is 10 and the exp_ is applied to 10, e.g., for a\n * prefix of c, the exponent will be -2. For prefixes that are not\n * decimal based, this will be null (but must not be undefined).\n *\n * @throws an error if the not all required parameters are provided\n */\n constructor(attrs) {\n\n if (attrs['code_'] === undefined || attrs['code_'] === null ||\n attrs['name_'] === undefined || attrs['name_'] === null ||\n attrs['value_'] === undefined || attrs['value_'] === null ||\n attrs['exp_'] === undefined) {\n throw(new Error('Prefix constructor called missing one or more parameters. ' +\n 'Prefix codes (cs or ci), name, value and exponent must all be specified ' +\n 'and all but the exponent must not be null.'));\n }\n\n /**\n * The prefix code, e.g., k for kilo. This should be the case-sensitive\n * code. Since there's no way to check to see if it's the case-sensitive\n * one as opposed to the case-insensitive one (because although\n * case-insensitive codes all seem to be uppercase, some case-sensitive\n * codes are also all uppercase), we'll just have to believe that the\n * right one was passed in.\n */\n this.code_ = attrs['code_'];\n\n /**\n * The case-insensitive code, e.g., K for kilo\n */\n this.ciCode_ = attrs['ciCode_'];\n\n /**\n * The prefix name, e.g., kilo\n */\n this.name_ = attrs['name_'];\n\n /**\n * The printSymbol for the prefix, e.g., k for kilo\n */\n this.printSymbol_ = attrs['printSymbol_'];\n\n /**\n * The value to use in multiplying the magnitude of a unit\n */\n if (typeof attrs['value_'] === 'string')\n this.value_ = parseFloat(attrs['value_']);\n else\n this.value_ = attrs['value_'] ;\n\n /**\n * The exponent used to create the value from 10. For prefixes that are\n * not based on 10, this will be null.\n */\n this.exp_ = attrs['exp_'] ;\n\n } // end constructor\n\n\n /**\n * Returns the value for the current prefix object\n * @return the value for the prefix object with the specified code\n * */\n getValue() {\n return this.value_;\n }\n\n\n /**\n * Returns the prefix code for the current prefix object\n * @return the code for the current prefix object\n */\n getCode() {\n return this.code_;\n }\n\n\n /**\n * Returns the case-insensitive code for the current prefix object\n * @return the case_insensitive code for the current prefix object\n */\n getCiCode() {\n return this.ciCode_;\n }\n\n\n /**\n * Returns the prefix name for the current prefix object\n * @return the name for the current prefix object\n */\n getName() {\n return this.name_;\n }\n\n\n /**\n * Returns the print symbol for the current prefix object\n * @return the print symbol for the current prefix object\n */\n getPrintSymbol() {\n return this.printSymbol_;\n }\n\n\n /**\n * Returns the exponent for the current prefix object\n * @return the exponent for the current prefix object\n */\n getExp() {\n return this.exp_;\n }\n\n\n /**\n * Provides way to tell if one prefix equals another. The second prefix\n * must match all attribute values.\n *\n * @param prefix2 prefix object to check for a match\n * @return true for a match; false if one or more attributes don't match\n */\n equals(prefix2) {\n return this.code_ === prefix2.code_ &&\n this.ciCode_ === prefix2.ciCode_ &&\n this.name_ === prefix2.name_ &&\n this.printSymbol_ === prefix2.printSymbol_ &&\n this.value_ === prefix2.value_ &&\n this.exp_ === prefix2.exp_ ;\n }\n} // end Prefix class\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIA,IAAI,GAAGC,OAAO,CAAC,aAAa,CAAC;AAE1B,MAAMC,MAAM,CAAC;EAElB;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAACC,KAAK,EAAE;IAEjB,IAAIA,KAAK,CAAC,OAAO,CAAC,KAAKC,SAAS,IAAID,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,IACvDA,KAAK,CAAC,OAAO,CAAC,KAAKC,SAAS,IAAID,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,IACvDA,KAAK,CAAC,QAAQ,CAAC,KAAKC,SAAS,IAAID,KAAK,CAAC,QAAQ,CAAC,KAAK,IAAI,IACzDA,KAAK,CAAC,MAAM,CAAC,KAAKC,SAAS,EAAE;MAC/B,MAAM,IAAIC,KAAK,CAAC,6DAA6D,GAC7E,0EAA0E,GAC1E,4CAA4C,CAAC;IAC/C;;IAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;IACI,IAAI,CAACC,KAAK,GAAGH,KAAK,CAAC,OAAO,CAAC;;IAE3B;AACJ;AACA;IACI,IAAI,CAACI,OAAO,GAAGJ,KAAK,CAAC,SAAS,CAAC;;IAE/B;AACJ;AACA;IACI,IAAI,CAACK,KAAK,GAAGL,KAAK,CAAC,OAAO,CAAC;;IAE3B;AACJ;AACA;IACI,IAAI,CAACM,YAAY,GAAGN,KA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AAApB,MAAA,GAAAA,MAAA"}
1
+ {"version":3,"file":"prefix.js","names":["Ucum","require","Prefix","constructor","attrs","undefined","Error","code_","ciCode_","name_","printSymbol_","value_","parseFloat","exp_","getValue","getCode","getCiCode","getName","getPrintSymbol","getExp","equals","prefix2","exports"],"sources":["../source/prefix.js"],"sourcesContent":["/**\n * Prefix objects are defined in this file.\n */\n\n/**\n * This class implements the prefix object. Prefixes are used as multipliers\n * for units, e.g., km for kilometers\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nvar Ucum = require('./config.js');\n\nexport class Prefix {\n\n /**\n * Creates a single prefix object.\n *\n * @param attrs a hash of the values to use in creating the prefix object.\n * They should be:\n * code_ - which is the case-sensitive code used for the prefix,\n * e.g., k for kilo\n * ciCode_ - which is the case-insensitive code used for the prefix,\n * e.g., K for kilo\n * name_ - which is the name of the prefix, e.g., kilo\n * printSymbol_ - which is the print symbol for the prefix, e.g., k for kilo\n * value_ - which is teh value to use in multiplying the magnitude of\n * a unit, e.g., for a prefix of c the value will be .01.\n * exp_ - which is the exponent used to get the value. For decimal based\n * prefixes the base is 10 and the exp_ is applied to 10, e.g., for a\n * prefix of c, the exponent will be -2. For prefixes that are not\n * decimal based, this will be null (but must not be undefined).\n *\n * @throws an error if the not all required parameters are provided\n */\n constructor(attrs) {\n\n if (attrs['code_'] === undefined || attrs['code_'] === null ||\n attrs['name_'] === undefined || attrs['name_'] === null ||\n attrs['value_'] === undefined || attrs['value_'] === null ||\n attrs['exp_'] === undefined) {\n throw(new Error('Prefix constructor called missing one or more parameters. ' +\n 'Prefix codes (cs or ci), name, value and exponent must all be specified ' +\n 'and all but the exponent must not be null.'));\n }\n\n /**\n * The prefix code, e.g., k for kilo. This should be the case-sensitive\n * code. Since there's no way to check to see if it's the case-sensitive\n * one as opposed to the case-insensitive one (because although\n * case-insensitive codes all seem to be uppercase, some case-sensitive\n * codes are also all uppercase), we'll just have to believe that the\n * right one was passed in.\n */\n this.code_ = attrs['code_'];\n\n /**\n * The case-insensitive code, e.g., K for kilo\n */\n this.ciCode_ = attrs['ciCode_'];\n\n /**\n * The prefix name, e.g., kilo\n */\n this.name_ = attrs['name_'];\n\n /**\n * The printSymbol for the prefix, e.g., k for kilo\n */\n this.printSymbol_ = attrs['printSymbol_'];\n\n /**\n * The value to use in multiplying the magnitude of a unit\n */\n if (typeof attrs['value_'] === 'string')\n this.value_ = parseFloat(attrs['value_']);\n else\n this.value_ = attrs['value_'] ;\n\n /**\n * The exponent used to create the value from 10. For prefixes that are\n * not based on 10, this will be null.\n */\n this.exp_ = attrs['exp_'] ;\n\n } // end constructor\n\n\n /**\n * Returns the value for the current prefix object\n * @return the value for the prefix object with the specified code\n * */\n getValue() {\n return this.value_;\n }\n\n\n /**\n * Returns the prefix code for the current prefix object\n * @return the code for the current prefix object\n */\n getCode() {\n return this.code_;\n }\n\n\n /**\n * Returns the case-insensitive code for the current prefix object\n * @return the case_insensitive code for the current prefix object\n */\n getCiCode() {\n return this.ciCode_;\n }\n\n\n /**\n * Returns the prefix name for the current prefix object\n * @return the name for the current prefix object\n */\n getName() {\n return this.name_;\n }\n\n\n /**\n * Returns the print symbol for the current prefix object\n * @return the print symbol for the current prefix object\n */\n getPrintSymbol() {\n return this.printSymbol_;\n }\n\n\n /**\n * Returns the exponent for the current prefix object\n * @return the exponent for the current prefix object\n */\n getExp() {\n return this.exp_;\n }\n\n\n /**\n * Provides way to tell if one prefix equals another. The second prefix\n * must match all attribute values.\n *\n * @param prefix2 prefix object to check for a match\n * @return true for a match; false if one or more attributes don't match\n */\n equals(prefix2) {\n return this.code_ === prefix2.code_ &&\n this.ciCode_ === prefix2.ciCode_ &&\n this.name_ === prefix2.name_ &&\n this.printSymbol_ === prefix2.printSymbol_ &&\n this.value_ === prefix2.value_ &&\n this.exp_ === prefix2.exp_ ;\n }\n} // end Prefix class\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIA,IAAI,G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AACA;AACA;EACEU,QAAQA,CAAA,EAAG;IACT,OAAO,IAAI,CAACH,MAAM;EACpB;;EAGA;AACF;AACA;AACA;EACEI,OAAOA,CAAA,EAAG;IACR,OAAO,IAAI,CAACR,KAAK;EACnB;;EAGA;AACF;AACA;AACA;EACES,SAASA,CAAA,EAAG;IACV,OAAO,IAAI,CAACR,OAAO;EACrB;;EAGA;AACF;AACA;AACA;EACES,OAAOA,CAAA,EAAG;IACR,OAAO,IAAI,CAACR,KAAK;EACnB;;EAGA;AACF;AACA;AACA;EACES,cAAcA,CAAA,EAAG;IACf,OAAO,IAAI,CAACR,YAAY;EAC1B;;EAGA;AACF;AACA;AACA;EACES,MAAMA,CAAA,EAAG;IACP,OAAO,IAAI,CAACN,IAAI;EAClB;;EAGA;AACF;AACA;AACA;AACA;AACA;AACA;EACEO,MAAMA,CAACC,OAAO,EAAE;IACd,OAAO,IAAI,CAACd,KAAK,KAAKc,OAAO,CAACd,KAAK,IAC3B,IAAI,CAACC,OAAO,KAAKa,OAAO,CAACb,OAAO,IAChC,IAAI,CAACC,KAAK,KAAKY,OAAO,CAACZ,KAAK,IAC5B,IAAI,CAACC,YAAY,KAAKW,OAAO,CAACX,YAAY,IAC1C,IAAI,CAACC,MAAM,KAAKU,OAAO,CAACV,MAAM,IAC9B,IAAI,CAACE,IAAI,KAAKQ,OAAO,CAACR,IAAI;EACpC;AACF,CAAC,CAAC;AAAAS,OAAA,CAAApB,MAAA,GAAAA,MAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"prefixTables.js","names":["PrefixTablesFactory","constructor","byCode_","byValue_","prefixCount","Object","keys","length","allPrefixesByValue","prefixBuff","pList","pLen","p","pfx","getPrefixByValue","code_","name_","value_","allPrefixesByCode","prefixList","sort","push","getPrefixByCode","add","prefixObj","getCode","getValue","isDefined","code","undefined","value","exports","prefixTablesInstance","PrefixTables","getInstance"],"sources":["../source/prefixTables.js"],"sourcesContent":["/**\n * The tables of defined prefixes is defined in this file.\n */\n\n/**\n * This class implements the table of multiplier prefixes.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nexport class PrefixTablesFactory {\n\n /**\n * Constructor. This creates the empty PrefixTable hashes once.\n * There is one hash whose key is the prefix code and one whose\n * key is the prefix value.\n *\n * Implementation of this as a singleton is based on the UnitTables\n * implementation. See that class for details.\n */\n constructor(){\n this.byCode_ = {} ;\n this.byValue_ = {};\n }\n\n\n /**\n * Provides the number of prefix objects in each table\n * @returns count of the number of prefix objects in each table\n */\n prefixCount() {\n return Object.keys(this.byCode_).length ;\n }\n\n\n /**\n * This is used to get all prefix objects by value. Currently it is used\n * to create a csv file with all prefixes and units.\n * @returns csv string containing all prefix objects, ordered by value.\n */\n allPrefixesByValue() {\n let prefixBuff = '';\n let pList = Object.keys(this.byValue_);\n //pList.sort() ;\n let pLen = pList.length;\n for (let p = 0; p < pLen; p++) {\n let pfx = this.getPrefixByValue(pList[p]) ;\n prefixBuff += pfx.code_ + ',' + pfx.name_ + ',,' + pfx.value_ + '\\r\\n';\n }\n return prefixBuff ;\n }\n\n /**\n * This is used to get all prefix objects. Currently it is used\n * to get the objects to write to the json ucum definitions file\n * that is used to provide prefix and unit definition objects for\n * conversions and validations.\n *\n * @returns an array containing all prefix objects, ordered by code.\n */\n allPrefixesByCode() {\n let prefixList = [];\n let pList = Object.keys(this.byCode_);\n pList.sort() ;\n let pLen = pList.length;\n for (let p = 0; p < pLen; p++) {\n prefixList.push(this.getPrefixByCode(pList[p])) ;\n }\n return prefixList ;\n }\n\n /**\n * Adds a prefix object to the tables\n *\n * @param prefixObj the object to be added to the tables\n */\n add(prefixObj){\n this.byCode_[prefixObj.getCode()] = prefixObj;\n this.byValue_[prefixObj.getValue()] = prefixObj;\n }\n\n\n /**\n * Tests whether a prefix object is found for a specified code. This\n * is used to determine whether or not a prefix object has been created\n * for the code.\n *\n * @param code the code to be used to find the prefix object\n * @return boolean indicating whether or not a prefix object was found\n * for the specified code\n */\n isDefined(code) {\n return this.byCode_[code] !== null && this.byCode_[code] !== undefined ;\n }\n\n\n /**\n * Obtains a prefix object for a specified code.\n *\n * @param code the code to be used to find the prefix object\n * @return the prefix object found, or null if nothing was found\n */\n getPrefixByCode(code) {\n return this.byCode_[code];\n }\n\n\n /**\n * Obtains a prefix object for a specified value.\n *\n * @param value the value to be used to find the prefix object\n * @return the prefix object found, or null if nothing was found\n */\n getPrefixByValue(value) {\n return this.byValue_[value];\n }\n\n} // end PrefixTablesFactory class\n\n\n// Create a singleton instance and (to preserve the existing API) an object that\n// provides that instance via getInstance().\nvar prefixTablesInstance = new PrefixTablesFactory();\nexport const PrefixTables = {\n getInstance: function() {\n return prefixTablesInstance;\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,mBAAmB,CAAC;EAE/B;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAAA,EAAE;IACX,IAAI,CAACC,OAAO,GAAG,CAAC,CAAC;IACjB,IAAI,CAACC,QAAQ,GAAG,CAAC,CAAC;EACpB;;EAGA;AACF;AACA;AACA;EACEC,WAAWA,CAAA,EAAG;IACZ,OAAOC,MAAM,CAACC,IAAI,CAAC,IAAI,CAACJ,OAAO,CAAC,CAACK,MAAM;EACzC;;EAGA;AACF;AACA;AACA;AACA;EACEC,kBAAkBA,CAAA,EAAG;IACnB,IAAIC,UAAU,GAAG,EAAE;IACnB,IAAIC,KAAK,GAAGL,MAAM,CAACC,IAAI,CAAC,IAAI,CAACH,QAAQ,CAAC;IACtC;IACA,IAAIQ,IAAI,GAAGD,KAAK,CAACH,MAAM;IACvB,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,IAAI,EAAEC,CAAC,EAAE,EAAE;MAC7B,IAAIC,GAAG,GAAG,IAAI,CAACC,gBAAgB,CAACJ,KAAK,CAACE,CAAC,CAAC,CAAC;MACzCH,UAAU,IAAII,GAAG,CAACE,KAAK,GAA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3B,QAAQ,CAAC2B,KAAK,CAAC;EAC7B;AAEF,CAAC,CAAC;;AAGF;AACA;AAAAC,OAAA,CAAA/B,mBAAA,GAAAA,mBAAA;AACA,IAAIgC,oBAAoB,GAAG,IAAIhC,mBAAmB,CAAC,CAAC;AAC7C,MAAMiC,YAAY,GAAG;EAC1BC,WAAW,EAAE,SAAAA,CAAA,EAAW;IACtB,OAAOF,oBAAoB;EAC7B;AACF,CAAC;AAAAD,OAAA,CAAAE,YAAA,GAAAA,YAAA"}
1
+ {"version":3,"file":"prefixTables.js","names":["PrefixTablesFactory","constructor","byCode_","byValue_","prefixCount","Object","keys","length","allPrefixesByValue","prefixBuff","pList","pLen","p","pfx","getPrefixByValue","code_","name_","value_","allPrefixesByCode","prefixList","sort","push","getPrefixByCode","add","prefixObj","getCode","getValue","isDefined","code","undefined","value","exports","prefixTablesInstance","PrefixTables","getInstance"],"sources":["../source/prefixTables.js"],"sourcesContent":["/**\n * The tables of defined prefixes is defined in this file.\n */\n\n/**\n * This class implements the table of multiplier prefixes.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\nexport class PrefixTablesFactory {\n\n /**\n * Constructor. This creates the empty PrefixTable hashes once.\n * There is one hash whose key is the prefix code and one whose\n * key is the prefix value.\n *\n * Implementation of this as a singleton is based on the UnitTables\n * implementation. See that class for details.\n */\n constructor(){\n this.byCode_ = {} ;\n this.byValue_ = {};\n }\n\n\n /**\n * Provides the number of prefix objects in each table\n * @returns count of the number of prefix objects in each table\n */\n prefixCount() {\n return Object.keys(this.byCode_).length ;\n }\n\n\n /**\n * This is used to get all prefix objects by value. Currently it is used\n * to create a csv file with all prefixes and units.\n * @returns csv string containing all prefix objects, ordered by value.\n */\n allPrefixesByValue() {\n let prefixBuff = '';\n let pList = Object.keys(this.byValue_);\n //pList.sort() ;\n let pLen = pList.length;\n for (let p = 0; p < pLen; p++) {\n let pfx = this.getPrefixByValue(pList[p]) ;\n prefixBuff += pfx.code_ + ',' + pfx.name_ + ',,' + pfx.value_ + '\\r\\n';\n }\n return prefixBuff ;\n }\n\n /**\n * This is used to get all prefix objects. Currently it is used\n * to get the objects to write to the json ucum definitions file\n * that is used to provide prefix and unit definition objects for\n * conversions and validations.\n *\n * @returns an array containing all prefix objects, ordered by code.\n */\n allPrefixesByCode() {\n let prefixList = [];\n let pList = Object.keys(this.byCode_);\n pList.sort() ;\n let pLen = pList.length;\n for (let p = 0; p < pLen; p++) {\n prefixList.push(this.getPrefixByCode(pList[p])) ;\n }\n return prefixList ;\n }\n\n /**\n * Adds a prefix object to the tables\n *\n * @param prefixObj the object to be added to the tables\n */\n add(prefixObj){\n this.byCode_[prefixObj.getCode()] = prefixObj;\n this.byValue_[prefixObj.getValue()] = prefixObj;\n }\n\n\n /**\n * Tests whether a prefix object is found for a specified code. This\n * is used to determine whether or not a prefix object has been created\n * for the code.\n *\n * @param code the code to be used to find the prefix object\n * @return boolean indicating whether or not a prefix object was found\n * for the specified code\n */\n isDefined(code) {\n return this.byCode_[code] !== null && this.byCode_[code] !== undefined ;\n }\n\n\n /**\n * Obtains a prefix object for a specified code.\n *\n * @param code the code to be used to find the prefix object\n * @return the prefix object found, or null if nothing was found\n */\n getPrefixByCode(code) {\n return this.byCode_[code];\n }\n\n\n /**\n * Obtains a prefix object for a specified value.\n *\n * @param value the value to be used to find the prefix object\n * @return the prefix object found, or null if nothing was found\n */\n getPrefixByValue(value) {\n return this.byValue_[value];\n }\n\n} // end PrefixTablesFactory class\n\n\n// Create a singleton instance and (to preserve the existing API) an object that\n// provides that instance via getInstance().\nvar prefixTablesInstance = new PrefixTablesFactory();\nexport const PrefixTables = {\n getInstance: function() {\n return prefixTablesInstance;\n }\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,mBAAmB,CAAC;EAE/B;AACF;AACA;AACA;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAAA,EAAE;IACX,IAAI,CAACC,OAAO,GAAG,CA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GA,CAACC,SAAS,EAAC;IACZ,IAAI,CAACtB,OAAO,CAACsB,SAAS,CAACC,OAAO,CAAC,CAAC,CAAC,GAAGD,SAAS;IAC7C,IAAI,CAACrB,QAAQ,CAACqB,SAAS,CAACE,QAAQ,CAAC,CAAC,CAAC,GAAGF,SAAS;EACjD;;EAGA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACEG,SAASA,CAACC,IAAI,EAAE;IACd,OAAO,IAAI,CAAC1B,OAAO,CAAC0B,IAAI,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC1B,OAAO,CAAC0B,IAAI,CAAC,KAAKC,SAAS;EACxE;;EAGA;AACF;AACA;AACA;AACA;AACA;EACEP,eAAeA,CAACM,IAAI,EAAE;IACpB,OAAO,IAAI,CAAC1B,OAAO,CAAC0B,IAAI,CAAC;EAC3B;;EAGA;AACF;AACA;AACA;AACA;AACA;EACEd,gBAAgBA,CAACgB,KAAK,EAAE;IACtB,OAAO,IAAI,CAAC3B,QAAQ,CAAC2B,KAAK,CAAC;EAC7B;AAEF,CAAC,CAAC;;AAGF;AACA;AAAAC,OAAA,CAAA/B,mBAAA,GAAAA,mBAAA;AACA,IAAIgC,oBAAoB,GAAG,IAAIhC,mBAAmB,CAAC,CAAC;AAC7C,MAAMiC,YAAY,GAAG;EAC1BC,WAAW,EAAE,SAAAA,CAAA,EAAW;IACtB,OAAOF,oBAAoB;EAC7B;AACF,CAAC;AAAAD,OAAA,CAAAE,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"ucumFunctions.js","names":["UcumFunctions","constructor","funcs","cnvTo","x","cnvFrom","Math","log","LN10","pow","exp","LN2","tan","atan","sqrt","func","forName","fname","toLowerCase","f","Error","isDefined","_default","exports","default"],"sources":["../source/ucumFunctions.js"],"sourcesContent":["/*\n * This class manages the special functions used by some units.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nclass UcumFunctions {\n\n /**\n * Constructor\n *\n * Creates the singleton object that contains the list of functions used\n * to convert special units.\n */\n constructor() {\n\n // Create the hash containing the function pairs\n this.funcs = {};\n\n // Celsius - convert to Celsius from kelvin and from Celsius to kelvin\n // where kelvin is the base unit for temperature\n this.funcs['cel'] = {cnvTo : function(x){return x - 273.15;},\n cnvFrom : function(x){return x + 273.15;}};\n\n // Fahrenheit - convert to Fahrenheit from kelvin and from Fahrenheit to\n // kelvin - which is the base unit for temperature\n this.funcs['degf'] = {cnvTo : function(x){return x - 459.67;},\n cnvFrom : function(x){return x + 459.67;}};\n\n // Reaumur - convert between Reaumur and Kelvin. Because of the way the\n // calling code in the Units class is set up (in the convertFrom method),\n // what is given here as the convertTo function is actually the convert\n // from method and vice versa.\n //this.funcs['degre'] = {cnvTo : function(x){return x + 273.15;},\n // cnvFrom : function(x){return x - 273.15;}};\n this.funcs['degre'] = {cnvTo : function(x){return x - 273.15;},\n cnvFrom : function(x){return x + 273.15;}};\n\n // pH - convert to pH from moles per liter and from moles per liter to pH\n // where a mole is an amount of a substance (a count of particles)\n this.funcs['ph'] = {cnvTo : function(x){return - Math.log(x) / Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, -x);}};\n\n // ln - natural logarithm (base e 2.71828) - apply (cnvTo) and invert (cnvFrom)\n // and 2ln - two times the natural logarithm\n this.funcs['ln'] = {cnvTo : function(x){return Math.log(x);},\n cnvFrom : function(x){return Math.exp(x);}};\n this.funcs['2ln'] = {cnvTo : function(x){return 2 * Math.log(x);},\n cnvFrom : function(x){return Math.exp(x / 2);}};\n\n // lg - the decadic logarithm (base 10)\n this.funcs['lg'] = {cnvTo : function(x){return Math.log(x) / Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x);}};\n this.funcs['10lg'] = {cnvTo : function(x){return 10 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 10);}};\n this.funcs['20lg'] = {cnvTo : function(x){return 20 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 20);}};\n // The plain text ucum units file uses '2lg'\n this.funcs['2lg'] = {cnvTo : function(x){return 2 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 2);}};\n // The xml essence ucum file uses lgTimes2\n this.funcs['lgtimes2'] = this.funcs['2lg'];\n\n // ld - dual logarithm (base 2)\n this.funcs['ld'] = {cnvTo : function(x){return Math.log(x)/Math.LN2;},\n cnvFrom : function(x){return Math.pow(2, x);}};\n\n // tan - tangent\n this.funcs['100tan'] = {cnvTo : function(x){return Math.tan(x) * 100;},\n cnvFrom : function(x){return Math.atan(x/100);}};\n // the xml essence ucum file uses both 100tan and tanTimes100\n this.funcs['tanTimes100'] = this.funcs['100tan'] ;\n\n // sqrt - square root\n this.funcs['sqrt'] = {cnvTo : function(x){return Math.sqrt(x);},\n cnvFrom : function(x){return x*x;}};\n\n // inv - inverse\n this.funcs['inv'] = {cnvTo : function(x){return 1.0 / x;},\n cnvFrom : function(x){return 1.0 / x;}};\n\n // homeopathic potency functions\n this.funcs['hpX'] = {cnvTo : function(x){return -(this.funcs['lg'](x));},\n cnvFrom : function(x){return Math.pow(10, -x);}};\n\n this.funcs['hpC'] = {cnvTo : function(x){\n return -(this.func['ln'](x))/this.funcs['ln'](100);},\n cnvFrom : function(x){return Math.pow(100, -x);}};\n\n this.funcs['hpM'] = {cnvTo : function(x){\n return -(this.funcs['ln'](x))/this.funcs['ln'](1000);},\n cnvFrom : function(x){return Math.pow(1000, -x);}};\n\n this.funcs['hpQ'] = {cnvTo : function(x){\n return -(this.funcs['ln'](x))/this.funcs['ln'](50000);},\n cnvFrom : function(x){return Math.pow(50000, -x);}};\n\n } // end of constructor\n\n\n /**\n * Returns the function with the name specified\n *\n * @param fname name of the function to be returned\n * @return the function with the specified name\n * @throws an error message if the function is not found\n */\n forName(fname) {\n fname = fname.toLowerCase();\n\n let f = this.funcs[fname] ;\n if (f === null)\n throw(new Error(`Requested function ${fname} is not defined`));\n return f;\n }\n\n\n /**\n * Returns a flag indicating whether or not the function has been\n * defined.\n *\n * @param fname name of the function in question\n * @return true if it has been defined; false if not\n */\n isDefined(fname) {\n fname = fname.toLowerCase();\n return this.funcs[fname] !== null;\n }\n\n} // end of UcumFunctions class\n\nexport default new UcumFunctions(); // one singleton instance\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,aAAa,CAAC;EAElB;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAAA,EAAG;IAEZ;IACA,IAAI,CAACC,KAAK,GAAG,CAAC,CAAC;;IAEf;IACA;IACA,IAAI,CAACA,KAAK,CAAC,KAAK,CAAC,GAAG;MAACC,KAAK,EAAK,SAAAA,CAASC,CAAC,EAAC;QAAC,OAAOA,CAAC,GAAG,MAAM;MAAC,CAAC;MAC5CC,OAAO,EAAG,SAAAA,CAASD,CAAC,EAAC;QAAC,OAAOA,CAAC,GAAG,MAAM;MAAC;IAAC,CAAC;;IAE5D;IACA;IACA,IAAI,CAACF,KAAK,CAAC,MAAM,CAAC,GAAG;MAACC,KAAK,EAAK,SAAAA,CAASC,CAAC,EAAC;QAAC,OAAOA,CAAC,GAAG,MAAM;MAAC,CAAC;MAC5CC,OAAO,EAAG,SAAAA,CAASD,CAAC,EAAC;QAAC,OAAOA,CAAC,GAAG,MAAM;MAAC;IAAC,CAAC;;IAE7D;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,CAACF,KAAK,CAAC,OAAO,CAAC,GAAG;MAACC,KAAK,EAAK,SAAAA,CAASC,CAAC,EAAC;QAAC,OAAOA,CAAC,GAAG,MAAM;MAAC,CAAC;MAC5CC,OAAO,EAAG,SAAAA,CAASD,CAAC,EAAC;QAAC,OAAOA,CAAC,GAAG,MAAM;MAAC;IAAC,CAAC;;IAE9D;IACA;IACA,IAAI,CAACF,KAAK,CAAC,IAAI,CAAC,GAAG;MAACC,KAAK,EAAI,SAAAA,CAASC,CAAC,EAAC;QAAC,OAAO,CAAEE,IAAI,CAACC,GAAG,CAACH,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K,CAAC;IACzB,IAAIE,CAAC,KAAK,IAAI,EACZ,MAAM,IAAIC,KAAK,CAAE,sBAAqBH,KAAM,iBAAgB,CAAC;IAC/D,OAAOE,CAAC;EACV;;EAGA;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,SAASA,CAACJ,KAAK,EAAE;IACfA,KAAK,GAAGA,KAAK,CAACC,WAAW,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAChB,KAAK,CAACe,KAAK,CAAC,KAAK,IAAI;EACnC;AAEF,CAAC,CAAC;AAAA,IAAAK,QAAA,GAEa,IAAItB,aAAa,CAAC,CAAC,EAAE;AAAAuB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
1
+ {"version":3,"file":"ucumFunctions.js","names":["UcumFunctions","constructor","funcs","cnvTo","x","cnvFrom","Math","log","LN10","pow","exp","LN2","tan","atan","sqrt","func","forName","fname","toLowerCase","f","Error","isDefined","_default","exports","default"],"sources":["../source/ucumFunctions.js"],"sourcesContent":["/*\n * This class manages the special functions used by some units.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nclass UcumFunctions {\n\n /**\n * Constructor\n *\n * Creates the singleton object that contains the list of functions used\n * to convert special units.\n */\n constructor() {\n\n // Create the hash containing the function pairs\n this.funcs = {};\n\n // Celsius - convert to Celsius from kelvin and from Celsius to kelvin\n // where kelvin is the base unit for temperature\n this.funcs['cel'] = {cnvTo : function(x){return x - 273.15;},\n cnvFrom : function(x){return x + 273.15;}};\n\n // Fahrenheit - convert to Fahrenheit from kelvin and from Fahrenheit to\n // kelvin - which is the base unit for temperature\n this.funcs['degf'] = {cnvTo : function(x){return x - 459.67;},\n cnvFrom : function(x){return x + 459.67;}};\n\n // Reaumur - convert between Reaumur and Kelvin. Because of the way the\n // calling code in the Units class is set up (in the convertFrom method),\n // what is given here as the convertTo function is actually the convert\n // from method and vice versa.\n //this.funcs['degre'] = {cnvTo : function(x){return x + 273.15;},\n // cnvFrom : function(x){return x - 273.15;}};\n this.funcs['degre'] = {cnvTo : function(x){return x - 273.15;},\n cnvFrom : function(x){return x + 273.15;}};\n\n // pH - convert to pH from moles per liter and from moles per liter to pH\n // where a mole is an amount of a substance (a count of particles)\n this.funcs['ph'] = {cnvTo : function(x){return - Math.log(x) / Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, -x);}};\n\n // ln - natural logarithm (base e 2.71828) - apply (cnvTo) and invert (cnvFrom)\n // and 2ln - two times the natural logarithm\n this.funcs['ln'] = {cnvTo : function(x){return Math.log(x);},\n cnvFrom : function(x){return Math.exp(x);}};\n this.funcs['2ln'] = {cnvTo : function(x){return 2 * Math.log(x);},\n cnvFrom : function(x){return Math.exp(x / 2);}};\n\n // lg - the decadic logarithm (base 10)\n this.funcs['lg'] = {cnvTo : function(x){return Math.log(x) / Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x);}};\n this.funcs['10lg'] = {cnvTo : function(x){return 10 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 10);}};\n this.funcs['20lg'] = {cnvTo : function(x){return 20 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 20);}};\n // The plain text ucum units file uses '2lg'\n this.funcs['2lg'] = {cnvTo : function(x){return 2 * Math.log(x)/Math.LN10;},\n cnvFrom : function(x){return Math.pow(10, x / 2);}};\n // The xml essence ucum file uses lgTimes2\n this.funcs['lgtimes2'] = this.funcs['2lg'];\n\n // ld - dual logarithm (base 2)\n this.funcs['ld'] = {cnvTo : function(x){return Math.log(x)/Math.LN2;},\n cnvFrom : function(x){return Math.pow(2, x);}};\n\n // tan - tangent\n this.funcs['100tan'] = {cnvTo : function(x){return Math.tan(x) * 100;},\n cnvFrom : function(x){return Math.atan(x/100);}};\n // the xml essence ucum file uses both 100tan and tanTimes100\n this.funcs['tanTimes100'] = this.funcs['100tan'] ;\n\n // sqrt - square root\n this.funcs['sqrt'] = {cnvTo : function(x){return Math.sqrt(x);},\n cnvFrom : function(x){return x*x;}};\n\n // inv - inverse\n this.funcs['inv'] = {cnvTo : function(x){return 1.0 / x;},\n cnvFrom : function(x){return 1.0 / x;}};\n\n // homeopathic potency functions\n this.funcs['hpX'] = {cnvTo : function(x){return -(this.funcs['lg'](x));},\n cnvFrom : function(x){return Math.pow(10, -x);}};\n\n this.funcs['hpC'] = {cnvTo : function(x){\n return -(this.func['ln'](x))/this.funcs['ln'](100);},\n cnvFrom : function(x){return Math.pow(100, -x);}};\n\n this.funcs['hpM'] = {cnvTo : function(x){\n return -(this.funcs['ln'](x))/this.funcs['ln'](1000);},\n cnvFrom : function(x){return Math.pow(1000, -x);}};\n\n this.funcs['hpQ'] = {cnvTo : function(x){\n return -(this.funcs['ln'](x))/this.funcs['ln'](50000);},\n cnvFrom : function(x){return Math.pow(50000, -x);}};\n\n } // end of constructor\n\n\n /**\n * Returns the function with the name specified\n *\n * @param fname name of the function to be returned\n * @return the function with the specified name\n * @throws an error message if the function is not found\n */\n forName(fname) {\n fname = fname.toLowerCase();\n\n let f = this.funcs[fname] ;\n if (f === null)\n throw(new Error(`Requested function ${fname} is not defined`));\n return f;\n }\n\n\n /**\n * Returns a flag indicating whether or not the function has been\n * defined.\n *\n * @param fname name of the function in question\n * @return true if it has been defined; false if not\n */\n isDefined(fname) {\n fname = fname.toLowerCase();\n return this.funcs[fname] !== null;\n }\n\n} // end of UcumFunctions class\n\nexport default new UcumFunctions(); // one singleton instance\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,aAAa,CAAC;EAElB;AACF;AACA;AACA;AACA;AACA;EACEC,WAAWA,CAAA,EAAG;IAEZ;IACA,IAAI,CAACC,KAAK,GAAG,CAAC,CAAC;;IAEf;IACA;IACA,IAAI,CAACA,KAAK,CAAC,KAAK,CAAC,GAAG;MAACC,KAAK,EAAK,SAAAA,CAASC,CAAC,EAAC;QAAC,OAAOA,CAAC,GAAG,MAAM;MAAC,CAAC;MAC5CC,OAAO,EAAG,SAAAA,CAASD,CA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,CAAC;MAAC,CAAC;MAC9DG,OAAO,EAAG,SAAAA,CAASD,CAAC,EAAC;QAAC,OAAOE,IAAI,CAACG,GAAG,CAAC,IAAI,EAAE,CAACL,CAAC,CAAC;MAAC;IAAC,CAAC;IAEpE,IAAI,CAACF,KAAK,CAAC,KAAK,CAAC,GAAG;MAACC,KAAK,EAAG,SAAAA,CAASC,CAAC,EAAC;QACd,OAAO,CAAE,IAAI,CAACF,KAAK,CAAC,IAAI,CAAC,CAACE,CAAC,CAAE,GAAC,IAAI,CAACF,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;MAAC,CAAC;MAC/DG,OAAO,EAAG,SAAAA,CAASD,CAAC,EAAC;QAAC,OAAOE,IAAI,CAACG,GAAG,CAAC,KAAK,EAAE,CAACL,CAAC,CAAC;MAAC;IAAC,CAAC;EAEvE,CAAC,CAAC;;EAGF;AACF;AACA;AACA;AACA;AACA;AACA;EACEY,OAAOA,CAACC,KAAK,EAAE;IACbA,KAAK,GAAGA,KAAK,CAACC,WAAW,CAAC,CAAC;IAE3B,IAAIC,CAAC,GAAG,IAAI,CAACjB,KAAK,CAACe,KAAK,CAAC;IACzB,IAAIE,CAAC,KAAK,IAAI,EACZ,MAAM,IAAIC,KAAK,CAAE,sBAAqBH,KAAM,iBAAgB,CAAC;IAC/D,OAAOE,CAAC;EACV;;EAGA;AACF;AACA;AACA;AACA;AACA;AACA;EACEE,SAASA,CAACJ,KAAK,EAAE;IACfA,KAAK,GAAGA,KAAK,CAACC,WAAW,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAChB,KAAK,CAACe,KAAK,CAAC,KAAK,IAAI;EACnC;AAEF,CAAC,CAAC;AAAA,IAAAK,QAAA,GAEa,IAAItB,aAAa,CAAC,CAAC,EAAE;AAAAuB,OAAA,CAAAC,OAAA,GAAAF,QAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"ucumInternalUtils.js","names":["UnitTables","require","isNumericString","theString","num","isNaN","parseFloat","isIntegerUnit","str","test","getSynonyms","theSyn","retObj","utab","getInstance","resp","getUnitBySynonym","aLen","length","a","theUnit","csCode_","name_","guidance_"],"sources":["../source/ucumInternalUtils.js"],"sourcesContent":["/**\n * Internal utilities used by multiple UCUM classes. For example,\n * isNumericString is used by both the UnitString and UcumLhcUtils\n * classes. If it's in the UnitString class the UcumLhcUtils class\n * needs to require the UnitString class. But the checkSynonyms\n * class is used by the UnitString class - but was in the UcumLhcUtils\n * class. Requiring the UcumLhcUtils class from the UnitString class\n * made everything break (cyclical requires).\n *\n * So now they're here.\n */\n\n/**\n * This module implements internal ucum utilities.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar UnitTables = require('./unitTables.js').UnitTables ;\n\n\n/**\n * This function tests a string to see if it contains only numbers (digits,\n * a period, leading - or +). This code was taken from a stackoverflow\n * solution:\n * https://stackoverflow.com/questions/175739/is-there-a-built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number/42356340#42356340\n *\n * @params theString\n * @returns true if the string contains only numbers; false otherwise\n */\nexport function isNumericString(theString) {\n let num = \"\" + theString; //coerce num to be a string\n return !isNaN(num) && !isNaN(parseFloat(num));\n} // end isNumericString\n\n\n/**\n * Checks whether a string qualifies as an integer unit. Section 2.2.8 (\"integer\n * numbers\", says, \"A positive integer number may appear in place of a simple\n * unit symbol. Only a pure string of decimal digits (‘0’–‘9’) is\n * interpreted as a number.\"\n * Note: This leaves open the question of whether \"0\" is a valid unit, since\n * it is positive, but you can't measure anything in units of zero.\n * @param str the string to check\n */\nexport function isIntegerUnit(str) {\n return /^\\d+$/.test(str);\n}\n\n\n/**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for. This is assumed to be\n * a string and not undefined. The calling method should do any\n * necessary checking before calling this.\n * @returns a hash with up to three elements:\n * 'status' contains the status of the request, which can be 'error',\n * 'failed' or succeeded';\n * 'msg' which contains a message for an error or if no units were found; and\n * 'units' which is an array that contains one array for each unit found:\n * the unit's csCode_, the unit's name_, and the unit's guidance_\n *\n */\nexport function getSynonyms(theSyn) {\n\n let retObj = {} ;\n let utab = UnitTables.getInstance();\n let resp = {} ;\n resp = utab.getUnitBySynonym(theSyn);\n\n // If we didn't get any units, transfer the status and message\n if (!resp['units']) {\n retObj['status'] = resp['status'];\n retObj['msg'] = resp['msg'];\n }\n else {\n retObj['status'] = 'succeeded';\n let aLen = resp['units'].length ;\n retObj['units'] = [];\n for (let a = 0; a < aLen; a++) {\n let theUnit = resp['units'][a];\n retObj['units'][a] = {\n 'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_};\n } // end do for all units returned\n } // end if we got a units list\n return retObj ;\n\n} // end getSynonyms\n\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIA,UAAU,GAAGC,OAAO,CAAC,iBAAiB,CAAC,CAACD,UAAU;;AAGtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAACC,SAAS,EAAE;EACzC,IAAIC,GAAG,GAAG,EAAE,GAAGD,SAAS,CAAC,CAAC;EAC1B,OAAO,CAACE,KAAK,CAACD,GAAG,CAAC,IAAI,CAACC,KAAK,CAACC,UAAU,CAACF,GAAG,CAAC,CAAC;AAC/C,CAAC,CAAC;;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAACC,GAAG,EAAE;EACjC,OAAO,OAAO,CAACC,IAAI,CAACD,GAAG,CAAC;AAC1B;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,WAAWA,CAACC,MAAM,EAAE;EAElC,IAAIC,MAAM,GAAG,CAAC,CAAC;EACf,IAAIC,IAAI,GAAGb,UAAU,CAACc,WAAW,CAAC,CAAC;EACnC,IAAIC,IAAI,GAAG,CAAC,CAAC;EACbA,IAAI,GAAGF,IAAI,CAACG,gBAAgB,CAACL,MAAM,CAAC;;EAEpC;EACA,IAAI,CAACI,IAAI,CAAC,OAAO,CAAC,EAAE;IAClBH,MAAM,CAAC,QAAQ,CAAC,GAAGG,IAAI,CAAC,QAAQ,CAAC;IACjCH,MAAM,CAAC,KAAK,CAAC,GAAGG,IAAI,CAAC,KAAK,CAAC;EAC7B,CAAC,MACI;IACHH,MAAM,CAAC,QAAQ,CAAC,GAAG,WAAW;IAC9B,IAAIK,IAAI,GAAGF,IAAI,CAAC,OAAO,CAAC,CAACG,MAAM;IAC/BN,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE;IACpB,KAAK,IAAIO,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,IAAI,EAAEE,CAAC,EAAE,EAAE;MAC7B,IAAIC,OAAO,GAAGL,IAAI,CAAC,OAAO,CAAC,CAACI,CAAC,CAAC;MAC9BP,MAAM,CAAC,OAAO,CAAC,CAACO,CAAC,CAAC,GAAG;QACnB,MAAM,EAAEC,OAAO,CAACC,OAAO;QACvB,MAAM,EAAED,OAAO,CAACE,KAAK;QACrB,UAAU,EAAEF,OAAO,CAACG;MAAS,CAAC;IAClC,CAAC,CAAC;EACJ,CAAC,CAAC;EACF,OAAOX,MAAM;AAEf,CAAC,CAAC"}
1
+ {"version":3,"file":"ucumInternalUtils.js","names":["UnitTables","require","isNumericString","theString","num","isNaN","parseFloat","isIntegerUnit","str","test","getSynonyms","theSyn","retObj","utab","getInstance","resp","getUnitBySynonym","aLen","length","a","theUnit","csCode_","name_","guidance_"],"sources":["../source/ucumInternalUtils.js"],"sourcesContent":["/**\n * Internal utilities used by multiple UCUM classes. For example,\n * isNumericString is used by both the UnitString and UcumLhcUtils\n * classes. If it's in the UnitString class the UcumLhcUtils class\n * needs to require the UnitString class. But the checkSynonyms\n * class is used by the UnitString class - but was in the UcumLhcUtils\n * class. Requiring the UcumLhcUtils class from the UnitString class\n * made everything break (cyclical requires).\n *\n * So now they're here.\n */\n\n/**\n * This module implements internal ucum utilities.\n *\n * @author Lee Mericle, based on java version by Gunther Schadow\n *\n */\n\nvar UnitTables = require('./unitTables.js').UnitTables ;\n\n\n/**\n * This function tests a string to see if it contains only numbers (digits,\n * a period, leading - or +). This code was taken from a stackoverflow\n * solution:\n * https://stackoverflow.com/questions/175739/is-there-a-built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number/42356340#42356340\n *\n * @params theString\n * @returns true if the string contains only numbers; false otherwise\n */\nexport function isNumericString(theString) {\n let num = \"\" + theString; //coerce num to be a string\n return !isNaN(num) && !isNaN(parseFloat(num));\n} // end isNumericString\n\n\n/**\n * Checks whether a string qualifies as an integer unit. Section 2.2.8 (\"integer\n * numbers\", says, \"A positive integer number may appear in place of a simple\n * unit symbol. Only a pure string of decimal digits (‘0’–‘9’) is\n * interpreted as a number.\"\n * Note: This leaves open the question of whether \"0\" is a valid unit, since\n * it is positive, but you can't measure anything in units of zero.\n * @param str the string to check\n */\nexport function isIntegerUnit(str) {\n return /^\\d+$/.test(str);\n}\n\n\n/**\n * This method accepts a term and looks for units that include it as\n * a synonym - or that include the term in its name.\n *\n * @param theSyn the term to search for. This is assumed to be\n * a string and not undefined. The calling method should do any\n * necessary checking before calling this.\n * @returns a hash with up to three elements:\n * 'status' contains the status of the request, which can be 'error',\n * 'failed' or succeeded';\n * 'msg' which contains a message for an error or if no units were found; and\n * 'units' which is an array that contains one array for each unit found:\n * the unit's csCode_, the unit's name_, and the unit's guidance_\n *\n */\nexport function getSynonyms(theSyn) {\n\n let retObj = {} ;\n let utab = UnitTables.getInstance();\n let resp = {} ;\n resp = utab.getUnitBySynonym(theSyn);\n\n // If we didn't get any units, transfer the status and message\n if (!resp['units']) {\n retObj['status'] = resp['status'];\n retObj['msg'] = resp['msg'];\n }\n else {\n retObj['status'] = 'succeeded';\n let aLen = resp['units'].length ;\n retObj['units'] = [];\n for (let a = 0; a < aLen; a++) {\n let theUnit = resp['units'][a];\n retObj['units'][a] = {\n 'code': theUnit.csCode_,\n 'name': theUnit.name_,\n 'guidance': theUnit.guidance_};\n } // end do for all units returned\n } // end if we got a units list\n return retObj ;\n\n} // end getSynonyms\n\n"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIA,UAAU,GAAGC,OAAO,CAAC,iBAAiB,CAAC,CAACD,UAAU;;AAGtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,eAAeA,CAACC,SAAS,EAAE;EACzC,IAAIC,GAAG,GAAG,EAAE,GAAGD,SAAS,CAAC,CAAC;EAC1B,OAAO,CAACE,KAAK,CAACD,GAAG,CAAC,IAAI,CAACC,KAAK,CAACC,UAAU,CAACF,GAAG,CAAC,CAAC;AAC/C,CAAC,CAAC;;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAACC,GAAG,EAAE;EACjC,OAAO,OAAO,CAACC,IAAI,CAACD,GAAG,CAAC;AAC1B;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,WAAWA,CAACC,MAAM,EAAE;EAElC,IAAIC,MAAM,GAAG,CAAC,CAAC;EACf,IAAIC,IAAI,GAAGb,UAAU,CAACc,WAAW,CAAC,CAAC;EACnC,IAAIC,IAAI,GAAG,CAAC,CAAC;EACbA,IAAI,GAAGF,IAAI,CAACG,gBAAgB,CAACL,MAAM,CAAC;;EAEpC;EACA,IAAI,CAACI,IAAI,CAAC,OAAO,CAAC,EAAE;IAClBH,MAAM,CAAC,QAAQ,CAAC,GAAGG,IAAI,CAAC,QAAQ,CAAC;IACjCH,MAAM,CAAC,KAAK,CAAC,GAAGG,IAAI,CAAC,KAAK,CAAC;EAC7B,CAAC,MACI;IACHH,MAAM,CAAC,QAAQ,CAAC,GAAG,WAAW;IAC9B,IAAIK,IAAI,GAAGF,IAAI,CAAC,OAAO,CAAC,CAACG,MAAM;IAC/BN,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE;IACpB,KAAK,IAAIO,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,IAAI,EAAEE,CAAC,EAAE,EAAE;MAC7B,IAAIC,OAAO,GAAGL,IAAI,CAAC,OAAO,CAAC,CAACI,CAAC,CAAC;MAC9BP,MAAM,CAAC,OAAO,CAAC,CAACO,CAAC,CAAC,GAAG;QACnB,MAAM,EAAEC,OAAO,CAACC,OAAO;QACvB,MAAM,EAAED,OAAO,CAACE,KAAK;QACrB,UAAU,EAAEF,OAAO,CAACG;MAAS,CAAC;IAClC,CAAC,CAAC;EACJ,CAAC,CAAC;EACF,OAAOX,MAAM;AAEf,CAAC,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"ucumJsonDefs.js","names":["Pfx","require","PfxT","Un","Utab","unpackArray","UcumJsonDefs","loadJsonDefs","jsonDefs","prefixes","units","UnitTables","getInstance","unitsCount","pTab","PrefixTables","plen","length","p","newPref","Prefix","add","uTab","ulen","u","newUnit","Unit","addUnit","exports","ucumJsonDefs"],"sources":["../source/ucumJsonDefs.js"],"sourcesContent":["/**\n * This class handles opening, reading and loading the JSON file of ucum\n * definitions (prefixes, base units, and unit atoms).\n *\n * @author Lee Mericle\n *\n */\n\nvar Pfx = require(\"./prefix.js\");\nvar PfxT = require(\"./prefixTables.js\");\nvar Un = require(\"./unit.js\");\nvar Utab = require('./unitTables.js');\nvar unpackArray = require('./jsonArrayPack.js').unpackArray;\n\nexport class UcumJsonDefs {\n\n /**\n * This method loads the JSON prefix and unit objects into the prefix and\n * unit tables.\n *\n * @returns nothing\n */\n loadJsonDefs() {\n // requiring the file will take care of opening it for use\n const jsonDefs = require('../data/ucumDefs.min.json');\n jsonDefs.prefixes = unpackArray(jsonDefs.prefixes);\n jsonDefs.units = unpackArray(jsonDefs.units);\n\n if (Utab.UnitTables.getInstance().unitsCount() === 0) {\n\n let pTab = PfxT.PrefixTables.getInstance();\n let prefixes = jsonDefs[\"prefixes\"];\n let plen = prefixes.length;\n\n for (let p = 0; p < plen; p++) {\n let newPref = new Pfx.Prefix(prefixes[p]);\n pTab.add(newPref);\n }\n\n let uTab = Utab.UnitTables.getInstance();\n let units = jsonDefs[\"units\"];\n let ulen = units.length;\n\n for (let u = 0; u < ulen; u++) {\n let newUnit = new Un.Unit(units[u]);\n uTab.addUnit(newUnit);\n }\n } // end if the data has not already been loaded\n } // end loadJsonDefs\n\n} // end UcumJsonDefs class\n\nvar ucumJsonDefs = new UcumJsonDefs();\nexport {ucumJsonDefs};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIA,GAAG,GAAGC,OAAO,CAAC,aAAa,CAAC;AAChC,IAAIC,IAAI,GAAGD,OAAO,CAAC,mBAAmB,CAAC;AACvC,IAAIE,EAAE,GAAGF,OAAO,CAAC,WAAW,CAAC;AAC7B,IAAIG,IAAI,GAAGH,OAAO,CAAC,iBAAiB,CAAC;AACrC,IAAII,WAAW,GAAGJ,OAAO,CAAC,oBAAoB,CAAC,CAACI,WAAW;AAEpD,MAAMC,YAAY,CAAC;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,YAAYA,CAAA,EAAG;IACb;IACA,MAAMC,QAAQ,GAAGP,OAAO,CAAC,2BAA2B,CAAC;IACrDO,QAAQ,CAACC,QAAQ,GAAGJ,WAAW,CAACG,QAAQ,CAACC,QAAQ,CAAC;IAClDD,QAAQ,CAACE,KAAK,GAAGL,WAAW,CAACG,QAAQ,CAACE,KAAK,CAAC;IAE5C,IAAIN,IAAI,CAACO,UAAU,CAACC,WAAW,CAAC,CAAC,CAACC,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE;MAEpD,IAAIC,IAAI,GAAGZ,IAAI,CAACa,YAAY,CAACH,WAAW,CAAC,CAAC;MAC1C,IAAIH,QAAQ,GAAGD,QAAQ,CAAC,UAAU,CAAC;MACnC,IAAIQ,IAAI,GAAGP,QAAQ,CAACQ,MAAM;MAE1B,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,IAAI,EAAEE,CAAC,EAAE,EAAE;QAC7B,IAAIC,OAAO,GAAG,IAAInB,GAAG,CAACoB,MAAM,CAACX,QAAQ,CAACS,CAAC,CAAC,CAAC;QACzCJ,IAAI,CAACO,GAAG,CAACF,OAAO,CAAC;MACnB;MAEA,IAAIG,IAAI,GAAGlB,IAAI,CAACO,UAAU,CAACC,WAAW,CAAC,CAAC;MACxC,IAAIF,KAAK,GAAGF,QAAQ,CAAC,OAAO,CAAC;MAC7B,IAAIe,IAAI,GAAGb,KAAK,CAACO,MAAM;MAEvB,KAAK,IAAIO,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,IAAI,EAAEC,CAAC,EAAE,EAAE;QAC7B,IAAIC,OAAO,GAAG,IAAItB,EAAE,CAACuB,IAAI,CAAChB,KAAK,CAACc,CAAC,CAAC,CAAC;QACnCF,IAAI,CAACK,OAAO,CAACF,OAAO,CAAC;MACvB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;AAEJ,CAAC,CAAC;AAAAG,OAAA,CAAAtB,YAAA,GAAAA,YAAA;AAEF,IAAIuB,YAAY,GAAG,IAAIvB,YAAY,CAAC,CAAC;AAACsB,OAAA,CAAAC,YAAA,GAAAA,YAAA"}
1
+ {"version":3,"file":"ucumJsonDefs.js","names":["Pfx","require","PfxT","Un","Utab","unpackArray","UcumJsonDefs","loadJsonDefs","jsonDefs","prefixes","units","UnitTables","getInstance","unitsCount","pTab","PrefixTables","plen","length","p","newPref","Prefix","add","uTab","ulen","u","newUnit","Unit","addUnit","exports","ucumJsonDefs"],"sources":["../source/ucumJsonDefs.js"],"sourcesContent":["/**\n * This class handles opening, reading and loading the JSON file of ucum\n * definitions (prefixes, base units, and unit atoms).\n *\n * @author Lee Mericle\n *\n */\n\nvar Pfx = require(\"./prefix.js\");\nvar PfxT = require(\"./prefixTables.js\");\nvar Un = require(\"./unit.js\");\nvar Utab = require('./unitTables.js');\nvar unpackArray = require('./jsonArrayPack.js').unpackArray;\n\nexport class UcumJsonDefs {\n\n /**\n * This method loads the JSON prefix and unit objects into the prefix and\n * unit tables.\n *\n * @returns nothing\n */\n loadJsonDefs() {\n // requiring the file will take care of opening it for use\n const jsonDefs = require('../data/ucumDefs.min.json');\n jsonDefs.prefixes = unpackArray(jsonDefs.prefixes);\n jsonDefs.units = unpackArray(jsonDefs.units);\n\n if (Utab.UnitTables.getInstance().unitsCount() === 0) {\n\n let pTab = PfxT.PrefixTables.getInstance();\n let prefixes = jsonDefs[\"prefixes\"];\n let plen = prefixes.length;\n\n for (let p = 0; p < plen; p++) {\n let newPref = new Pfx.Prefix(prefixes[p]);\n pTab.add(newPref);\n }\n\n let uTab = Utab.UnitTables.getInstance();\n let units = jsonDefs[\"units\"];\n let ulen = units.length;\n\n for (let u = 0; u < ulen; u++) {\n let newUnit = new Un.Unit(units[u]);\n uTab.addUnit(newUnit);\n }\n } // end if the data has not already been loaded\n } // end loadJsonDefs\n\n} // end UcumJsonDefs class\n\nvar ucumJsonDefs = new UcumJsonDefs();\nexport {ucumJsonDefs};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAIA,GAAG,GAAGC,OAAO,CAAC,aAAa,CAAC;AAChC,IAAIC,IAAI,GAAGD,OAAO,CAAC,mBAAmB,CAAC;AACvC,IAAIE,EAAE,GAAGF,OAAO,CAAC,WAAW,CAAC;AAC7B,IAAIG,IAAI,GAAGH,OAAO,CAAC,iBAAiB,CAAC;AACrC,IAAII,WAAW,GAAGJ,OAAO,CAAC,oBAAoB,CAAC,CAACI,WAAW;AAEpD,MAAMC,YAAY,CAAC;EAExB;AACF;AACA;AACA;AACA;AACA;EACEC,YAAYA,CAAA,EAAG;IACb;IACA,MAAMC,QAAQ,GAAGP,O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