@bentley/imodeljs-quantity
Advanced tools
Comparing version 0.190.0 to 0.191.0
@@ -5,2 +5,23 @@ { | ||
{ | ||
"version": "0.191.0", | ||
"tag": "@bentley/imodeljs-quantity_v0.191.0", | ||
"date": "Mon, 13 May 2019 15:52:05 GMT", | ||
"comments": { | ||
"none": [ | ||
{ | ||
"comment": "Adds parameter for api-extractor to validate missing release tags" | ||
}, | ||
{ | ||
"comment": "Put sourcemap in npm package." | ||
}, | ||
{ | ||
"comment": "documentation cleanup" | ||
}, | ||
{ | ||
"comment": "Upgrade TypeDoc dependency to 0.14.2" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "0.190.0", | ||
@@ -7,0 +28,0 @@ "tag": "@bentley/imodeljs-quantity_v0.190.0", |
# Change Log - @bentley/imodeljs-quantity | ||
This log was last generated on Thu, 14 Mar 2019 14:26:49 GMT and should not be manually modified. | ||
This log was last generated on Mon, 13 May 2019 15:52:05 GMT and should not be manually modified. | ||
## 0.191.0 | ||
Mon, 13 May 2019 15:52:05 GMT | ||
### Updates | ||
- Adds parameter for api-extractor to validate missing release tags | ||
- Put sourcemap in npm package. | ||
- documentation cleanup | ||
- Upgrade TypeDoc dependency to 0.14.2 | ||
## 0.190.0 | ||
@@ -6,0 +16,0 @@ Thu, 14 Mar 2019 14:26:49 GMT |
@@ -6,3 +6,3 @@ import { BentleyError } from "@bentley/bentleyjs-core"; | ||
*/ | ||
export declare const enum QuantityStatus { | ||
export declare enum QuantityStatus { | ||
QUANTITY_ERROR_BASE = 35039, | ||
@@ -9,0 +9,0 @@ Success = 0, |
@@ -82,3 +82,5 @@ import { FormatProps } from "./Interfaces"; | ||
} | ||
/** Interface the defines the format of the data needed to convert a quantity from one unit to another. */ | ||
/** Interface the defines the format of the data needed to convert a quantity from one unit to another. | ||
* @alpha | ||
*/ | ||
export interface UnitConversionSpec { | ||
@@ -89,3 +91,5 @@ name: string; | ||
} | ||
/** A class that contains both formatting information and the conversion factors necessary to convert from an input unit to the units specified in the format. */ | ||
/** A class that contains both formatting information and the conversion factors necessary to convert from an input unit to the units specified in the format. | ||
* @alpha | ||
*/ | ||
export declare class FormatterSpec { | ||
@@ -92,0 +96,0 @@ private _name; |
@@ -5,2 +5,3 @@ "use strict"; | ||
const Constants_1 = require("../Constants"); | ||
const FormatEnums_1 = require("./FormatEnums"); | ||
// cSpell:ignore ZERONORMALIZED, nosign, onlynegative, signalways, negativeparentheses | ||
@@ -18,5 +19,5 @@ // cSpell:ignore trailzeroes, keepsinglezero, zeroempty, keepdecimalpoint, applyrounding, fractiondash, showunitlabel, prependunitlabel, exponentonlynegative | ||
this._roundFactor = 0.0; | ||
this._type = 0 /* Decimal */; // required; options are decimal, fractional, scientific, station | ||
this._precision = 6 /* Six */; // required | ||
this._showSignOption = 1 /* OnlyNegative */; // options: noSign, onlyNegative, signAlways, negativeParentheses | ||
this._type = FormatEnums_1.FormatType.Decimal; // required; options are decimal, fractional, scientific, station | ||
this._precision = FormatEnums_1.DecimalPrecision.Six; // required | ||
this._showSignOption = FormatEnums_1.ShowSignOption.OnlyNegative; // options: noSign, onlyNegative, signAlways, negativeParentheses | ||
this._decimalSeparator = Constants_1.QuantityConstants.LocaleSpecificDecimalSeparator; | ||
@@ -50,3 +51,3 @@ this._thousandSeparator = Constants_1.QuantityConstants.LocaleSpecificThousandSeparator; | ||
static scientificTypeToString(scientificType) { | ||
if (scientificType === 0 /* Normalized */) | ||
if (scientificType === FormatEnums_1.ScientificType.Normalized) | ||
return "Normalized"; | ||
@@ -60,7 +61,7 @@ else | ||
case "normalized": | ||
return 0 /* Normalized */; | ||
return FormatEnums_1.ScientificType.Normalized; | ||
case "zeronormalized": | ||
return 1 /* ZeroNormalized */; | ||
return FormatEnums_1.ScientificType.ZeroNormalized; | ||
default: | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${formatName} has an invalid 'SCIENTIFIC_TYPE' attribute.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'SCIENTIFIC_TYPE' attribute.`); | ||
} | ||
@@ -71,9 +72,9 @@ } | ||
switch (showSign) { | ||
case 3 /* NegativeParentheses */: | ||
case FormatEnums_1.ShowSignOption.NegativeParentheses: | ||
return "NegativeParentheses"; | ||
case 0 /* NoSign */: | ||
case FormatEnums_1.ShowSignOption.NoSign: | ||
return "NoSign"; | ||
case 1 /* OnlyNegative */: | ||
case FormatEnums_1.ShowSignOption.OnlyNegative: | ||
return "OnlyNegative"; | ||
case 2 /* SignAlways */: | ||
case FormatEnums_1.ShowSignOption.SignAlways: | ||
return "SignAlways"; | ||
@@ -86,11 +87,11 @@ } | ||
case "nosign": | ||
return 0 /* NoSign */; | ||
return FormatEnums_1.ShowSignOption.NoSign; | ||
case "onlynegative": | ||
return 1 /* OnlyNegative */; | ||
return FormatEnums_1.ShowSignOption.OnlyNegative; | ||
case "signalways": | ||
return 2 /* SignAlways */; | ||
return FormatEnums_1.ShowSignOption.SignAlways; | ||
case "negativeparentheses": | ||
return 3 /* NegativeParentheses */; | ||
return FormatEnums_1.ShowSignOption.NegativeParentheses; | ||
default: | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${formatName} has an invalid 'showSignOption' attribute.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'showSignOption' attribute.`); | ||
} | ||
@@ -101,21 +102,21 @@ } | ||
const formatTraitsArr = Array(); | ||
if ((currentFormatTrait & 1 /* TrailZeroes */) === 1 /* TrailZeroes */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.TrailZeroes) === FormatEnums_1.FormatTraits.TrailZeroes) | ||
formatTraitsArr.push("trailZeroes"); | ||
if ((currentFormatTrait & 2 /* KeepSingleZero */) === 2 /* KeepSingleZero */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.KeepSingleZero) === FormatEnums_1.FormatTraits.KeepSingleZero) | ||
formatTraitsArr.push("keepSingleZero"); | ||
if ((currentFormatTrait & 4 /* ZeroEmpty */) === 4 /* ZeroEmpty */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.ZeroEmpty) === FormatEnums_1.FormatTraits.ZeroEmpty) | ||
formatTraitsArr.push("zeroEmpty"); | ||
if ((currentFormatTrait & 8 /* KeepDecimalPoint */) === 8 /* KeepDecimalPoint */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.KeepDecimalPoint) === FormatEnums_1.FormatTraits.KeepDecimalPoint) | ||
formatTraitsArr.push("keepDecimalPoint"); | ||
if ((currentFormatTrait & 16 /* ApplyRounding */) === 16 /* ApplyRounding */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.ApplyRounding) === FormatEnums_1.FormatTraits.ApplyRounding) | ||
formatTraitsArr.push("applyRounding"); | ||
if ((currentFormatTrait & 32 /* FractionDash */) === 32 /* FractionDash */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.FractionDash) === FormatEnums_1.FormatTraits.FractionDash) | ||
formatTraitsArr.push("fractionDash"); | ||
if ((currentFormatTrait & 64 /* ShowUnitLabel */) === 64 /* ShowUnitLabel */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.ShowUnitLabel) === FormatEnums_1.FormatTraits.ShowUnitLabel) | ||
formatTraitsArr.push("showUnitLabel"); | ||
if ((currentFormatTrait & 128 /* PrependUnitLabel */) === 128 /* PrependUnitLabel */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.PrependUnitLabel) === FormatEnums_1.FormatTraits.PrependUnitLabel) | ||
formatTraitsArr.push("prependUnitLabel"); | ||
if ((currentFormatTrait & 256 /* Use1000Separator */) === 256 /* Use1000Separator */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.Use1000Separator) === FormatEnums_1.FormatTraits.Use1000Separator) | ||
formatTraitsArr.push("use1000Separator"); | ||
if ((currentFormatTrait & 512 /* ExponentOnlyNegative */) === 512 /* ExponentOnlyNegative */) | ||
if ((currentFormatTrait & FormatEnums_1.FormatTraits.ExponentOnlyNegative) === FormatEnums_1.FormatTraits.ExponentOnlyNegative) | ||
formatTraitsArr.push("exponentOnlyNegative"); | ||
@@ -129,33 +130,33 @@ return formatTraitsArr; | ||
case "trailzeroes": | ||
formatTrait = currentFormatTrait | 1 /* TrailZeroes */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.TrailZeroes; | ||
break; | ||
case "keepsinglezero": | ||
formatTrait = currentFormatTrait | 2 /* KeepSingleZero */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.KeepSingleZero; | ||
break; | ||
case "zeroempty": | ||
formatTrait = currentFormatTrait | 4 /* ZeroEmpty */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.ZeroEmpty; | ||
break; | ||
case "keepdecimalpoint": | ||
formatTrait = currentFormatTrait | 8 /* KeepDecimalPoint */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.KeepDecimalPoint; | ||
break; | ||
case "applyrounding": | ||
formatTrait = currentFormatTrait | 16 /* ApplyRounding */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.ApplyRounding; | ||
break; | ||
case "fractiondash": | ||
formatTrait = currentFormatTrait | 32 /* FractionDash */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.FractionDash; | ||
break; | ||
case "showunitlabel": | ||
formatTrait = currentFormatTrait | 64 /* ShowUnitLabel */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.ShowUnitLabel; | ||
break; | ||
case "prependunitlabel": | ||
formatTrait = currentFormatTrait | 128 /* PrependUnitLabel */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.PrependUnitLabel; | ||
break; | ||
case "use1000separator": | ||
formatTrait = currentFormatTrait | 256 /* Use1000Separator */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.Use1000Separator; | ||
break; | ||
case "exponentonlynegative": | ||
formatTrait = currentFormatTrait | 512 /* ExponentOnlyNegative */; | ||
formatTrait = currentFormatTrait | FormatEnums_1.FormatTraits.ExponentOnlyNegative; | ||
break; | ||
default: | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `Format has an invalid 'formatTraits' option.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `Format has an invalid 'formatTraits' option.`); | ||
} | ||
@@ -167,9 +168,9 @@ return formatTrait; | ||
switch (type) { | ||
case 0 /* Decimal */: | ||
case FormatEnums_1.FormatType.Decimal: | ||
return "Decimal"; | ||
case 2 /* Scientific */: | ||
case FormatEnums_1.FormatType.Scientific: | ||
return "Scientific"; | ||
case 3 /* Station */: | ||
case FormatEnums_1.FormatType.Station: | ||
return "Station"; | ||
case 1 /* Fractional */: | ||
case FormatEnums_1.FormatType.Fractional: | ||
return "Fractional"; | ||
@@ -182,11 +183,11 @@ } | ||
case "decimal": | ||
return 0 /* Decimal */; | ||
return FormatEnums_1.FormatType.Decimal; | ||
case "scientific": | ||
return 2 /* Scientific */; | ||
return FormatEnums_1.FormatType.Scientific; | ||
case "station": | ||
return 3 /* Station */; | ||
return FormatEnums_1.FormatType.Station; | ||
case "fractional": | ||
return 1 /* Fractional */; | ||
return FormatEnums_1.FormatType.Fractional; | ||
default: | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${formatName} has an invalid 'type' attribute.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'type' attribute.`); | ||
} | ||
@@ -198,29 +199,29 @@ } | ||
case 0: | ||
return 0 /* Zero */; | ||
return FormatEnums_1.DecimalPrecision.Zero; | ||
case 1: | ||
return 1 /* One */; | ||
return FormatEnums_1.DecimalPrecision.One; | ||
case 2: | ||
return 2 /* Two */; | ||
return FormatEnums_1.DecimalPrecision.Two; | ||
case 3: | ||
return 3 /* Three */; | ||
return FormatEnums_1.DecimalPrecision.Three; | ||
case 4: | ||
return 4 /* Four */; | ||
return FormatEnums_1.DecimalPrecision.Four; | ||
case 5: | ||
return 5 /* Five */; | ||
return FormatEnums_1.DecimalPrecision.Five; | ||
case 6: | ||
return 6 /* Six */; | ||
return FormatEnums_1.DecimalPrecision.Six; | ||
case 7: | ||
return 7 /* Seven */; | ||
return FormatEnums_1.DecimalPrecision.Seven; | ||
case 8: | ||
return 8 /* Eight */; | ||
return FormatEnums_1.DecimalPrecision.Eight; | ||
case 9: | ||
return 9 /* Nine */; | ||
return FormatEnums_1.DecimalPrecision.Nine; | ||
case 10: | ||
return 10 /* Ten */; | ||
return FormatEnums_1.DecimalPrecision.Ten; | ||
case 11: | ||
return 11 /* Eleven */; | ||
return FormatEnums_1.DecimalPrecision.Eleven; | ||
case 12: | ||
return 12 /* Twelve */; | ||
return FormatEnums_1.DecimalPrecision.Twelve; | ||
default: | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The 'precision' attribute must be an integer in the range 0-12.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The 'precision' attribute must be an integer in the range 0-12.`); | ||
} | ||
@@ -232,21 +233,21 @@ } | ||
case 1: | ||
return 1 /* One */; | ||
return FormatEnums_1.FractionalPrecision.One; | ||
case 2: | ||
return 2 /* Two */; | ||
return FormatEnums_1.FractionalPrecision.Two; | ||
case 4: | ||
return 4 /* Four */; | ||
return FormatEnums_1.FractionalPrecision.Four; | ||
case 8: | ||
return 8 /* Eight */; | ||
return FormatEnums_1.FractionalPrecision.Eight; | ||
case 16: | ||
return 16 /* Sixteen */; | ||
return FormatEnums_1.FractionalPrecision.Sixteen; | ||
case 32: | ||
return 32 /* ThirtyTwo */; | ||
return FormatEnums_1.FractionalPrecision.ThirtyTwo; | ||
case 64: | ||
return 64 /* SixtyFour */; | ||
return FormatEnums_1.FractionalPrecision.SixtyFour; | ||
case 128: | ||
return 128 /* OneHundredTwentyEight */; | ||
return FormatEnums_1.FractionalPrecision.OneHundredTwentyEight; | ||
case 256: | ||
return 256 /* TwoHundredFiftySix */; | ||
return FormatEnums_1.FractionalPrecision.TwoHundredFiftySix; | ||
default: | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${formatName} has an invalid 'precision' attribute.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`); | ||
} | ||
@@ -257,7 +258,7 @@ } | ||
switch (type) { // type must be decimal, fractional, scientific, or station | ||
case 0 /* Decimal */: | ||
case 2 /* Scientific */: | ||
case 3 /* Station */: | ||
case FormatEnums_1.FormatType.Decimal: | ||
case FormatEnums_1.FormatType.Scientific: | ||
case FormatEnums_1.FormatType.Station: | ||
return Format.parseDecimalPrecision(precision); | ||
case 1 /* Fractional */: | ||
case FormatEnums_1.FormatType.Fractional: | ||
return Format.parseFractionalPrecision(precision, formatName); | ||
@@ -279,11 +280,11 @@ } | ||
if (name === undefined || typeof (name) !== "string" || (label !== undefined && typeof (label) !== "string")) // throws if name is undefined or name isn't a string or if label is defined and isn't a string | ||
return Promise.reject(new Exception_1.QuantityError(35040 /* InvalidJson */, `This Composite has a unit with an invalid 'name' or 'label' attribute.`)); | ||
return Promise.reject(new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `This Composite has a unit with an invalid 'name' or 'label' attribute.`)); | ||
for (const unit of this.units) { | ||
const unitObj = unit[0].name; | ||
if (unitObj.toLowerCase() === name.toLowerCase()) // duplicate names are not allowed | ||
return Promise.reject(new Exception_1.QuantityError(35040 /* InvalidJson */, `The unit ${unitObj} has a duplicate name.`)); | ||
return Promise.reject(new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The unit ${unitObj} has a duplicate name.`)); | ||
} | ||
newUnit = await unitsProvider.findUnit(name); | ||
if (!newUnit || !newUnit.isValid) | ||
return Promise.reject(new Exception_1.QuantityError(35040 /* InvalidJson */, `Invalid unit name '${name}'.`)); | ||
return Promise.reject(new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `Invalid unit name '${name}'.`)); | ||
this.units.push([newUnit, label]); | ||
@@ -293,27 +294,27 @@ } | ||
if (undefined === jsonObj.type) // type is required | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} does not have the required 'type' attribute.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} does not have the required 'type' attribute.`); | ||
if (typeof (jsonObj.type) !== "string") | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'type' attribute. It should be of type 'string'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'type' attribute. It should be of type 'string'.`); | ||
this._type = Format.parseFormatType(jsonObj.type, this.name); | ||
if (undefined === jsonObj.precision) // precision is required | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} does not have the required 'precision' attribute.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} does not have the required 'precision' attribute.`); | ||
else if (typeof (jsonObj.precision) !== "number") // must be a number | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'precision' attribute. It should be of type 'number'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'precision' attribute. It should be of type 'number'.`); | ||
else if (!Number.isInteger(jsonObj.precision)) // must be an integer | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'precision' attribute. It should be an integer.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'precision' attribute. It should be an integer.`); | ||
this._precision = Format.parsePrecision(jsonObj.precision, this.name, this._type); | ||
if (this.type === 2 /* Scientific */) { | ||
if (this.type === FormatEnums_1.FormatType.Scientific) { | ||
if (undefined === jsonObj.scientificType) // if format type is scientific and scientific type is undefined, throw | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has type 'Scientific' therefore attribute 'scientificType' is required.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has type 'Scientific' therefore attribute 'scientificType' is required.`); | ||
if (typeof (jsonObj.scientificType) !== "string") | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'scientificType' attribute. It should be of type 'string'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'scientificType' attribute. It should be of type 'string'.`); | ||
this._scientificType = Format.parseScientificType(jsonObj.scientificType.toLowerCase(), this.name); | ||
} | ||
if (this.type === 3 /* Station */) { | ||
if (this.type === FormatEnums_1.FormatType.Station) { | ||
if (undefined === jsonObj.stationOffsetSize) | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has type 'Station' therefore attribute 'stationOffsetSize' is required.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has type 'Station' therefore attribute 'stationOffsetSize' is required.`); | ||
if (typeof (jsonObj.stationOffsetSize) !== "number") | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'stationOffsetSize' attribute. It should be of type 'number'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'stationOffsetSize' attribute. It should be of type 'number'.`); | ||
if (!Number.isInteger(jsonObj.stationOffsetSize) || jsonObj.stationOffsetSize <= 0) // must be a positive int > 0 | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'stationOffsetSize' attribute. It should be a positive integer.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'stationOffsetSize' attribute. It should be a positive integer.`); | ||
this._stationOffsetSize = jsonObj.stationOffsetSize; | ||
@@ -323,3 +324,3 @@ } | ||
if (typeof (jsonObj.roundFactor) !== "number") | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'roundFactor' attribute. It should be of type 'number'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'roundFactor' attribute. It should be of type 'number'.`); | ||
if (jsonObj.roundFactor !== this.roundFactor) // if roundFactor isn't default value of 0.0, reassign roundFactor variable | ||
@@ -330,5 +331,5 @@ this._roundFactor = jsonObj.roundFactor; | ||
if (typeof (jsonObj.minWidth) !== "number") | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'minWidth' attribute. It should be of type 'number'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'minWidth' attribute. It should be of type 'number'.`); | ||
if (!Number.isInteger(jsonObj.minWidth) || jsonObj.minWidth < 0) // must be a positive int | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'minWidth' attribute. It should be a positive integer.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'minWidth' attribute. It should be a positive integer.`); | ||
this._minWidth = jsonObj.minWidth; | ||
@@ -338,3 +339,3 @@ } | ||
if (typeof (jsonObj.showSignOption) !== "string") | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'showSignOption' attribute. It should be of type 'string'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'showSignOption' attribute. It should be of type 'string'.`); | ||
this._showSignOption = Format.parseShowSignOption(jsonObj.showSignOption, this.name); | ||
@@ -344,3 +345,3 @@ } | ||
if (!Array.isArray(jsonObj.formatTraits) && typeof (jsonObj.formatTraits) !== "string") // must be either an array of strings or a string | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'formatTraits' attribute. It should be of type 'string' or 'string[]'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'formatTraits' attribute. It should be of type 'string' or 'string[]'.`); | ||
this.verifyFormatTraitsOptions(jsonObj.formatTraits); // check that all of the options for formatTraits are valid. If now, throw | ||
@@ -350,5 +351,5 @@ } | ||
if (typeof (jsonObj.decimalSeparator) !== "string") // not a string or not a one character string | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'decimalSeparator' attribute. It should be of type 'string'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'decimalSeparator' attribute. It should be of type 'string'.`); | ||
if (jsonObj.decimalSeparator.length !== 1) | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'decimalSeparator' attribute. It must be a one character string.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'decimalSeparator' attribute. It must be a one character string.`); | ||
this._decimalSeparator = jsonObj.decimalSeparator; | ||
@@ -358,5 +359,5 @@ } | ||
if (typeof (jsonObj.thousandSeparator) !== "string") | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'thousandSeparator' attribute. It should be of type 'string'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'thousandSeparator' attribute. It should be of type 'string'.`); | ||
if (jsonObj.thousandSeparator.length !== 1) | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'thousandSeparator' attribute. It must be a one character string.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'thousandSeparator' attribute. It must be a one character string.`); | ||
this._thousandSeparator = jsonObj.thousandSeparator; | ||
@@ -366,5 +367,5 @@ } | ||
if (typeof (jsonObj.uomSeparator) !== "string") | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'uomSeparator' attribute. It should be of type 'string'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'uomSeparator' attribute. It should be of type 'string'.`); | ||
if (jsonObj.uomSeparator.length < 0 || jsonObj.uomSeparator.length > 1) | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'uomSeparator' attribute. It must be empty or a string with a single character.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'uomSeparator' attribute. It must be empty or a string with a single character.`); | ||
this._uomSeparator = jsonObj.uomSeparator; | ||
@@ -374,5 +375,5 @@ } | ||
if (typeof (jsonObj.stationSeparator) !== "string") | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'stationSeparator' attribute. It should be of type 'string'.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'stationSeparator' attribute. It should be of type 'string'.`); | ||
if (jsonObj.stationSeparator.length !== 1) | ||
throw new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has an invalid 'stationSeparator' attribute. It must be a one character string.`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has an invalid 'stationSeparator' attribute. It must be a one character string.`); | ||
this._stationSeparator = jsonObj.stationSeparator; | ||
@@ -390,3 +391,3 @@ } | ||
if (typeof (jsonObj.composite.includeZero) !== "boolean") // includeZero must be a boolean IF it is defined | ||
return Promise.reject(new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has a Composite with an invalid 'includeZero' attribute. It should be of type 'boolean'.`)); | ||
return Promise.reject(new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has a Composite with an invalid 'includeZero' attribute. It should be of type 'boolean'.`)); | ||
this._includeZero = jsonObj.composite.includeZero; | ||
@@ -396,5 +397,5 @@ } | ||
if (typeof (jsonObj.composite.spacer) !== "string") | ||
return Promise.reject(new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has a Composite with an invalid 'spacer' attribute. It must be of type 'string'.`)); | ||
return Promise.reject(new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has a Composite with an invalid 'spacer' attribute. It must be of type 'string'.`)); | ||
if (jsonObj.composite.spacer.length < 0 || jsonObj.composite.spacer.length > 1) | ||
return Promise.reject(new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has a Composite with an invalid 'spacer' attribute. It must be empty or a string with a single character.`)); | ||
return Promise.reject(new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has a Composite with an invalid 'spacer' attribute. It must be empty or a string with a single character.`)); | ||
this._spacer = jsonObj.composite.spacer; | ||
@@ -404,3 +405,3 @@ } | ||
if (!Array.isArray(jsonObj.composite.units)) { // must be an array | ||
return Promise.reject(new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has a Composite with an invalid 'units' attribute. It must be of type 'array'`)); | ||
return Promise.reject(new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has a Composite with an invalid 'units' attribute. It must be of type 'array'`)); | ||
} | ||
@@ -421,3 +422,3 @@ if (jsonObj.composite.units.length > 0 && jsonObj.composite.units.length <= 4) { // Composite requires 1-4 units | ||
if (undefined === this.units || this.units.length === 0) | ||
return Promise.reject(new Exception_1.QuantityError(35040 /* InvalidJson */, `The Format ${this.name} has a Composite with no valid 'units'`)); | ||
return Promise.reject(new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${this.name} has a Composite with no valid 'units'`)); | ||
} | ||
@@ -468,3 +469,5 @@ } | ||
exports.Format = Format; | ||
/** A class that contains both formatting information and the conversion factors necessary to convert from an input unit to the units specified in the format. */ | ||
/** A class that contains both formatting information and the conversion factors necessary to convert from an input unit to the units specified in the format. | ||
* @alpha | ||
*/ | ||
class FormatterSpec { | ||
@@ -471,0 +474,0 @@ /** Constructor |
/** @alpha */ | ||
export declare const enum FormatTraits { | ||
export declare enum FormatTraits { | ||
TrailZeroes = 1, | ||
@@ -15,3 +15,3 @@ KeepSingleZero = 2, | ||
/** @alpha */ | ||
export declare const enum FractionalPrecision { | ||
export declare enum FractionalPrecision { | ||
One = 1, | ||
@@ -28,3 +28,3 @@ Two = 2, | ||
/** @alpha */ | ||
export declare const enum DecimalPrecision { | ||
export declare enum DecimalPrecision { | ||
Zero = 0, | ||
@@ -45,3 +45,3 @@ One = 1, | ||
/** @alpha */ | ||
export declare const enum FormatType { | ||
export declare enum FormatType { | ||
Decimal = 0, | ||
@@ -53,3 +53,3 @@ Fractional = 1, | ||
/** @alpha */ | ||
export declare const enum ScientificType { | ||
export declare enum ScientificType { | ||
Normalized = 0, | ||
@@ -59,3 +59,3 @@ ZeroNormalized = 1 | ||
/** @alpha */ | ||
export declare const enum ShowSignOption { | ||
export declare enum ShowSignOption { | ||
NoSign = 0, | ||
@@ -62,0 +62,0 @@ OnlyNegative = 1, |
@@ -9,2 +9,3 @@ "use strict"; | ||
const Exception_1 = require("../Exception"); | ||
const FormatEnums_1 = require("./FormatEnums"); | ||
/** rounding additive | ||
@@ -109,3 +110,3 @@ * @internal | ||
let formattedValue = wholePart.toFixed(0); | ||
if ((formattedValue.length > 3) && (spec.format.hasFormatTraitSet(256 /* Use1000Separator */) && (spec.format.thousandSeparator.length > 0))) { | ||
if ((formattedValue.length > 3) && (spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.Use1000Separator) && (spec.format.thousandSeparator.length > 0))) { | ||
let numSeparators = Math.floor(formattedValue.length / 3); | ||
@@ -154,3 +155,3 @@ let groupLength = formattedValue.length % 3; | ||
} | ||
if (spec.format.hasFormatTraitSet(64 /* ShowUnitLabel */)) { | ||
if (spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.ShowUnitLabel)) { | ||
componentText = componentText + spec.format.uomSeparator + label; | ||
@@ -172,3 +173,3 @@ } | ||
let posMagnitude = Math.abs(magnitude); | ||
if ((Math.abs(posMagnitude) < 0.0001) && spec.format.hasFormatTraitSet(4 /* ZeroEmpty */)) | ||
if ((Math.abs(posMagnitude) < 0.0001) && spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.ZeroEmpty)) | ||
return ""; | ||
@@ -180,5 +181,5 @@ // tslint:disable-next-line:prefer-for-of | ||
if (unitConversion.factor < 1.0) | ||
throw new Exception_1.QuantityError(35041 /* InvalidCompositeFormat */, `The Format ${spec.format.name} has a invalid unit specification..`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification..`); | ||
if (i > 0 && unitConversion.offset !== 0) | ||
throw new Exception_1.QuantityError(35041 /* InvalidCompositeFormat */, `The Format ${spec.format.name} has a invalid unit specification..`); | ||
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification..`); | ||
const unitValue = (posMagnitude * unitConversion.factor) + unitConversion.offset; // offset should only ever be defined for major unit | ||
@@ -203,14 +204,14 @@ if (i < spec.format.units.length - 1) { | ||
let posMagnitude = Math.abs(magnitude); | ||
if ((Math.abs(posMagnitude) < 0.0001) && spec.format.hasFormatTraitSet(4 /* ZeroEmpty */)) | ||
if ((Math.abs(posMagnitude) < 0.0001) && spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.ZeroEmpty)) | ||
return ""; | ||
if (spec.format.hasFormatTraitSet(16 /* ApplyRounding */)) | ||
if (spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.ApplyRounding)) | ||
posMagnitude = Math.abs(Formatter.roundDouble(magnitude, spec.format.roundFactor)); | ||
const isSci = ((posMagnitude > 1.0e12) || spec.format.type === 2 /* Scientific */); | ||
const isDecimal = (isSci || spec.format.type === 0 /* Decimal */); | ||
const isFractional = (!isDecimal && spec.format.type === 1 /* Fractional */); | ||
const isSci = ((posMagnitude > 1.0e12) || spec.format.type === FormatEnums_1.FormatType.Scientific); | ||
const isDecimal = (isSci || spec.format.type === FormatEnums_1.FormatType.Decimal); | ||
const isFractional = (!isDecimal && spec.format.type === FormatEnums_1.FormatType.Fractional); | ||
/*const usesStops = spec.format.type === FormatType.Station;*/ | ||
const isPrecisionZero = spec.format.precision === 0 /* Zero */; | ||
const isKeepSingleZero = spec.format.hasFormatTraitSet(2 /* KeepSingleZero */); | ||
const isPrecisionZero = spec.format.precision === FormatEnums_1.DecimalPrecision.Zero; | ||
const isKeepSingleZero = spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.KeepSingleZero); | ||
const precisionScale = Math.pow(10.0, spec.format.precision); | ||
const isKeepTrailingZeroes = spec.format.hasFormatTraitSet(1 /* TrailZeroes */); | ||
const isKeepTrailingZeroes = spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.TrailZeroes); | ||
let expInt = 0.0; | ||
@@ -225,6 +226,6 @@ if (isSci && (posMagnitude !== 0.0)) { | ||
expInt = Math.floor(exp); | ||
if (spec.format.type === 2 /* Scientific */) { | ||
if (spec.format.scientificType === 1 /* ZeroNormalized */ && posMagnitude > 1.0) | ||
if (spec.format.type === FormatEnums_1.FormatType.Scientific) { | ||
if (spec.format.scientificType === FormatEnums_1.ScientificType.ZeroNormalized && posMagnitude > 1.0) | ||
expInt += 1.0; | ||
else if (spec.format.scientificType === 0 /* Normalized */ && posMagnitude < 1.0) | ||
else if (spec.format.scientificType === FormatEnums_1.ScientificType.Normalized && posMagnitude < 1.0) | ||
expInt += 1.0; | ||
@@ -265,3 +266,3 @@ if (negativeExp) | ||
else { | ||
if (spec.format.hasFormatTraitSet(8 /* KeepDecimalPoint */)) | ||
if (spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.KeepDecimalPoint)) | ||
formattedValue = formattedValue + spec.format.decimalSeparator; | ||
@@ -279,3 +280,3 @@ } | ||
if (!fn.isZero && fn.hasFractionPart) { | ||
const wholeFractionSeparator = spec.format.hasFormatTraitSet(32 /* FractionDash */) ? "-" : " "; | ||
const wholeFractionSeparator = spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.FractionDash) ? "-" : " "; | ||
const fractionString = fn.getNumeratorString() + "/" + fn.getDenominatorString(); | ||
@@ -304,3 +305,3 @@ formattedValue = formattedValue + wholeFractionSeparator + fractionString; | ||
fractionString = spec.format.decimalSeparator + "".padEnd(spec.format.precision, "0"); | ||
else if (spec.format.hasFormatTraitSet(8 /* KeepDecimalPoint */)) | ||
else if (spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.KeepDecimalPoint)) | ||
fractionString = spec.format.decimalSeparator; | ||
@@ -322,3 +323,3 @@ formattedValue = stationString + fractionString; | ||
switch (spec.format.showSignOption) { | ||
case 3 /* NegativeParentheses */: | ||
case FormatEnums_1.ShowSignOption.NegativeParentheses: | ||
if (valueIsNegative) { | ||
@@ -329,7 +330,7 @@ prefix = "("; | ||
break; | ||
case 1 /* OnlyNegative */: | ||
case FormatEnums_1.ShowSignOption.OnlyNegative: | ||
if (valueIsNegative) | ||
prefix = "-"; | ||
break; | ||
case 2 /* SignAlways */: | ||
case FormatEnums_1.ShowSignOption.SignAlways: | ||
if (valueIsNegative) | ||
@@ -340,3 +341,3 @@ prefix = "-"; | ||
break; | ||
case 0 /* NoSign */: | ||
case FormatEnums_1.ShowSignOption.NoSign: | ||
default: | ||
@@ -352,4 +353,4 @@ break; | ||
formattedMagnitude = Formatter.formatMagnitude(magnitude, spec); | ||
if (formattedMagnitude.length > 0 && spec.unitConversions.length > 0 && spec.format.hasFormatTraitSet(64 /* ShowUnitLabel */)) { | ||
if (spec.format.hasFormatTraitSet(128 /* PrependUnitLabel */)) | ||
if (formattedMagnitude.length > 0 && spec.unitConversions.length > 0 && spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.ShowUnitLabel)) { | ||
if (spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.PrependUnitLabel)) | ||
formattedMagnitude = spec.unitConversions[0].label + spec.format.uomSeparator + formattedMagnitude; | ||
@@ -356,0 +357,0 @@ else |
@@ -9,2 +9,3 @@ "use strict"; | ||
const Quantity_1 = require("./Quantity"); | ||
const FormatEnums_1 = require("./Formatter/FormatEnums"); | ||
/** A ParseToken holds either a numeric or string token extracted from a string that represents a quantity value. | ||
@@ -124,5 +125,5 @@ * @alpha | ||
const skipCodes = [format.thousandSeparator.charCodeAt(0)]; | ||
if (format.type === 3 /* Station */ && format.stationSeparator && format.stationSeparator.length === 1) | ||
if (format.type === FormatEnums_1.FormatType.Station && format.stationSeparator && format.stationSeparator.length === 1) | ||
skipCodes.push(format.stationSeparator.charCodeAt(0)); | ||
if (format.type === 1 /* Fractional */ && format.hasFormatTraitSet(32 /* FractionDash */)) { | ||
if (format.type === FormatEnums_1.FormatType.Fractional && format.hasFormatTraitSet(FormatEnums_1.FormatTraits.FractionDash)) { | ||
fractionDashCode = Constants_1.QuantityConstants.CHAR_MINUS; | ||
@@ -129,0 +130,0 @@ } |
{ | ||
"name": "@bentley/imodeljs-quantity", | ||
"version": "0.190.0", | ||
"description": "Quantity formatting and parsing concepts in typescript", | ||
"version": "0.191.0", | ||
"description": "Quantity parsing, formatting and conversions for iModel.js", | ||
"license": "MIT", | ||
@@ -39,5 +39,5 @@ "main": "lib/imodeljs-quantity.js", | ||
"devDependencies": { | ||
"@bentley/bentleyjs-core": "0.190.0", | ||
"@bentley/build-tools": "0.190.0", | ||
"@bentley/webpack-tools": "0.190.0", | ||
"@bentley/bentleyjs-core": "0.191.0", | ||
"@bentley/build-tools": "0.191.0", | ||
"@bentley/webpack-tools": "0.191.0", | ||
"@types/chai": "^4.1.4", | ||
@@ -47,3 +47,3 @@ "@types/chai-as-promised": "^7", | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "10.12.18", | ||
"@types/node": "10.14.1", | ||
"@types/sinon": "^5.0.5", | ||
@@ -53,3 +53,3 @@ "chai": "^4.1.2", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.0.1", | ||
"nyc": "^14.0.0", | ||
"rimraf": "^2.6.2", | ||
@@ -59,3 +59,4 @@ "sinon": "^7.1.1", | ||
"tslint": "^5.11.0", | ||
"typedoc": "^0.11.1", | ||
"tslint-etc": "^1.5.2", | ||
"typedoc": "^0.14.2", | ||
"typescript": "~3.2.2" | ||
@@ -65,3 +66,3 @@ }, | ||
"peerDependencies": { | ||
"@bentley/bentleyjs-core": "0.190.0" | ||
"@bentley/bentleyjs-core": "^0.191.0" | ||
}, | ||
@@ -68,0 +69,0 @@ "nyc": { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
309470
30
3834
20
3