This commit is contained in:
David Štaleker
2025-07-18 05:33:16 +02:00
parent 401a367e5d
commit db0cc8d3de
14776 changed files with 9251484 additions and 0 deletions

View File

@@ -0,0 +1,326 @@
/**
* Globalize Runtime v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
"use strict";
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define( factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory();
} else {
// Globalize
root.Globalize = factory();
}
}( this, function() {
/**
* A toString method that outputs meaningful values for objects or arrays and
* still performs as fast as a plain string in case variable is string, or as
* fast as `"" + number` in case variable is a number.
* Ref: http://jsperf.com/my-stringify
*/
var toString = function( variable ) {
return typeof variable === "string" ? variable : ( typeof variable === "number" ? "" +
variable : JSON.stringify( variable ) );
};
/**
* formatMessage( message, data )
*
* @message [String] A message with optional {vars} to be replaced.
*
* @data [Array or JSON] Object with replacing-variables content.
*
* Return the formatted message. For example:
*
* - formatMessage( "{0} second", [ 1 ] ); // 1 second
*
* - formatMessage( "{0}/{1}", ["m", "s"] ); // m/s
*
* - formatMessage( "{name} <{email}>", {
* name: "Foo",
* email: "bar@baz.qux"
* }); // Foo <bar@baz.qux>
*/
var formatMessage = function( message, data ) {
// Replace {attribute}'s
message = message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( name ) {
name = name.replace( /^{([^}]*)}$/, "$1" );
return toString( data[ name ] );
});
return message;
};
var objectExtend = function() {
var destination = arguments[ 0 ],
sources = [].slice.call( arguments, 1 );
sources.forEach(function( source ) {
var prop;
for ( prop in source ) {
destination[ prop ] = source[ prop ];
}
});
return destination;
};
var createError = function( code, message, attributes ) {
var error;
message = code + ( message ? ": " + formatMessage( message, attributes ) : "" );
error = new Error( message );
error.code = code;
objectExtend( error, attributes );
return error;
};
/**
* Pushes part to parts array, concat two consecutive parts of the same type.
*/
var partsPush = function( parts, type, value ) {
// Concat two consecutive parts of same type
if ( parts.length && parts[ parts.length - 1 ].type === type ) {
parts[ parts.length - 1 ].value += value;
return;
}
parts.push( { type: type, value: value } );
};
/**
* formatMessage( message, data )
*
* @message [String] A message with optional {vars} to be replaced.
*
* @data [Array or JSON] Object with replacing-variables content.
*
* Return the formatted message. For example:
*
* - formatMessage( "{0} second", [ 1 ] );
* > [{type: "variable", value: "1", name: "0"}, {type: "literal", value: " second"}]
*
* - formatMessage( "{0}/{1}", ["m", "s"] );
* > [
* { type: "variable", value: "m", name: "0" },
* { type: "literal", value: " /" },
* { type: "variable", value: "s", name: "1" }
* ]
*/
var formatMessageToParts = function( message, data ) {
var lastOffset = 0,
parts = [];
// Create parts.
message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( nameIncludingBrackets, offset ) {
var name = nameIncludingBrackets.slice( 1, -1 );
partsPush( parts, "literal", message.slice( lastOffset, offset ));
partsPush( parts, "variable", data[ name ] );
parts[ parts.length - 1 ].name = name;
lastOffset += offset + nameIncludingBrackets.length;
});
// Skip empty ones such as `{ type: 'literal', value: '' }`.
return parts.filter(function( part ) {
return part.value !== "";
});
};
/**
* Returns joined parts values.
*/
var partsJoin = function( parts ) {
return parts.map( function( part ) {
return part.value;
}).join( "" );
};
var runtimeStringify = function( args ) {
return JSON.stringify( args, function( _key, value ) {
if ( value && value.runtimeKey ) {
return value.runtimeKey;
}
return value;
} );
};
// Based on http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
var stringHash = function( str ) {
return [].reduce.call( str, function( hash, i ) {
var chr = i.charCodeAt( 0 );
hash = ( ( hash << 5 ) - hash ) + chr;
return hash | 0;
}, 0 );
};
var runtimeKey = function( fnName, locale, args, argsStr ) {
var hash;
argsStr = argsStr || runtimeStringify( args );
hash = stringHash( fnName + locale + argsStr );
return hash > 0 ? "a" + hash : "b" + Math.abs( hash );
};
var validate = function( code, message, check, attributes ) {
if ( !check ) {
throw createError( code, message, attributes );
}
};
var validateParameterPresence = function( value, name ) {
validate( "E_MISSING_PARAMETER", "Missing required parameter `{name}`.",
value !== undefined, { name: name });
};
var validateParameterType = function( value, name, check, expected ) {
validate(
"E_INVALID_PAR_TYPE",
"Invalid `{name}` parameter ({value}). {expected} expected.",
check,
{
expected: expected,
name: name,
value: value
}
);
};
var validateParameterTypeString = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || typeof value === "string",
"a string"
);
};
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions?redirectlocale=en-US&redirectslug=JavaScript%2FGuide%2FRegular_Expressions
var regexpEscape = function( string ) {
return string.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1" );
};
var stringPad = function( str, count, right ) {
var length;
if ( typeof str !== "string" ) {
str = String( str );
}
for ( length = str.length; length < count; length += 1 ) {
str = ( right ? ( str + "0" ) : ( "0" + str ) );
}
return str;
};
function Globalize( locale ) {
if ( !( this instanceof Globalize ) ) {
return new Globalize( locale );
}
validateParameterPresence( locale, "locale" );
validateParameterTypeString( locale, "locale" );
this._locale = locale;
}
Globalize.locale = function( locale ) {
validateParameterTypeString( locale, "locale" );
if ( arguments.length ) {
this._locale = locale;
}
return this._locale;
};
Globalize._createError = createError;
Globalize._formatMessage = formatMessage;
Globalize._formatMessageToParts = formatMessageToParts;
Globalize._partsJoin = partsJoin;
Globalize._partsPush = partsPush;
Globalize._regexpEscape = regexpEscape;
Globalize._runtimeKey = runtimeKey;
Globalize._stringPad = stringPad;
Globalize._validateParameterPresence = validateParameterPresence;
Globalize._validateParameterTypeString = validateParameterTypeString;
Globalize._validateParameterType = validateParameterType;
return Globalize;
}));

View File

@@ -0,0 +1,183 @@
/**
* Globalize Runtime v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
"use strict";
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"../globalize-runtime",
"./number"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory(
require( "../globalize-runtime" ),
require( "./number" )
);
} else {
// Extend global
factory( root.Globalize );
}
}(this, function( Globalize ) {
var formatMessageToParts = Globalize._formatMessageToParts,
partsJoin = Globalize._partsJoin,
partsPush = Globalize._partsPush,
runtimeKey = Globalize._runtimeKey,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterTypeNumber = Globalize._validateParameterTypeNumber;
var currencyFormatterFn = function( currencyToPartsFormatter ) {
return function currencyFormatter( value ) {
return partsJoin( currencyToPartsFormatter( value ));
};
};
/**
* nameFormat( formattedNumber, pluralForm, properties )
*
* Return the appropriate name form currency format.
*/
var currencyNameFormat = function( formattedNumber, pluralForm, properties ) {
var displayName, unitPattern,
parts = [],
displayNames = properties.displayNames || {},
unitPatterns = properties.unitPatterns;
displayName = displayNames[ "displayName-count-" + pluralForm ] ||
displayNames[ "displayName-count-other" ] ||
displayNames.displayName ||
properties.currency;
unitPattern = unitPatterns[ "unitPattern-count-" + pluralForm ] ||
unitPatterns[ "unitPattern-count-other" ];
formatMessageToParts( unitPattern, [ formattedNumber, displayName ]).forEach(function( part ) {
if ( part.type === "variable" && part.name === "0" ) {
part.value.forEach(function( part ) {
partsPush( parts, part.type, part.value );
});
} else if ( part.type === "variable" && part.name === "1" ) {
partsPush( parts, "currency", part.value );
} else {
partsPush( parts, "literal", part.value );
}
});
return parts;
};
/**
* symbolFormat( parts, symbol )
*
* Return the appropriate symbol/account form format.
*/
var currencySymbolFormat = function( parts, symbol ) {
parts.forEach(function( part ) {
if ( part.type === "currency" ) {
part.value = symbol;
}
});
return parts;
};
var currencyToPartsFormatterFn = function( numberToPartsFormatter, pluralGenerator, properties ) {
var fn;
// Return formatter when style is "name".
if ( pluralGenerator && properties ) {
fn = function currencyToPartsFormatter( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return currencyNameFormat(
numberToPartsFormatter( value ),
pluralGenerator( value ),
properties
);
};
// Return formatter when style is "symbol", "accounting", or "code".
} else {
fn = function currencyToPartsFormatter( value ) {
// 1: Reusing pluralGenerator argument, but in this case it is actually `symbol`
return currencySymbolFormat( numberToPartsFormatter( value ), pluralGenerator /* 1 */ );
};
}
return fn;
};
Globalize._currencyFormatterFn = currencyFormatterFn;
Globalize._currencyNameFormat = currencyNameFormat;
Globalize._currencyToPartsFormatterFn = currencyToPartsFormatterFn;
Globalize.currencyFormatter =
Globalize.prototype.currencyFormatter = function( currency, options ) {
options = options || {};
return Globalize[ runtimeKey( "currencyFormatter", this._locale, [ currency, options ] ) ];
};
Globalize.currencyToPartsFormatter =
Globalize.prototype.currencyToPartsFormatter = function( currency, options ) {
options = options || {};
return Globalize[
runtimeKey( "currencyToPartsFormatter", this._locale, [ currency, options ] )
];
};
Globalize.formatCurrency =
Globalize.prototype.formatCurrency = function( value, currency, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.currencyFormatter( currency, options )( value );
};
Globalize.formatCurrencyToParts =
Globalize.prototype.formatCurrencyToParts = function( value, currency, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.currencyToPartsFormatter( currency, options )( value );
};
return Globalize;
}));

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,120 @@
/**
* Globalize Runtime v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
"use strict";
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"../globalize-runtime"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory( require( "../globalize-runtime" ) );
} else {
// Extend global
factory( root.Globalize );
}
}(this, function( Globalize ) {
var runtimeKey = Globalize._runtimeKey,
validateParameterType = Globalize._validateParameterType;
/**
* Function inspired by jQuery Core, but reduced to our use case.
*/
var isPlainObject = function( obj ) {
return obj !== null && "" + obj === "[object Object]";
};
var validateParameterTypeMessageVariables = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || isPlainObject( value ) || Array.isArray( value ),
"Array or Plain Object"
);
};
var messageFormatterFn = function( formatter ) {
return function messageFormatter( variables ) {
if ( typeof variables === "number" || typeof variables === "string" ) {
variables = [].slice.call( arguments, 0 );
}
validateParameterTypeMessageVariables( variables, "variables" );
return formatter( variables );
};
};
Globalize._messageFormatterFn = messageFormatterFn;
/* eslint-disable */
Globalize._messageFormat = (function() {
var number = function(value, offset) {
if (isNaN(value)) throw new Error("'" + value + "' isn't a number.");
return value - (offset || 0);
};
var plural = function(value, offset, lcfunc, data, isOrdinal) {
if ({}.hasOwnProperty.call(data, value)) return data[value]();
if (offset) value -= offset;
var key = lcfunc(value, isOrdinal);
if (key in data) return data[key]();
return data.other();
};
var select = function(value, data) {
if ({}.hasOwnProperty.call(data, value)) return data[value]();
return data.other()
};
return {number: number, plural: plural, select: select};
}());
/* eslint-enable */
Globalize._validateParameterTypeMessageVariables = validateParameterTypeMessageVariables;
Globalize.messageFormatter =
Globalize.prototype.messageFormatter = function( /* path */ ) {
return Globalize[
runtimeKey( "messageFormatter", this._locale, [].slice.call( arguments, 0 ) )
];
};
Globalize.formatMessage =
Globalize.prototype.formatMessage = function( path /* , variables */ ) {
return this.messageFormatter( path ).apply( {}, [].slice.call( arguments, 1 ) );
};
return Globalize;
}));

View File

@@ -0,0 +1,919 @@
/**
* Globalize Runtime v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
"use strict";
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"../globalize-runtime"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory( require( "../globalize-runtime" ) );
} else {
// Extend global
factory( root.Globalize );
}
}(this, function( Globalize ) {
var createError = Globalize._createError,
partsJoin = Globalize._partsJoin,
partsPush = Globalize._partsPush,
regexpEscape = Globalize._regexpEscape,
runtimeKey = Globalize._runtimeKey,
stringPad = Globalize._stringPad,
validateParameterType = Globalize._validateParameterType,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterTypeString = Globalize._validateParameterTypeString;
var createErrorUnsupportedFeature = function( feature ) {
return createError( "E_UNSUPPORTED", "Unsupported {feature}.", {
feature: feature
});
};
var validateParameterTypeNumber = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || typeof value === "number",
"Number"
);
};
/**
* EBNF representation:
*
* compact_pattern_re = prefix?
* number_pattern_re
* suffix?
*
* number_pattern_re = 0+
*
* Regexp groups:
*
* 0: compact_pattern_re
* 1: prefix
* 2: number_pattern_re (the number pattern to use in compact mode)
* 3: suffix
*/
var numberCompactPatternRe = ( /^([^0]*)(0+)([^0]*)$/ );
/**
* goupingSeparator( number, primaryGroupingSize, secondaryGroupingSize )
*
* @number [Number].
*
* @primaryGroupingSize [Number]
*
* @secondaryGroupingSize [Number]
*
* Return the formatted number with group separator.
*/
var numberFormatGroupingSeparator = function( number, primaryGroupingSize, secondaryGroupingSize ) {
var index,
currentGroupingSize = primaryGroupingSize,
ret = "",
sep = ",",
switchToSecondary = secondaryGroupingSize ? true : false;
number = String( number ).split( "." );
index = number[ 0 ].length;
while ( index > currentGroupingSize ) {
ret = number[ 0 ].slice( index - currentGroupingSize, index ) +
( ret.length ? sep : "" ) + ret;
index -= currentGroupingSize;
if ( switchToSecondary ) {
currentGroupingSize = secondaryGroupingSize;
switchToSecondary = false;
}
}
number[ 0 ] = number[ 0 ].slice( 0, index ) + ( ret.length ? sep : "" ) + ret;
return number.join( "." );
};
/**
* integerFractionDigits( number, minimumIntegerDigits, minimumFractionDigits,
* maximumFractionDigits, round, roundIncrement )
*
* @number [Number]
*
* @minimumIntegerDigits [Number]
*
* @minimumFractionDigits [Number]
*
* @maximumFractionDigits [Number]
*
* @round [Function]
*
* @roundIncrement [Function]
*
* Return the formatted integer and fraction digits.
*/
var numberFormatIntegerFractionDigits = function( number, minimumIntegerDigits, minimumFractionDigits, maximumFractionDigits, round,
roundIncrement ) {
// Fraction
if ( maximumFractionDigits ) {
// Rounding
if ( roundIncrement ) {
number = round( number, roundIncrement );
// Maximum fraction digits
} else {
number = round( number, { exponent: -maximumFractionDigits } );
}
} else {
number = round( number );
}
number = String( number );
// Maximum integer digits (post string phase)
if ( maximumFractionDigits && /e-/.test( number ) ) {
// Use toFixed( maximumFractionDigits ) to make sure small numbers like 1e-7 are
// displayed using plain digits instead of scientific notation.
// 1: Remove leading decimal zeros.
// 2: Remove leading decimal separator.
// Note: String() is still preferred so it doesn't mess up with a number precision
// unnecessarily, e.g., (123456789.123).toFixed(10) === "123456789.1229999959",
// String(123456789.123) === "123456789.123".
number = ( +number ).toFixed( maximumFractionDigits )
.replace( /0+$/, "" ) /* 1 */
.replace( /\.$/, "" ); /* 2 */
}
// Minimum fraction digits (post string phase)
if ( minimumFractionDigits ) {
number = number.split( "." );
number[ 1 ] = stringPad( number[ 1 ] || "", minimumFractionDigits, true );
number = number.join( "." );
}
// Minimum integer digits
if ( minimumIntegerDigits ) {
number = number.split( "." );
number[ 0 ] = stringPad( number[ 0 ], minimumIntegerDigits );
number = number.join( "." );
}
return number;
};
/**
* toPrecision( number, precision, round )
*
* @number (Number)
*
* @precision (Number) significant figures precision (not decimal precision).
*
* @round (Function)
*
* Return number.toPrecision( precision ) using the given round function.
*/
var numberToPrecision = function( number, precision, round ) {
var roundOrder;
if ( number === 0 ) { // Fix #706
return number;
}
roundOrder = Math.ceil( Math.log( Math.abs( number ) ) / Math.log( 10 ) );
roundOrder -= precision;
return round( number, { exponent: roundOrder } );
};
/**
* toPrecision( number, minimumSignificantDigits, maximumSignificantDigits, round )
*
* @number [Number]
*
* @minimumSignificantDigits [Number]
*
* @maximumSignificantDigits [Number]
*
* @round [Function]
*
* Return the formatted significant digits number.
*/
var numberFormatSignificantDigits = function( number, minimumSignificantDigits, maximumSignificantDigits, round ) {
var atMinimum, atMaximum;
// Sanity check.
if ( minimumSignificantDigits > maximumSignificantDigits ) {
maximumSignificantDigits = minimumSignificantDigits;
}
atMinimum = numberToPrecision( number, minimumSignificantDigits, round );
atMaximum = numberToPrecision( number, maximumSignificantDigits, round );
// Use atMaximum only if it has more significant digits than atMinimum.
number = +atMinimum === +atMaximum ? atMinimum : atMaximum;
// Expand integer numbers, eg. 123e5 to 12300.
number = ( +number ).toString( 10 );
if ( ( /e/ ).test( number ) ) {
throw createErrorUnsupportedFeature({
feature: "integers out of (1e21, 1e-7)"
});
}
// Add trailing zeros if necessary.
if ( minimumSignificantDigits - number.replace( /^0+|\./g, "" ).length > 0 ) {
number = number.split( "." );
number[ 1 ] = stringPad( number[ 1 ] || "", minimumSignificantDigits - number[ 0 ].replace( /^0+/, "" ).length, true );
number = number.join( "." );
}
return number;
};
var numberSymbolName = {
".": "decimal",
",": "group",
"%": "percentSign",
"+": "plusSign",
"-": "minusSign",
"E": "exponential",
"\u2030": "perMille"
};
/**
* removeLiteralQuotes( string )
*
* Return:
* - `'` if input string is `''`.
* - `o'clock` if input string is `'o''clock'`.
* - `foo` if input string is `foo`, i.e., return the same value in case it isn't a single-quoted
* string.
*/
var removeLiteralQuotes = function( string ) {
if ( string[ 0 ] + string[ string.length - 1 ] !== "''" ) {
return string;
}
if ( string === "''" ) {
return "'";
}
return string.replace( /''/g, "'" ).slice( 1, -1 );
};
/**
* format( number, properties )
*
* @number [Number].
*
* @properties [Object] Output of number/format-properties.
*
* Return the formatted number.
* ref: http://www.unicode.org/reports/tr35/tr35-numbers.html
*/
var numberFormat = function( number, properties, pluralGenerator ) {
var aux, compactMap, infinitySymbol, maximumFractionDigits, maximumSignificantDigits,
minimumFractionDigits, minimumIntegerDigits, minimumSignificantDigits, nanSymbol,
nuDigitsMap, prefix, primaryGroupingSize, pattern, round, roundIncrement,
secondaryGroupingSize, stringToParts, suffix, symbolMap;
minimumIntegerDigits = properties[ 2 ];
minimumFractionDigits = properties[ 3 ];
maximumFractionDigits = properties[ 4 ];
minimumSignificantDigits = properties[ 5 ];
maximumSignificantDigits = properties[ 6 ];
roundIncrement = properties[ 7 ];
primaryGroupingSize = properties[ 8 ];
secondaryGroupingSize = properties[ 9 ];
round = properties[ 15 ];
infinitySymbol = properties[ 16 ];
nanSymbol = properties[ 17 ];
symbolMap = properties[ 18 ];
nuDigitsMap = properties[ 19 ];
compactMap = properties[ 20 ];
// NaN
if ( isNaN( number ) ) {
return [ { type: "nan", value: nanSymbol } ];
}
if ( number < 0 ) {
pattern = properties[ 12 ];
prefix = properties[ 13 ];
suffix = properties[ 14 ];
} else {
pattern = properties[ 11 ];
prefix = properties[ 0 ];
suffix = properties[ 10 ];
}
// For prefix, suffix, and number parts.
stringToParts = function( string ) {
var numberType = "integer",
parts = [];
// TODO Move the tokenization of all parts that don't depend on number into
// format-properties.
string.replace( /('([^']|'')+'|'')|./g, function( character, literal ) {
// Literals
if ( literal ) {
partsPush( parts, "literal", removeLiteralQuotes( literal ) );
return;
}
// Currency symbol
if ( character === "\u00A4" ) {
partsPush( parts, "currency", character );
return;
}
// Symbols
character = character.replace( /[.,\-+E%\u2030]/, function( symbol ) {
if ( symbol === "." ) {
numberType = "fraction";
}
partsPush( parts, numberSymbolName[ symbol ], symbolMap[ symbol ] );
// "Erase" handled character.
return "";
});
// Number
character = character.replace( /[0-9]/, function( digit ) {
// Numbering system
if ( nuDigitsMap ) {
digit = nuDigitsMap[ +digit ];
}
partsPush( parts, numberType, digit );
// "Erase" handled character.
return "";
});
// Etc
character.replace( /./, function( etc ) {
partsPush( parts, "literal", etc );
});
});
return parts;
};
prefix = stringToParts( prefix );
suffix = stringToParts( suffix );
// Infinity
if ( !isFinite( number ) ) {
return prefix.concat(
{ type: "infinity", value: infinitySymbol },
suffix
);
}
// Percent
if ( pattern.indexOf( "%" ) !== -1 ) {
number *= 100;
// Per mille
} else if ( pattern.indexOf( "\u2030" ) !== -1 ) {
number *= 1000;
}
var compactPattern, compactDigits, compactProperties, divisor, numberExponent, pluralForm;
// Compact mode: initial number digit processing
if ( compactMap ) {
numberExponent = Math.abs( Math.floor( number ) ).toString().length - 1;
numberExponent = Math.min( numberExponent, compactMap.maxExponent );
// Use default plural form to perform initial decimal shift
if ( numberExponent >= 3 ) {
compactPattern = compactMap[ numberExponent ] && compactMap[ numberExponent ].other;
}
if ( compactPattern === "0" ) {
compactPattern = null;
} else if ( compactPattern ) {
compactDigits = compactPattern.split( "0" ).length - 1;
divisor = numberExponent - ( compactDigits - 1 );
number = number / Math.pow( 10, divisor );
}
}
// Significant digit format
if ( !isNaN( minimumSignificantDigits * maximumSignificantDigits ) ) {
number = numberFormatSignificantDigits( number, minimumSignificantDigits,
maximumSignificantDigits, round );
// Integer and fractional format
} else {
number = numberFormatIntegerFractionDigits( number, minimumIntegerDigits,
minimumFractionDigits, maximumFractionDigits, round, roundIncrement );
}
// Compact mode: apply formatting
if ( compactMap && compactPattern ) {
// Get plural form after possible roundings
pluralForm = pluralGenerator ? pluralGenerator( +number ) : "other";
compactPattern = compactMap[ numberExponent ][ pluralForm ] || compactPattern;
compactProperties = compactPattern.match( numberCompactPatternRe );
// TODO Move the tokenization of all parts that don't depend on number into
// format-properties.
aux = function( string ) {
var parts = [];
string.replace( /(\s+)|([^\s0]+)/g, function( _garbage, space, compact ) {
// Literals
if ( space ) {
partsPush( parts, "literal", space );
return;
}
// Compact value
if ( compact ) {
partsPush( parts, "compact", compact );
return;
}
});
return parts;
};
// update prefix/suffix with compact prefix/suffix
prefix = prefix.concat( aux( compactProperties[ 1 ] ) );
suffix = aux( compactProperties[ 3 ] ).concat( suffix );
}
// Remove the possible number minus sign
number = number.replace( /^-/, "" );
// Grouping separators
if ( primaryGroupingSize ) {
number = numberFormatGroupingSeparator( number, primaryGroupingSize,
secondaryGroupingSize );
}
// Scientific notation
// TODO implement here
// Padding/'([^']|'')+'|''|[.,\-+E%\u2030]/g
// TODO implement here
return prefix.concat(
stringToParts( number ),
suffix
);
};
var numberFormatterFn = function( numberToPartsFormatter ) {
return function numberFormatter( value ) {
return partsJoin( numberToPartsFormatter( value ));
};
};
/**
* Generated by:
*
* var regenerate = require( "regenerate" );
* var formatSymbols = require( "@unicode/unicode-13.0.0/General_Category/Format/symbols" );
* regenerate().add( formatSymbols ).toString();
*
* https://github.com/mathiasbynens/regenerate
* https://github.com/node-unicode/unicode-13.0.0
*/
var regexpCfG = /[\xAD\u0600-\u0605\u061C\u06DD\u070F\u08E2\u180E\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u206F\uFEFF\uFFF9-\uFFFB]|\uD804[\uDCBD\uDCCD]|\uD80D[\uDC30-\uDC38]|\uD82F[\uDCA0-\uDCA3]|\uD834[\uDD73-\uDD7A]|\uDB40[\uDC01\uDC20-\uDC7F]/g;
/**
* Generated by:
*
* var regenerate = require( "regenerate" );
* var dashSymbols = require( "https://github.com/node-unicode/unicode-13.0.0/General_Category/Dash_Punctuation/symbols" );
* regenerate().add( dashSymbols ).toString();
*
* https://github.com/mathiasbynens/regenerate
* https://github.com/node-unicode/unicode-13.0.0
*
* NOTE: In addition to [:dash:], the below includes MINUS SIGN U+2212.
*/
var regexpDashG = /[\x2D\u058A\u05BE\u1400\u1806\u2010-\u2015\u2E17\u2E1A\u2E3A\u2E3B\u2E40\u301C\u3030\u30A0\uFE31\uFE32\uFE58\uFE63\uFF0D\u2212]|\uD803\uDEAD/g;
/**
* Generated by:
*
* var regenerate = require( "regenerate" );
* var spaceSeparatorSymbols = require( "@unicode/unicode-13.0.0/General_Category/Space_Separator/symbols" );
* regenerate().add( spaceSeparatorSymbols ).toString();
*
* https://github.com/mathiasbynens/regenerate
* https://github.com/node-unicode/unicode-13.0.0
*/
var regexpZsG = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/g;
/**
* Loose Matching:
* - Ignore all format characters, which includes RLM, LRM or ALM used to control BIDI
* formatting.
* - Map all characters in [:Zs:] to U+0020 SPACE;
* - Map all characters in [:Dash:] to U+002D HYPHEN-MINUS;
*/
var looseMatching = function( value ) {
return value
.replace( regexpCfG, "" )
.replace( regexpDashG, "-" )
.replace( regexpZsG, " " );
};
/**
* parse( value, properties )
*
* @value [String].
*
* @properties [Object] Parser properties is a reduced pre-processed cldr
* data set returned by numberParserProperties().
*
* Return the parsed Number (including Infinity) or NaN when value is invalid.
* ref: http://www.unicode.org/reports/tr35/tr35-numbers.html
*/
var numberParse = function( value, properties ) {
var grammar, invertedNuDigitsMap, invertedSymbolMap, negative, number, prefix, prefixNSuffix,
suffix, tokenizer, valid;
// Grammar:
// - Value <= NaN | PositiveNumber | NegativeNumber
// - PositiveNumber <= PositivePrefix NumberOrInf PositiveSufix
// - NegativeNumber <= NegativePrefix NumberOrInf
// - NumberOrInf <= Number | Inf
grammar = [
[ "nan" ],
[ "prefix", "infinity", "suffix" ],
[ "prefix", "number", "suffix" ],
[ "negativePrefix", "infinity", "negativeSuffix" ],
[ "negativePrefix", "number", "negativeSuffix" ]
];
invertedSymbolMap = properties[ 0 ];
invertedNuDigitsMap = properties[ 1 ] || {};
tokenizer = properties[ 2 ];
value = looseMatching( value );
function parse( type ) {
return function( lexeme ) {
// Reverse localized symbols and numbering system.
lexeme = lexeme.split( "" ).map(function( character ) {
return invertedSymbolMap[ character ] ||
invertedNuDigitsMap[ character ] ||
character;
}).join( "" );
switch ( type ) {
case "infinity":
number = Infinity;
break;
case "nan":
number = NaN;
break;
case "number":
// Remove grouping separators.
lexeme = lexeme.replace( /,/g, "" );
number = +lexeme;
break;
case "prefix":
case "negativePrefix":
prefix = lexeme;
break;
case "suffix":
suffix = lexeme;
break;
case "negativeSuffix":
suffix = lexeme;
negative = true;
break;
// This should never be reached.
default:
throw new Error( "Internal error" );
}
return "";
};
}
function tokenizeNParse( _value, grammar ) {
return grammar.some(function( statement ) {
var value = _value;
// The whole grammar statement should be used (i.e., .every() return true) and value be
// entirely consumed (i.e., !value.length).
return statement.every(function( type ) {
if ( value.match( tokenizer[ type ] ) === null ) {
return false;
}
// Consume and parse it.
value = value.replace( tokenizer[ type ], parse( type ) );
return true;
}) && !value.length;
});
}
valid = tokenizeNParse( value, grammar );
// NaN
if ( !valid || isNaN( number ) ) {
return NaN;
}
prefixNSuffix = "" + prefix + suffix;
// Percent
if ( prefixNSuffix.indexOf( "%" ) !== -1 ) {
number /= 100;
// Per mille
} else if ( prefixNSuffix.indexOf( "\u2030" ) !== -1 ) {
number /= 1000;
}
// Negative number
if ( negative ) {
number *= -1;
}
return number;
};
var numberParserFn = function( properties ) {
return function numberParser( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeString( value, "value" );
return numberParse( value, properties );
};
};
var numberToPartsFormatterFn = function( properties, pluralGenerator ) {
return function numberToPartsFormatter( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return numberFormat( value, properties, pluralGenerator );
};
};
var numberTruncate = function( value ) {
if ( isNaN( value ) ) {
return NaN;
}
return Math[ value < 0 ? "ceil" : "floor" ]( value );
};
/**
* round( method )
*
* @method [String] with either "round", "ceil", "floor", or "truncate".
*
* Return function( value, incrementOrExp ):
*
* @value [Number] eg. 123.45.
*
* @incrementOrExp [Number] optional, eg. 0.1; or
* [Object] Either { increment: <value> } or { exponent: <value> }
*
* Return the rounded number, eg:
* - round( "round" )( 123.45 ): 123;
* - round( "ceil" )( 123.45 ): 124;
* - round( "floor" )( 123.45 ): 123;
* - round( "truncate" )( 123.45 ): 123;
* - round( "round" )( 123.45, 0.1 ): 123.5;
* - round( "round" )( 123.45, 10 ): 120;
*
* Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
* Ref: #376
*/
var numberRound = function( method ) {
method = method || "round";
method = method === "truncate" ? numberTruncate : Math[ method ];
return function( value, incrementOrExp ) {
var exp, increment;
value = +value;
// If the value is not a number, return NaN.
if ( isNaN( value ) ) {
return NaN;
}
// Exponent given.
if ( typeof incrementOrExp === "object" && incrementOrExp.exponent ) {
exp = +incrementOrExp.exponent;
increment = 1;
if ( exp === 0 ) {
return method( value );
}
// If the exp is not an integer, return NaN.
if ( !( typeof exp === "number" && exp % 1 === 0 ) ) {
return NaN;
}
// Increment given.
} else {
increment = +incrementOrExp || 1;
if ( increment === 1 ) {
return method( value );
}
// If the increment is not a number, return NaN.
if ( isNaN( increment ) ) {
return NaN;
}
increment = increment.toExponential().split( "e" );
exp = +increment[ 1 ];
increment = +increment[ 0 ];
}
// Shift & Round
value = value.toString().split( "e" );
value[ 0 ] = +value[ 0 ] / increment;
value[ 1 ] = value[ 1 ] ? ( +value[ 1 ] - exp ) : -exp;
value = method( +( value[ 0 ] + "e" + value[ 1 ] ) );
// Shift back
value = value.toString().split( "e" );
value[ 0 ] = +value[ 0 ] * increment;
value[ 1 ] = value[ 1 ] ? ( +value[ 1 ] + exp ) : exp;
return +( value[ 0 ] + "e" + value[ 1 ] );
};
};
Globalize._createErrorUnsupportedFeature = createErrorUnsupportedFeature;
Globalize._looseMatching = looseMatching;
Globalize._numberFormat = numberFormat;
Globalize._numberFormatterFn = numberFormatterFn;
Globalize._numberParse = numberParse;
Globalize._numberParserFn = numberParserFn;
Globalize._numberRound = numberRound;
Globalize._numberToPartsFormatterFn = numberToPartsFormatterFn;
Globalize._removeLiteralQuotes = removeLiteralQuotes;
Globalize._validateParameterPresence = validateParameterPresence;
Globalize._validateParameterTypeNumber = validateParameterTypeNumber;
Globalize._validateParameterTypeString = validateParameterTypeString;
// Stamp runtimeKey and return cached fn.
// Note, this function isn't made common to all formatters and parsers, because in practice this is
// only used (at the moment) for numberFormatter used by unitFormatter.
// TODO: Move this function into a common place when this is used by different formatters.
function cached( runtimeKey ) {
Globalize[ runtimeKey ].runtimeKey = runtimeKey;
return Globalize[ runtimeKey ];
}
Globalize.numberFormatter =
Globalize.prototype.numberFormatter = function( options ) {
options = options || {};
return cached( runtimeKey( "numberFormatter", this._locale, [ options ] ) );
};
Globalize.numberToPartsFormatter =
Globalize.prototype.numberToPartsFormatter = function( options ) {
options = options || {};
return cached( runtimeKey( "numberToPartsFormatter", this._locale, [ options ] ) );
};
Globalize.numberParser =
Globalize.prototype.numberParser = function( options ) {
options = options || {};
return Globalize[ runtimeKey( "numberParser", this._locale, [ options ] ) ];
};
Globalize.formatNumber =
Globalize.prototype.formatNumber = function( value, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.numberFormatter( options )( value );
};
Globalize.formatNumberToParts =
Globalize.prototype.formatNumberToParts = function( value, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.numberFormatter( options )( value );
};
Globalize.parseNumber =
Globalize.prototype.parseNumber = function( value, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeString( value, "value" );
return this.numberParser( options )( value );
};
return Globalize;
}));

View File

@@ -0,0 +1,90 @@
/**
* Globalize Runtime v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
"use strict";
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"../globalize-runtime"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory( require( "../globalize-runtime" ) );
} else {
// Extend global
factory( root.Globalize );
}
}(this, function( Globalize ) {
var runtimeKey = Globalize._runtimeKey,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterType = Globalize._validateParameterType;
var validateParameterTypeNumber = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || typeof value === "number",
"Number"
);
};
var pluralGeneratorFn = function( plural ) {
return function pluralGenerator( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return plural( value );
};
};
Globalize._pluralGeneratorFn = pluralGeneratorFn;
Globalize._validateParameterTypeNumber = validateParameterTypeNumber;
Globalize.plural =
Globalize.prototype.plural = function( value, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.pluralGenerator( options )( value );
};
Globalize.pluralGenerator =
Globalize.prototype.pluralGenerator = function( options ) {
options = options || {};
return Globalize[ runtimeKey( "pluralGenerator", this._locale, [ options ] ) ];
};
return Globalize;
}));

View File

@@ -0,0 +1,120 @@
/**
* Globalize Runtime v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
"use strict";
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"../globalize-runtime",
"./number",
"./plural"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory(
require( "../globalize-runtime" ),
require( "./number" ),
require( "./plural" )
);
} else {
// Extend global
factory( root.Globalize );
}
}(this, function( Globalize ) {
var formatMessage = Globalize._formatMessage,
runtimeKey = Globalize._runtimeKey,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterTypeNumber = Globalize._validateParameterTypeNumber;
/**
* format( value, numberFormatter, pluralGenerator, properties )
*
* @value [Number] The number to format
*
* @numberFormatter [String] A numberFormatter from Globalize.numberFormatter
*
* @pluralGenerator [String] A pluralGenerator from Globalize.pluralGenerator
*
* @properties [Object] containing relative time plural message.
*
* Format relative time.
*/
var relativeTimeFormat = function( value, numberFormatter, pluralGenerator, properties ) {
var relativeTime,
message = properties[ "relative-type-" + value ];
if ( message ) {
return message;
}
relativeTime = value <= 0 ? properties[ "relativeTime-type-past" ] :
properties[ "relativeTime-type-future" ];
value = Math.abs( value );
message = relativeTime[ "relativeTimePattern-count-" + pluralGenerator( value ) ];
return formatMessage( message, [ numberFormatter( value ) ] );
};
var relativeTimeFormatterFn = function( numberFormatter, pluralGenerator, properties ) {
return function relativeTimeFormatter( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return relativeTimeFormat( value, numberFormatter, pluralGenerator, properties );
};
};
Globalize._relativeTimeFormatterFn = relativeTimeFormatterFn;
Globalize.formatRelativeTime =
Globalize.prototype.formatRelativeTime = function( value, unit, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.relativeTimeFormatter( unit, options )( value );
};
Globalize.relativeTimeFormatter =
Globalize.prototype.relativeTimeFormatter = function( unit, options ) {
options = options || {};
return Globalize[ runtimeKey( "relativeTimeFormatter", this._locale, [ unit, options ] ) ];
};
return Globalize;
}));

View File

@@ -0,0 +1,132 @@
/**
* Globalize Runtime v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize Runtime v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
"use strict";
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"../globalize-runtime",
"./number",
"./plural"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory(
require( "../globalize-runtime" ),
require( "./number" ),
require( "./plural" )
);
} else {
// Extend global
factory( root.Globalize );
}
}(this, function( Globalize ) {
var formatMessage = Globalize._formatMessage,
runtimeKey = Globalize._runtimeKey,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterTypeNumber = Globalize._validateParameterTypeNumber;
/**
* format( value, numberFormatter, pluralGenerator, unitProperies )
*
* @value [Number]
*
* @numberFormatter [Object]: A numberFormatter from Globalize.numberFormatter.
*
* @pluralGenerator [Object]: A pluralGenerator from Globalize.pluralGenerator.
*
* @unitProperies [Object]: localized unit data from cldr.
*
* Format units such as seconds, minutes, days, weeks, etc.
*
* OBS:
*
* Unit Sequences are not implemented.
* http://www.unicode.org/reports/tr35/tr35-35/tr35-general.html#Unit_Sequences
*
* Duration Unit (for composed time unit durations) is not implemented.
* http://www.unicode.org/reports/tr35/tr35-35/tr35-general.html#durationUnit
*/
var unitFormat = function( value, numberFormatter, pluralGenerator, unitProperties ) {
var compoundUnitPattern = unitProperties.compoundUnitPattern, dividend, dividendProperties,
formattedValue, divisor, divisorProperties, message, pluralValue, oneProperty;
unitProperties = unitProperties.unitProperties;
formattedValue = numberFormatter( value );
pluralValue = pluralGenerator( value );
// computed compound unit, eg. "megabyte-per-second".
if ( unitProperties instanceof Array ) {
dividendProperties = unitProperties[ 0 ];
divisorProperties = unitProperties[ 1 ];
oneProperty = divisorProperties.hasOwnProperty( "one" ) ? "one" : "other";
dividend = formatMessage( dividendProperties[ pluralValue ], [ formattedValue ] );
divisor = formatMessage( divisorProperties[ oneProperty ], [ "" ] ).trim();
return formatMessage( compoundUnitPattern, [ dividend, divisor ] );
}
message = unitProperties[ pluralValue ];
return formatMessage( message, [ formattedValue ] );
};
var unitFormatterFn = function( numberFormatter, pluralGenerator, unitProperties ) {
return function unitFormatter( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return unitFormat( value, numberFormatter, pluralGenerator, unitProperties );
};
};
Globalize._unitFormatterFn = unitFormatterFn;
Globalize.formatUnit =
Globalize.prototype.formatUnit = function( value, unit, options ) {
return this.unitFormatter( unit, options )( value );
};
Globalize.unitFormatter =
Globalize.prototype.unitFormatter = function( unit, options ) {
options = options || {};
return Globalize[ runtimeKey( "unitFormatter", this._locale, [ unit, options ] ) ];
};
return Globalize;
}));

View File

@@ -0,0 +1,507 @@
/**
* Globalize v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"cldr",
"cldr/event"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory( require( "cldrjs" ) );
} else {
// Global
root.Globalize = factory( root.Cldr );
}
}( this, function( Cldr ) {
/**
* A toString method that outputs meaningful values for objects or arrays and
* still performs as fast as a plain string in case variable is string, or as
* fast as `"" + number` in case variable is a number.
* Ref: http://jsperf.com/my-stringify
*/
var toString = function( variable ) {
return typeof variable === "string" ? variable : ( typeof variable === "number" ? "" +
variable : JSON.stringify( variable ) );
};
/**
* formatMessage( message, data )
*
* @message [String] A message with optional {vars} to be replaced.
*
* @data [Array or JSON] Object with replacing-variables content.
*
* Return the formatted message. For example:
*
* - formatMessage( "{0} second", [ 1 ] ); // 1 second
*
* - formatMessage( "{0}/{1}", ["m", "s"] ); // m/s
*
* - formatMessage( "{name} <{email}>", {
* name: "Foo",
* email: "bar@baz.qux"
* }); // Foo <bar@baz.qux>
*/
var formatMessage = function( message, data ) {
// Replace {attribute}'s
message = message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( name ) {
name = name.replace( /^{([^}]*)}$/, "$1" );
return toString( data[ name ] );
});
return message;
};
var objectExtend = function() {
var destination = arguments[ 0 ],
sources = [].slice.call( arguments, 1 );
sources.forEach(function( source ) {
var prop;
for ( prop in source ) {
destination[ prop ] = source[ prop ];
}
});
return destination;
};
var createError = function( code, message, attributes ) {
var error;
message = code + ( message ? ": " + formatMessage( message, attributes ) : "" );
error = new Error( message );
error.code = code;
objectExtend( error, attributes );
return error;
};
/**
* Pushes part to parts array, concat two consecutive parts of the same type.
*/
var partsPush = function( parts, type, value ) {
// Concat two consecutive parts of same type
if ( parts.length && parts[ parts.length - 1 ].type === type ) {
parts[ parts.length - 1 ].value += value;
return;
}
parts.push( { type: type, value: value } );
};
/**
* formatMessage( message, data )
*
* @message [String] A message with optional {vars} to be replaced.
*
* @data [Array or JSON] Object with replacing-variables content.
*
* Return the formatted message. For example:
*
* - formatMessage( "{0} second", [ 1 ] );
* > [{type: "variable", value: "1", name: "0"}, {type: "literal", value: " second"}]
*
* - formatMessage( "{0}/{1}", ["m", "s"] );
* > [
* { type: "variable", value: "m", name: "0" },
* { type: "literal", value: " /" },
* { type: "variable", value: "s", name: "1" }
* ]
*/
var formatMessageToParts = function( message, data ) {
var lastOffset = 0,
parts = [];
// Create parts.
message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( nameIncludingBrackets, offset ) {
var name = nameIncludingBrackets.slice( 1, -1 );
partsPush( parts, "literal", message.slice( lastOffset, offset ));
partsPush( parts, "variable", data[ name ] );
parts[ parts.length - 1 ].name = name;
lastOffset += offset + nameIncludingBrackets.length;
});
// Skip empty ones such as `{ type: 'literal', value: '' }`.
return parts.filter(function( part ) {
return part.value !== "";
});
};
/**
* Returns joined parts values.
*/
var partsJoin = function( parts ) {
return parts.map( function( part ) {
return part.value;
}).join( "" );
};
var runtimeStringify = function( args ) {
return JSON.stringify( args, function( _key, value ) {
if ( value && value.runtimeKey ) {
return value.runtimeKey;
}
return value;
} );
};
// Based on http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
var stringHash = function( str ) {
return [].reduce.call( str, function( hash, i ) {
var chr = i.charCodeAt( 0 );
hash = ( ( hash << 5 ) - hash ) + chr;
return hash | 0;
}, 0 );
};
var runtimeKey = function( fnName, locale, args, argsStr ) {
var hash;
argsStr = argsStr || runtimeStringify( args );
hash = stringHash( fnName + locale + argsStr );
return hash > 0 ? "a" + hash : "b" + Math.abs( hash );
};
var functionName = function( fn ) {
if ( fn.name !== undefined ) {
return fn.name;
}
// fn.name is not supported by IE.
var matches = /^function\s+([\w\$]+)\s*\(/.exec( fn.toString() );
if ( matches && matches.length > 0 ) {
return matches[ 1 ];
}
};
var runtimeBind = function( args, cldr, fn, runtimeArgs ) {
var argsStr = runtimeStringify( args ),
fnName = functionName( fn ),
locale = cldr.locale;
// If name of the function is not available, this is most likely due to uglification,
// which most likely means we are in production, and runtimeBind here is not necessary.
if ( !fnName ) {
return fn;
}
fn.runtimeKey = runtimeKey( fnName, locale, null, argsStr );
fn.generatorString = function() {
return "Globalize(\"" + locale + "\")." + fnName + "(" + argsStr.slice( 1, -1 ) + ")";
};
fn.runtimeArgs = runtimeArgs;
return fn;
};
var validate = function( code, message, check, attributes ) {
if ( !check ) {
throw createError( code, message, attributes );
}
};
var alwaysArray = function( stringOrArray ) {
return Array.isArray( stringOrArray ) ? stringOrArray : stringOrArray ? [ stringOrArray ] : [];
};
var validateCldr = function( path, value, options ) {
var skipBoolean;
options = options || {};
skipBoolean = alwaysArray( options.skip ).some(function( pathRe ) {
return pathRe.test( path );
});
validate( "E_MISSING_CLDR", "Missing required CLDR content `{path}`.", value || skipBoolean, {
path: path
});
};
var validateDefaultLocale = function( value ) {
validate( "E_DEFAULT_LOCALE_NOT_DEFINED", "Default locale has not been defined.",
value !== undefined, {} );
};
var validateParameterPresence = function( value, name ) {
validate( "E_MISSING_PARAMETER", "Missing required parameter `{name}`.",
value !== undefined, { name: name });
};
/**
* range( value, name, minimum, maximum )
*
* @value [Number].
*
* @name [String] name of variable.
*
* @minimum [Number]. The lowest valid value, inclusive.
*
* @maximum [Number]. The greatest valid value, inclusive.
*/
var validateParameterRange = function( value, name, minimum, maximum ) {
validate(
"E_PAR_OUT_OF_RANGE",
"Parameter `{name}` has value `{value}` out of range [{minimum}, {maximum}].",
value === undefined || value >= minimum && value <= maximum,
{
maximum: maximum,
minimum: minimum,
name: name,
value: value
}
);
};
var validateParameterType = function( value, name, check, expected ) {
validate(
"E_INVALID_PAR_TYPE",
"Invalid `{name}` parameter ({value}). {expected} expected.",
check,
{
expected: expected,
name: name,
value: value
}
);
};
var validateParameterTypeLocale = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || typeof value === "string" || value instanceof Cldr,
"String or Cldr instance"
);
};
/**
* Function inspired by jQuery Core, but reduced to our use case.
*/
var isPlainObject = function( obj ) {
return obj !== null && "" + obj === "[object Object]";
};
var validateParameterTypePlainObject = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || isPlainObject( value ),
"Plain Object"
);
};
var alwaysCldr = function( localeOrCldr ) {
return localeOrCldr instanceof Cldr ? localeOrCldr : new Cldr( localeOrCldr );
};
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions?redirectlocale=en-US&redirectslug=JavaScript%2FGuide%2FRegular_Expressions
var regexpEscape = function( string ) {
return string.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1" );
};
var stringPad = function( str, count, right ) {
var length;
if ( typeof str !== "string" ) {
str = String( str );
}
for ( length = str.length; length < count; length += 1 ) {
str = ( right ? ( str + "0" ) : ( "0" + str ) );
}
return str;
};
function validateLikelySubtags( cldr ) {
cldr.once( "get", validateCldr );
cldr.get( "supplemental/likelySubtags" );
}
/**
* [new] Globalize( locale|cldr )
*
* @locale [String]
*
* @cldr [Cldr instance]
*
* Create a Globalize instance.
*/
function Globalize( locale ) {
if ( !( this instanceof Globalize ) ) {
return new Globalize( locale );
}
validateParameterPresence( locale, "locale" );
validateParameterTypeLocale( locale, "locale" );
this.cldr = alwaysCldr( locale );
validateLikelySubtags( this.cldr );
}
/**
* Globalize.load( json, ... )
*
* @json [JSON]
*
* Load resolved or unresolved cldr data.
* Somewhat equivalent to previous Globalize.addCultureInfo(...).
*/
Globalize.load = function() {
// validations are delegated to Cldr.load().
Cldr.load.apply( Cldr, arguments );
};
/**
* Globalize.locale( [locale|cldr] )
*
* @locale [String]
*
* @cldr [Cldr instance]
*
* Set default Cldr instance if locale or cldr argument is passed.
*
* Return the default Cldr instance.
*/
Globalize.locale = function( locale ) {
validateParameterTypeLocale( locale, "locale" );
if ( arguments.length ) {
this.cldr = alwaysCldr( locale );
validateLikelySubtags( this.cldr );
}
return this.cldr;
};
/**
* Optimization to avoid duplicating some internal functions across modules.
*/
Globalize._alwaysArray = alwaysArray;
Globalize._createError = createError;
Globalize._formatMessage = formatMessage;
Globalize._formatMessageToParts = formatMessageToParts;
Globalize._isPlainObject = isPlainObject;
Globalize._objectExtend = objectExtend;
Globalize._partsJoin = partsJoin;
Globalize._partsPush = partsPush;
Globalize._regexpEscape = regexpEscape;
Globalize._runtimeBind = runtimeBind;
Globalize._stringPad = stringPad;
Globalize._validate = validate;
Globalize._validateCldr = validateCldr;
Globalize._validateDefaultLocale = validateDefaultLocale;
Globalize._validateParameterPresence = validateParameterPresence;
Globalize._validateParameterRange = validateParameterRange;
Globalize._validateParameterTypePlainObject = validateParameterTypePlainObject;
Globalize._validateParameterType = validateParameterType;
return Globalize;
}));

View File

@@ -0,0 +1,590 @@
/*!
* Globalize v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
(function( root, factory ) {
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"cldr",
"../globalize",
"./number",
"cldr/event",
"cldr/supplemental"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory( require( "cldrjs" ), require( "../globalize" ) );
} else {
// Global
factory( root.Cldr, root.Globalize );
}
}(this, function( Cldr, Globalize ) {
var alwaysArray = Globalize._alwaysArray,
createError = Globalize._createError,
formatMessageToParts = Globalize._formatMessageToParts,
numberNumberingSystem = Globalize._numberNumberingSystem,
numberPattern = Globalize._numberPattern,
partsJoin = Globalize._partsJoin,
partsPush = Globalize._partsPush,
runtimeBind = Globalize._runtimeBind,
stringPad = Globalize._stringPad,
validateCldr = Globalize._validateCldr,
validateDefaultLocale = Globalize._validateDefaultLocale,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterType = Globalize._validateParameterType,
validateParameterTypeNumber = Globalize._validateParameterTypeNumber,
validateParameterTypePlainObject = Globalize._validateParameterTypePlainObject;
var createErrorPluralModulePresence = function() {
return createError( "E_MISSING_PLURAL_MODULE", "Plural module not loaded." );
};
var validateParameterTypeCurrency = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || typeof value === "string" && ( /^[A-Za-z]{3}$/ ).test( value ),
"3-letter currency code string as defined by ISO 4217"
);
};
var currencyFormatterFn = function( currencyToPartsFormatter ) {
return function currencyFormatter( value ) {
return partsJoin( currencyToPartsFormatter( value ));
};
};
/**
* supplementalOverride( currency, pattern, cldr )
*
* Return pattern with fraction digits overriden by supplemental currency data.
*/
var currencySupplementalOverride = function( currency, pattern, cldr ) {
var digits,
fraction = "",
fractionData = cldr.supplemental([ "currencyData/fractions", currency ]) ||
cldr.supplemental( "currencyData/fractions/DEFAULT" );
digits = +fractionData._digits;
if ( digits ) {
fraction = "." + stringPad( "0", digits ).slice( 0, -1 ) + fractionData._rounding;
}
return pattern.replace( /\.(#+|0*[0-9]|0+[0-9]?)/g, fraction );
};
var objectFilter = function( object, testRe ) {
var key,
copy = {};
for ( key in object ) {
if ( testRe.test( key ) ) {
copy[ key ] = object[ key ];
}
}
return copy;
};
var currencyUnitPatterns = function( cldr ) {
return objectFilter( cldr.main([
"numbers",
"currencyFormats-numberSystem-" + numberNumberingSystem( cldr )
]), /^unitPattern/ );
};
/**
* nameProperties( currency, cldr )
*
* Return number pattern with the appropriate currency code in as literal.
*/
var currencyNameProperties = function( currency, cldr ) {
var pattern = numberPattern( "decimal", cldr );
// The number of decimal places and the rounding for each currency is not locale-specific. Those
// values overridden by Supplemental Currency Data.
pattern = currencySupplementalOverride( currency, pattern, cldr );
return {
displayNames: objectFilter( cldr.main([
"numbers/currencies",
currency
]), /^displayName/ ),
pattern: pattern,
unitPatterns: currencyUnitPatterns( cldr )
};
};
/**
* Unicode regular expression for: everything except symbols from the category S
*
* Generated by:
*
* var s = regenerate()
* .addRange( 0x0, 0x10FFFF )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Math_Symbol/symbols" ) )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Currency_Symbol/symbols" ) )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Modifier_Symbol/symbols" ) )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Other_Symbol/symbols" ) )
*
* https://github.com/mathiasbynens/regenerate
* https://github.com/node-unicode/unicode-13.0.0
* http://www.unicode.org/reports/tr44/#General_Category_Values
*/
var regexpNotS = /[\0-#%-\*,-;\?-\]_a-\{\}\x7F-\xA1\xA7\xAA\xAB\xAD\xB2\xB3\xB5-\xB7\xB9-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376-\u0383\u0386-\u03F5\u03F7-\u0481\u0483-\u058C\u0590-\u0605\u0609\u060A\u060C\u060D\u0610-\u06DD\u06DF-\u06E8\u06EA-\u06FC\u06FF-\u07F5\u07F7-\u07FD\u0800-\u09F1\u09F4-\u09F9\u09FC-\u0AF0\u0AF2-\u0B6F\u0B71-\u0BF2\u0BFB-\u0C7E\u0C80-\u0D4E\u0D50-\u0D78\u0D7A-\u0E3E\u0E40-\u0F00\u0F04-\u0F12\u0F14\u0F18\u0F19\u0F20-\u0F33\u0F35\u0F37\u0F39-\u0FBD\u0FC6\u0FCD\u0FD0-\u0FD4\u0FD9-\u109D\u10A0-\u138F\u139A-\u166C\u166E-\u17DA\u17DC-\u193F\u1941-\u19DD\u1A00-\u1B60\u1B6B-\u1B73\u1B7D-\u1FBC\u1FBE\u1FC2-\u1FCC\u1FD0-\u1FDC\u1FE0-\u1FEC\u1FF0-\u1FFC\u1FFF-\u2043\u2045-\u2051\u2053-\u2079\u207D-\u2089\u208D-\u209F\u20C0-\u20FF\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u218C-\u218F\u2308-\u230B\u2329\u232A\u2427-\u243F\u244B-\u249B\u24EA-\u24FF\u2768-\u2793\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2B74\u2B75\u2B96\u2C00-\u2CE4\u2CEB-\u2E4F\u2E52-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u3003\u3005-\u3011\u3014-\u301F\u3021-\u3035\u3038-\u303D\u3040-\u309A\u309D-\u318F\u3192-\u3195\u31A0-\u31BF\u31E4-\u31FF\u321F-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48F\uA4C7-\uA6FF\uA717-\uA71F\uA722-\uA788\uA78B-\uA827\uA82C-\uA835\uA83A-\uAA76\uAA7A-\uAB5A\uAB5C-\uAB69\uAB6C-\uD7FF\uE000-\uFB28\uFB2A-\uFBB1\uFBC2-\uFDFB\uFDFE-\uFE61\uFE63\uFE67\uFE68\uFE6A-\uFF03\uFF05-\uFF0A\uFF0C-\uFF1B\uFF1F-\uFF3D\uFF3F\uFF41-\uFF5B\uFF5D\uFF5F-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF]|\uD800[\uDC00-\uDD36\uDD40-\uDD78\uDD8A\uDD8B\uDD8F\uDD9D-\uDD9F\uDDA1-\uDDCF\uDDFD-\uDFFF]|[\uD801\uD803\uD804\uD806\uD808-\uD819\uD81B-\uD82E\uD830-\uD833\uD837\uD839\uD83A\uD83F-\uDBFF][\uDC00-\uDFFF]|\uD802[\uDC00-\uDC76\uDC79-\uDEC7\uDEC9-\uDFFF]|\uD805[\uDC00-\uDF3E\uDF40-\uDFFF]|\uD807[\uDC00-\uDFD4\uDFF2-\uDFFF]|\uD81A[\uDC00-\uDF3B\uDF40-\uDF44\uDF46-\uDFFF]|\uD82F[\uDC00-\uDC9B\uDC9D-\uDFFF]|\uD834[\uDCF6-\uDCFF\uDD27\uDD28\uDD65-\uDD69\uDD6D-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDDE9-\uDDFF\uDE42-\uDE44\uDE46-\uDEFF\uDF57-\uDFFF]|\uD835[\uDC00-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE87-\uDFFF]|\uD838[\uDC00-\uDD4E\uDD50-\uDEFE\uDF00-\uDFFF]|\uD83B[\uDC00-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDD2D\uDD2F-\uDEEF\uDEF2-\uDFFF]|\uD83C[\uDC2C-\uDC2F\uDC94-\uDC9F\uDCAF\uDCB0\uDCC0\uDCD0\uDCF6-\uDD0C\uDDAE-\uDDE5\uDE03-\uDE0F\uDE3C-\uDE3F\uDE49-\uDE4F\uDE52-\uDE5F\uDE66-\uDEFF]|\uD83D[\uDED8-\uDEDF\uDEED-\uDEEF\uDEFD-\uDEFF\uDF74-\uDF7F\uDFD9-\uDFDF\uDFEC-\uDFFF]|\uD83E[\uDC0C-\uDC0F\uDC48-\uDC4F\uDC5A-\uDC5F\uDC88-\uDC8F\uDCAE\uDCAF\uDCB2-\uDCFF\uDD79\uDDCC\uDE54-\uDE5F\uDE6E\uDE6F\uDE75-\uDE77\uDE7B-\uDE7F\uDE87-\uDE8F\uDEA9-\uDEAF\uDEB7-\uDEBF\uDEC3-\uDECF\uDED7-\uDEFF\uDF93\uDFCB-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
/**
* Unicode regular expression for: everything except symbols from categories S and Z
*
* Generated by:
*
* var s = regenerate()
* .addRange( 0x0, 0x10FFFF )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Math_Symbol/symbols" ) )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Currency_Symbol/symbols" ) )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Modifier_Symbol/symbols" ) )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Other_Symbol/symbols" ) )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Space_Separator/symbols" ) )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Line_Separator/symbols" ) )
* .remove( require( "@unicode/unicode-13.0.0/General_Category/Paragraph_Separator/symbols" ) );
*
* https://github.com/mathiasbynens/regenerate
* https://github.com/node-unicode/unicode-13.0.0
* http://www.unicode.org/reports/tr44/#General_Category_Values
*/
var regexpNotSAndZ = /[\0-\x1F!-#%-\*,-;\?-\]_a-\{\}\x7F-\x9F\xA1\xA7\xAA\xAB\xAD\xB2\xB3\xB5-\xB7\xB9-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376-\u0383\u0386-\u03F5\u03F7-\u0481\u0483-\u058C\u0590-\u0605\u0609\u060A\u060C\u060D\u0610-\u06DD\u06DF-\u06E8\u06EA-\u06FC\u06FF-\u07F5\u07F7-\u07FD\u0800-\u09F1\u09F4-\u09F9\u09FC-\u0AF0\u0AF2-\u0B6F\u0B71-\u0BF2\u0BFB-\u0C7E\u0C80-\u0D4E\u0D50-\u0D78\u0D7A-\u0E3E\u0E40-\u0F00\u0F04-\u0F12\u0F14\u0F18\u0F19\u0F20-\u0F33\u0F35\u0F37\u0F39-\u0FBD\u0FC6\u0FCD\u0FD0-\u0FD4\u0FD9-\u109D\u10A0-\u138F\u139A-\u166C\u166E-\u167F\u1681-\u17DA\u17DC-\u193F\u1941-\u19DD\u1A00-\u1B60\u1B6B-\u1B73\u1B7D-\u1FBC\u1FBE\u1FC2-\u1FCC\u1FD0-\u1FDC\u1FE0-\u1FEC\u1FF0-\u1FFC\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u2043\u2045-\u2051\u2053-\u205E\u2060-\u2079\u207D-\u2089\u208D-\u209F\u20C0-\u20FF\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u218C-\u218F\u2308-\u230B\u2329\u232A\u2427-\u243F\u244B-\u249B\u24EA-\u24FF\u2768-\u2793\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2B74\u2B75\u2B96\u2C00-\u2CE4\u2CEB-\u2E4F\u2E52-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u2FFF\u3001-\u3003\u3005-\u3011\u3014-\u301F\u3021-\u3035\u3038-\u303D\u3040-\u309A\u309D-\u318F\u3192-\u3195\u31A0-\u31BF\u31E4-\u31FF\u321F-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48F\uA4C7-\uA6FF\uA717-\uA71F\uA722-\uA788\uA78B-\uA827\uA82C-\uA835\uA83A-\uAA76\uAA7A-\uAB5A\uAB5C-\uAB69\uAB6C-\uD7FF\uE000-\uFB28\uFB2A-\uFBB1\uFBC2-\uFDFB\uFDFE-\uFE61\uFE63\uFE67\uFE68\uFE6A-\uFF03\uFF05-\uFF0A\uFF0C-\uFF1B\uFF1F-\uFF3D\uFF3F\uFF41-\uFF5B\uFF5D\uFF5F-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF]|\uD800[\uDC00-\uDD36\uDD40-\uDD78\uDD8A\uDD8B\uDD8F\uDD9D-\uDD9F\uDDA1-\uDDCF\uDDFD-\uDFFF]|[\uD801\uD803\uD804\uD806\uD808-\uD819\uD81B-\uD82E\uD830-\uD833\uD837\uD839\uD83A\uD83F-\uDBFF][\uDC00-\uDFFF]|\uD802[\uDC00-\uDC76\uDC79-\uDEC7\uDEC9-\uDFFF]|\uD805[\uDC00-\uDF3E\uDF40-\uDFFF]|\uD807[\uDC00-\uDFD4\uDFF2-\uDFFF]|\uD81A[\uDC00-\uDF3B\uDF40-\uDF44\uDF46-\uDFFF]|\uD82F[\uDC00-\uDC9B\uDC9D-\uDFFF]|\uD834[\uDCF6-\uDCFF\uDD27\uDD28\uDD65-\uDD69\uDD6D-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDDE9-\uDDFF\uDE42-\uDE44\uDE46-\uDEFF\uDF57-\uDFFF]|\uD835[\uDC00-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE87-\uDFFF]|\uD838[\uDC00-\uDD4E\uDD50-\uDEFE\uDF00-\uDFFF]|\uD83B[\uDC00-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDD2D\uDD2F-\uDEEF\uDEF2-\uDFFF]|\uD83C[\uDC2C-\uDC2F\uDC94-\uDC9F\uDCAF\uDCB0\uDCC0\uDCD0\uDCF6-\uDD0C\uDDAE-\uDDE5\uDE03-\uDE0F\uDE3C-\uDE3F\uDE49-\uDE4F\uDE52-\uDE5F\uDE66-\uDEFF]|\uD83D[\uDED8-\uDEDF\uDEED-\uDEEF\uDEFD-\uDEFF\uDF74-\uDF7F\uDFD9-\uDFDF\uDFEC-\uDFFF]|\uD83E[\uDC0C-\uDC0F\uDC48-\uDC4F\uDC5A-\uDC5F\uDC88-\uDC8F\uDCAE\uDCAF\uDCB2-\uDCFF\uDD79\uDDCC\uDE54-\uDE5F\uDE6E\uDE6F\uDE75-\uDE77\uDE7B-\uDE7F\uDE87-\uDE8F\uDEA9-\uDEAF\uDEB7-\uDEBF\uDEC3-\uDECF\uDED7-\uDEFF\uDF93\uDFCB-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
/**
* symbolProperties( currency, cldr )
*
* Return pattern replacing `¤` with the appropriate currency symbol literal.
*/
var currencySymbolProperties = function( currency, cldr, options ) {
var currencySpacing, pattern, symbol, symbolEntries,
regexp = {
"[:digit:]": /\d/,
"[:^S:]": regexpNotS,
"[[:^S:]&[:^Z:]]": regexpNotSAndZ
};
if ( options.style === "code" ) {
symbol = currency;
} else {
symbolEntries = [ "symbol" ];
// If options.symbolForm === "narrow" was passed, prepend it.
if ( options.symbolForm === "narrow" ) {
symbolEntries.unshift( "symbol-alt-narrow" );
}
symbolEntries.some(function( symbolEntry ) {
return symbol = cldr.main([
"numbers/currencies",
currency,
symbolEntry
]);
});
}
currencySpacing = [ "beforeCurrency", "afterCurrency" ].map(function( position ) {
return cldr.main([
"numbers",
"currencyFormats-numberSystem-" + numberNumberingSystem( cldr ),
"currencySpacing",
position
]);
});
pattern = cldr.main([
"numbers",
"currencyFormats-numberSystem-" + numberNumberingSystem( cldr ),
options.style === "accounting" ? "accounting" : "standard"
]);
pattern =
// The number of decimal places and the rounding for each currency is not locale-specific.
// Those values are overridden by Supplemental Currency Data.
currencySupplementalOverride( currency, pattern, cldr )
// Replace "¤" (\u00A4) with the appropriate symbol literal.
.split( ";" ).map(function( pattern ) {
return pattern.split( "\u00A4" ).map(function( part, i ) {
var currencyMatch = regexp[ currencySpacing[ i ].currencyMatch ],
surroundingMatch = regexp[ currencySpacing[ i ].surroundingMatch ],
insertBetween = "";
// For currencyMatch and surroundingMatch definitions, read [1].
// When i === 0, beforeCurrency is being handled. Otherwise, afterCurrency.
// 1: http://www.unicode.org/reports/tr35/tr35-numbers.html#Currencies
currencyMatch = currencyMatch.test( symbol.charAt( i ? symbol.length - 1 : 0 ) );
surroundingMatch = surroundingMatch.test(
part.charAt( i ? 0 : part.length - 1 ).replace( /[#@,.]/g, "0" )
);
if ( currencyMatch && part && surroundingMatch ) {
insertBetween = currencySpacing[ i ].insertBetween;
}
return ( i ? insertBetween : "" ) + part + ( i ? "" : insertBetween );
}).join( "\u00A4" );
}).join( ";" );
return {
pattern: pattern,
symbol: symbol
};
};
/**
* nameFormat( formattedNumber, pluralForm, properties )
*
* Return the appropriate name form currency format.
*/
var currencyNameFormat = function( formattedNumber, pluralForm, properties ) {
var displayName, unitPattern,
parts = [],
displayNames = properties.displayNames || {},
unitPatterns = properties.unitPatterns;
displayName = displayNames[ "displayName-count-" + pluralForm ] ||
displayNames[ "displayName-count-other" ] ||
displayNames.displayName ||
properties.currency;
unitPattern = unitPatterns[ "unitPattern-count-" + pluralForm ] ||
unitPatterns[ "unitPattern-count-other" ];
formatMessageToParts( unitPattern, [ formattedNumber, displayName ]).forEach(function( part ) {
if ( part.type === "variable" && part.name === "0" ) {
part.value.forEach(function( part ) {
partsPush( parts, part.type, part.value );
});
} else if ( part.type === "variable" && part.name === "1" ) {
partsPush( parts, "currency", part.value );
} else {
partsPush( parts, "literal", part.value );
}
});
return parts;
};
/**
* symbolFormat( parts, symbol )
*
* Return the appropriate symbol/account form format.
*/
var currencySymbolFormat = function( parts, symbol ) {
parts.forEach(function( part ) {
if ( part.type === "currency" ) {
part.value = symbol;
}
});
return parts;
};
var currencyToPartsFormatterFn = function( numberToPartsFormatter, pluralGenerator, properties ) {
var fn;
// Return formatter when style is "name".
if ( pluralGenerator && properties ) {
fn = function currencyToPartsFormatter( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return currencyNameFormat(
numberToPartsFormatter( value ),
pluralGenerator( value ),
properties
);
};
// Return formatter when style is "symbol", "accounting", or "code".
} else {
fn = function currencyToPartsFormatter( value ) {
// 1: Reusing pluralGenerator argument, but in this case it is actually `symbol`
return currencySymbolFormat( numberToPartsFormatter( value ), pluralGenerator /* 1 */ );
};
}
return fn;
};
/**
* objectOmit( object, keys )
*
* Return a copy of the object, filtered to omit the blacklisted key or array of keys.
*/
var objectOmit = function( object, keys ) {
var key,
copy = {};
keys = alwaysArray( keys );
for ( key in object ) {
if ( keys.indexOf( key ) === -1 ) {
copy[ key ] = object[ key ];
}
}
return copy;
};
function validateRequiredCldr( path, value ) {
validateCldr( path, value, {
skip: [
/numbers\/currencies\/[^/]+\/symbol-alt-/,
/supplemental\/currencyData\/fractions\/[A-Za-z]{3}$/
]
});
}
/**
* .currencyFormatter( currency [, options] )
*
* @currency [String] 3-letter currency code as defined by ISO 4217.
*
* @options [Object]:
* - style: [String] "symbol" (default), "accounting", "code" or "name".
* - see also number/format options.
*
* Return a function that formats a currency according to the given options and default/instance
* locale.
*/
Globalize.currencyFormatter =
Globalize.prototype.currencyFormatter = function( currency, options ) {
var args, currencyToPartsFormatter, returnFn;
validateParameterPresence( currency, "currency" );
validateParameterTypeCurrency( currency, "currency" );
validateParameterTypePlainObject( options, "options" );
options = options || {};
args = [ currency, options ];
currencyToPartsFormatter = this.currencyToPartsFormatter( currency, options );
returnFn = currencyFormatterFn( currencyToPartsFormatter );
runtimeBind( args, this.cldr, returnFn, [ currencyToPartsFormatter ] );
return returnFn;
};
/**
* .currencyToPartsFormatter( currency [, options] )
*
* @currency [String] 3-letter currency code as defined by ISO 4217.
*
* @options [Object]:
* - style: [String] "symbol" (default), "accounting", "code" or "name".
* - see also number/format options.
*
* Return a currency formatter function (of the form below) according to the given options and the
* default/instance locale.
*
* fn( value )
*
* @value [Number]
*
* Return a function that formats a currency to parts according to the given options
* and the default/instance locale.
*/
Globalize.currencyToPartsFormatter =
Globalize.prototype.currencyToPartsFormatter = function( currency, options ) {
var args, cldr, numberToPartsFormatter, pluralGenerator, properties, returnFn, style;
validateParameterPresence( currency, "currency" );
validateParameterTypeCurrency( currency, "currency" );
validateParameterTypePlainObject( options, "options" );
cldr = this.cldr;
options = options || {};
args = [ currency, options ];
style = options.style || "symbol";
validateDefaultLocale( cldr );
// Get properties given style ("symbol" default, "code" or "name").
cldr.on( "get", validateRequiredCldr );
try {
properties = ({
accounting: currencySymbolProperties,
code: currencySymbolProperties,
name: currencyNameProperties,
symbol: currencySymbolProperties
}[ style ] )( currency, cldr, options );
} finally {
cldr.off( "get", validateRequiredCldr );
}
// options = options minus style, plus raw pattern.
options = objectOmit( options, "style" );
options.raw = properties.pattern;
// Return formatter when style is "symbol", "accounting", or "code".
if ( style === "symbol" || style === "accounting" || style === "code" ) {
numberToPartsFormatter = this.numberToPartsFormatter( options );
returnFn = currencyToPartsFormatterFn( numberToPartsFormatter, properties.symbol );
runtimeBind( args, cldr, returnFn, [ numberToPartsFormatter, properties.symbol ] );
// Return formatter when style is "name".
} else {
numberToPartsFormatter = this.numberToPartsFormatter( options );
// Is plural module present? Yes, use its generator. Nope, use an error generator.
pluralGenerator = this.plural !== undefined ?
this.pluralGenerator() :
createErrorPluralModulePresence;
returnFn = currencyToPartsFormatterFn(
numberToPartsFormatter,
pluralGenerator,
properties
);
runtimeBind( args, cldr, returnFn, [
numberToPartsFormatter,
pluralGenerator,
properties
]);
}
return returnFn;
};
/**
* .currencyParser( currency [, options] )
*
* @currency [String] 3-letter currency code as defined by ISO 4217.
*
* @options [Object] see currencyFormatter.
*
* Return the currency parser according to the given options and the default/instance locale.
*/
Globalize.currencyParser =
Globalize.prototype.currencyParser = function( /* currency, options */ ) {
// TODO implement parser.
};
/**
* .formatCurrency( value, currency [, options] )
*
* @value [Number] number to be formatted.
*
* @currency [String] 3-letter currency code as defined by ISO 4217.
*
* @options [Object] see currencyFormatter.
*
* Format a currency according to the given options and the default/instance locale.
*/
Globalize.formatCurrency =
Globalize.prototype.formatCurrency = function( value, currency, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.currencyFormatter( currency, options )( value );
};
/**
* .formatCurrencyToParts( value, currency [, options] )
*
* @value [Number] number to be formatted.
*
* @currency [String] 3-letter currency code as defined by ISO 4217.
*
* @options [Object] see currencyFormatter.
*
* Format a currency to parts according to the given options and the default/instance locale.
*/
Globalize.formatCurrencyToParts =
Globalize.prototype.formatCurrencyToParts = function( value, currency, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.currencyToPartsFormatter( currency, options )( value );
};
/**
* .parseCurrency( value, currency [, options] )
*
* @value [String]
*
* @currency [String] 3-letter currency code as defined by ISO 4217.
*
* @options [Object]: See currencyFormatter.
*
* Return the parsed currency or NaN when value is invalid.
*/
Globalize.parseCurrency =
Globalize.prototype.parseCurrency = function( /* value, currency, options */ ) {
};
return Globalize;
}));

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,376 @@
/**
* Globalize v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"cldr",
"../globalize",
"cldr/event",
"cldr/supplemental"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory( require( "cldrjs" ), require( "../globalize" ) );
} else {
// Global
factory( root.Cldr, root.Globalize );
}
}(this, function( Cldr, Globalize ) {
var runtimeBind = Globalize._runtimeBind,
validateCldr = Globalize._validateCldr,
validateDefaultLocale = Globalize._validateDefaultLocale,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterType = Globalize._validateParameterType,
validateParameterTypePlainObject = Globalize._validateParameterTypePlainObject;
var MakePlural;
/* eslint-disable */
MakePlural = (function() {
'use strict';
var _toArray = function (arr) { return Array.isArray(arr) ? arr : Array.from(arr); };
var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } };
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
/**
* make-plural.js -- https://github.com/eemeli/make-plural.js/
* Copyright (c) 2014-2015 by Eemeli Aro <eemeli@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* The software is provided "as is" and the author disclaims all warranties
* with regard to this software including all implied warranties of
* merchantability and fitness. In no event shall the author be liable for
* any special, direct, indirect, or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether in an
* action of contract, negligence or other tortious action, arising out of
* or in connection with the use or performance of this software.
*/
var Parser = (function () {
function Parser() {
_classCallCheck(this, Parser);
}
_createClass(Parser, [{
key: 'parse',
value: function parse(cond) {
var _this = this;
if (cond === 'i = 0 or n = 1') {
return 'n >= 0 && n <= 1';
}if (cond === 'i = 0,1') {
return 'n >= 0 && n < 2';
}if (cond === 'i = 1 and v = 0') {
this.v0 = 1;
return 'n == 1 && v0';
}
return cond.replace(/([tv]) (!?)= 0/g, function (m, sym, noteq) {
var sn = sym + '0';
_this[sn] = 1;
return noteq ? '!' + sn : sn;
}).replace(/\b[fintv]\b/g, function (m) {
_this[m] = 1;
return m;
}).replace(/([fin]) % (10+)/g, function (m, sym, num) {
var sn = sym + num;
_this[sn] = 1;
return sn;
}).replace(/n10+ = 0/g, 't0 && $&').replace(/(\w+ (!?)= )([0-9.]+,[0-9.,]+)/g, function (m, se, noteq, x) {
if (m === 'n = 0,1') return '(n == 0 || n == 1)';
if (noteq) return se + x.split(',').join(' && ' + se);
return '(' + se + x.split(',').join(' || ' + se) + ')';
}).replace(/(\w+) (!?)= ([0-9]+)\.\.([0-9]+)/g, function (m, sym, noteq, x0, x1) {
if (Number(x0) + 1 === Number(x1)) {
if (noteq) return '' + sym + ' != ' + x0 + ' && ' + sym + ' != ' + x1;
return '(' + sym + ' == ' + x0 + ' || ' + sym + ' == ' + x1 + ')';
}
if (noteq) return '(' + sym + ' < ' + x0 + ' || ' + sym + ' > ' + x1 + ')';
if (sym === 'n') {
_this.t0 = 1;return '(t0 && n >= ' + x0 + ' && n <= ' + x1 + ')';
}
return '(' + sym + ' >= ' + x0 + ' && ' + sym + ' <= ' + x1 + ')';
}).replace(/ and /g, ' && ').replace(/ or /g, ' || ').replace(/ = /g, ' == ');
}
}, {
key: 'vars',
value: (function (_vars) {
function vars() {
return _vars.apply(this, arguments);
}
vars.toString = function () {
return _vars.toString();
};
return vars;
})(function () {
var vars = [];
if (this.i) vars.push('i = s[0]');
if (this.f || this.v) vars.push('f = s[1] || \'\'');
if (this.t) vars.push('t = (s[1] || \'\').replace(/0+$/, \'\')');
if (this.v) vars.push('v = f.length');
if (this.v0) vars.push('v0 = !s[1]');
if (this.t0 || this.n10 || this.n100) vars.push('t0 = Number(s[0]) == n');
for (var k in this) {
if (/^.10+$/.test(k)) {
var k0 = k[0] === 'n' ? 't0 && s[0]' : k[0];
vars.push('' + k + ' = ' + k0 + '.slice(-' + k.substr(2).length + ')');
}
}if (!vars.length) return '';
return 'var ' + ['s = String(n).split(\'.\')'].concat(vars).join(', ');
})
}]);
return Parser;
})();
var MakePlural = (function () {
function MakePlural(lc) {
var _ref = arguments[1] === undefined ? MakePlural : arguments[1];
var cardinals = _ref.cardinals;
var ordinals = _ref.ordinals;
_classCallCheck(this, MakePlural);
if (!cardinals && !ordinals) throw new Error('At least one type of plural is required');
this.lc = lc;
this.categories = { cardinal: [], ordinal: [] };
this.parser = new Parser();
this.fn = this.buildFunction(cardinals, ordinals);
this.fn._obj = this;
this.fn.categories = this.categories;
this.fn.toString = this.fnToString.bind(this);
return this.fn;
}
_createClass(MakePlural, [{
key: 'compile',
value: function compile(type, req) {
var cases = [];
var rules = MakePlural.rules[type][this.lc];
if (!rules) {
if (req) throw new Error('Locale "' + this.lc + '" ' + type + ' rules not found');
this.categories[type] = ['other'];
return '\'other\'';
}
for (var r in rules) {
var _rules$r$trim$split = rules[r].trim().split(/\s*@\w*/);
var _rules$r$trim$split2 = _toArray(_rules$r$trim$split);
var cond = _rules$r$trim$split2[0];
var examples = _rules$r$trim$split2.slice(1);
var cat = r.replace('pluralRule-count-', '');
if (cond) cases.push([this.parser.parse(cond), cat]);
}
this.categories[type] = cases.map(function (c) {
return c[1];
}).concat('other');
if (cases.length === 1) {
return '(' + cases[0][0] + ') ? \'' + cases[0][1] + '\' : \'other\'';
} else {
return [].concat(_toConsumableArray(cases.map(function (c) {
return '(' + c[0] + ') ? \'' + c[1] + '\'';
})), ['\'other\'']).join('\n : ');
}
}
}, {
key: 'buildFunction',
value: function buildFunction(cardinals, ordinals) {
var _this3 = this;
var compile = function compile(c) {
return c ? (c[1] ? 'return ' : 'if (ord) return ') + _this3.compile.apply(_this3, _toConsumableArray(c)) : '';
},
fold = { vars: function vars(str) {
return (' ' + str + ';').replace(/(.{1,78})(,|$) ?/g, '$1$2\n ');
},
cond: function cond(str) {
return (' ' + str + ';').replace(/(.{1,78}) (\|\| |$) ?/gm, '$1\n $2');
} },
cond = [ordinals && ['ordinal', !cardinals], cardinals && ['cardinal', true]].map(compile).map(fold.cond),
body = [fold.vars(this.parser.vars())].concat(_toConsumableArray(cond)).join('\n').replace(/\s+$/gm, '').replace(/^[\s;]*[\r\n]+/gm, ''),
args = ordinals && cardinals ? 'n, ord' : 'n';
return new Function(args, body);
}
}, {
key: 'fnToString',
value: function fnToString(name) {
return Function.prototype.toString.call(this.fn).replace(/^function( \w+)?/, name ? 'function ' + name : 'function').replace('\n/**/', '');
}
}], [{
key: 'load',
value: function load() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
args.forEach(function (cldr) {
var data = cldr && cldr.supplemental || null;
if (!data) throw new Error('Data does not appear to be CLDR data');
MakePlural.rules = {
cardinal: data['plurals-type-cardinal'] || MakePlural.rules.cardinal,
ordinal: data['plurals-type-ordinal'] || MakePlural.rules.ordinal
};
});
return MakePlural;
}
}]);
return MakePlural;
})();
MakePlural.cardinals = true;
MakePlural.ordinals = false;
MakePlural.rules = { cardinal: {}, ordinal: {} };
return MakePlural;
}());
/* eslint-enable */
var validateParameterTypeNumber = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || typeof value === "number",
"Number"
);
};
var validateParameterTypePluralType = function( value, name ) {
validateParameterType(
value,
name,
value === undefined || value === "cardinal" || value === "ordinal",
"String \"cardinal\" or \"ordinal\""
);
};
var pluralGeneratorFn = function( plural ) {
return function pluralGenerator( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return plural( value );
};
};
/**
* .plural( value )
*
* @value [Number]
*
* Return the corresponding form (zero | one | two | few | many | other) of a
* value given locale.
*/
Globalize.plural =
Globalize.prototype.plural = function( value, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.pluralGenerator( options )( value );
};
/**
* .pluralGenerator( [options] )
*
* Return a plural function (of the form below).
*
* fn( value )
*
* @value [Number]
*
* Return the corresponding form (zero | one | two | few | many | other) of a value given the
* default/instance locale.
*/
Globalize.pluralGenerator =
Globalize.prototype.pluralGenerator = function( options ) {
var args, cldr, isOrdinal, plural, returnFn, type;
validateParameterTypePlainObject( options, "options" );
options = options || {};
cldr = this.cldr;
args = [ options ];
type = options.type || "cardinal";
validateParameterTypePluralType( options.type, "options.type" );
validateDefaultLocale( cldr );
isOrdinal = type === "ordinal";
cldr.on( "get", validateCldr );
try {
cldr.supplemental([ "plurals-type-" + type, "{language}" ]);
} finally {
cldr.off( "get", validateCldr );
}
MakePlural.rules = {};
MakePlural.rules[ type ] = cldr.supplemental( "plurals-type-" + type );
plural = new MakePlural( cldr.attributes.language, {
"ordinals": isOrdinal,
"cardinals": !isOrdinal
});
returnFn = pluralGeneratorFn( plural );
runtimeBind( args, cldr, returnFn, [ plural ] );
return returnFn;
};
return Globalize;
}));

View File

@@ -0,0 +1,203 @@
/**
* Globalize v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"cldr",
"../globalize",
"./number",
"./plural",
"cldr/event",
"cldr/supplemental"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory( require( "cldrjs" ), require( "../globalize" ) );
} else {
// Extend global
factory( root.Cldr, root.Globalize );
}
}(this, function( Cldr, Globalize ) {
var formatMessage = Globalize._formatMessage,
runtimeBind = Globalize._runtimeBind,
validateCldr = Globalize._validateCldr,
validateDefaultLocale = Globalize._validateDefaultLocale,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterTypeString = Globalize._validateParameterTypeString,
validateParameterTypeNumber = Globalize._validateParameterTypeNumber;
/**
* format( value, numberFormatter, pluralGenerator, properties )
*
* @value [Number] The number to format
*
* @numberFormatter [String] A numberFormatter from Globalize.numberFormatter
*
* @pluralGenerator [String] A pluralGenerator from Globalize.pluralGenerator
*
* @properties [Object] containing relative time plural message.
*
* Format relative time.
*/
var relativeTimeFormat = function( value, numberFormatter, pluralGenerator, properties ) {
var relativeTime,
message = properties[ "relative-type-" + value ];
if ( message ) {
return message;
}
relativeTime = value <= 0 ? properties[ "relativeTime-type-past" ] :
properties[ "relativeTime-type-future" ];
value = Math.abs( value );
message = relativeTime[ "relativeTimePattern-count-" + pluralGenerator( value ) ];
return formatMessage( message, [ numberFormatter( value ) ] );
};
var relativeTimeFormatterFn = function( numberFormatter, pluralGenerator, properties ) {
return function relativeTimeFormatter( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return relativeTimeFormat( value, numberFormatter, pluralGenerator, properties );
};
};
/**
* properties( unit, cldr, options )
*
* @unit [String] eg. "day", "week", "month", etc.
*
* @cldr [Cldr instance].
*
* @options [Object]
* - form: [String] eg. "short" or "narrow". Or falsy for default long form.
*
* Return relative time properties.
*/
var relativeTimeProperties = function( unit, cldr, options ) {
var form = options.form,
raw, properties, key, match;
if ( form ) {
unit = unit + "-" + form;
}
raw = cldr.main( [ "dates", "fields", unit ] );
properties = {
"relativeTime-type-future": raw[ "relativeTime-type-future" ],
"relativeTime-type-past": raw[ "relativeTime-type-past" ]
};
for ( key in raw ) {
if ( raw.hasOwnProperty( key ) ) {
match = /relative-type-(-?[0-9]+)/.exec( key );
if ( match ) {
properties[ key ] = raw[ key ];
}
}
}
return properties;
};
/**
* .formatRelativeTime( value, unit [, options] )
*
* @value [Number] The number of unit to format.
*
* @unit [String] see .relativeTimeFormatter() for details.
*
* @options [Object] see .relativeTimeFormatter() for details.
*
* Formats a relative time according to the given unit, options, and the default/instance locale.
*/
Globalize.formatRelativeTime =
Globalize.prototype.formatRelativeTime = function( value, unit, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.relativeTimeFormatter( unit, options )( value );
};
/**
* .relativeTimeFormatter( unit [, options ])
*
* @unit [String] String value indicating the unit to be formatted. eg. "day", "week", "month", etc.
*
* @options [Object]
* - form: [String] eg. "short" or "narrow". Or falsy for default long form.
*
* Returns a function that formats a relative time according to the given unit, options, and the
* default/instance locale.
*/
Globalize.relativeTimeFormatter =
Globalize.prototype.relativeTimeFormatter = function( unit, options ) {
var args, cldr, numberFormatter, pluralGenerator, properties, returnFn;
validateParameterPresence( unit, "unit" );
validateParameterTypeString( unit, "unit" );
cldr = this.cldr;
options = options || {};
args = [ unit, options ];
validateDefaultLocale( cldr );
cldr.on( "get", validateCldr );
try {
properties = relativeTimeProperties( unit, cldr, options );
} finally {
cldr.off( "get", validateCldr );
}
numberFormatter = this.numberFormatter( options );
pluralGenerator = this.pluralGenerator();
returnFn = relativeTimeFormatterFn( numberFormatter, pluralGenerator, properties );
runtimeBind( args, cldr, returnFn, [ numberFormatter, pluralGenerator, properties ] );
return returnFn;
};
return Globalize;
}));

View File

@@ -0,0 +1,301 @@
/**
* Globalize v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
/*!
* Globalize v1.7.0 2021-08-02T11:53Z Released under the MIT license
* http://git.io/TrdQbw
*/
(function( root, factory ) {
// UMD returnExports
if ( typeof define === "function" && define.amd ) {
// AMD
define([
"cldr",
"../globalize",
"./number",
"./plural"
], factory );
} else if ( typeof exports === "object" ) {
// Node, CommonJS
module.exports = factory( require( "cldrjs" ), require( "../globalize" ) );
} else {
// Extend global
factory( root.Cldr, root.Globalize );
}
}(this, function( Cldr, Globalize ) {
var formatMessage = Globalize._formatMessage,
runtimeBind = Globalize._runtimeBind,
validateParameterPresence = Globalize._validateParameterPresence,
validateParameterTypePlainObject = Globalize._validateParameterTypePlainObject,
validateParameterTypeNumber = Globalize._validateParameterTypeNumber,
validateParameterTypeString = Globalize._validateParameterTypeString;
/**
* format( value, numberFormatter, pluralGenerator, unitProperies )
*
* @value [Number]
*
* @numberFormatter [Object]: A numberFormatter from Globalize.numberFormatter.
*
* @pluralGenerator [Object]: A pluralGenerator from Globalize.pluralGenerator.
*
* @unitProperies [Object]: localized unit data from cldr.
*
* Format units such as seconds, minutes, days, weeks, etc.
*
* OBS:
*
* Unit Sequences are not implemented.
* http://www.unicode.org/reports/tr35/tr35-35/tr35-general.html#Unit_Sequences
*
* Duration Unit (for composed time unit durations) is not implemented.
* http://www.unicode.org/reports/tr35/tr35-35/tr35-general.html#durationUnit
*/
var unitFormat = function( value, numberFormatter, pluralGenerator, unitProperties ) {
var compoundUnitPattern = unitProperties.compoundUnitPattern, dividend, dividendProperties,
formattedValue, divisor, divisorProperties, message, pluralValue, oneProperty;
unitProperties = unitProperties.unitProperties;
formattedValue = numberFormatter( value );
pluralValue = pluralGenerator( value );
// computed compound unit, eg. "megabyte-per-second".
if ( unitProperties instanceof Array ) {
dividendProperties = unitProperties[ 0 ];
divisorProperties = unitProperties[ 1 ];
oneProperty = divisorProperties.hasOwnProperty( "one" ) ? "one" : "other";
dividend = formatMessage( dividendProperties[ pluralValue ], [ formattedValue ] );
divisor = formatMessage( divisorProperties[ oneProperty ], [ "" ] ).trim();
return formatMessage( compoundUnitPattern, [ dividend, divisor ] );
}
message = unitProperties[ pluralValue ];
return formatMessage( message, [ formattedValue ] );
};
var unitFormatterFn = function( numberFormatter, pluralGenerator, unitProperties ) {
return function unitFormatter( value ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return unitFormat( value, numberFormatter, pluralGenerator, unitProperties );
};
};
/**
* categories()
*
* Return all unit categories.
*/
var unitCategories = [ "acceleration", "angle", "area", "digital", "duration", "length", "mass", "power",
"pressure", "speed", "temperature", "volume" ];
function stripPluralGarbage( data ) {
var aux, pluralCount;
if ( data ) {
aux = {};
for ( pluralCount in data ) {
aux[ pluralCount.replace( /unitPattern-count-/, "" ) ] = data[ pluralCount ];
}
}
return aux;
}
/**
* get( unit, form, cldr )
*
* @unit [String] The full type-unit name (eg. duration-second), or the short unit name
* (eg. second).
*
* @form [String] A string describing the form of the unit representation (eg. long,
* short, narrow).
*
* @cldr [Cldr instance].
*
* Return the plural map of a unit, eg: "second"
* { "one": "{0} second",
* "other": "{0} seconds" }
* }
*
* Or the Array of plural maps of a compound-unit, eg: "foot-per-second"
* [ { "one": "{0} foot",
* "other": "{0} feet" },
* { "one": "{0} second",
* "other": "{0} seconds" } ]
*
* Uses the precomputed form of a compound-unit if available, eg: "mile-per-hour"
* { "displayName": "miles per hour",
* "unitPattern-count-one": "{0} mile per hour",
* "unitPattern-count-other": "{0} miles per hour"
* },
*
* Also supports "/" instead of "-per-", eg. "foot/second", using the precomputed form if
* available.
*
* Or the Array of plural maps of a compound-unit, eg: "foot-per-second"
* [ { "one": "{0} foot",
* "other": "{0} feet" },
* { "one": "{0} second",
* "other": "{0} seconds" } ]
*
* Or undefined in case the unit (or a unit of the compound-unit) doesn't exist.
*/
var get = function( unit, form, cldr ) {
var ret;
// Ensure that we get the 'precomputed' form, if present.
unit = unit.replace( /\//, "-per-" );
// Get unit or <category>-unit (eg. "duration-second").
[ "" ].concat( unitCategories ).some(function( category ) {
return ret = cldr.main([
"units",
form,
category.length ? category + "-" + unit : unit
]);
});
// Rename keys s/unitPattern-count-//g.
ret = stripPluralGarbage( ret );
// Compound Unit, eg. "foot-per-second" or "foot/second".
if ( !ret && ( /-per-/ ).test( unit ) ) {
// "Some units already have 'precomputed' forms, such as kilometer-per-hour;
// where such units exist, they should be used in preference" UTS#35.
// Note that precomputed form has already been handled above (!ret).
// Get both recursively.
unit = unit.split( "-per-" );
ret = unit.map(function( unit ) {
return get( unit, form, cldr );
});
if ( !ret[ 0 ] || !ret[ 1 ] ) {
return;
}
}
return ret;
};
var unitGet = get;
/**
* properties( unit, form, cldr )
*
* @unit [String] The full type-unit name (eg. duration-second), or the short unit name
* (eg. second).
*
* @form [String] A string describing the form of the unit representation (eg. long,
* short, narrow).
*
* @cldr [Cldr instance].
*/
var unitProperties = function( unit, form, cldr ) {
var compoundUnitPattern, unitProperties;
compoundUnitPattern = cldr.main( [ "units", form, "per/compoundUnitPattern" ] );
unitProperties = unitGet( unit, form, cldr );
return {
compoundUnitPattern: compoundUnitPattern,
unitProperties: unitProperties
};
};
/**
* Globalize.formatUnit( value, unit, options )
*
* @value [Number]
*
* @unit [String]: The unit (e.g "second", "day", "year")
*
* @options [Object]
* - form: [String] "long", "short" (default), or "narrow".
*
* Format units such as seconds, minutes, days, weeks, etc.
*/
Globalize.formatUnit =
Globalize.prototype.formatUnit = function( value, unit, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );
return this.unitFormatter( unit, options )( value );
};
/**
* Globalize.unitFormatter( unit, options )
*
* @unit [String]: The unit (e.g "second", "day", "year")
*
* @options [Object]
* - form: [String] "long", "short" (default), or "narrow".
*
* - numberFormatter: [Function] a number formatter function. Defaults to Globalize
* `.numberFormatter()` for the current locale using the default options.
*/
Globalize.unitFormatter =
Globalize.prototype.unitFormatter = function( unit, options ) {
var args, form, numberFormatter, pluralGenerator, returnFn, properties;
validateParameterPresence( unit, "unit" );
validateParameterTypeString( unit, "unit" );
validateParameterTypePlainObject( options, "options" );
options = options || {};
args = [ unit, options ];
form = options.form || "long";
properties = unitProperties( unit, form, this.cldr );
numberFormatter = options.numberFormatter || this.numberFormatter();
pluralGenerator = this.pluralGenerator();
returnFn = unitFormatterFn( numberFormatter, pluralGenerator, properties );
runtimeBind( args, this.cldr, returnFn, [ numberFormatter, pluralGenerator, properties ] );
return returnFn;
};
return Globalize;
}));

View File

@@ -0,0 +1,27 @@
/*!
* Globalize v1.7.0
*
* https://github.com/globalizejs/globalize
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2021-08-02T11:53Z
*/
// Core
module.exports = require( "./globalize" );
// Extent core with the following modules
require( "./globalize/message" );
require( "./globalize/number" );
require( "./globalize/plural" );
// Load after globalize/number
require( "./globalize/currency" );
require( "./globalize/date" );
// Load after globalize/number and globalize/plural
require( "./globalize/relative-time" );
require( "./globalize/unit" );