-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
11,979 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
/** | ||
* Globalize Runtime v1.4.0 | ||
* | ||
* http://github.com/jquery/globalize | ||
* | ||
* Copyright jQuery Foundation and other contributors | ||
* Released under the MIT license | ||
* http://jquery.org/license | ||
* | ||
* Date: 2018-07-17T20:38Z | ||
*/ | ||
/*! | ||
* Globalize Runtime v1.4.0 2018-07-17T20:38Z 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; | ||
}; | ||
|
||
|
||
|
||
|
||
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._regexpEscape = regexpEscape; | ||
Globalize._runtimeKey = runtimeKey; | ||
Globalize._stringPad = stringPad; | ||
Globalize._validateParameterPresence = validateParameterPresence; | ||
Globalize._validateParameterTypeString = validateParameterTypeString; | ||
Globalize._validateParameterType = validateParameterType; | ||
|
||
return Globalize; | ||
|
||
|
||
|
||
|
||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* Globalize Runtime v1.4.0 | ||
* | ||
* http://github.com/jquery/globalize | ||
* | ||
* Copyright jQuery Foundation and other contributors | ||
* Released under the MIT license | ||
* http://jquery.org/license | ||
* | ||
* Date: 2018-07-17T20:38Z | ||
*/ | ||
/*! | ||
* Globalize Runtime v1.4.0 2018-07-17T20:38Z 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 formatMessage = Globalize._formatMessage, | ||
runtimeKey = Globalize._runtimeKey, | ||
validateParameterPresence = Globalize._validateParameterPresence, | ||
validateParameterTypeNumber = Globalize._validateParameterTypeNumber; | ||
|
||
|
||
/** | ||
* nameFormat( formattedNumber, pluralForm, properties ) | ||
* | ||
* Return the appropriate name form currency format. | ||
*/ | ||
var currencyNameFormat = function( formattedNumber, pluralForm, properties ) { | ||
var displayName, unitPattern, | ||
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" ]; | ||
|
||
return formatMessage( unitPattern, [ formattedNumber, displayName ]); | ||
}; | ||
|
||
|
||
|
||
|
||
var currencyFormatterFn = function( numberFormatter, pluralGenerator, properties ) { | ||
var fn; | ||
|
||
// Return formatter when style is "code" or "name". | ||
if ( pluralGenerator && properties ) { | ||
fn = function currencyFormatter( value ) { | ||
validateParameterPresence( value, "value" ); | ||
validateParameterTypeNumber( value, "value" ); | ||
return currencyNameFormat( | ||
numberFormatter( value ), | ||
pluralGenerator( value ), | ||
properties | ||
); | ||
}; | ||
|
||
// Return formatter when style is "symbol" or "accounting". | ||
} else { | ||
fn = function currencyFormatter( value ) { | ||
return numberFormatter( value ); | ||
}; | ||
} | ||
|
||
return fn; | ||
}; | ||
|
||
|
||
|
||
|
||
Globalize._currencyFormatterFn = currencyFormatterFn; | ||
Globalize._currencyNameFormat = currencyNameFormat; | ||
|
||
Globalize.currencyFormatter = | ||
Globalize.prototype.currencyFormatter = function( currency, options ) { | ||
options = options || {}; | ||
return Globalize[ runtimeKey( "currencyFormatter", 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 ); | ||
}; | ||
|
||
return Globalize; | ||
|
||
|
||
|
||
|
||
})); |
Oops, something went wrong.