Skip to content

Commit f24f229

Browse files
committed
Build: Include distribution files
1 parent 9103965 commit f24f229

17 files changed

+11981
-0
lines changed

dist/globalize-runtime.js

+252
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
/**
2+
* Globalize Runtime v1.4.1
3+
*
4+
* http://github.com/jquery/globalize
5+
*
6+
* Copyright jQuery Foundation and other contributors
7+
* Released under the MIT license
8+
* http://jquery.org/license
9+
*
10+
* Date: 2019-03-06T12:26Z
11+
*/
12+
/*!
13+
* Globalize Runtime v1.4.1 2019-03-06T12:26Z Released under the MIT license
14+
* http://git.io/TrdQbw
15+
*/
16+
(function( root, factory ) {
17+
18+
"use strict";
19+
20+
// UMD returnExports
21+
if ( typeof define === "function" && define.amd ) {
22+
23+
// AMD
24+
define( factory );
25+
} else if ( typeof exports === "object" ) {
26+
27+
// Node, CommonJS
28+
module.exports = factory();
29+
} else {
30+
31+
// Globalize
32+
root.Globalize = factory();
33+
}
34+
}( this, function() {
35+
36+
37+
38+
39+
/**
40+
* A toString method that outputs meaningful values for objects or arrays and
41+
* still performs as fast as a plain string in case variable is string, or as
42+
* fast as `"" + number` in case variable is a number.
43+
* Ref: http://jsperf.com/my-stringify
44+
*/
45+
var toString = function( variable ) {
46+
return typeof variable === "string" ? variable : ( typeof variable === "number" ? "" +
47+
variable : JSON.stringify( variable ) );
48+
};
49+
50+
51+
52+
53+
/**
54+
* formatMessage( message, data )
55+
*
56+
* @message [String] A message with optional {vars} to be replaced.
57+
*
58+
* @data [Array or JSON] Object with replacing-variables content.
59+
*
60+
* Return the formatted message. For example:
61+
*
62+
* - formatMessage( "{0} second", [ 1 ] ); // 1 second
63+
*
64+
* - formatMessage( "{0}/{1}", ["m", "s"] ); // m/s
65+
*
66+
* - formatMessage( "{name} <{email}>", {
67+
* name: "Foo",
68+
* email: "bar@baz.qux"
69+
* }); // Foo <bar@baz.qux>
70+
*/
71+
var formatMessage = function( message, data ) {
72+
73+
// Replace {attribute}'s
74+
message = message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( name ) {
75+
name = name.replace( /^{([^}]*)}$/, "$1" );
76+
return toString( data[ name ] );
77+
});
78+
79+
return message;
80+
};
81+
82+
83+
84+
85+
var objectExtend = function() {
86+
var destination = arguments[ 0 ],
87+
sources = [].slice.call( arguments, 1 );
88+
89+
sources.forEach(function( source ) {
90+
var prop;
91+
for ( prop in source ) {
92+
destination[ prop ] = source[ prop ];
93+
}
94+
});
95+
96+
return destination;
97+
};
98+
99+
100+
101+
102+
var createError = function( code, message, attributes ) {
103+
var error;
104+
105+
message = code + ( message ? ": " + formatMessage( message, attributes ) : "" );
106+
error = new Error( message );
107+
error.code = code;
108+
109+
objectExtend( error, attributes );
110+
111+
return error;
112+
};
113+
114+
115+
116+
117+
var runtimeStringify = function( args ) {
118+
return JSON.stringify( args, function( key, value ) {
119+
if ( value && value.runtimeKey ) {
120+
return value.runtimeKey;
121+
}
122+
return value;
123+
} );
124+
};
125+
126+
127+
128+
129+
// Based on http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
130+
var stringHash = function( str ) {
131+
return [].reduce.call( str, function( hash, i ) {
132+
var chr = i.charCodeAt( 0 );
133+
hash = ( ( hash << 5 ) - hash ) + chr;
134+
return hash | 0;
135+
}, 0 );
136+
};
137+
138+
139+
140+
141+
var runtimeKey = function( fnName, locale, args, argsStr ) {
142+
var hash;
143+
argsStr = argsStr || runtimeStringify( args );
144+
hash = stringHash( fnName + locale + argsStr );
145+
return hash > 0 ? "a" + hash : "b" + Math.abs( hash );
146+
};
147+
148+
149+
150+
151+
var validate = function( code, message, check, attributes ) {
152+
if ( !check ) {
153+
throw createError( code, message, attributes );
154+
}
155+
};
156+
157+
158+
159+
160+
var validateParameterPresence = function( value, name ) {
161+
validate( "E_MISSING_PARAMETER", "Missing required parameter `{name}`.",
162+
value !== undefined, { name: name });
163+
};
164+
165+
166+
167+
168+
var validateParameterType = function( value, name, check, expected ) {
169+
validate(
170+
"E_INVALID_PAR_TYPE",
171+
"Invalid `{name}` parameter ({value}). {expected} expected.",
172+
check,
173+
{
174+
expected: expected,
175+
name: name,
176+
value: value
177+
}
178+
);
179+
};
180+
181+
182+
183+
184+
var validateParameterTypeString = function( value, name ) {
185+
validateParameterType(
186+
value,
187+
name,
188+
value === undefined || typeof value === "string",
189+
"a string"
190+
);
191+
};
192+
193+
194+
195+
196+
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions?redirectlocale=en-US&redirectslug=JavaScript%2FGuide%2FRegular_Expressions
197+
var regexpEscape = function( string ) {
198+
return string.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1" );
199+
};
200+
201+
202+
203+
204+
var stringPad = function( str, count, right ) {
205+
var length;
206+
if ( typeof str !== "string" ) {
207+
str = String( str );
208+
}
209+
for ( length = str.length; length < count; length += 1 ) {
210+
str = ( right ? ( str + "0" ) : ( "0" + str ) );
211+
}
212+
return str;
213+
};
214+
215+
216+
217+
218+
function Globalize( locale ) {
219+
if ( !( this instanceof Globalize ) ) {
220+
return new Globalize( locale );
221+
}
222+
223+
validateParameterPresence( locale, "locale" );
224+
validateParameterTypeString( locale, "locale" );
225+
226+
this._locale = locale;
227+
}
228+
229+
Globalize.locale = function( locale ) {
230+
validateParameterTypeString( locale, "locale" );
231+
232+
if ( arguments.length ) {
233+
this._locale = locale;
234+
}
235+
return this._locale;
236+
};
237+
238+
Globalize._createError = createError;
239+
Globalize._formatMessage = formatMessage;
240+
Globalize._regexpEscape = regexpEscape;
241+
Globalize._runtimeKey = runtimeKey;
242+
Globalize._stringPad = stringPad;
243+
Globalize._validateParameterPresence = validateParameterPresence;
244+
Globalize._validateParameterTypeString = validateParameterTypeString;
245+
Globalize._validateParameterType = validateParameterType;
246+
247+
return Globalize;
248+
249+
250+
251+
252+
}));

dist/globalize-runtime/currency.js

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* Globalize Runtime v1.4.1
3+
*
4+
* http://github.com/jquery/globalize
5+
*
6+
* Copyright jQuery Foundation and other contributors
7+
* Released under the MIT license
8+
* http://jquery.org/license
9+
*
10+
* Date: 2019-03-06T12:26Z
11+
*/
12+
/*!
13+
* Globalize Runtime v1.4.1 2019-03-06T12:26Z Released under the MIT license
14+
* http://git.io/TrdQbw
15+
*/
16+
(function( root, factory ) {
17+
18+
"use strict";
19+
20+
// UMD returnExports
21+
if ( typeof define === "function" && define.amd ) {
22+
23+
// AMD
24+
define([
25+
"../globalize-runtime",
26+
"./number"
27+
], factory );
28+
} else if ( typeof exports === "object" ) {
29+
30+
// Node, CommonJS
31+
module.exports = factory(
32+
require( "../globalize-runtime" ),
33+
require( "./number" )
34+
);
35+
} else {
36+
37+
// Extend global
38+
factory( root.Globalize );
39+
}
40+
}(this, function( Globalize ) {
41+
42+
43+
44+
var formatMessage = Globalize._formatMessage,
45+
runtimeKey = Globalize._runtimeKey,
46+
validateParameterPresence = Globalize._validateParameterPresence,
47+
validateParameterTypeNumber = Globalize._validateParameterTypeNumber;
48+
49+
50+
/**
51+
* nameFormat( formattedNumber, pluralForm, properties )
52+
*
53+
* Return the appropriate name form currency format.
54+
*/
55+
var currencyNameFormat = function( formattedNumber, pluralForm, properties ) {
56+
var displayName, unitPattern,
57+
displayNames = properties.displayNames || {},
58+
unitPatterns = properties.unitPatterns;
59+
60+
displayName = displayNames[ "displayName-count-" + pluralForm ] ||
61+
displayNames[ "displayName-count-other" ] ||
62+
displayNames.displayName ||
63+
properties.currency;
64+
unitPattern = unitPatterns[ "unitPattern-count-" + pluralForm ] ||
65+
unitPatterns[ "unitPattern-count-other" ];
66+
67+
return formatMessage( unitPattern, [ formattedNumber, displayName ]);
68+
};
69+
70+
71+
72+
73+
var currencyFormatterFn = function( numberFormatter, pluralGenerator, properties ) {
74+
var fn;
75+
76+
// Return formatter when style is "code" or "name".
77+
if ( pluralGenerator && properties ) {
78+
fn = function currencyFormatter( value ) {
79+
validateParameterPresence( value, "value" );
80+
validateParameterTypeNumber( value, "value" );
81+
return currencyNameFormat(
82+
numberFormatter( value ),
83+
pluralGenerator( value ),
84+
properties
85+
);
86+
};
87+
88+
// Return formatter when style is "symbol" or "accounting".
89+
} else {
90+
fn = function currencyFormatter( value ) {
91+
return numberFormatter( value );
92+
};
93+
}
94+
95+
return fn;
96+
};
97+
98+
99+
100+
101+
Globalize._currencyFormatterFn = currencyFormatterFn;
102+
Globalize._currencyNameFormat = currencyNameFormat;
103+
104+
Globalize.currencyFormatter =
105+
Globalize.prototype.currencyFormatter = function( currency, options ) {
106+
options = options || {};
107+
return Globalize[ runtimeKey( "currencyFormatter", this._locale, [ currency, options ] ) ];
108+
};
109+
110+
Globalize.formatCurrency =
111+
Globalize.prototype.formatCurrency = function( value, currency, options ) {
112+
validateParameterPresence( value, "value" );
113+
validateParameterTypeNumber( value, "value" );
114+
115+
return this.currencyFormatter( currency, options )( value );
116+
};
117+
118+
return Globalize;
119+
120+
121+
122+
123+
}));

0 commit comments

Comments
 (0)