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