Add files

This commit is contained in:
DoomRye 2022-07-26 10:06:20 -07:00
commit bb80829159
18195 changed files with 2122994 additions and 0 deletions

View file

@ -0,0 +1,23 @@
/* jshint node:true */
'use strict';
var IntlMessageFormat = require('./lib/main')['default'];
// Add all locale data to `IntlMessageFormat`. This module will be ignored when
// bundling for the browser with Browserify/Webpack.
require('./lib/locales');
// 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;
//////////////////
// WEBPACK FOOTER
// ./~/intl-messageformat/index.js
// module id = 692
// module chunks = 4

View file

@ -0,0 +1,216 @@
/*
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 */
"use strict";
exports["default"] = Compiler;
function Compiler(locales, formats, pluralFn) {
this.locales = locales;
this.formats = formats;
this.pluralFn = pluralFn;
}
Compiler.prototype.compile = function (ast) {
this.pluralStack = [];
this.currentPlural = null;
this.pluralNumberFormat = null;
return this.compileMessage(ast);
};
Compiler.prototype.compileMessage = function (ast) {
if (!(ast && ast.type === 'messageFormatPattern')) {
throw new Error('Message AST is not of type: "messageFormatPattern"');
}
var elements = ast.elements,
pattern = [];
var i, len, element;
for (i = 0, len = elements.length; i < len; i += 1) {
element = elements[i];
switch (element.type) {
case 'messageTextElement':
pattern.push(this.compileMessageText(element));
break;
case 'argumentElement':
pattern.push(this.compileArgument(element));
break;
default:
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;
if (!format) {
return new StringFormat(element.id);
}
var formats = this.formats,
locales = this.locales,
pluralFn = this.pluralFn,
options;
switch (format.type) {
case 'numberFormat':
options = formats.number[format.style];
return {
id : element.id,
format: new Intl.NumberFormat(locales, options).format
};
case 'dateFormat':
options = formats.date[format.style];
return {
id : element.id,
format: new Intl.DateTimeFormat(locales, options).format
};
case 'timeFormat':
options = formats.time[format.style];
return {
id : element.id,
format: new Intl.DateTimeFormat(locales, options).format
};
case 'pluralFormat':
options = this.compileOptions(element);
return new PluralFormat(
element.id, format.ordinal, format.offset, options, pluralFn
);
case 'selectFormat':
options = this.compileOptions(element);
return new SelectFormat(element.id, options);
default:
throw new Error('Message element does not have a valid format type');
}
};
Compiler.prototype.compileOptions = function (element) {
var format = element.format,
options = format.options,
optionsHash = {};
// 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 i, len, option;
for (i = 0, len = options.length; i < len; i += 1) {
option = options[i];
// Compile the sub-pattern and save it under the options's selector.
optionsHash[option.selector] = this.compileMessage(option.value);
}
// Pop the plural stack to put back the original current plural value.
this.currentPlural = this.pluralStack.pop();
return optionsHash;
};
// -- Compiler Helper Classes --------------------------------------------------
function StringFormat(id) {
this.id = id;
}
StringFormat.prototype.format = function (value) {
if (!value) {
return '';
}
return typeof value === 'string' ? value : String(value);
};
function PluralFormat(id, useOrdinal, offset, options, pluralFn) {
this.id = id;
this.useOrdinal = useOrdinal;
this.offset = offset;
this.options = options;
this.pluralFn = pluralFn;
}
PluralFormat.prototype.getOption = function (value) {
var options = this.options;
var option = options['=' + value] ||
options[this.pluralFn(value - this.offset, this.useOrdinal)];
return option || options.other;
};
function PluralOffsetString(id, offset, numberFormat, string) {
this.id = id;
this.offset = offset;
this.numberFormat = numberFormat;
this.string = string;
}
PluralOffsetString.prototype.format = function (value) {
var number = this.numberFormat.format(value - this.offset);
return this.string
.replace(/(^|[^\\])#/g, '$1' + number)
.replace(/\\#/g, '#');
};
function SelectFormat(id, options) {
this.id = id;
this.options = options;
}
SelectFormat.prototype.getOption = function (value) {
var options = this.options;
return options[value] || options.other;
};
//# sourceMappingURL=compiler.js.map
//////////////////
// WEBPACK FOOTER
// ./~/intl-messageformat/lib/compiler.js
// module id = 2551
// module chunks = 4

View file

@ -0,0 +1,271 @@
/*
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 */
"use strict";
var src$utils$$ = require("./utils"), src$es5$$ = require("./es5"), src$compiler$$ = require("./compiler"), intl$messageformat$parser$$ = require("intl-messageformat-parser");
exports["default"] = MessageFormat;
// -- MessageFormat --------------------------------------------------------
function MessageFormat(message, locales, formats) {
// Parse string messages into an AST.
var ast = typeof message === 'string' ?
MessageFormat.__parse(message) : message;
if (!(ast && 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.
formats = this._mergeFormats(MessageFormat.formats, formats);
// Defined first because it's used to build the format pattern.
src$es5$$.defineProperty(this, '_locale', {value: this._resolveLocale(locales)});
// 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.
var pluralFn = this._findPluralRuleFunction(this._locale);
var pattern = this._compilePattern(ast, locales, formats, pluralFn);
// "Bind" `format()` method to `this` so it can be passed by reference like
// the other `Intl` APIs.
var messageFormat = this;
this.format = function (values) {
return messageFormat._format(pattern, values);
};
}
// 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.
src$es5$$.defineProperty(MessageFormat, 'formats', {
enumerable: true,
value: {
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'
}
}
}
});
// Define internal private properties for dealing with locale data.
src$es5$$.defineProperty(MessageFormat, '__localeData__', {value: src$es5$$.objCreate(null)});
src$es5$$.defineProperty(MessageFormat, '__addLocaleData', {value: function (data) {
if (!(data && data.locale)) {
throw new Error(
'Locale data provided to IntlMessageFormat is missing a ' +
'`locale` property'
);
}
MessageFormat.__localeData__[data.locale.toLowerCase()] = data;
}});
// Defines `__parse()` static method as an exposed private.
src$es5$$.defineProperty(MessageFormat, '__parse', {value: intl$messageformat$parser$$["default"].parse});
// Define public `defaultLocale` property which defaults to English, but can be
// set by the developer.
src$es5$$.defineProperty(MessageFormat, 'defaultLocale', {
enumerable: true,
writable : true,
value : undefined
});
MessageFormat.prototype.resolvedOptions = function () {
// TODO: Provide anything else?
return {
locale: this._locale
};
};
MessageFormat.prototype._compilePattern = function (ast, locales, formats, pluralFn) {
var compiler = new src$compiler$$["default"](locales, formats, pluralFn);
return compiler.compile(ast);
};
MessageFormat.prototype._findPluralRuleFunction = function (locale) {
var localeData = MessageFormat.__localeData__;
var data = localeData[locale.toLowerCase()];
// The locale data is de-duplicated, so we have to traverse the locale's
// hierarchy until we find a `pluralRuleFunction` to return.
while (data) {
if (data.pluralRuleFunction) {
return data.pluralRuleFunction;
}
data = data.parentLocale && localeData[data.parentLocale.toLowerCase()];
}
throw new Error(
'Locale data added to IntlMessageFormat is missing a ' +
'`pluralRuleFunction` for :' + locale
);
};
MessageFormat.prototype._format = function (pattern, values) {
var result = '',
i, len, part, id, value;
for (i = 0, len = pattern.length; i < len; i += 1) {
part = pattern[i];
// Exist early for string parts.
if (typeof part === 'string') {
result += part;
continue;
}
id = part.id;
// Enforce that all required values are provided by the caller.
if (!(values && src$utils$$.hop.call(values, id))) {
throw new Error('A value must be provided for: ' + id);
}
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 (part.options) {
result += this._format(part.getOption(value), values);
} else {
result += part.format(value);
}
}
return result;
};
MessageFormat.prototype._mergeFormats = function (defaults, formats) {
var mergedFormats = {},
type, mergedType;
for (type in defaults) {
if (!src$utils$$.hop.call(defaults, type)) { continue; }
mergedFormats[type] = mergedType = src$es5$$.objCreate(defaults[type]);
if (formats && src$utils$$.hop.call(formats, type)) {
src$utils$$.extend(mergedType, formats[type]);
}
}
return mergedFormats;
};
MessageFormat.prototype._resolveLocale = function (locales) {
if (typeof locales === 'string') {
locales = [locales];
}
// Create a copy of the array so we can push on the default locale.
locales = (locales || []).concat(MessageFormat.defaultLocale);
var localeData = MessageFormat.__localeData__;
var i, len, localeParts, data;
// Using the set of locales + the default locale, we look for the first one
// which that has been registered. When data does not exist for a locale, we
// traverse its ancestors to find something that's been registered within
// its hierarchy of locales. Since we lack the proper `parentLocale` data
// here, we must take a naive approach to traversal.
for (i = 0, len = locales.length; i < len; i += 1) {
localeParts = locales[i].toLowerCase().split('-');
while (localeParts.length) {
data = localeData[localeParts.join('-')];
if (data) {
// Return the normalized locale string; e.g., we return "en-US",
// instead of "en-us".
return data.locale;
}
localeParts.pop();
}
}
var defaultLocale = locales.pop();
throw new Error(
'No locale data has been added to IntlMessageFormat for: ' +
locales.join(', ') + ', or the default locale: ' + defaultLocale
);
};
//# sourceMappingURL=core.js.map
//////////////////
// WEBPACK FOOTER
// ./~/intl-messageformat/lib/core.js
// module id = 2552
// module chunks = 4

View file

@ -0,0 +1,12 @@
// GENERATED FILE
"use strict";
exports["default"] = {"locale":"en","pluralRuleFunction":function (n,ord){var s=String(n).split("."),v0=!s[1],t0=Number(s[0])==n,n10=t0&&s[0].slice(-1),n100=t0&&s[0].slice(-2);if(ord)return n10==1&&n100!=11?"one":n10==2&&n100!=12?"two":n10==3&&n100!=13?"few":"other";return n==1&&v0?"one":"other"}};
//# sourceMappingURL=en.js.map
//////////////////
// WEBPACK FOOTER
// ./~/intl-messageformat/lib/en.js
// module id = 2553
// module chunks = 4

View file

@ -0,0 +1,56 @@
/*
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 */
"use strict";
var src$utils$$ = require("./utils");
// Purposely using the same implementation as the Intl.js `Intl` polyfill.
// Copyright 2013 Andy Earnshaw, MIT License
var realDefineProp = (function () {
try { return !!Object.defineProperty({}, 'a', {}); }
catch (e) { return false; }
})();
var es3 = !realDefineProp && !Object.prototype.__defineGetter__;
var defineProperty = realDefineProp ? Object.defineProperty :
function (obj, name, desc) {
if ('get' in desc && obj.__defineGetter__) {
obj.__defineGetter__(name, desc.get);
} else if (!src$utils$$.hop.call(obj, name) || 'value' in desc) {
obj[name] = desc.value;
}
};
var objCreate = Object.create || function (proto, props) {
var obj, k;
function F() {}
F.prototype = proto;
obj = new F();
for (k in props) {
if (src$utils$$.hop.call(props, k)) {
defineProperty(obj, k, props[k]);
}
}
return obj;
};
exports.defineProperty = defineProperty, exports.objCreate = objCreate;
//# sourceMappingURL=es5.js.map
//////////////////
// WEBPACK FOOTER
// ./~/intl-messageformat/lib/es5.js
// module id = 2554
// module chunks = 4

View file

@ -0,0 +1,18 @@
/* jslint esnext: true */
"use strict";
var src$core$$ = require("./core"), src$en$$ = require("./en");
src$core$$["default"].__addLocaleData(src$en$$["default"]);
src$core$$["default"].defaultLocale = 'en';
exports["default"] = src$core$$["default"];
//# sourceMappingURL=main.js.map
//////////////////
// WEBPACK FOOTER
// ./~/intl-messageformat/lib/main.js
// module id = 2555
// module chunks = 4

View file

@ -0,0 +1,39 @@
/*
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 */
"use strict";
exports.extend = extend;
var hop = Object.prototype.hasOwnProperty;
function extend(obj) {
var sources = Array.prototype.slice.call(arguments, 1),
i, len, source, key;
for (i = 0, len = sources.length; i < len; i += 1) {
source = sources[i];
if (!source) { continue; }
for (key in source) {
if (hop.call(source, key)) {
obj[key] = source[key];
}
}
}
return obj;
}
exports.hop = hop;
//# sourceMappingURL=utils.js.map
//////////////////
// WEBPACK FOOTER
// ./~/intl-messageformat/lib/utils.js
// module id = 966
// module chunks = 4