Skip to content

Commit ff03f39

Browse files
committed
Build: Include distribution files
1 parent 083d88e commit ff03f39

17 files changed

+11907
-0
lines changed

dist/globalize-runtime.js

+240
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
/**
2+
* Globalize Runtime v1.4.0-alpha.3
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: 2018-06-22T12:51Z
11+
*/
12+
/*!
13+
* Globalize Runtime v1.4.0-alpha.3 2018-06-22T12:51Z 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+
// Based on http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
118+
var stringHash = function( str ) {
119+
return [].reduce.call( str, function( hash, i ) {
120+
var chr = i.charCodeAt( 0 );
121+
hash = ( ( hash << 5 ) - hash ) + chr;
122+
return hash | 0;
123+
}, 0 );
124+
};
125+
126+
127+
128+
129+
var runtimeKey = function( fnName, locale, args, argsStr ) {
130+
var hash;
131+
argsStr = argsStr || JSON.stringify( args );
132+
hash = stringHash( fnName + locale + argsStr );
133+
return hash > 0 ? "a" + hash : "b" + Math.abs( hash );
134+
};
135+
136+
137+
138+
139+
var validate = function( code, message, check, attributes ) {
140+
if ( !check ) {
141+
throw createError( code, message, attributes );
142+
}
143+
};
144+
145+
146+
147+
148+
var validateParameterPresence = function( value, name ) {
149+
validate( "E_MISSING_PARAMETER", "Missing required parameter `{name}`.",
150+
value !== undefined, { name: name });
151+
};
152+
153+
154+
155+
156+
var validateParameterType = function( value, name, check, expected ) {
157+
validate(
158+
"E_INVALID_PAR_TYPE",
159+
"Invalid `{name}` parameter ({value}). {expected} expected.",
160+
check,
161+
{
162+
expected: expected,
163+
name: name,
164+
value: value
165+
}
166+
);
167+
};
168+
169+
170+
171+
172+
var validateParameterTypeString = function( value, name ) {
173+
validateParameterType(
174+
value,
175+
name,
176+
value === undefined || typeof value === "string",
177+
"a string"
178+
);
179+
};
180+
181+
182+
183+
184+
// ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions?redirectlocale=en-US&redirectslug=JavaScript%2FGuide%2FRegular_Expressions
185+
var regexpEscape = function( string ) {
186+
return string.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1" );
187+
};
188+
189+
190+
191+
192+
var stringPad = function( str, count, right ) {
193+
var length;
194+
if ( typeof str !== "string" ) {
195+
str = String( str );
196+
}
197+
for ( length = str.length; length < count; length += 1 ) {
198+
str = ( right ? ( str + "0" ) : ( "0" + str ) );
199+
}
200+
return str;
201+
};
202+
203+
204+
205+
206+
function Globalize( locale ) {
207+
if ( !( this instanceof Globalize ) ) {
208+
return new Globalize( locale );
209+
}
210+
211+
validateParameterPresence( locale, "locale" );
212+
validateParameterTypeString( locale, "locale" );
213+
214+
this._locale = locale;
215+
}
216+
217+
Globalize.locale = function( locale ) {
218+
validateParameterTypeString( locale, "locale" );
219+
220+
if ( arguments.length ) {
221+
this._locale = locale;
222+
}
223+
return this._locale;
224+
};
225+
226+
Globalize._createError = createError;
227+
Globalize._formatMessage = formatMessage;
228+
Globalize._regexpEscape = regexpEscape;
229+
Globalize._runtimeKey = runtimeKey;
230+
Globalize._stringPad = stringPad;
231+
Globalize._validateParameterPresence = validateParameterPresence;
232+
Globalize._validateParameterTypeString = validateParameterTypeString;
233+
Globalize._validateParameterType = validateParameterType;
234+
235+
return Globalize;
236+
237+
238+
239+
240+
}));

dist/globalize-runtime/currency.js

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* Globalize Runtime v1.4.0-alpha.3
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: 2018-06-22T12:51Z
11+
*/
12+
/*!
13+
* Globalize Runtime v1.4.0-alpha.3 2018-06-22T12:51Z 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)