intl-messageformat-parser
Advanced tools
Comparing version 6.1.3 to 6.2.0
@@ -128,2 +128,4 @@ import { __assign } from "tslib"; | ||
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?$/g; | ||
var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g; | ||
var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/; | ||
function parseSignificantPrecision(str) { | ||
@@ -259,7 +261,30 @@ var result = {}; | ||
continue; | ||
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width | ||
case 'integer-width': | ||
if (token.options.length > 1) { | ||
throw new RangeError('integer-width stems only accept a single optional option'); | ||
} | ||
token.options[0].replace(INTEGER_WIDTH_REGEX, function (_, g1, g2, g3, g4, g5) { | ||
if (g1) { | ||
result.minimumIntegerDigits = g2.length; | ||
} | ||
else if (g3 && g4) { | ||
throw new Error('We currently do not support maximum integer digits'); | ||
} | ||
else if (g5) { | ||
throw new Error('We currently do not support exact integer digits'); | ||
} | ||
return ''; | ||
}); | ||
continue; | ||
} | ||
// Precision | ||
// https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#fraction-precision | ||
// precision-integer case | ||
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width | ||
if (CONCISE_INTEGER_WIDTH_REGEX.test(token.stem)) { | ||
result.minimumIntegerDigits = token.stem.length; | ||
continue; | ||
} | ||
if (FRACTION_PRECISION_REGEX.test(token.stem)) { | ||
// Precision | ||
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#fraction-precision | ||
// precision-integer case | ||
if (token.options.length > 1) { | ||
@@ -293,2 +318,3 @@ throw new RangeError('Fraction-precision stems only accept a single optional option'); | ||
} | ||
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#significant-digits-precision | ||
if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) { | ||
@@ -295,0 +321,0 @@ result = __assign(__assign({}, result), parseSignificantPrecision(token.stem)); |
{ | ||
"name": "intl-messageformat-parser", | ||
"version": "6.1.3", | ||
"version": "6.2.0", | ||
"description": "Parses ICU Message strings into an AST via JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -132,2 +132,4 @@ "use strict"; | ||
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?$/g; | ||
var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g; | ||
var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/; | ||
function parseSignificantPrecision(str) { | ||
@@ -263,7 +265,30 @@ var result = {}; | ||
continue; | ||
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width | ||
case 'integer-width': | ||
if (token.options.length > 1) { | ||
throw new RangeError('integer-width stems only accept a single optional option'); | ||
} | ||
token.options[0].replace(INTEGER_WIDTH_REGEX, function (_, g1, g2, g3, g4, g5) { | ||
if (g1) { | ||
result.minimumIntegerDigits = g2.length; | ||
} | ||
else if (g3 && g4) { | ||
throw new Error('We currently do not support maximum integer digits'); | ||
} | ||
else if (g5) { | ||
throw new Error('We currently do not support exact integer digits'); | ||
} | ||
return ''; | ||
}); | ||
continue; | ||
} | ||
// Precision | ||
// https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#fraction-precision | ||
// precision-integer case | ||
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width | ||
if (CONCISE_INTEGER_WIDTH_REGEX.test(token.stem)) { | ||
result.minimumIntegerDigits = token.stem.length; | ||
continue; | ||
} | ||
if (FRACTION_PRECISION_REGEX.test(token.stem)) { | ||
// Precision | ||
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#fraction-precision | ||
// precision-integer case | ||
if (token.options.length > 1) { | ||
@@ -297,2 +322,3 @@ throw new RangeError('Fraction-precision stems only accept a single optional option'); | ||
} | ||
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#significant-digits-precision | ||
if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) { | ||
@@ -299,0 +325,0 @@ result = tslib_1.__assign(tslib_1.__assign({}, result), parseSignificantPrecision(token.stem)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
302803
7908