fix: prevent asset conflicts between React and Grid.js versions

Add coexistence checks to all enqueue methods to prevent loading
both React and Grid.js assets simultaneously.

Changes:
- ReactAdmin.php: Only enqueue React assets when ?react=1
- Init.php: Skip Grid.js when React active on admin pages
- Form.php, Coupon.php, Access.php: Restore classic assets when ?react=0
- Customer.php, Product.php, License.php: Add coexistence checks

Now the toggle between Classic and React versions works correctly.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-04-18 17:02:14 +07:00
parent bd9cdac02e
commit e8fbfb14c1
74973 changed files with 6658406 additions and 71 deletions

88
node_modules/intl-messageformat/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,88 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [4.4.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.3.0...intl-messageformat@4.4.0) (2019-06-28)
### Features
- **intl-messageformat:** export core entry point ([ca7eeae](https://github.com/formatjs/formatjs/commit/ca7eeae))
# [4.3.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.2.1...intl-messageformat@4.3.0) (2019-06-27)
### Features
- **intl-messageformat:** allow passing in formatters ([#107](https://github.com/formatjs/formatjs/issues/107)) ([3605693](https://github.com/formatjs/formatjs/commit/3605693))
## [4.2.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.2.0...intl-messageformat@4.2.1) (2019-06-26)
**Note:** Version bump only for package intl-messageformat
# [4.2.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.1.2...intl-messageformat@4.2.0) (2019-06-27)
### Features
- **intl-relativetimeformat:** make intl-relativetimeformat test262-compliant ([#95](https://github.com/formatjs/formatjs/issues/95)) ([91669a3](https://github.com/formatjs/formatjs/commit/91669a3))
- **intl-utils:** Add intl-utils ([#98](https://github.com/formatjs/formatjs/issues/98)) ([2329c57](https://github.com/formatjs/formatjs/commit/2329c57))
## [4.1.2](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.1.1...intl-messageformat@4.1.2) (2019-06-18)
**Note:** Version bump only for package intl-messageformat
## [4.1.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.1.0...intl-messageformat@4.1.1) (2019-06-18)
**Note:** Version bump only for package intl-messageformat
# [4.1.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.0.1...intl-messageformat@4.1.0) (2019-06-18)
### Features
- **intl-format-cache:** fix TS definition ([71ae9eb](https://github.com/formatjs/formatjs/commit/71ae9eb))
## [4.0.1](https://github.com/formatjs/formatjs/compare/intl-messageformat@4.0.0...intl-messageformat@4.0.1) (2019-06-12)
**Note:** Version bump only for package intl-messageformat
# [4.0.0](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.3.0...intl-messageformat@4.0.0) (2019-06-05)
### Features
- add package intl-relativetimeformat ([#51](https://github.com/formatjs/intl-messageformat/issues/51)) ([48c0f43](https://github.com/formatjs/intl-messageformat/commit/48c0f43))
- **intl-messageformat:** rm bundled intl-pluralrules ([a8526c3](https://github.com/formatjs/intl-messageformat/commit/a8526c3))
- **intl-messageformat:** rm rolluped dist ([a126939](https://github.com/formatjs/intl-messageformat/commit/a126939))
### BREAKING CHANGES
- **intl-messageformat:** Change dist files packaged. Entry point should stay the
same though.
- **intl-messageformat:** We no longer include intl-pluralrules in our main index
file. Consumer should polyfill accordingly.
# [3.3.0](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.4...intl-messageformat@3.3.0) (2019-06-03)
### Features
- **intl-messageformat:** Add `getAst` method ([3d6c289](https://github.com/formatjs/intl-messageformat/commit/3d6c289))
# [3.2.0](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.4...intl-messageformat@3.2.0) (2019-06-03)
### Features
- **intl-messageformat:** Add `getAst` method ([3d6c289](https://github.com/formatjs/intl-messageformat/commit/3d6c289))
## [3.1.4](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.3...intl-messageformat@3.1.4) (2019-05-31)
**Note:** Version bump only for package intl-messageformat
## [3.1.3](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.2...intl-messageformat@3.1.3) (2019-05-28)
### Bug Fixes
- **intl-messageformat:** fix [#36](https://github.com/formatjs/intl-messageformat/issues/36) and config merging ([#40](https://github.com/formatjs/intl-messageformat/issues/40)) ([4a9969f](https://github.com/formatjs/intl-messageformat/commit/4a9969f))
## [3.1.2](https://github.com/formatjs/intl-messageformat/compare/intl-messageformat@3.1.2...intl-messageformat@3.1.2) (2019-05-28)
### Bug Fixes
- **intl-messageformat:** fix [#36](https://github.com/formatjs/intl-messageformat/issues/36) and config merging ([#40](https://github.com/formatjs/intl-messageformat/issues/40)) ([4a9969f](https://github.com/formatjs/intl-messageformat/commit/4a9969f))

39
node_modules/intl-messageformat/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,39 @@
Copyright 2013 Yahoo! Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Yahoo! Inc. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL YAHOO! INC. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------
Pluralization rules built from
https://github.com/papandreou/node-cldr
which is licensed under the BSD license and has the following license:
Copyright (c) 2012, Andreas Lind Petersen
All rights reserved.
See the following for more details:
https://github.com/papandreou/node-cldr/blob/master/LICENSE

282
node_modules/intl-messageformat/README.md generated vendored Normal file
View File

@@ -0,0 +1,282 @@
# Intl MessageFormat
Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.
[![npm Version][npm-badge]][npm]
| Package | Minzipped Size |
| ------------------------- | -------------- |
| `intl-messageformat` | `5.14kB` |
| `intl-messageformat/core` | `2.19kB` |
## Overview
### Goals
This package aims to provide a way for you to manage and format your JavaScript app's string messages into localized strings for people using your app. You can use this package in the browser and on the server via Node.js.
This implementation is based on the [Strawman proposal][strawman], but there are a few places this implementation diverges.
_Note: This `IntlMessageFormat` API may change to stay in sync with ECMA-402, but this package will follow [semver][]._
### How It Works
Messages are provided into the constructor as a `String` message, or a [pre-parsed AST][parser] object.
```js
var msg = new IntlMessageFormat(message, locales, [formats], [opts]);
```
The string `message` is parsed, then stored internally in a compiled form that is optimized for the `format()` method to produce the formatted string for displaying to the user.
```js
var output = msg.format(values);
```
### Common Usage Example
A very common example is formatting messages that have numbers with plural labels. With this package you can make sure that the string is properly formatted for a person's locale, e.g.:
```js
var MESSAGES = {
'en-US': {
NUM_PHOTOS:
'You have {numPhotos, plural, ' +
'=0 {no photos.}' +
'=1 {one photo.}' +
'other {# photos.}}'
},
'es-MX': {
NUM_PHOTOS:
'Usted {numPhotos, plural, ' +
'=0 {no tiene fotos.}' +
'=1 {tiene una foto.}' +
'other {tiene # fotos.}}'
}
};
var output;
var enNumPhotos = new IntlMessageFormat(MESSAGES['en-US'].NUM_PHOTOS, 'en-US');
output = enNumPhotos.format({ numPhotos: 1000 });
console.log(output); // => "You have 1,000 photos."
var esNumPhotos = new IntlMessageFormat(MESSAGES['es-MX'].NUM_PHOTOS, 'es-MX');
output = esNumPhotos.format({ numPhotos: 1000 });
console.log(output); // => "Usted tiene 1,000 fotos."
```
### Message Syntax
The message syntax that this package uses is not proprietary, in fact it's a common standard message syntax that works across programming languages and one that professional translators are familiar with. This package uses the **[ICU Message syntax][icu]** and works for all [CLDR languages][cldr] which have pluralization rules defined.
### Features
- Uses industry standards: [ICU Message syntax][icu] and [CLDR locale data][cldr].
- Supports **plural**, **select**, and **selectordinal** message arguments.
- Formats numbers and dates/times in messages using [`Intl.NumberFormat`][intl-nf] and [`Intl.DateTimeFormat`][intl-dtf], respectively.
- Optimized for repeated calls to an `IntlMessageFormat` instance's `format()` method.
- Supports defining custom format styles/options.
- Supports escape sequences for message syntax chars, e.g.: `"\\{foo\\}"` will output: `"{foo}"` in the formatted output instead of interpreting it as a `foo` argument.
## Usage
### Modern `Intl` Dependency
This package assumes that the [`Intl`][intl] global object exists in the runtime. `Intl` is present in all modern browsers (IE11+) and Node (with full ICU). The `Intl` methods we rely on are:
1. `Intl.NumberFormat` for number formatting (can be polyfilled using [Intl.js][])
2. `Intl.DateTimeFormat` for date time formatting (can be polyfilled using [Intl.js][])
3. `Intl.PluralRules` for plural/ordinal formatting (can be polyfilled using [intl-pluralrules][])
### Loading Intl MessageFormat in a browser
```html
<script src="intl-messageformat/intl-messageformat.min.js"></script>
```
### Loading Intl MessageFormat in Node.js
Simply `require()` this package:
```js
var IntlMessageFormat = require('intl-messageformat');
```
**NOTE: Your Node has to include [full ICU](https://nodejs.org/api/intl.html)**
### Public API
#### `IntlMessageFormat` Constructor
To create a message to format, use the `IntlMessageFormat` constructor. The constructor takes three parameters:
- **message** - _{String | AST}_ - String message (or pre-parsed AST) that serves as formatting pattern.
- **locales** - _{String | String[]}_ - A string with a BCP 47 language tag, or an array of such strings. If you do not provide a locale, the default locale will be used. When an array of locales is provided, each item and its ancestor locales are checked and the first one with registered locale data is returned. **See: [Locale Resolution](#locale-resolution) for more details.**
- **[formats]** - _{Object}_ - Optional object with user defined options for format styles.
- **[opts]** - `{ formatters?: Formatters }`: Optional options.
- `formatters`: Map containing memoized formatters for performance.
```js
var msg = new IntlMessageFormat('My name is {name}.', 'en-US');
```
#### Locale Resolution
`IntlMessageFormat` uses `Intl.NumberFormat.supportedLocalesOf()` to determine which locale data to use based on the `locales` value passed to the constructor. The result of this resolution process can be determined by call the `resolvedOptions()` prototype method.
#### `resolvedOptions()` Method
This method returns an object with the options values that were resolved during instance creation. It currently only contains a `locale` property; here's an example:
```js
var msg = new IntlMessageFormat('', 'en-us');
console.log(msg.resolvedOptions().locale); // => "en-US"
```
Notice how the specified locale was the all lower-case value: `"en-us"`, but it was resolved and normalized to: `"en-US"`.
#### `format(values)` Method
Once the message is created, formatting the message is done by calling the `format()` method on the instance and passing a collection of `values`:
```js
var output = msg.format({ name: 'Eric' });
console.log(output); // => "My name is Eric."
```
_Note: A value **must** be supplied for every argument in the message pattern the instance was constructed with._
#### `getAst` Method
Return the underlying AST for the compiled message
#### User Defined Formats
Define custom format styles is useful you need supply a set of options to the underlying formatter; e.g., outputting a number in USD:
```js
var msg = new IntlMessageFormat('The price is: {price, number, USD}', 'en-US', {
number: {
USD: {
style: 'currency',
currency: 'USD'
}
}
});
var output = msg.format({ price: 100 });
console.log(output); // => "The price is: $100.00"
```
In this example, we're defining a `USD` number format style which is passed to the underlying `Intl.NumberFormat` instance as its options.
## Advanced Usage
### Core entry point
We also expose another entry point via `intl-messageformat/core` that does not contain the parser from `intl-messageformat-parser`. This is significantly smaller than the regular package but expects the message passed in to be in `AST` form instead of string. E.g:
```ts
import IntlMessageFormat from 'intl-messageformat';
new IntlMessageFormat('hello').format(); // prints out hello
// is equivalent to
import IntlMessageFormat from 'intl-messageformat/core';
import parser from 'intl-messageformat-parser';
new IntlMessageFormat(parser.parse('hello')).format(); // prints out hello
```
This helps performance for cases like SSR or preload/precompilation-supported platforms since `AST` can be cached.
### Formatters
For complex messages, initializing `Intl.*` constructors can be expensive. Therefore, we allow user to pass in `formatters` to provide memoized instances of these `Intl` objects. This opts combines with passing in AST + using [core entry point](#core-entry-point) and `intl-format-cache` can speed things up by 30x per the benchmark down below.
For example:
```ts
import IntlMessageFormat from 'intl-messageformat';
import memoizeIntlConstructor from 'intl-format-cache';
const formatters = {
getNumberFormat: memoizeIntlConstructor(Intl.NumberFormat),
getDateTimeFormat: memoizeIntlConstructor(Intl.DateTimeFormat),
getPluralRules: memoizeIntlConstructor(Intl.PluralRules)
};
new IntlMessageFormat('hello {number, number}', 'en', undefined, {
formatters
}).format({ number: 3 }); // prints out `hello, 3`
```
## Examples
### Plural Label
This example shows how to use the [ICU Message syntax][icu] to define a message that has a plural label; e.g., `"You have 10 photos"`:
```
You have {numPhotos, plural,
=0 {no photos.}
=1 {one photo.}
other {# photos.}
}
```
```js
var MESSAGES = {
photos: '...', // String from code block above.
...
};
var msg = new IntlMessageFormat(MESSAGES.photos, 'en-US');
console.log(msg.format({numPhotos: 0})); // => "You have no photos."
console.log(msg.format({numPhotos: 1})); // => "You have one photo."
console.log(msg.format({numPhotos: 1000})); // => "You have 1,000 photos."
```
_Note: how when `numPhotos` was `1000`, the number is formatted with the correct thousands separator._
## Benchmark
```
format_cached_complex_msg x 539,674 ops/sec ±1.87% (87 runs sampled)
format_cached_string_msg x 99,311,640 ops/sec ±2.15% (87 runs sampled)
new_complex_msg_preparsed x 1,490 ops/sec ±8.37% (54 runs sampled)
new_complex_msg x 836 ops/sec ±31.96% (67 runs sampled)
new_string_msg x 27,752 ops/sec ±8.25% (65 runs sampled)
complex msg format x 799 ops/sec ±9.38% (55 runs sampled)
complex msg w/ formatters format x 1,878 ops/sec ±16.63% (64 runs sampled)
complex preparsed msg w/ formatters format x 26,482 ops/sec ±2.55% (84 runs sampled)
```
## License
This software is free to use under the Yahoo! Inc. BSD license.
See the [LICENSE file][license] for license text and copyright information.
[npm]: https://www.npmjs.org/package/intl-messageformat
[npm-badge]: https://img.shields.io/npm/v/intl-messageformat.svg?style=flat-square
[strawman]: http://wiki.ecmascript.org/doku.php?id=globalization:messageformatting
[parser]: https://github.com/formatjs/formatjs/blob/master/packages/intl-messageformat-parser
[icu]: http://userguide.icu-project.org/formatparse/messages
[cldr]: http://cldr.unicode.org/
[intl]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl
[intl-nf]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
[intl-dtf]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
[intl-node]: https://github.com/joyent/node/issues/6371
[intl.js]: https://github.com/andyearnshaw/Intl.js
[rawgit]: https://rawgit.com/
[semver]: http://semver.org/
[license]: https://github.com/formatjs/formatjs/blob/master/LICENSE
[intl-pluralrules]: https://github.com/eemeli/intl-pluralrules

1
node_modules/intl-messageformat/core.js generated vendored Normal file

File diff suppressed because one or more lines are too long

57
node_modules/intl-messageformat/dist/compiler.d.ts generated vendored Normal file
View File

@@ -0,0 +1,57 @@
import { MessageFormatPattern, MessageTextElement, ArgumentElement } from 'intl-messageformat-parser';
export interface Formats {
number: Record<string, Intl.NumberFormatOptions>;
date: Record<string, Intl.DateTimeFormatOptions>;
time: Record<string, Intl.DateTimeFormatOptions>;
}
export interface Formatters {
getNumberFormat(...args: ConstructorParameters<typeof Intl.NumberFormat>): Intl.NumberFormat;
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
}
export declare type Pattern = string | PluralOffsetString | PluralFormat | SelectFormat | StringFormat;
export default class Compiler {
private locales;
private formats;
private pluralNumberFormat;
private currentPlural;
private pluralStack;
private formatters;
constructor(locales: string | string[], formats: Formats, formatters: Formatters);
compile(ast: MessageFormatPattern): Pattern[];
compileMessage(ast: MessageFormatPattern): Pattern[];
compileMessageText(element: MessageTextElement): string | PluralOffsetString;
compileArgument(element: ArgumentElement): PluralFormat | SelectFormat | StringFormat;
compileOptions(element: ArgumentElement): {};
}
declare abstract class Formatter {
id: string;
constructor(id: string);
abstract format(value: string | number): string;
}
declare class StringFormat extends Formatter {
format(value: number | string): string;
}
declare class PluralFormat {
id: string;
private offset;
private options;
private pluralRules;
constructor(id: string, offset: number, options: Record<string, Pattern[]>, pluralRules: Intl.PluralRules);
getOption(value: number): Pattern[];
}
export declare class PluralOffsetString extends Formatter {
private offset;
private numberFormat;
private string;
constructor(id: string, offset: number, numberFormat: Intl.NumberFormat, string: string);
format(value: number): string;
}
export declare class SelectFormat {
id: string;
private options;
constructor(id: string, options: Record<string, Pattern[]>);
getOption(value: string): Pattern[];
}
export declare function isSelectOrPluralFormat(f: any): f is SelectFormat | PluralFormat;
export {};

200
node_modules/intl-messageformat/dist/compiler.js generated vendored Normal file
View File

@@ -0,0 +1,200 @@
"use strict";
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Compiler = /** @class */ (function () {
function Compiler(locales, formats, formatters) {
this.locales = [];
this.formats = {
number: {},
date: {},
time: {}
};
this.pluralNumberFormat = null;
this.currentPlural = null;
this.pluralStack = [];
this.locales = locales;
this.formats = formats;
this.formatters = formatters;
}
Compiler.prototype.compile = function (ast) {
this.pluralStack = [];
this.currentPlural = null;
this.pluralNumberFormat = null;
return this.compileMessage(ast);
};
Compiler.prototype.compileMessage = function (ast) {
var _this = this;
if (!(ast && ast.type === 'messageFormatPattern')) {
throw new Error('Message AST is not of type: "messageFormatPattern"');
}
var elements = ast.elements;
var pattern = elements
.filter(function (el) {
return el.type === 'messageTextElement' || el.type === 'argumentElement';
})
.map(function (el) {
return el.type === 'messageTextElement'
? _this.compileMessageText(el)
: _this.compileArgument(el);
});
if (pattern.length !== elements.length) {
throw new Error('Message element does not have a valid type');
}
return pattern;
};
Compiler.prototype.compileMessageText = function (element) {
// When this `element` is part of plural sub-pattern and its value contains
// an unescaped '#', use a `PluralOffsetString` helper to properly output
// the number with the correct offset in the string.
if (this.currentPlural && /(^|[^\\])#/g.test(element.value)) {
// Create a cache a NumberFormat instance that can be reused for any
// PluralOffsetString instance in this message.
if (!this.pluralNumberFormat) {
this.pluralNumberFormat = new Intl.NumberFormat(this.locales);
}
return new PluralOffsetString(this.currentPlural.id, this.currentPlural.format.offset, this.pluralNumberFormat, element.value);
}
// Unescape the escaped '#'s in the message text.
return element.value.replace(/\\#/g, '#');
};
Compiler.prototype.compileArgument = function (element) {
var format = element.format, id = element.id;
var formatters = this.formatters;
if (!format) {
return new StringFormat(id);
}
var _a = this, formats = _a.formats, locales = _a.locales;
switch (format.type) {
case 'numberFormat':
return {
id: id,
format: formatters.getNumberFormat(locales, formats.number[format.style]).format
};
case 'dateFormat':
return {
id: id,
format: formatters.getDateTimeFormat(locales, formats.date[format.style]).format
};
case 'timeFormat':
return {
id: id,
format: formatters.getDateTimeFormat(locales, formats.time[format.style]).format
};
case 'pluralFormat':
return new PluralFormat(id, format.offset, this.compileOptions(element), formatters.getPluralRules(locales, {
type: format.ordinal ? 'ordinal' : 'cardinal'
}));
case 'selectFormat':
return new SelectFormat(id, this.compileOptions(element));
default:
throw new Error('Message element does not have a valid format type');
}
};
Compiler.prototype.compileOptions = function (element) {
var _this = this;
var format = element.format;
var options = format.options;
// Save the current plural element, if any, then set it to a new value when
// compiling the options sub-patterns. This conforms the spec's algorithm
// for handling `"#"` syntax in message text.
this.pluralStack.push(this.currentPlural);
this.currentPlural = format.type === 'pluralFormat' ? element : null;
var optionsHash = options.reduce(function (all, option) {
// Compile the sub-pattern and save it under the options's selector.
all[option.selector] = _this.compileMessage(option.value);
return all;
}, {});
// Pop the plural stack to put back the original current plural value.
this.currentPlural = this.pluralStack.pop();
return optionsHash;
};
return Compiler;
}());
exports.default = Compiler;
// -- Compiler Helper Classes --------------------------------------------------
var Formatter = /** @class */ (function () {
function Formatter(id) {
this.id = id;
}
return Formatter;
}());
var StringFormat = /** @class */ (function (_super) {
__extends(StringFormat, _super);
function StringFormat() {
return _super !== null && _super.apply(this, arguments) || this;
}
StringFormat.prototype.format = function (value) {
if (!value && typeof value !== 'number') {
return '';
}
return typeof value === 'string' ? value : String(value);
};
return StringFormat;
}(Formatter));
var PluralFormat = /** @class */ (function () {
function PluralFormat(id, offset, options, pluralRules) {
this.id = id;
this.offset = offset;
this.options = options;
this.pluralRules = pluralRules;
}
PluralFormat.prototype.getOption = function (value) {
var options = this.options;
var option = options['=' + value] ||
options[this.pluralRules.select(value - this.offset)];
return option || options.other;
};
return PluralFormat;
}());
var PluralOffsetString = /** @class */ (function (_super) {
__extends(PluralOffsetString, _super);
function PluralOffsetString(id, offset, numberFormat, string) {
var _this = _super.call(this, id) || this;
_this.offset = offset;
_this.numberFormat = numberFormat;
_this.string = string;
return _this;
}
PluralOffsetString.prototype.format = function (value) {
var number = this.numberFormat.format(value - this.offset);
return this.string
.replace(/(^|[^\\])#/g, '$1' + number)
.replace(/\\#/g, '#');
};
return PluralOffsetString;
}(Formatter));
exports.PluralOffsetString = PluralOffsetString;
var SelectFormat = /** @class */ (function () {
function SelectFormat(id, options) {
this.id = id;
this.options = options;
}
SelectFormat.prototype.getOption = function (value) {
var options = this.options;
return options[value] || options.other;
};
return SelectFormat;
}());
exports.SelectFormat = SelectFormat;
function isSelectOrPluralFormat(f) {
return !!f.options;
}
exports.isSelectOrPluralFormat = isSelectOrPluralFormat;
//# sourceMappingURL=compiler.js.map

1
node_modules/intl-messageformat/dist/compiler.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

78
node_modules/intl-messageformat/dist/core.d.ts generated vendored Normal file
View File

@@ -0,0 +1,78 @@
import { Formats, Formatters } from './compiler';
import parser, { MessageFormatPattern } from 'intl-messageformat-parser';
export interface Options {
formatters?: Formatters;
}
export declare function createDefaultFormatters(): Formatters;
export declare class IntlMessageFormat {
private ast;
private locale;
private pattern;
private message;
constructor(message: string | MessageFormatPattern, locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
format: (values?: Record<string, string | number | boolean | null | undefined> | undefined) => string;
resolvedOptions(): {
locale: string;
};
getAst(): MessageFormatPattern;
static defaultLocale: string;
static __parse: typeof parser['parse'] | undefined;
static formats: {
number: {
currency: {
style: string;
};
percent: {
style: string;
};
};
date: {
short: {
month: string;
day: string;
year: string;
};
medium: {
month: string;
day: string;
year: string;
};
long: {
month: string;
day: string;
year: string;
};
full: {
weekday: string;
month: string;
day: string;
year: string;
};
};
time: {
short: {
hour: string;
minute: string;
};
medium: {
hour: string;
minute: string;
second: string;
};
long: {
hour: string;
minute: string;
second: string;
timeZoneName: string;
};
full: {
hour: string;
minute: string;
second: string;
timeZoneName: string;
};
};
};
}
export { Formats, Pattern } from './compiler';
export default IntlMessageFormat;

248
node_modules/intl-messageformat/dist/core.js generated vendored Normal file
View File

@@ -0,0 +1,248 @@
"use strict";
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
/* jslint esnext: true */
var compiler_1 = require("./compiler");
// -- MessageFormat --------------------------------------------------------
function resolveLocale(locales) {
if (typeof locales === 'string') {
locales = [locales];
}
try {
return Intl.NumberFormat.supportedLocalesOf(locales, {
// IE11 localeMatcher `lookup` seems to convert `en` -> `en-US`
// but not other browsers,
localeMatcher: 'best fit'
})[0];
}
catch (e) {
return IntlMessageFormat.defaultLocale;
}
}
function formatPatterns(pattern, values) {
var result = '';
for (var _i = 0, pattern_1 = pattern; _i < pattern_1.length; _i++) {
var part = pattern_1[_i];
// Exist early for string parts.
if (typeof part === 'string') {
result += part;
continue;
}
var id = part.id;
// Enforce that all required values are provided by the caller.
if (!(values && id in values)) {
throw new FormatError("A value must be provided for: " + id, id);
}
var value = values[id];
// Recursively format plural and select parts' option — which can be a
// nested pattern structure. The choosing of the option to use is
// abstracted-by and delegated-to the part helper object.
if (compiler_1.isSelectOrPluralFormat(part)) {
result += formatPatterns(part.getOption(value), values);
}
else {
result += part.format(value);
}
}
return result;
}
function mergeConfig(c1, c2) {
if (!c2) {
return c1;
}
return __assign({}, (c1 || {}), (c2 || {}), Object.keys(c1).reduce(function (all, k) {
all[k] = __assign({}, c1[k], (c2[k] || {}));
return all;
}, {}));
}
function mergeConfigs(defaultConfig, configs) {
if (!configs) {
return defaultConfig;
}
return Object.keys(defaultConfig).reduce(function (all, k) {
all[k] = mergeConfig(defaultConfig[k], configs[k]);
return all;
}, __assign({}, defaultConfig));
}
var FormatError = /** @class */ (function (_super) {
__extends(FormatError, _super);
function FormatError(msg, variableId) {
var _this = _super.call(this, msg) || this;
_this.variableId = variableId;
return _this;
}
return FormatError;
}(Error));
function createDefaultFormatters() {
return {
getNumberFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.NumberFormat).bind.apply(_a, [void 0].concat(args)))();
},
getDateTimeFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, [void 0].concat(args)))();
},
getPluralRules: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.PluralRules).bind.apply(_a, [void 0].concat(args)))();
}
};
}
exports.createDefaultFormatters = createDefaultFormatters;
var IntlMessageFormat = /** @class */ (function () {
function IntlMessageFormat(message, locales, overrideFormats, opts) {
var _this = this;
if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; }
this.format = function (values) {
try {
return formatPatterns(_this.pattern, values);
}
catch (e) {
if (e.variableId) {
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + _this.message + "'");
}
else {
throw e;
}
}
};
if (typeof message === 'string') {
if (!IntlMessageFormat.__parse) {
throw new TypeError('IntlMessageFormat.__parse must be set to process `message` of type `string`');
}
// Parse string messages into an AST.
this.ast = IntlMessageFormat.__parse(message);
}
else {
this.ast = message;
}
this.message = message;
if (!(this.ast && this.ast.type === 'messageFormatPattern')) {
throw new TypeError('A message must be provided as a String or AST.');
}
// Creates a new object with the specified `formats` merged with the default
// formats.
var formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
this.locale = resolveLocale(locales || []);
var formatters = (opts && opts.formatters) || createDefaultFormatters();
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
this.pattern = new compiler_1.default(locales, formats, formatters).compile(this.ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
}
IntlMessageFormat.prototype.resolvedOptions = function () {
return { locale: this.locale };
};
IntlMessageFormat.prototype.getAst = function () {
return this.ast;
};
IntlMessageFormat.defaultLocale = 'en';
IntlMessageFormat.__parse = undefined;
// Default format options used as the prototype of the `formats` provided to the
// constructor. These are used when constructing the internal Intl.NumberFormat
// and Intl.DateTimeFormat instances.
IntlMessageFormat.formats = {
number: {
currency: {
style: 'currency'
},
percent: {
style: 'percent'
}
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
},
medium: {
month: 'short',
day: 'numeric',
year: 'numeric'
},
long: {
month: 'long',
day: 'numeric',
year: 'numeric'
},
full: {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric'
}
},
time: {
short: {
hour: 'numeric',
minute: 'numeric'
},
medium: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
},
long: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
},
full: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
}
}
};
return IntlMessageFormat;
}());
exports.IntlMessageFormat = IntlMessageFormat;
exports.default = IntlMessageFormat;
//# sourceMappingURL=core.js.map

1
node_modules/intl-messageformat/dist/core.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";AAAA;;;;EAIE;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,yBAAyB;AAEzB,uCAKoB;AAGpB,4EAA4E;AAE5E,SAAS,aAAa,CAAC,OAA0B;IAC/C,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC;KACrB;IACD,IAAI;QACF,OAAO,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,OAAO,EAAE;YACnD,+DAA+D;YAC/D,0BAA0B;YAC1B,aAAa,EAAE,UAAU;SAC1B,CAAC,CAAC,CAAC,CAAC,CAAC;KAC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AAE,SAAS;gBACjB,MAAM,EAAE,SAAS;aAClB;YAED,IAAI,EAAE;gBACJ,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,SAAS;gBACjB,YAAY,EAAE,OAAO;aACtB;YAED,IAAI,EAAE;gBACJ,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE,SAAS;gBACjB,YAAY,EAAE,OAAO;aACtB;SACF;KACF,CAAC;IACJ,wBAAC;CAAA,AA1ID,IA0IC;AA1IY,8CAAiB;AA6I9B,kBAAe,iBAAiB,CAAC"}

5
node_modules/intl-messageformat/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,5 @@
import IntlMessageFormat from './core';
export { Formats, Pattern } from './compiler';
export * from './core';
export { Formatters } from './compiler';
export default IntlMessageFormat;

16
node_modules/intl-messageformat/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
"use strict";
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var intl_messageformat_parser_1 = require("intl-messageformat-parser");
var core_1 = require("./core");
core_1.default.__parse = intl_messageformat_parser_1.default.parse;
__export(require("./core"));
exports.default = core_1.default;
//# sourceMappingURL=index.js.map

1
node_modules/intl-messageformat/dist/index.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;EAIE;;;;;AAEF,uEAA+C;AAC/C,+BAAuC;AAEvC,cAAiB,CAAC,OAAO,GAAG,mCAAM,CAAC,KAAK,CAAC;AAGzC,4BAAuB;AAEvB,kBAAe,cAAiB,CAAC"}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

8
node_modules/intl-messageformat/index.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
'use strict';
var IntlMessageFormat = require('./dist').default;
// Re-export `IntlMessageFormat` as the CommonJS default exports with all the
// locale data registered, and with English set as the default locale. Define
// the `default` prop for use with other compiled ES6 Modules.
exports = module.exports = IntlMessageFormat;
exports['default'] = exports;

57
node_modules/intl-messageformat/lib/compiler.d.ts generated vendored Normal file
View File

@@ -0,0 +1,57 @@
import { MessageFormatPattern, MessageTextElement, ArgumentElement } from 'intl-messageformat-parser';
export interface Formats {
number: Record<string, Intl.NumberFormatOptions>;
date: Record<string, Intl.DateTimeFormatOptions>;
time: Record<string, Intl.DateTimeFormatOptions>;
}
export interface Formatters {
getNumberFormat(...args: ConstructorParameters<typeof Intl.NumberFormat>): Intl.NumberFormat;
getDateTimeFormat(...args: ConstructorParameters<typeof Intl.DateTimeFormat>): Intl.DateTimeFormat;
getPluralRules(...args: ConstructorParameters<typeof Intl.PluralRules>): Intl.PluralRules;
}
export declare type Pattern = string | PluralOffsetString | PluralFormat | SelectFormat | StringFormat;
export default class Compiler {
private locales;
private formats;
private pluralNumberFormat;
private currentPlural;
private pluralStack;
private formatters;
constructor(locales: string | string[], formats: Formats, formatters: Formatters);
compile(ast: MessageFormatPattern): Pattern[];
compileMessage(ast: MessageFormatPattern): Pattern[];
compileMessageText(element: MessageTextElement): string | PluralOffsetString;
compileArgument(element: ArgumentElement): PluralFormat | SelectFormat | StringFormat;
compileOptions(element: ArgumentElement): {};
}
declare abstract class Formatter {
id: string;
constructor(id: string);
abstract format(value: string | number): string;
}
declare class StringFormat extends Formatter {
format(value: number | string): string;
}
declare class PluralFormat {
id: string;
private offset;
private options;
private pluralRules;
constructor(id: string, offset: number, options: Record<string, Pattern[]>, pluralRules: Intl.PluralRules);
getOption(value: number): Pattern[];
}
export declare class PluralOffsetString extends Formatter {
private offset;
private numberFormat;
private string;
constructor(id: string, offset: number, numberFormat: Intl.NumberFormat, string: string);
format(value: number): string;
}
export declare class SelectFormat {
id: string;
private options;
constructor(id: string, options: Record<string, Pattern[]>);
getOption(value: string): Pattern[];
}
export declare function isSelectOrPluralFormat(f: any): f is SelectFormat | PluralFormat;
export {};

197
node_modules/intl-messageformat/lib/compiler.js generated vendored Normal file
View File

@@ -0,0 +1,197 @@
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Compiler = /** @class */ (function () {
function Compiler(locales, formats, formatters) {
this.locales = [];
this.formats = {
number: {},
date: {},
time: {}
};
this.pluralNumberFormat = null;
this.currentPlural = null;
this.pluralStack = [];
this.locales = locales;
this.formats = formats;
this.formatters = formatters;
}
Compiler.prototype.compile = function (ast) {
this.pluralStack = [];
this.currentPlural = null;
this.pluralNumberFormat = null;
return this.compileMessage(ast);
};
Compiler.prototype.compileMessage = function (ast) {
var _this = this;
if (!(ast && ast.type === 'messageFormatPattern')) {
throw new Error('Message AST is not of type: "messageFormatPattern"');
}
var elements = ast.elements;
var pattern = elements
.filter(function (el) {
return el.type === 'messageTextElement' || el.type === 'argumentElement';
})
.map(function (el) {
return el.type === 'messageTextElement'
? _this.compileMessageText(el)
: _this.compileArgument(el);
});
if (pattern.length !== elements.length) {
throw new Error('Message element does not have a valid type');
}
return pattern;
};
Compiler.prototype.compileMessageText = function (element) {
// When this `element` is part of plural sub-pattern and its value contains
// an unescaped '#', use a `PluralOffsetString` helper to properly output
// the number with the correct offset in the string.
if (this.currentPlural && /(^|[^\\])#/g.test(element.value)) {
// Create a cache a NumberFormat instance that can be reused for any
// PluralOffsetString instance in this message.
if (!this.pluralNumberFormat) {
this.pluralNumberFormat = new Intl.NumberFormat(this.locales);
}
return new PluralOffsetString(this.currentPlural.id, this.currentPlural.format.offset, this.pluralNumberFormat, element.value);
}
// Unescape the escaped '#'s in the message text.
return element.value.replace(/\\#/g, '#');
};
Compiler.prototype.compileArgument = function (element) {
var format = element.format, id = element.id;
var formatters = this.formatters;
if (!format) {
return new StringFormat(id);
}
var _a = this, formats = _a.formats, locales = _a.locales;
switch (format.type) {
case 'numberFormat':
return {
id: id,
format: formatters.getNumberFormat(locales, formats.number[format.style]).format
};
case 'dateFormat':
return {
id: id,
format: formatters.getDateTimeFormat(locales, formats.date[format.style]).format
};
case 'timeFormat':
return {
id: id,
format: formatters.getDateTimeFormat(locales, formats.time[format.style]).format
};
case 'pluralFormat':
return new PluralFormat(id, format.offset, this.compileOptions(element), formatters.getPluralRules(locales, {
type: format.ordinal ? 'ordinal' : 'cardinal'
}));
case 'selectFormat':
return new SelectFormat(id, this.compileOptions(element));
default:
throw new Error('Message element does not have a valid format type');
}
};
Compiler.prototype.compileOptions = function (element) {
var _this = this;
var format = element.format;
var options = format.options;
// Save the current plural element, if any, then set it to a new value when
// compiling the options sub-patterns. This conforms the spec's algorithm
// for handling `"#"` syntax in message text.
this.pluralStack.push(this.currentPlural);
this.currentPlural = format.type === 'pluralFormat' ? element : null;
var optionsHash = options.reduce(function (all, option) {
// Compile the sub-pattern and save it under the options's selector.
all[option.selector] = _this.compileMessage(option.value);
return all;
}, {});
// Pop the plural stack to put back the original current plural value.
this.currentPlural = this.pluralStack.pop();
return optionsHash;
};
return Compiler;
}());
export default Compiler;
// -- Compiler Helper Classes --------------------------------------------------
var Formatter = /** @class */ (function () {
function Formatter(id) {
this.id = id;
}
return Formatter;
}());
var StringFormat = /** @class */ (function (_super) {
__extends(StringFormat, _super);
function StringFormat() {
return _super !== null && _super.apply(this, arguments) || this;
}
StringFormat.prototype.format = function (value) {
if (!value && typeof value !== 'number') {
return '';
}
return typeof value === 'string' ? value : String(value);
};
return StringFormat;
}(Formatter));
var PluralFormat = /** @class */ (function () {
function PluralFormat(id, offset, options, pluralRules) {
this.id = id;
this.offset = offset;
this.options = options;
this.pluralRules = pluralRules;
}
PluralFormat.prototype.getOption = function (value) {
var options = this.options;
var option = options['=' + value] ||
options[this.pluralRules.select(value - this.offset)];
return option || options.other;
};
return PluralFormat;
}());
var PluralOffsetString = /** @class */ (function (_super) {
__extends(PluralOffsetString, _super);
function PluralOffsetString(id, offset, numberFormat, string) {
var _this = _super.call(this, id) || this;
_this.offset = offset;
_this.numberFormat = numberFormat;
_this.string = string;
return _this;
}
PluralOffsetString.prototype.format = function (value) {
var number = this.numberFormat.format(value - this.offset);
return this.string
.replace(/(^|[^\\])#/g, '$1' + number)
.replace(/\\#/g, '#');
};
return PluralOffsetString;
}(Formatter));
export { PluralOffsetString };
var SelectFormat = /** @class */ (function () {
function SelectFormat(id, options) {
this.id = id;
this.options = options;
}
SelectFormat.prototype.getOption = function (value) {
var options = this.options;
return options[value] || options.other;
};
return SelectFormat;
}());
export { SelectFormat };
export function isSelectOrPluralFormat(f) {
return !!f.options;
}
//# sourceMappingURL=compiler.js.map

1
node_modules/intl-messageformat/lib/compiler.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

78
node_modules/intl-messageformat/lib/core.d.ts generated vendored Normal file
View File

@@ -0,0 +1,78 @@
import { Formats, Formatters } from './compiler';
import parser, { MessageFormatPattern } from 'intl-messageformat-parser';
export interface Options {
formatters?: Formatters;
}
export declare function createDefaultFormatters(): Formatters;
export declare class IntlMessageFormat {
private ast;
private locale;
private pattern;
private message;
constructor(message: string | MessageFormatPattern, locales?: string | string[], overrideFormats?: Partial<Formats>, opts?: Options);
format: (values?: Record<string, string | number | boolean | null | undefined> | undefined) => string;
resolvedOptions(): {
locale: string;
};
getAst(): MessageFormatPattern;
static defaultLocale: string;
static __parse: typeof parser['parse'] | undefined;
static formats: {
number: {
currency: {
style: string;
};
percent: {
style: string;
};
};
date: {
short: {
month: string;
day: string;
year: string;
};
medium: {
month: string;
day: string;
year: string;
};
long: {
month: string;
day: string;
year: string;
};
full: {
weekday: string;
month: string;
day: string;
year: string;
};
};
time: {
short: {
hour: string;
minute: string;
};
medium: {
hour: string;
minute: string;
second: string;
};
long: {
hour: string;
minute: string;
second: string;
timeZoneName: string;
};
full: {
hour: string;
minute: string;
second: string;
timeZoneName: string;
};
};
};
}
export { Formats, Pattern } from './compiler';
export default IntlMessageFormat;

245
node_modules/intl-messageformat/lib/core.js generated vendored Normal file
View File

@@ -0,0 +1,245 @@
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/* jslint esnext: true */
import Compiler, { isSelectOrPluralFormat } from './compiler';
// -- MessageFormat --------------------------------------------------------
function resolveLocale(locales) {
if (typeof locales === 'string') {
locales = [locales];
}
try {
return Intl.NumberFormat.supportedLocalesOf(locales, {
// IE11 localeMatcher `lookup` seems to convert `en` -> `en-US`
// but not other browsers,
localeMatcher: 'best fit'
})[0];
}
catch (e) {
return IntlMessageFormat.defaultLocale;
}
}
function formatPatterns(pattern, values) {
var result = '';
for (var _i = 0, pattern_1 = pattern; _i < pattern_1.length; _i++) {
var part = pattern_1[_i];
// Exist early for string parts.
if (typeof part === 'string') {
result += part;
continue;
}
var id = part.id;
// Enforce that all required values are provided by the caller.
if (!(values && id in values)) {
throw new FormatError("A value must be provided for: " + id, id);
}
var value = values[id];
// Recursively format plural and select parts' option — which can be a
// nested pattern structure. The choosing of the option to use is
// abstracted-by and delegated-to the part helper object.
if (isSelectOrPluralFormat(part)) {
result += formatPatterns(part.getOption(value), values);
}
else {
result += part.format(value);
}
}
return result;
}
function mergeConfig(c1, c2) {
if (!c2) {
return c1;
}
return __assign({}, (c1 || {}), (c2 || {}), Object.keys(c1).reduce(function (all, k) {
all[k] = __assign({}, c1[k], (c2[k] || {}));
return all;
}, {}));
}
function mergeConfigs(defaultConfig, configs) {
if (!configs) {
return defaultConfig;
}
return Object.keys(defaultConfig).reduce(function (all, k) {
all[k] = mergeConfig(defaultConfig[k], configs[k]);
return all;
}, __assign({}, defaultConfig));
}
var FormatError = /** @class */ (function (_super) {
__extends(FormatError, _super);
function FormatError(msg, variableId) {
var _this = _super.call(this, msg) || this;
_this.variableId = variableId;
return _this;
}
return FormatError;
}(Error));
export function createDefaultFormatters() {
return {
getNumberFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.NumberFormat).bind.apply(_a, [void 0].concat(args)))();
},
getDateTimeFormat: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.DateTimeFormat).bind.apply(_a, [void 0].concat(args)))();
},
getPluralRules: function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return new ((_a = Intl.PluralRules).bind.apply(_a, [void 0].concat(args)))();
}
};
}
var IntlMessageFormat = /** @class */ (function () {
function IntlMessageFormat(message, locales, overrideFormats, opts) {
var _this = this;
if (locales === void 0) { locales = IntlMessageFormat.defaultLocale; }
this.format = function (values) {
try {
return formatPatterns(_this.pattern, values);
}
catch (e) {
if (e.variableId) {
throw new Error("The intl string context variable '" + e.variableId + "' was not provided to the string '" + _this.message + "'");
}
else {
throw e;
}
}
};
if (typeof message === 'string') {
if (!IntlMessageFormat.__parse) {
throw new TypeError('IntlMessageFormat.__parse must be set to process `message` of type `string`');
}
// Parse string messages into an AST.
this.ast = IntlMessageFormat.__parse(message);
}
else {
this.ast = message;
}
this.message = message;
if (!(this.ast && this.ast.type === 'messageFormatPattern')) {
throw new TypeError('A message must be provided as a String or AST.');
}
// Creates a new object with the specified `formats` merged with the default
// formats.
var formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
this.locale = resolveLocale(locales || []);
var formatters = (opts && opts.formatters) || createDefaultFormatters();
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
this.pattern = new Compiler(locales, formats, formatters).compile(this.ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
}
IntlMessageFormat.prototype.resolvedOptions = function () {
return { locale: this.locale };
};
IntlMessageFormat.prototype.getAst = function () {
return this.ast;
};
IntlMessageFormat.defaultLocale = 'en';
IntlMessageFormat.__parse = undefined;
// Default format options used as the prototype of the `formats` provided to the
// constructor. These are used when constructing the internal Intl.NumberFormat
// and Intl.DateTimeFormat instances.
IntlMessageFormat.formats = {
number: {
currency: {
style: 'currency'
},
percent: {
style: 'percent'
}
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
},
medium: {
month: 'short',
day: 'numeric',
year: 'numeric'
},
long: {
month: 'long',
day: 'numeric',
year: 'numeric'
},
full: {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric'
}
},
time: {
short: {
hour: 'numeric',
minute: 'numeric'
},
medium: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
},
long: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
},
full: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
}
}
};
return IntlMessageFormat;
}());
export { IntlMessageFormat };
export default IntlMessageFormat;
//# sourceMappingURL=core.js.map

1
node_modules/intl-messageformat/lib/core.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

5
node_modules/intl-messageformat/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,5 @@
import IntlMessageFormat from './core';
export { Formats, Pattern } from './compiler';
export * from './core';
export { Formatters } from './compiler';
export default IntlMessageFormat;

11
node_modules/intl-messageformat/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
import parser from 'intl-messageformat-parser';
import IntlMessageFormat from './core';
IntlMessageFormat.__parse = parser.parse;
export * from './core';
export default IntlMessageFormat;
//# sourceMappingURL=index.js.map

1
node_modules/intl-messageformat/lib/index.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,iBAAiB,MAAM,QAAQ,CAAC;AAEvC,iBAAiB,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC;AAGzC,cAAc,QAAQ,CAAC;AAEvB,eAAe,iBAAiB,CAAC"}

50
node_modules/intl-messageformat/package.json generated vendored Normal file
View File

@@ -0,0 +1,50 @@
{
"name": "intl-messageformat",
"version": "4.4.0",
"description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.",
"keywords": [
"i18n",
"intl",
"internationalization",
"localization",
"globalization",
"messageformat",
"parser",
"plural",
"icu"
],
"author": "Eric Ferraiuolo <eferraiuolo@gmail.com>",
"contributors": [
"Anthony Pipkin <a.pipkin@yahoo.com>",
"Caridy Patino <caridy@gmail.com>",
"Drew Folta <drew@folta.net>",
"Long Ho <holevietlong@gmail.com"
],
"bugs": {
"url": "https://github.com/formatjs/formatjs/issues"
},
"repository": {
"type": "git",
"url": "git@github.com:formatjs/formatjs.git"
},
"main": "index.js",
"module": "lib/index.js",
"typings": "lib/index.d.ts",
"dependencies": {
"intl-messageformat-parser": "^1.8.1"
},
"scripts": {
"clean": "rimraf dist lib",
"benchmark": "ts-node --project ./tsconfig.cjs.json tests/benchmark",
"build": "tsc && tsc -p tsconfig.cjs.json && rollup -c rollup.config.js",
"test": "mocha --opts ../../mocha.opts tests/index.ts",
"karma:local": "karma start karma.conf.js",
"karma:ci": "karma start karma.conf-ci.js"
},
"homepage": "https://github.com/formatjs/formatjs",
"directories": {
"test": "tests"
},
"license": "BSD-3-Clause",
"gitHead": "60ddf374ed659ffe2f3807c3c7df411c80492761"
}

286
node_modules/intl-messageformat/src/compiler.ts generated vendored Normal file
View File

@@ -0,0 +1,286 @@
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
import {
MessageFormatPattern,
MessageTextElement,
ArgumentElement,
PluralFormat as ParserPluralFormat,
SelectFormat as ParserSelectFormat
} from 'intl-messageformat-parser';
export interface Formats {
number: Record<string, Intl.NumberFormatOptions>;
date: Record<string, Intl.DateTimeFormatOptions>;
time: Record<string, Intl.DateTimeFormatOptions>;
}
export interface Formatters {
getNumberFormat(
...args: ConstructorParameters<typeof Intl.NumberFormat>
): Intl.NumberFormat;
getDateTimeFormat(
...args: ConstructorParameters<typeof Intl.DateTimeFormat>
): Intl.DateTimeFormat;
getPluralRules(
...args: ConstructorParameters<typeof Intl.PluralRules>
): Intl.PluralRules;
}
export type Pattern =
| string
| PluralOffsetString
| PluralFormat
| SelectFormat
| StringFormat;
export default class Compiler {
private locales: string | string[] = [];
private formats: Formats = {
number: {},
date: {},
time: {}
};
private pluralNumberFormat: Intl.NumberFormat | null = null;
private currentPlural: ArgumentElement | null | undefined = null;
private pluralStack: Array<ArgumentElement | null | undefined> = [];
private formatters: Formatters;
constructor(
locales: string | string[],
formats: Formats,
formatters: Formatters
) {
this.locales = locales;
this.formats = formats;
this.formatters = formatters;
}
compile(ast: MessageFormatPattern): Pattern[] {
this.pluralStack = [];
this.currentPlural = null;
this.pluralNumberFormat = null;
return this.compileMessage(ast);
}
compileMessage(ast: MessageFormatPattern) {
if (!(ast && ast.type === 'messageFormatPattern')) {
throw new Error('Message AST is not of type: "messageFormatPattern"');
}
const { elements } = ast;
const pattern = elements
.filter<MessageTextElement | ArgumentElement>(
(el): el is MessageTextElement | ArgumentElement =>
el.type === 'messageTextElement' || el.type === 'argumentElement'
)
.map(el =>
el.type === 'messageTextElement'
? this.compileMessageText(el)
: this.compileArgument(el)
);
if (pattern.length !== elements.length) {
throw new Error('Message element does not have a valid type');
}
return pattern;
}
compileMessageText(element: MessageTextElement) {
// When this `element` is part of plural sub-pattern and its value contains
// an unescaped '#', use a `PluralOffsetString` helper to properly output
// the number with the correct offset in the string.
if (this.currentPlural && /(^|[^\\])#/g.test(element.value)) {
// Create a cache a NumberFormat instance that can be reused for any
// PluralOffsetString instance in this message.
if (!this.pluralNumberFormat) {
this.pluralNumberFormat = new Intl.NumberFormat(this.locales);
}
return new PluralOffsetString(
this.currentPlural.id,
(this.currentPlural.format as ParserPluralFormat).offset,
this.pluralNumberFormat,
element.value
);
}
// Unescape the escaped '#'s in the message text.
return element.value.replace(/\\#/g, '#');
}
compileArgument(element: ArgumentElement) {
const { format, id } = element;
const { formatters } = this;
if (!format) {
return new StringFormat(id);
}
const { formats, locales } = this;
switch (format.type) {
case 'numberFormat':
return {
id,
format: formatters.getNumberFormat(
locales,
formats.number[format.style]
).format
};
case 'dateFormat':
return {
id,
format: formatters.getDateTimeFormat(
locales,
formats.date[format.style]
).format
};
case 'timeFormat':
return {
id,
format: formatters.getDateTimeFormat(
locales,
formats.time[format.style]
).format
};
case 'pluralFormat':
return new PluralFormat(
id,
format.offset,
this.compileOptions(element),
formatters.getPluralRules(locales, {
type: format.ordinal ? 'ordinal' : 'cardinal'
})
);
case 'selectFormat':
return new SelectFormat(id, this.compileOptions(element));
default:
throw new Error('Message element does not have a valid format type');
}
}
compileOptions(element: ArgumentElement) {
const format = element.format as ParserPluralFormat | ParserSelectFormat;
const { options } = format;
// Save the current plural element, if any, then set it to a new value when
// compiling the options sub-patterns. This conforms the spec's algorithm
// for handling `"#"` syntax in message text.
this.pluralStack.push(this.currentPlural);
this.currentPlural = format.type === 'pluralFormat' ? element : null;
const optionsHash = options.reduce(
(all: Record<string, Array<Pattern>>, option) => {
// Compile the sub-pattern and save it under the options's selector.
all[option.selector] = this.compileMessage(option.value);
return all;
},
{}
);
// Pop the plural stack to put back the original current plural value.
this.currentPlural = this.pluralStack.pop();
return optionsHash;
}
}
// -- Compiler Helper Classes --------------------------------------------------
abstract class Formatter {
public id: string;
constructor(id: string) {
this.id = id;
}
abstract format(value: string | number): string;
}
class StringFormat extends Formatter {
format(value: number | string) {
if (!value && typeof value !== 'number') {
return '';
}
return typeof value === 'string' ? value : String(value);
}
}
class PluralFormat {
public id: string;
private offset: number;
private options: Record<string, Pattern[]>;
private pluralRules: Intl.PluralRules;
constructor(
id: string,
offset: number,
options: Record<string, Pattern[]>,
pluralRules: Intl.PluralRules
) {
this.id = id;
this.offset = offset;
this.options = options;
this.pluralRules = pluralRules;
}
getOption(value: number) {
const { options } = this;
const option =
options['=' + value] ||
options[this.pluralRules.select(value - this.offset)];
return option || options.other;
}
}
export class PluralOffsetString extends Formatter {
private offset: number;
private numberFormat: Intl.NumberFormat;
private string: string;
constructor(
id: string,
offset: number,
numberFormat: Intl.NumberFormat,
string: string
) {
super(id);
this.offset = offset;
this.numberFormat = numberFormat;
this.string = string;
}
format(value: number) {
const number = this.numberFormat.format(value - this.offset);
return this.string
.replace(/(^|[^\\])#/g, '$1' + number)
.replace(/\\#/g, '#');
}
}
export class SelectFormat {
public id: string;
private options: Record<string, Pattern[]>;
constructor(id: string, options: Record<string, Pattern[]>) {
this.id = id;
this.options = options;
}
getOption(value: string) {
const { options } = this;
return options[value] || options.other;
}
}
export function isSelectOrPluralFormat(
f: any
): f is SelectFormat | PluralFormat {
return !!f.options;
}

269
node_modules/intl-messageformat/src/core.ts generated vendored Normal file
View File

@@ -0,0 +1,269 @@
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
/* jslint esnext: true */
import Compiler, {
Formats,
isSelectOrPluralFormat,
Pattern,
Formatters
} from './compiler';
import parser, { MessageFormatPattern } from 'intl-messageformat-parser';
// -- MessageFormat --------------------------------------------------------
function resolveLocale(locales: string | string[]): string {
if (typeof locales === 'string') {
locales = [locales];
}
try {
return Intl.NumberFormat.supportedLocalesOf(locales, {
// IE11 localeMatcher `lookup` seems to convert `en` -> `en-US`
// but not other browsers,
localeMatcher: 'best fit'
})[0];
} catch (e) {
return IntlMessageFormat.defaultLocale;
}
}
function formatPatterns(
pattern: Pattern[],
values?: Record<string, string | number | boolean | null | undefined>
) {
let result = '';
for (const part of pattern) {
// Exist early for string parts.
if (typeof part === 'string') {
result += part;
continue;
}
const { id } = part;
// Enforce that all required values are provided by the caller.
if (!(values && id in values)) {
throw new FormatError(`A value must be provided for: ${id}`, id);
}
const value = values[id];
// Recursively format plural and select parts' option — which can be a
// nested pattern structure. The choosing of the option to use is
// abstracted-by and delegated-to the part helper object.
if (isSelectOrPluralFormat(part)) {
result += formatPatterns(part.getOption(value as any), values);
} else {
result += part.format(value as any);
}
}
return result;
}
function mergeConfig(c1: Record<string, object>, c2?: Record<string, object>) {
if (!c2) {
return c1;
}
return {
...(c1 || {}),
...(c2 || {}),
...Object.keys(c1).reduce((all: Record<string, object>, k) => {
all[k] = {
...c1[k],
...(c2[k] || {})
};
return all;
}, {})
};
}
function mergeConfigs(
defaultConfig: Formats,
configs?: Partial<Formats>
): Formats {
if (!configs) {
return defaultConfig;
}
return (Object.keys(defaultConfig) as Array<keyof Formats>).reduce(
(all: Formats, k: keyof Formats) => {
all[k] = mergeConfig(defaultConfig[k], configs[k]);
return all;
},
{ ...defaultConfig }
);
}
class FormatError extends Error {
public readonly variableId?: string;
constructor(msg?: string, variableId?: string) {
super(msg);
this.variableId = variableId;
}
}
export interface Options {
formatters?: Formatters;
}
export function createDefaultFormatters(): Formatters {
return {
getNumberFormat(...args) {
return new Intl.NumberFormat(...args);
},
getDateTimeFormat(...args) {
return new Intl.DateTimeFormat(...args);
},
getPluralRules(...args) {
return new Intl.PluralRules(...args);
}
};
}
export class IntlMessageFormat {
private ast: MessageFormatPattern;
private locale: string;
private pattern: Pattern[];
private message: string | MessageFormatPattern;
constructor(
message: string | MessageFormatPattern,
locales: string | string[] = IntlMessageFormat.defaultLocale,
overrideFormats?: Partial<Formats>,
opts?: Options
) {
if (typeof message === 'string') {
if (!IntlMessageFormat.__parse) {
throw new TypeError(
'IntlMessageFormat.__parse must be set to process `message` of type `string`'
);
}
// Parse string messages into an AST.
this.ast = IntlMessageFormat.__parse(message);
} else {
this.ast = message;
}
this.message = message;
if (!(this.ast && this.ast.type === 'messageFormatPattern')) {
throw new TypeError('A message must be provided as a String or AST.');
}
// Creates a new object with the specified `formats` merged with the default
// formats.
const formats = mergeConfigs(IntlMessageFormat.formats, overrideFormats);
// Defined first because it's used to build the format pattern.
this.locale = resolveLocale(locales || []);
let formatters = (opts && opts.formatters) || createDefaultFormatters();
// Compile the `ast` to a pattern that is highly optimized for repeated
// `format()` invocations. **Note:** This passes the `locales` set provided
// to the constructor instead of just the resolved locale.
this.pattern = new Compiler(locales, formats, formatters).compile(this.ast);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
}
format = (
values?: Record<string, string | number | boolean | null | undefined>
) => {
try {
return formatPatterns(this.pattern, values);
} catch (e) {
if (e.variableId) {
throw new Error(
`The intl string context variable '${e.variableId}' was not provided to the string '${this.message}'`
);
} else {
throw e;
}
}
};
resolvedOptions() {
return { locale: this.locale };
}
getAst() {
return this.ast;
}
static defaultLocale = 'en';
static __parse: typeof parser['parse'] | undefined = undefined;
// Default format options used as the prototype of the `formats` provided to the
// constructor. These are used when constructing the internal Intl.NumberFormat
// and Intl.DateTimeFormat instances.
static formats = {
number: {
currency: {
style: 'currency'
},
percent: {
style: 'percent'
}
},
date: {
short: {
month: 'numeric',
day: 'numeric',
year: '2-digit'
},
medium: {
month: 'short',
day: 'numeric',
year: 'numeric'
},
long: {
month: 'long',
day: 'numeric',
year: 'numeric'
},
full: {
weekday: 'long',
month: 'long',
day: 'numeric',
year: 'numeric'
}
},
time: {
short: {
hour: 'numeric',
minute: 'numeric'
},
medium: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric'
},
long: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
},
full: {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZoneName: 'short'
}
}
};
}
export { Formats, Pattern } from './compiler';
export default IntlMessageFormat;

15
node_modules/intl-messageformat/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
/*
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
Copyrights licensed under the New BSD License.
See the accompanying LICENSE file for terms.
*/
import parser from 'intl-messageformat-parser';
import IntlMessageFormat from './core';
IntlMessageFormat.__parse = parser.parse;
export { Formats, Pattern } from './compiler';
export * from './core';
export { Formatters } from './compiler';
export default IntlMessageFormat;