@lhncbc/ucum-lhc 6.0.0 → 6.0.2

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": "6.0.0",
3
+ "version": "6.0.2",
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/",
@@ -1153,10 +1153,17 @@ export class UnitString {
1153
1153
  // Look first for an exponent. If we got one, separate it out and
1154
1154
  // try to get the unit again
1155
1155
  let codeAndExp = this._isCodeWithExponent(uCode);
1156
+ let isIntegerUnitWithExp = false;
1156
1157
  if (codeAndExp) {
1157
1158
  uCode = codeAndExp[0];
1158
1159
  exp = codeAndExp[1];
1159
- origUnit = this.utabs_.getUnitByCode(uCode);
1160
+ isIntegerUnitWithExp = intUtils_.isIntegerUnit(uCode);
1161
+ origUnit = isIntegerUnitWithExp ?
1162
+ new Unit({'csCode_' : uCode,
1163
+ 'ciCode_' : uCode,
1164
+ 'magnitude_' : Number(uCode),
1165
+ 'name_' : uCode}) :
1166
+ this.utabs_.getUnitByCode(uCode);
1160
1167
  }
1161
1168
 
1162
1169
  // If an exponent is found but it's not a valid number, e.g. "2-1",
@@ -1294,10 +1301,11 @@ export class UnitString {
1294
1301
  }
1295
1302
  if (exp) {
1296
1303
  let expStr = exp.toString();
1304
+ const intergerUnitExpSign = isIntegerUnitWithExp && exp > 0 ? '+' : '';
1297
1305
  retUnit.assignVals({
1298
1306
  'name_': theName + '<sup>' + expStr + '</sup>',
1299
- 'csCode_': theCode + expStr,
1300
- 'ciCode_': theCiCode + expStr,
1307
+ 'csCode_': theCode + intergerUnitExpSign + expStr,
1308
+ 'ciCode_': theCiCode + intergerUnitExpSign + expStr,
1301
1309
  'printSymbol_': thePrintSymbol + '<sup>' + expStr + '</sup>'
1302
1310
  });
1303
1311
  }
@@ -1383,7 +1391,10 @@ export class UnitString {
1383
1391
  // /100{cells}. But f it is a number, just set the return unit to
1384
1392
  // the number.
1385
1393
  if (intUtils_.isIntegerUnit(befAnnoText)) {
1386
- retUnit = befAnnoText ;
1394
+ retUnit = new Unit({'csCode_' : befAnnoText + annoText,
1395
+ 'ciCode_' : befAnnoText + annoText.toUpperCase(),
1396
+ 'magnitude_' : Number(befAnnoText),
1397
+ 'name_': befAnnoText + annoText});
1387
1398
  }
1388
1399
  // Otherwise try to find a unit
1389
1400
  else {
@@ -1055,10 +1055,17 @@ class UnitString {
1055
1055
  // Look first for an exponent. If we got one, separate it out and
1056
1056
  // try to get the unit again
1057
1057
  let codeAndExp = this._isCodeWithExponent(uCode);
1058
+ let isIntegerUnitWithExp = false;
1058
1059
  if (codeAndExp) {
1059
1060
  uCode = codeAndExp[0];
1060
1061
  exp = codeAndExp[1];
1061
- origUnit = this.utabs_.getUnitByCode(uCode);
1062
+ isIntegerUnitWithExp = intUtils_.isIntegerUnit(uCode);
1063
+ origUnit = isIntegerUnitWithExp ? new Unit({
1064
+ 'csCode_': uCode,
1065
+ 'ciCode_': uCode,
1066
+ 'magnitude_': Number(uCode),
1067
+ 'name_': uCode
1068
+ }) : this.utabs_.getUnitByCode(uCode);
1062
1069
  }
1063
1070
 
1064
1071
  // If an exponent is found but it's not a valid number, e.g. "2-1",
@@ -1195,10 +1202,11 @@ class UnitString {
1195
1202
  }
1196
1203
  if (exp) {
1197
1204
  let expStr = exp.toString();
1205
+ const intergerUnitExpSign = isIntegerUnitWithExp && exp > 0 ? '+' : '';
1198
1206
  retUnit.assignVals({
1199
1207
  'name_': theName + '<sup>' + expStr + '</sup>',
1200
- 'csCode_': theCode + expStr,
1201
- 'ciCode_': theCiCode + expStr,
1208
+ 'csCode_': theCode + intergerUnitExpSign + expStr,
1209
+ 'ciCode_': theCiCode + intergerUnitExpSign + expStr,
1202
1210
  'printSymbol_': thePrintSymbol + '<sup>' + expStr + '</sup>'
1203
1211
  });
1204
1212
  }
@@ -1277,7 +1285,12 @@ class UnitString {
1277
1285
  // /100{cells}. But f it is a number, just set the return unit to
1278
1286
  // the number.
1279
1287
  if (intUtils_.isIntegerUnit(befAnnoText)) {
1280
- retUnit = befAnnoText;
1288
+ retUnit = new Unit({
1289
+ 'csCode_': befAnnoText + annoText,
1290
+ 'ciCode_': befAnnoText + annoText.toUpperCase(),
1291
+ 'magnitude_': Number(befAnnoText),
1292
+ 'name_': befAnnoText + annoText
1293
+ });
1281
1294
  }
1282
1295
  // Otherwise try to find a unit
1283
1296
  else {