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-messageformat-parser

Package Overview
Dependencies
Maintainers
3
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version
3.0.4
to
3.1.0
+3
-3
package.json
{
"name": "@formatjs/icu-messageformat-parser",
"version": "3.0.4",
"version": "3.1.0",
"license": "MIT",

@@ -15,4 +15,4 @@ "type": "module",

"tslib": "^2.8.0",
"@formatjs/icu-skeleton-parser": "2.0.3",
"@formatjs/ecma402-abstract": "3.0.3"
"@formatjs/ecma402-abstract": "3.0.4",
"@formatjs/icu-skeleton-parser": "2.0.4"
},

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

+12
-370

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

var _a;
import { __assign } from "tslib";

@@ -15,64 +14,5 @@ import { ErrorKind } from './error.js';

// Consolidate these variables up top for easier toggling during debugging
var hasNativeStartsWith = !!String.prototype.startsWith && '_a'.startsWith('a', 1);
var hasNativeFromCodePoint = !!String.fromCodePoint;
var hasNativeFromEntries = !!Object.fromEntries;
var hasNativeCodePointAt = !!String.prototype.codePointAt;
var hasTrimStart = !!String.prototype.trimStart;
var hasTrimEnd = !!String.prototype.trimEnd;
var hasNativeIsSafeInteger = !!Number.isSafeInteger;
var isSafeInteger = hasNativeIsSafeInteger
? Number.isSafeInteger
: function (n) {
return (typeof n === 'number' &&
isFinite(n) &&
Math.floor(n) === n &&
Math.abs(n) <= 0x1fffffffffffff);
};
// IE11 does not support y and u.
var REGEX_SUPPORTS_U_AND_Y = true;
try {
var re = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu');
/**
* legacy Edge or Xbox One browser
* Unicode flag support: supported
* Pattern_Syntax support: not supported
* See https://github.com/formatjs/formatjs/issues/2822
*/
REGEX_SUPPORTS_U_AND_Y = ((_a = re.exec('a')) === null || _a === void 0 ? void 0 : _a[0]) === 'a';
}
catch (_b) {
REGEX_SUPPORTS_U_AND_Y = false;
}
var startsWith = hasNativeStartsWith
? // Native
function startsWith(s, search, position) {
return s.startsWith(search, position);
}
: // For IE11
function startsWith(s, search, position) {
return s.slice(position, position + search.length) === search;
};
var fromCodePoint = hasNativeFromCodePoint
? String.fromCodePoint
: // IE11
function fromCodePoint() {
var codePoints = [];
for (var _i = 0; _i < arguments.length; _i++) {
codePoints[_i] = arguments[_i];
}
var elements = '';
var length = codePoints.length;
var i = 0;
var code;
while (length > i) {
code = codePoints[i++];
if (code > 0x10ffff)
throw RangeError(code + ' is not a valid code point');
elements +=
code < 0x10000
? String.fromCharCode(code)
: String.fromCharCode(((code -= 0x10000) >> 10) + 0xd800, (code % 0x400) + 0xdc00);
}
return elements;
};
var fromEntries =

@@ -91,23 +31,2 @@ // native

};
var codePointAt = hasNativeCodePointAt
? // Native
function codePointAt(s, index) {
return s.codePointAt(index);
}
: // IE 11
function codePointAt(s, index) {
var size = s.length;
if (index < 0 || index >= size) {
return undefined;
}
var first = s.charCodeAt(index);
var second;
return first < 0xd800 ||
first > 0xdbff ||
index + 1 === size ||
(second = s.charCodeAt(index + 1)) < 0xdc00 ||
second > 0xdfff
? first
: ((first - 0xd800) << 10) + (second - 0xdc00) + 0x10000;
};
var trimStart = hasTrimStart

@@ -131,33 +50,10 @@ ? // Native

};
// Prevent minifier to translate new RegExp to literal form that might cause syntax error on IE11.
function RE(s, flag) {
return new RegExp(s, flag);
}
// #endregion
var matchIdentifierAtIndex;
if (REGEX_SUPPORTS_U_AND_Y) {
// Native
var IDENTIFIER_PREFIX_RE_1 = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu');
matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) {
var _a;
IDENTIFIER_PREFIX_RE_1.lastIndex = index;
var match = IDENTIFIER_PREFIX_RE_1.exec(s);
return (_a = match[1]) !== null && _a !== void 0 ? _a : '';
};
var IDENTIFIER_PREFIX_RE = new RegExp('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu');
function matchIdentifierAtIndex(s, index) {
var _a;
IDENTIFIER_PREFIX_RE.lastIndex = index;
var match = IDENTIFIER_PREFIX_RE.exec(s);
return (_a = match[1]) !== null && _a !== void 0 ? _a : '';
}
else {
// IE11
matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) {
var match = [];
while (true) {
var c = codePointAt(s, index);
if (c === undefined || _isWhiteSpace(c) || _isPatternSyntax(c)) {
break;
}
match.push(c);
index += c >= 0x10000 ? 2 : 1;
}
return fromCodePoint.apply(void 0, match);
};
}
var Parser = /** @class */ (function () {

@@ -408,3 +304,3 @@ function Parser(message, options) {

}
return fromCodePoint.apply(void 0, codePoints);
return String.fromCodePoint.apply(String, codePoints);
};

@@ -425,3 +321,3 @@ Parser.prototype.tryParseUnquoted = function (nestingLevel, parentArgType) {

this.bump();
return fromCodePoint(ch);
return String.fromCodePoint(ch);
}

@@ -530,3 +426,3 @@ };

// Extract style or skeleton
if (styleAndLocation && startsWith(styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style, '::', 0)) {
if (styleAndLocation && styleAndLocation.style.startsWith('::')) {
// Skeleton starts with `::`.

@@ -846,3 +742,3 @@ var skeleton = trimStart(styleAndLocation.style.slice(2));

decimal *= sign;
if (!isSafeInteger(decimal)) {
if (!Number.isSafeInteger(decimal)) {
return this.error(invalidNumberError, location);

@@ -875,3 +771,3 @@ }

}
var code = codePointAt(this.message, offset);
var code = this.message.codePointAt(offset);
if (code === undefined) {

@@ -916,3 +812,3 @@ throw Error("Offset ".concat(offset, " is at invalid UTF-16 code unit boundary"));

Parser.prototype.bumpIf = function (prefix) {
if (startsWith(this.message, prefix, this.offset())) {
if (this.message.startsWith(prefix, this.offset())) {
for (var i = 0; i < prefix.length; i++) {

@@ -1032,255 +928,1 @@ this.bump();

}
/**
* Code point equivalent of regex `\p{Pattern_Syntax}`.
* See https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt
*/
function _isPatternSyntax(c) {
return ((c >= 0x0021 && c <= 0x0023) ||
c === 0x0024 ||
(c >= 0x0025 && c <= 0x0027) ||
c === 0x0028 ||
c === 0x0029 ||
c === 0x002a ||
c === 0x002b ||
c === 0x002c ||
c === 0x002d ||
(c >= 0x002e && c <= 0x002f) ||
(c >= 0x003a && c <= 0x003b) ||
(c >= 0x003c && c <= 0x003e) ||
(c >= 0x003f && c <= 0x0040) ||
c === 0x005b ||
c === 0x005c ||
c === 0x005d ||
c === 0x005e ||
c === 0x0060 ||
c === 0x007b ||
c === 0x007c ||
c === 0x007d ||
c === 0x007e ||
c === 0x00a1 ||
(c >= 0x00a2 && c <= 0x00a5) ||
c === 0x00a6 ||
c === 0x00a7 ||
c === 0x00a9 ||
c === 0x00ab ||
c === 0x00ac ||
c === 0x00ae ||
c === 0x00b0 ||
c === 0x00b1 ||
c === 0x00b6 ||
c === 0x00bb ||
c === 0x00bf ||
c === 0x00d7 ||
c === 0x00f7 ||
(c >= 0x2010 && c <= 0x2015) ||
(c >= 0x2016 && c <= 0x2017) ||
c === 0x2018 ||
c === 0x2019 ||
c === 0x201a ||
(c >= 0x201b && c <= 0x201c) ||
c === 0x201d ||
c === 0x201e ||
c === 0x201f ||
(c >= 0x2020 && c <= 0x2027) ||
(c >= 0x2030 && c <= 0x2038) ||
c === 0x2039 ||
c === 0x203a ||
(c >= 0x203b && c <= 0x203e) ||
(c >= 0x2041 && c <= 0x2043) ||
c === 0x2044 ||
c === 0x2045 ||
c === 0x2046 ||
(c >= 0x2047 && c <= 0x2051) ||
c === 0x2052 ||
c === 0x2053 ||
(c >= 0x2055 && c <= 0x205e) ||
(c >= 0x2190 && c <= 0x2194) ||
(c >= 0x2195 && c <= 0x2199) ||
(c >= 0x219a && c <= 0x219b) ||
(c >= 0x219c && c <= 0x219f) ||
c === 0x21a0 ||
(c >= 0x21a1 && c <= 0x21a2) ||
c === 0x21a3 ||
(c >= 0x21a4 && c <= 0x21a5) ||
c === 0x21a6 ||
(c >= 0x21a7 && c <= 0x21ad) ||
c === 0x21ae ||
(c >= 0x21af && c <= 0x21cd) ||
(c >= 0x21ce && c <= 0x21cf) ||
(c >= 0x21d0 && c <= 0x21d1) ||
c === 0x21d2 ||
c === 0x21d3 ||
c === 0x21d4 ||
(c >= 0x21d5 && c <= 0x21f3) ||
(c >= 0x21f4 && c <= 0x22ff) ||
(c >= 0x2300 && c <= 0x2307) ||
c === 0x2308 ||
c === 0x2309 ||
c === 0x230a ||
c === 0x230b ||
(c >= 0x230c && c <= 0x231f) ||
(c >= 0x2320 && c <= 0x2321) ||
(c >= 0x2322 && c <= 0x2328) ||
c === 0x2329 ||
c === 0x232a ||
(c >= 0x232b && c <= 0x237b) ||
c === 0x237c ||
(c >= 0x237d && c <= 0x239a) ||
(c >= 0x239b && c <= 0x23b3) ||
(c >= 0x23b4 && c <= 0x23db) ||
(c >= 0x23dc && c <= 0x23e1) ||
(c >= 0x23e2 && c <= 0x2426) ||
(c >= 0x2427 && c <= 0x243f) ||
(c >= 0x2440 && c <= 0x244a) ||
(c >= 0x244b && c <= 0x245f) ||
(c >= 0x2500 && c <= 0x25b6) ||
c === 0x25b7 ||
(c >= 0x25b8 && c <= 0x25c0) ||
c === 0x25c1 ||
(c >= 0x25c2 && c <= 0x25f7) ||
(c >= 0x25f8 && c <= 0x25ff) ||
(c >= 0x2600 && c <= 0x266e) ||
c === 0x266f ||
(c >= 0x2670 && c <= 0x2767) ||
c === 0x2768 ||
c === 0x2769 ||
c === 0x276a ||
c === 0x276b ||
c === 0x276c ||
c === 0x276d ||
c === 0x276e ||
c === 0x276f ||
c === 0x2770 ||
c === 0x2771 ||
c === 0x2772 ||
c === 0x2773 ||
c === 0x2774 ||
c === 0x2775 ||
(c >= 0x2794 && c <= 0x27bf) ||
(c >= 0x27c0 && c <= 0x27c4) ||
c === 0x27c5 ||
c === 0x27c6 ||
(c >= 0x27c7 && c <= 0x27e5) ||
c === 0x27e6 ||
c === 0x27e7 ||
c === 0x27e8 ||
c === 0x27e9 ||
c === 0x27ea ||
c === 0x27eb ||
c === 0x27ec ||
c === 0x27ed ||
c === 0x27ee ||
c === 0x27ef ||
(c >= 0x27f0 && c <= 0x27ff) ||
(c >= 0x2800 && c <= 0x28ff) ||
(c >= 0x2900 && c <= 0x2982) ||
c === 0x2983 ||
c === 0x2984 ||
c === 0x2985 ||
c === 0x2986 ||
c === 0x2987 ||
c === 0x2988 ||
c === 0x2989 ||
c === 0x298a ||
c === 0x298b ||
c === 0x298c ||
c === 0x298d ||
c === 0x298e ||
c === 0x298f ||
c === 0x2990 ||
c === 0x2991 ||
c === 0x2992 ||
c === 0x2993 ||
c === 0x2994 ||
c === 0x2995 ||
c === 0x2996 ||
c === 0x2997 ||
c === 0x2998 ||
(c >= 0x2999 && c <= 0x29d7) ||
c === 0x29d8 ||
c === 0x29d9 ||
c === 0x29da ||
c === 0x29db ||
(c >= 0x29dc && c <= 0x29fb) ||
c === 0x29fc ||
c === 0x29fd ||
(c >= 0x29fe && c <= 0x2aff) ||
(c >= 0x2b00 && c <= 0x2b2f) ||
(c >= 0x2b30 && c <= 0x2b44) ||
(c >= 0x2b45 && c <= 0x2b46) ||
(c >= 0x2b47 && c <= 0x2b4c) ||
(c >= 0x2b4d && c <= 0x2b73) ||
(c >= 0x2b74 && c <= 0x2b75) ||
(c >= 0x2b76 && c <= 0x2b95) ||
c === 0x2b96 ||
(c >= 0x2b97 && c <= 0x2bff) ||
(c >= 0x2e00 && c <= 0x2e01) ||
c === 0x2e02 ||
c === 0x2e03 ||
c === 0x2e04 ||
c === 0x2e05 ||
(c >= 0x2e06 && c <= 0x2e08) ||
c === 0x2e09 ||
c === 0x2e0a ||
c === 0x2e0b ||
c === 0x2e0c ||
c === 0x2e0d ||
(c >= 0x2e0e && c <= 0x2e16) ||
c === 0x2e17 ||
(c >= 0x2e18 && c <= 0x2e19) ||
c === 0x2e1a ||
c === 0x2e1b ||
c === 0x2e1c ||
c === 0x2e1d ||
(c >= 0x2e1e && c <= 0x2e1f) ||
c === 0x2e20 ||
c === 0x2e21 ||
c === 0x2e22 ||
c === 0x2e23 ||
c === 0x2e24 ||
c === 0x2e25 ||
c === 0x2e26 ||
c === 0x2e27 ||
c === 0x2e28 ||
c === 0x2e29 ||
(c >= 0x2e2a && c <= 0x2e2e) ||
c === 0x2e2f ||
(c >= 0x2e30 && c <= 0x2e39) ||
(c >= 0x2e3a && c <= 0x2e3b) ||
(c >= 0x2e3c && c <= 0x2e3f) ||
c === 0x2e40 ||
c === 0x2e41 ||
c === 0x2e42 ||
(c >= 0x2e43 && c <= 0x2e4f) ||
(c >= 0x2e50 && c <= 0x2e51) ||
c === 0x2e52 ||
(c >= 0x2e53 && c <= 0x2e7f) ||
(c >= 0x3001 && c <= 0x3003) ||
c === 0x3008 ||
c === 0x3009 ||
c === 0x300a ||
c === 0x300b ||
c === 0x300c ||
c === 0x300d ||
c === 0x300e ||
c === 0x300f ||
c === 0x3010 ||
c === 0x3011 ||
(c >= 0x3012 && c <= 0x3013) ||
c === 0x3014 ||
c === 0x3015 ||
c === 0x3016 ||
c === 0x3017 ||
c === 0x3018 ||
c === 0x3019 ||
c === 0x301a ||
c === 0x301b ||
c === 0x301c ||
c === 0x301d ||
(c >= 0x301e && c <= 0x301f) ||
c === 0x3020 ||
c === 0x3030 ||
c === 0xfd3e ||
c === 0xfd3f ||
(c >= 0xfe45 && c <= 0xfe46));
}

@@ -8,19 +8,12 @@ # MessageFormat Parser

```
$ node benchmark
complex_msg AST length 10861
normal_msg AST length 1665
simple_msg AST length 364
string_msg AST length 131
$ bazel run //packages/icu-messageformat-parser/benchmark:benchmark
complex_msg AST length 2599
normal_msg AST length 400
simple_msg AST length 79
string_msg AST length 36
== Baseline ==
complex_msg x 4,884 ops/sec ±0.97% (91 runs sampled)
normal_msg x 40,113 ops/sec ±1.08% (92 runs sampled)
simple_msg x 200,401 ops/sec ±1.12% (91 runs sampled)
string_msg x 241,103 ops/sec ±0.84% (92 runs sampled)
== This package ==
complex_msg x 31,590 ops/sec ±0.80% (88 runs sampled)
normal_msg x 278,703 ops/sec ±0.83% (95 runs sampled)
simple_msg x 2,038,061 ops/sec ±0.90% (96 runs sampled)
string_msg x 2,392,794 ops/sec ±0.67% (96 runs sampled)
complex_msg x 58,910 ops/sec ±0.33%
normal_msg x 405,440 ops/sec ±0.53%
simple_msg x 2,592,098 ops/sec ±0.44%
string_msg x 4,511,129 ops/sec ±2.22%
```
// @generated from time-data-gen.ts
// prettier-ignore
// prettier-ignore
export var timeData = {

@@ -4,0 +4,0 @@ "001": [