Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@formatjs/icu-skeleton-parser

Package Overview
Dependencies
Maintainers
3
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/icu-skeleton-parser - npm Package Compare versions

Comparing version
2.0.7
to
2.0.8
+5
-5
date-time.d.ts
/**
* Parse Date time skeleton into Intl.DateTimeFormatOptions
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
* @public
* @param skeleton skeleton string
*/
* Parse Date time skeleton into Intl.DateTimeFormatOptions
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
* @public
* @param skeleton skeleton string
*/
export declare function parseDateTimeSkeleton(skeleton: string): Intl.DateTimeFormatOptions;
+114
-117
/**
* https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
* Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
* with some tweaks
*/
var DATE_TIME_REGEX = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
* https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
* Credit: https://github.com/caridy/intl-datetimeformat-pattern/blob/master/index.js
* with some tweaks
*/
const DATE_TIME_REGEX = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
/**
* Parse Date time skeleton into Intl.DateTimeFormatOptions
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
* @public
* @param skeleton skeleton string
*/
* Parse Date time skeleton into Intl.DateTimeFormatOptions
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
* @public
* @param skeleton skeleton string
*/
export function parseDateTimeSkeleton(skeleton) {
var result = {};
skeleton.replace(DATE_TIME_REGEX, function (match) {
var len = match.length;
switch (match[0]) {
// Era
case 'G':
result.era = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short';
break;
// Year
case 'y':
result.year = len === 2 ? '2-digit' : 'numeric';
break;
case 'Y':
case 'u':
case 'U':
case 'r':
throw new RangeError('`Y/u/U/r` (year) patterns are not supported, use `y` instead');
// Quarter
case 'q':
case 'Q':
throw new RangeError('`q/Q` (quarter) patterns are not supported');
// Month
case 'M':
case 'L':
result.month = ['numeric', '2-digit', 'short', 'long', 'narrow'][len - 1];
break;
// Week
case 'w':
case 'W':
throw new RangeError('`w/W` (week) patterns are not supported');
case 'd':
result.day = ['numeric', '2-digit'][len - 1];
break;
case 'D':
case 'F':
case 'g':
throw new RangeError('`D/F/g` (day) patterns are not supported, use `d` instead');
// Weekday
case 'E':
result.weekday = len === 4 ? 'long' : len === 5 ? 'narrow' : 'short';
break;
case 'e':
if (len < 4) {
throw new RangeError('`e..eee` (weekday) patterns are not supported');
}
result.weekday = ['short', 'long', 'narrow', 'short'][len - 4];
break;
case 'c':
if (len < 4) {
throw new RangeError('`c..ccc` (weekday) patterns are not supported');
}
result.weekday = ['short', 'long', 'narrow', 'short'][len - 4];
break;
// Period
case 'a': // AM, PM
result.hour12 = true;
break;
case 'b': // am, pm, noon, midnight
case 'B': // flexible day periods
throw new RangeError('`b/B` (period) patterns are not supported, use `a` instead');
// Hour
case 'h':
result.hourCycle = 'h12';
result.hour = ['numeric', '2-digit'][len - 1];
break;
case 'H':
result.hourCycle = 'h23';
result.hour = ['numeric', '2-digit'][len - 1];
break;
case 'K':
result.hourCycle = 'h11';
result.hour = ['numeric', '2-digit'][len - 1];
break;
case 'k':
result.hourCycle = 'h24';
result.hour = ['numeric', '2-digit'][len - 1];
break;
case 'j':
case 'J':
case 'C':
throw new RangeError('`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead');
// Minute
case 'm':
result.minute = ['numeric', '2-digit'][len - 1];
break;
// Second
case 's':
result.second = ['numeric', '2-digit'][len - 1];
break;
case 'S':
case 'A':
throw new RangeError('`S/A` (second) patterns are not supported, use `s` instead');
// Zone
case 'z': // 1..3, 4: specific non-location format
result.timeZoneName = len < 4 ? 'short' : 'long';
break;
case 'Z': // 1..3, 4, 5: The ISO8601 varios formats
case 'O': // 1, 4: milliseconds in day short, long
case 'v': // 1, 4: generic non-location format
case 'V': // 1, 2, 3, 4: time zone ID or city
case 'X': // 1, 2, 3, 4: The ISO8601 varios formats
case 'x': // 1, 2, 3, 4: The ISO8601 varios formats
throw new RangeError('`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead');
}
return '';
});
return result;
const result = {};
skeleton.replace(DATE_TIME_REGEX, (match) => {
const len = match.length;
switch (match[0]) {
case "G":
result.era = len === 4 ? "long" : len === 5 ? "narrow" : "short";
break;
case "y":
result.year = len === 2 ? "2-digit" : "numeric";
break;
case "Y":
case "u":
case "U":
case "r": throw new RangeError("`Y/u/U/r` (year) patterns are not supported, use `y` instead");
case "q":
case "Q": throw new RangeError("`q/Q` (quarter) patterns are not supported");
case "M":
case "L":
result.month = [
"numeric",
"2-digit",
"short",
"long",
"narrow"
][len - 1];
break;
case "w":
case "W": throw new RangeError("`w/W` (week) patterns are not supported");
case "d":
result.day = ["numeric", "2-digit"][len - 1];
break;
case "D":
case "F":
case "g": throw new RangeError("`D/F/g` (day) patterns are not supported, use `d` instead");
case "E":
result.weekday = len === 4 ? "long" : len === 5 ? "narrow" : "short";
break;
case "e":
if (len < 4) {
throw new RangeError("`e..eee` (weekday) patterns are not supported");
}
result.weekday = [
"short",
"long",
"narrow",
"short"
][len - 4];
break;
case "c":
if (len < 4) {
throw new RangeError("`c..ccc` (weekday) patterns are not supported");
}
result.weekday = [
"short",
"long",
"narrow",
"short"
][len - 4];
break;
case "a":
result.hour12 = true;
break;
case "b":
case "B": throw new RangeError("`b/B` (period) patterns are not supported, use `a` instead");
case "h":
result.hourCycle = "h12";
result.hour = ["numeric", "2-digit"][len - 1];
break;
case "H":
result.hourCycle = "h23";
result.hour = ["numeric", "2-digit"][len - 1];
break;
case "K":
result.hourCycle = "h11";
result.hour = ["numeric", "2-digit"][len - 1];
break;
case "k":
result.hourCycle = "h24";
result.hour = ["numeric", "2-digit"][len - 1];
break;
case "j":
case "J":
case "C": throw new RangeError("`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead");
case "m":
result.minute = ["numeric", "2-digit"][len - 1];
break;
case "s":
result.second = ["numeric", "2-digit"][len - 1];
break;
case "S":
case "A": throw new RangeError("`S/A` (second) patterns are not supported, use `s` instead");
case "z":
result.timeZoneName = len < 4 ? "short" : "long";
break;
case "Z":
case "O":
case "v":
case "V":
case "X":
case "x": throw new RangeError("`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead");
}
return "";
});
return result;
}

@@ -1,2 +0,2 @@

export * from './date-time.js';
export * from './number.js';
export * from "./date-time.js";
export * from "./number.js";

@@ -1,2 +0,2 @@

export * from './date-time.js';
export * from './number.js';
export * from "./date-time.js";
export * from "./number.js";

@@ -1,13 +0,13 @@

import type { NumberFormatOptions } from '@formatjs/ecma402-abstract';
import type { NumberFormatOptions } from "@formatjs/ecma402-abstract";
export interface ExtendedNumberFormatOptions extends NumberFormatOptions {
scale?: number;
scale?: number;
}
export interface NumberSkeletonToken {
stem: string;
options: string[];
stem: string;
options: string[];
}
export declare function parseNumberSkeletonFromString(skeleton: string): NumberSkeletonToken[];
/**
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
*/
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
*/
export declare function parseNumberSkeleton(tokens: NumberSkeletonToken[]): ExtendedNumberFormatOptions;
+286
-301

@@ -1,316 +0,301 @@

import { __assign } from "tslib";
import { WHITE_SPACE_REGEX } from './regex.generated.js';
import { WHITE_SPACE_REGEX } from "./regex.generated.js";
export function parseNumberSkeletonFromString(skeleton) {
if (skeleton.length === 0) {
throw new Error('Number skeleton cannot be empty');
}
// Parse the skeleton
var stringTokens = skeleton
.split(WHITE_SPACE_REGEX)
.filter(function (x) { return x.length > 0; });
var tokens = [];
for (var _i = 0, stringTokens_1 = stringTokens; _i < stringTokens_1.length; _i++) {
var stringToken = stringTokens_1[_i];
var stemAndOptions = stringToken.split('/');
if (stemAndOptions.length === 0) {
throw new Error('Invalid number skeleton');
}
var stem = stemAndOptions[0], options = stemAndOptions.slice(1);
for (var _a = 0, options_1 = options; _a < options_1.length; _a++) {
var option = options_1[_a];
if (option.length === 0) {
throw new Error('Invalid number skeleton');
}
}
tokens.push({ stem: stem, options: options });
}
return tokens;
if (skeleton.length === 0) {
throw new Error("Number skeleton cannot be empty");
}
// Parse the skeleton
const stringTokens = skeleton.split(WHITE_SPACE_REGEX).filter((x) => x.length > 0);
const tokens = [];
for (const stringToken of stringTokens) {
let stemAndOptions = stringToken.split("/");
if (stemAndOptions.length === 0) {
throw new Error("Invalid number skeleton");
}
const [stem, ...options] = stemAndOptions;
for (const option of options) {
if (option.length === 0) {
throw new Error("Invalid number skeleton");
}
}
tokens.push({
stem,
options
});
}
return tokens;
}
function icuUnitToEcma(unit) {
return unit.replace(/^(.*?)-/, '');
return unit.replace(/^(.*?)-/, "");
}
var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?[rs]?$/g;
var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
const FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
const SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?[rs]?$/g;
const INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
const CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
function parseSignificantPrecision(str) {
var result = {};
if (str[str.length - 1] === 'r') {
result.roundingPriority = 'morePrecision';
}
else if (str[str.length - 1] === 's') {
result.roundingPriority = 'lessPrecision';
}
str.replace(SIGNIFICANT_PRECISION_REGEX, function (_, g1, g2) {
// @@@ case
if (typeof g2 !== 'string') {
result.minimumSignificantDigits = g1.length;
result.maximumSignificantDigits = g1.length;
}
// @@@+ case
else if (g2 === '+') {
result.minimumSignificantDigits = g1.length;
}
// .### case
else if (g1[0] === '#') {
result.maximumSignificantDigits = g1.length;
}
// .@@## or .@@@ case
else {
result.minimumSignificantDigits = g1.length;
result.maximumSignificantDigits =
g1.length + (typeof g2 === 'string' ? g2.length : 0);
}
return '';
});
return result;
const result = {};
if (str[str.length - 1] === "r") {
result.roundingPriority = "morePrecision";
} else if (str[str.length - 1] === "s") {
result.roundingPriority = "lessPrecision";
}
str.replace(SIGNIFICANT_PRECISION_REGEX, function(_, g1, g2) {
// @@@ case
if (typeof g2 !== "string") {
result.minimumSignificantDigits = g1.length;
result.maximumSignificantDigits = g1.length;
} else if (g2 === "+") {
result.minimumSignificantDigits = g1.length;
} else if (g1[0] === "#") {
result.maximumSignificantDigits = g1.length;
} else {
result.minimumSignificantDigits = g1.length;
result.maximumSignificantDigits = g1.length + (typeof g2 === "string" ? g2.length : 0);
}
return "";
});
return result;
}
function parseSign(str) {
switch (str) {
case 'sign-auto':
return {
signDisplay: 'auto',
};
case 'sign-accounting':
case '()':
return {
currencySign: 'accounting',
};
case 'sign-always':
case '+!':
return {
signDisplay: 'always',
};
case 'sign-accounting-always':
case '()!':
return {
signDisplay: 'always',
currencySign: 'accounting',
};
case 'sign-except-zero':
case '+?':
return {
signDisplay: 'exceptZero',
};
case 'sign-accounting-except-zero':
case '()?':
return {
signDisplay: 'exceptZero',
currencySign: 'accounting',
};
case 'sign-never':
case '+_':
return {
signDisplay: 'never',
};
}
switch (str) {
case "sign-auto": return { signDisplay: "auto" };
case "sign-accounting":
case "()": return { currencySign: "accounting" };
case "sign-always":
case "+!": return { signDisplay: "always" };
case "sign-accounting-always":
case "()!": return {
signDisplay: "always",
currencySign: "accounting"
};
case "sign-except-zero":
case "+?": return { signDisplay: "exceptZero" };
case "sign-accounting-except-zero":
case "()?": return {
signDisplay: "exceptZero",
currencySign: "accounting"
};
case "sign-never":
case "+_": return { signDisplay: "never" };
}
}
function parseConciseScientificAndEngineeringStem(stem) {
// Engineering
var result;
if (stem[0] === 'E' && stem[1] === 'E') {
result = {
notation: 'engineering',
};
stem = stem.slice(2);
}
else if (stem[0] === 'E') {
result = {
notation: 'scientific',
};
stem = stem.slice(1);
}
if (result) {
var signDisplay = stem.slice(0, 2);
if (signDisplay === '+!') {
result.signDisplay = 'always';
stem = stem.slice(2);
}
else if (signDisplay === '+?') {
result.signDisplay = 'exceptZero';
stem = stem.slice(2);
}
if (!CONCISE_INTEGER_WIDTH_REGEX.test(stem)) {
throw new Error('Malformed concise eng/scientific notation');
}
result.minimumIntegerDigits = stem.length;
}
return result;
// Engineering
let result;
if (stem[0] === "E" && stem[1] === "E") {
result = { notation: "engineering" };
stem = stem.slice(2);
} else if (stem[0] === "E") {
result = { notation: "scientific" };
stem = stem.slice(1);
}
if (result) {
const signDisplay = stem.slice(0, 2);
if (signDisplay === "+!") {
result.signDisplay = "always";
stem = stem.slice(2);
} else if (signDisplay === "+?") {
result.signDisplay = "exceptZero";
stem = stem.slice(2);
}
if (!CONCISE_INTEGER_WIDTH_REGEX.test(stem)) {
throw new Error("Malformed concise eng/scientific notation");
}
result.minimumIntegerDigits = stem.length;
}
return result;
}
function parseNotationOptions(opt) {
var result = {};
var signOpts = parseSign(opt);
if (signOpts) {
return signOpts;
}
return result;
const result = {};
const signOpts = parseSign(opt);
if (signOpts) {
return signOpts;
}
return result;
}
/**
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
*/
* https://github.com/unicode-org/icu/blob/master/docs/userguide/format_parse/numbers/skeletons.md#skeleton-stems-and-options
*/
export function parseNumberSkeleton(tokens) {
var result = {};
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
var token = tokens_1[_i];
switch (token.stem) {
case 'percent':
case '%':
result.style = 'percent';
continue;
case '%x100':
result.style = 'percent';
result.scale = 100;
continue;
case 'currency':
result.style = 'currency';
result.currency = token.options[0];
continue;
case 'group-off':
case ',_':
result.useGrouping = false;
continue;
case 'precision-integer':
case '.':
result.maximumFractionDigits = 0;
continue;
case 'measure-unit':
case 'unit':
result.style = 'unit';
result.unit = icuUnitToEcma(token.options[0]);
continue;
case 'compact-short':
case 'K':
result.notation = 'compact';
result.compactDisplay = 'short';
continue;
case 'compact-long':
case 'KK':
result.notation = 'compact';
result.compactDisplay = 'long';
continue;
case 'scientific':
result = __assign(__assign(__assign({}, result), { notation: 'scientific' }), token.options.reduce(function (all, opt) { return (__assign(__assign({}, all), parseNotationOptions(opt))); }, {}));
continue;
case 'engineering':
result = __assign(__assign(__assign({}, result), { notation: 'engineering' }), token.options.reduce(function (all, opt) { return (__assign(__assign({}, all), parseNotationOptions(opt))); }, {}));
continue;
case 'notation-simple':
result.notation = 'standard';
continue;
// https://github.com/unicode-org/icu/blob/master/icu4c/source/i18n/unicode/unumberformatter.h
case 'unit-width-narrow':
result.currencyDisplay = 'narrowSymbol';
result.unitDisplay = 'narrow';
continue;
case 'unit-width-short':
result.currencyDisplay = 'code';
result.unitDisplay = 'short';
continue;
case 'unit-width-full-name':
result.currencyDisplay = 'name';
result.unitDisplay = 'long';
continue;
case 'unit-width-iso-code':
result.currencyDisplay = 'symbol';
continue;
case 'scale':
result.scale = parseFloat(token.options[0]);
continue;
case 'rounding-mode-floor':
result.roundingMode = 'floor';
continue;
case 'rounding-mode-ceiling':
result.roundingMode = 'ceil';
continue;
case 'rounding-mode-down':
result.roundingMode = 'trunc';
continue;
case 'rounding-mode-up':
result.roundingMode = 'expand';
continue;
case 'rounding-mode-half-even':
result.roundingMode = 'halfEven';
continue;
case 'rounding-mode-half-down':
result.roundingMode = 'halfTrunc';
continue;
case 'rounding-mode-half-up':
result.roundingMode = 'halfExpand';
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;
}
// 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) {
throw new RangeError('Fraction-precision stems only accept a single optional option');
}
token.stem.replace(FRACTION_PRECISION_REGEX, function (_, g1, g2, g3, g4, g5) {
// .000* case (before ICU67 it was .000+)
if (g2 === '*') {
result.minimumFractionDigits = g1.length;
}
// .### case
else if (g3 && g3[0] === '#') {
result.maximumFractionDigits = g3.length;
}
// .00## case
else if (g4 && g5) {
result.minimumFractionDigits = g4.length;
result.maximumFractionDigits = g4.length + g5.length;
}
else {
result.minimumFractionDigits = g1.length;
result.maximumFractionDigits = g1.length;
}
return '';
});
var opt = token.options[0];
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#trailing-zero-display
if (opt === 'w') {
result = __assign(__assign({}, result), { trailingZeroDisplay: 'stripIfInteger' });
}
else if (opt) {
result = __assign(__assign({}, result), parseSignificantPrecision(opt));
}
continue;
}
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#significant-digits-precision
if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) {
result = __assign(__assign({}, result), parseSignificantPrecision(token.stem));
continue;
}
var signOpts = parseSign(token.stem);
if (signOpts) {
result = __assign(__assign({}, result), signOpts);
}
var conciseScientificAndEngineeringOpts = parseConciseScientificAndEngineeringStem(token.stem);
if (conciseScientificAndEngineeringOpts) {
result = __assign(__assign({}, result), conciseScientificAndEngineeringOpts);
}
}
return result;
let result = {};
for (const token of tokens) {
switch (token.stem) {
case "percent":
case "%":
result.style = "percent";
continue;
case "%x100":
result.style = "percent";
result.scale = 100;
continue;
case "currency":
result.style = "currency";
result.currency = token.options[0];
continue;
case "group-off":
case ",_":
result.useGrouping = false;
continue;
case "precision-integer":
case ".":
result.maximumFractionDigits = 0;
continue;
case "measure-unit":
case "unit":
result.style = "unit";
result.unit = icuUnitToEcma(token.options[0]);
continue;
case "compact-short":
case "K":
result.notation = "compact";
result.compactDisplay = "short";
continue;
case "compact-long":
case "KK":
result.notation = "compact";
result.compactDisplay = "long";
continue;
case "scientific":
result = {
...result,
notation: "scientific",
...token.options.reduce((all, opt) => ({
...all,
...parseNotationOptions(opt)
}), {})
};
continue;
case "engineering":
result = {
...result,
notation: "engineering",
...token.options.reduce((all, opt) => ({
...all,
...parseNotationOptions(opt)
}), {})
};
continue;
case "notation-simple":
result.notation = "standard";
continue;
case "unit-width-narrow":
result.currencyDisplay = "narrowSymbol";
result.unitDisplay = "narrow";
continue;
case "unit-width-short":
result.currencyDisplay = "code";
result.unitDisplay = "short";
continue;
case "unit-width-full-name":
result.currencyDisplay = "name";
result.unitDisplay = "long";
continue;
case "unit-width-iso-code":
result.currencyDisplay = "symbol";
continue;
case "scale":
result.scale = parseFloat(token.options[0]);
continue;
case "rounding-mode-floor":
result.roundingMode = "floor";
continue;
case "rounding-mode-ceiling":
result.roundingMode = "ceil";
continue;
case "rounding-mode-down":
result.roundingMode = "trunc";
continue;
case "rounding-mode-up":
result.roundingMode = "expand";
continue;
case "rounding-mode-half-even":
result.roundingMode = "halfEven";
continue;
case "rounding-mode-half-down":
result.roundingMode = "halfTrunc";
continue;
case "rounding-mode-half-up":
result.roundingMode = "halfExpand";
continue;
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;
}
// 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) {
throw new RangeError("Fraction-precision stems only accept a single optional option");
}
token.stem.replace(FRACTION_PRECISION_REGEX, function(_, g1, g2, g3, g4, g5) {
// .000* case (before ICU67 it was .000+)
if (g2 === "*") {
result.minimumFractionDigits = g1.length;
} else if (g3 && g3[0] === "#") {
result.maximumFractionDigits = g3.length;
} else if (g4 && g5) {
result.minimumFractionDigits = g4.length;
result.maximumFractionDigits = g4.length + g5.length;
} else {
result.minimumFractionDigits = g1.length;
result.maximumFractionDigits = g1.length;
}
return "";
});
const opt = token.options[0];
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#trailing-zero-display
if (opt === "w") {
result = {
...result,
trailingZeroDisplay: "stripIfInteger"
};
} else if (opt) {
result = {
...result,
...parseSignificantPrecision(opt)
};
}
continue;
}
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#significant-digits-precision
if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) {
result = {
...result,
...parseSignificantPrecision(token.stem)
};
continue;
}
const signOpts = parseSign(token.stem);
if (signOpts) {
result = {
...result,
...signOpts
};
}
const conciseScientificAndEngineeringOpts = parseConciseScientificAndEngineeringStem(token.stem);
if (conciseScientificAndEngineeringOpts) {
result = {
...result,
...conciseScientificAndEngineeringOpts
};
}
}
return result;
}
{
"name": "@formatjs/icu-skeleton-parser",
"version": "2.0.7",
"version": "2.0.8",
"license": "MIT",

@@ -12,3 +12,3 @@ "type": "module",

"tslib": "^2.8.0",
"@formatjs/ecma402-abstract": "3.0.7"
"@formatjs/ecma402-abstract": "3.0.8"
},

@@ -15,0 +15,0 @@ "repository": {

@@ -0,1 +1,2 @@

// @generated from regex-gen.ts
export declare const WHITE_SPACE_REGEX: RegExp;
// @generated from regex-gen.ts
export var WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/i;
export const WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/i;