globalize-rpk 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/globalize/currency.js +590 -0
  2. package/globalize/date.js +3139 -0
  3. package/globalize/globalize-runtime.js +326 -0
  4. package/globalize/globalize.js +507 -0
  5. package/globalize/message.js +2076 -0
  6. package/globalize/number.js +1727 -0
  7. package/globalize/plural.js +376 -0
  8. package/globalize/relative-time.js +203 -0
  9. package/globalize/unit.js +301 -0
  10. package/node-main.js +27 -0
  11. package/package.json +3 -26
  12. package/CONTRIBUTING.md +0 -5
  13. package/README.md +0 -818
  14. package/doc/api/core/constructor.md +0 -28
  15. package/doc/api/core/load.md +0 -96
  16. package/doc/api/core/locale.md +0 -43
  17. package/doc/api/currency/currency-formatter.md +0 -196
  18. package/doc/api/currency/currency-to-parts-formatter.md +0 -117
  19. package/doc/api/date/date-formatter.md +0 -203
  20. package/doc/api/date/date-parser.md +0 -60
  21. package/doc/api/date/date-to-parts-formatter.md +0 -176
  22. package/doc/api/date/load-iana-time-zone.md +0 -29
  23. package/doc/api/message/load-messages.md +0 -105
  24. package/doc/api/message/message-formatter.md +0 -208
  25. package/doc/api/number/number-formatter.md +0 -202
  26. package/doc/api/number/number-parser.md +0 -130
  27. package/doc/api/number/number-to-parts-formatter.md +0 -140
  28. package/doc/api/plural/plural-generator.md +0 -84
  29. package/doc/api/relative-time/relative-time-formatter.md +0 -60
  30. package/doc/api/unit/unit-formatter.md +0 -72
  31. package/doc/blog-post/2017-07-xx-1.3.0-announcement.md +0 -177
  32. package/doc/cldr.md +0 -114
  33. package/doc/error/e-default-locale-not-defined.md +0 -9
  34. package/doc/error/e-invalid-cldr.md +0 -14
  35. package/doc/error/e-invalid-par-type.md +0 -12
  36. package/doc/error/e-invalid-par-value.md +0 -11
  37. package/doc/error/e-missing-cldr.md +0 -11
  38. package/doc/error/e-missing-parameter.md +0 -10
  39. package/doc/error/e-missing-plural-module.md +0 -9
  40. package/doc/error/e-par-missing-key.md +0 -11
  41. package/doc/error/e-par-out-of-range.md +0 -13
  42. package/doc/error/e-unsupported.md +0 -10
  43. package/doc/migrating-from-0.x.md +0 -64
  44. package/examples/amd-bower/.bowerrc +0 -7
  45. package/examples/amd-bower/README.md +0 -65
  46. package/examples/amd-bower/bower.json +0 -13
  47. package/examples/amd-bower/index.html +0 -46
  48. package/examples/amd-bower/main.js +0 -141
  49. package/examples/amd-bower/messages/en.json +0 -12
  50. package/examples/amd-bower/package.json +0 -14
  51. package/examples/app-npm-webpack/README.md +0 -74
  52. package/examples/app-npm-webpack/app/index.js +0 -89
  53. package/examples/app-npm-webpack/index-template.html +0 -71
  54. package/examples/app-npm-webpack/messages/ar.json +0 -25
  55. package/examples/app-npm-webpack/messages/de.json +0 -21
  56. package/examples/app-npm-webpack/messages/en.json +0 -21
  57. package/examples/app-npm-webpack/messages/es.json +0 -21
  58. package/examples/app-npm-webpack/messages/pt.json +0 -21
  59. package/examples/app-npm-webpack/messages/ru.json +0 -23
  60. package/examples/app-npm-webpack/messages/zh.json +0 -20
  61. package/examples/app-npm-webpack/package.json +0 -17
  62. package/examples/app-npm-webpack/webpack-config.js +0 -63
  63. package/examples/globalize-compiler/README.md +0 -45
  64. package/examples/globalize-compiler/app.js +0 -58
  65. package/examples/globalize-compiler/development.html +0 -121
  66. package/examples/globalize-compiler/messages.json +0 -12
  67. package/examples/globalize-compiler/package.json +0 -15
  68. package/examples/globalize-compiler/production.html +0 -75
  69. package/examples/node-npm/README.md +0 -57
  70. package/examples/node-npm/main.js +0 -65
  71. package/examples/node-npm/messages/en.json +0 -12
  72. package/examples/node-npm/package.json +0 -10
  73. package/examples/plain-javascript/README.md +0 -81
  74. package/examples/plain-javascript/index.html +0 -445
@@ -0,0 +1,507 @@
1
+ /**
2
+ * Globalize v1.7.0
3
+ *
4
+ * https://github.com/globalizejs/globalize
5
+ *
6
+ * Copyright OpenJS Foundation and other contributors
7
+ * Released under the MIT license
8
+ * https://jquery.org/license
9
+ *
10
+ * Date: 2021-08-02T11:53Z
11
+ */
12
+ /*!
13
+ * Globalize v1.7.0 2021-08-02T11:53Z 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([
23
+ "cldr",
24
+ "cldr/event"
25
+ ], factory );
26
+ } else if ( typeof exports === "object" ) {
27
+
28
+ // Node, CommonJS
29
+ module.exports = factory( require( "cldrjs" ) );
30
+ } else {
31
+
32
+ // Global
33
+ root.Globalize = factory( root.Cldr );
34
+ }
35
+ }( this, function( Cldr ) {
36
+
37
+
38
+ /**
39
+ * A toString method that outputs meaningful values for objects or arrays and
40
+ * still performs as fast as a plain string in case variable is string, or as
41
+ * fast as `"" + number` in case variable is a number.
42
+ * Ref: http://jsperf.com/my-stringify
43
+ */
44
+ var toString = function( variable ) {
45
+ return typeof variable === "string" ? variable : ( typeof variable === "number" ? "" +
46
+ variable : JSON.stringify( variable ) );
47
+ };
48
+
49
+
50
+
51
+
52
+ /**
53
+ * formatMessage( message, data )
54
+ *
55
+ * @message [String] A message with optional {vars} to be replaced.
56
+ *
57
+ * @data [Array or JSON] Object with replacing-variables content.
58
+ *
59
+ * Return the formatted message. For example:
60
+ *
61
+ * - formatMessage( "{0} second", [ 1 ] ); // 1 second
62
+ *
63
+ * - formatMessage( "{0}/{1}", ["m", "s"] ); // m/s
64
+ *
65
+ * - formatMessage( "{name} <{email}>", {
66
+ * name: "Foo",
67
+ * email: "bar@baz.qux"
68
+ * }); // Foo <bar@baz.qux>
69
+ */
70
+ var formatMessage = function( message, data ) {
71
+
72
+ // Replace {attribute}'s
73
+ message = message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( name ) {
74
+ name = name.replace( /^{([^}]*)}$/, "$1" );
75
+ return toString( data[ name ] );
76
+ });
77
+
78
+ return message;
79
+ };
80
+
81
+
82
+
83
+
84
+ var objectExtend = function() {
85
+ var destination = arguments[ 0 ],
86
+ sources = [].slice.call( arguments, 1 );
87
+
88
+ sources.forEach(function( source ) {
89
+ var prop;
90
+ for ( prop in source ) {
91
+ destination[ prop ] = source[ prop ];
92
+ }
93
+ });
94
+
95
+ return destination;
96
+ };
97
+
98
+
99
+
100
+
101
+ var createError = function( code, message, attributes ) {
102
+ var error;
103
+
104
+ message = code + ( message ? ": " + formatMessage( message, attributes ) : "" );
105
+ error = new Error( message );
106
+ error.code = code;
107
+
108
+ objectExtend( error, attributes );
109
+
110
+ return error;
111
+ };
112
+
113
+
114
+
115
+
116
+ /**
117
+ * Pushes part to parts array, concat two consecutive parts of the same type.
118
+ */
119
+ var partsPush = function( parts, type, value ) {
120
+
121
+ // Concat two consecutive parts of same type
122
+ if ( parts.length && parts[ parts.length - 1 ].type === type ) {
123
+ parts[ parts.length - 1 ].value += value;
124
+ return;
125
+ }
126
+
127
+ parts.push( { type: type, value: value } );
128
+ };
129
+
130
+
131
+
132
+
133
+ /**
134
+ * formatMessage( message, data )
135
+ *
136
+ * @message [String] A message with optional {vars} to be replaced.
137
+ *
138
+ * @data [Array or JSON] Object with replacing-variables content.
139
+ *
140
+ * Return the formatted message. For example:
141
+ *
142
+ * - formatMessage( "{0} second", [ 1 ] );
143
+ * > [{type: "variable", value: "1", name: "0"}, {type: "literal", value: " second"}]
144
+ *
145
+ * - formatMessage( "{0}/{1}", ["m", "s"] );
146
+ * > [
147
+ * { type: "variable", value: "m", name: "0" },
148
+ * { type: "literal", value: " /" },
149
+ * { type: "variable", value: "s", name: "1" }
150
+ * ]
151
+ */
152
+ var formatMessageToParts = function( message, data ) {
153
+
154
+ var lastOffset = 0,
155
+ parts = [];
156
+
157
+ // Create parts.
158
+ message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( nameIncludingBrackets, offset ) {
159
+ var name = nameIncludingBrackets.slice( 1, -1 );
160
+ partsPush( parts, "literal", message.slice( lastOffset, offset ));
161
+ partsPush( parts, "variable", data[ name ] );
162
+ parts[ parts.length - 1 ].name = name;
163
+ lastOffset += offset + nameIncludingBrackets.length;
164
+ });
165
+
166
+ // Skip empty ones such as `{ type: 'literal', value: '' }`.
167
+ return parts.filter(function( part ) {
168
+ return part.value !== "";
169
+ });
170
+ };
171
+
172
+
173
+
174
+
175
+ /**
176
+ * Returns joined parts values.
177
+ */
178
+ var partsJoin = function( parts ) {
179
+ return parts.map( function( part ) {
180
+ return part.value;
181
+ }).join( "" );
182
+ };
183
+
184
+
185
+
186
+
187
+ var runtimeStringify = function( args ) {
188
+ return JSON.stringify( args, function( _key, value ) {
189
+ if ( value && value.runtimeKey ) {
190
+ return value.runtimeKey;
191
+ }
192
+ return value;
193
+ } );
194
+ };
195
+
196
+
197
+
198
+
199
+ // Based on http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
200
+ var stringHash = function( str ) {
201
+ return [].reduce.call( str, function( hash, i ) {
202
+ var chr = i.charCodeAt( 0 );
203
+ hash = ( ( hash << 5 ) - hash ) + chr;
204
+ return hash | 0;
205
+ }, 0 );
206
+ };
207
+
208
+
209
+
210
+
211
+ var runtimeKey = function( fnName, locale, args, argsStr ) {
212
+ var hash;
213
+ argsStr = argsStr || runtimeStringify( args );
214
+ hash = stringHash( fnName + locale + argsStr );
215
+ return hash > 0 ? "a" + hash : "b" + Math.abs( hash );
216
+ };
217
+
218
+
219
+
220
+
221
+ var functionName = function( fn ) {
222
+ if ( fn.name !== undefined ) {
223
+ return fn.name;
224
+ }
225
+
226
+ // fn.name is not supported by IE.
227
+ var matches = /^function\s+([\w\$]+)\s*\(/.exec( fn.toString() );
228
+
229
+ if ( matches && matches.length > 0 ) {
230
+ return matches[ 1 ];
231
+ }
232
+ };
233
+
234
+
235
+
236
+
237
+ var runtimeBind = function( args, cldr, fn, runtimeArgs ) {
238
+
239
+ var argsStr = runtimeStringify( args ),
240
+ fnName = functionName( fn ),
241
+ locale = cldr.locale;
242
+
243
+ // If name of the function is not available, this is most likely due to uglification,
244
+ // which most likely means we are in production, and runtimeBind here is not necessary.
245
+ if ( !fnName ) {
246
+ return fn;
247
+ }
248
+
249
+ fn.runtimeKey = runtimeKey( fnName, locale, null, argsStr );
250
+
251
+ fn.generatorString = function() {
252
+ return "Globalize(\"" + locale + "\")." + fnName + "(" + argsStr.slice( 1, -1 ) + ")";
253
+ };
254
+
255
+ fn.runtimeArgs = runtimeArgs;
256
+
257
+ return fn;
258
+ };
259
+
260
+
261
+
262
+
263
+ var validate = function( code, message, check, attributes ) {
264
+ if ( !check ) {
265
+ throw createError( code, message, attributes );
266
+ }
267
+ };
268
+
269
+
270
+
271
+
272
+ var alwaysArray = function( stringOrArray ) {
273
+ return Array.isArray( stringOrArray ) ? stringOrArray : stringOrArray ? [ stringOrArray ] : [];
274
+ };
275
+
276
+
277
+
278
+
279
+ var validateCldr = function( path, value, options ) {
280
+ var skipBoolean;
281
+ options = options || {};
282
+
283
+ skipBoolean = alwaysArray( options.skip ).some(function( pathRe ) {
284
+ return pathRe.test( path );
285
+ });
286
+
287
+ validate( "E_MISSING_CLDR", "Missing required CLDR content `{path}`.", value || skipBoolean, {
288
+ path: path
289
+ });
290
+ };
291
+
292
+
293
+
294
+
295
+ var validateDefaultLocale = function( value ) {
296
+ validate( "E_DEFAULT_LOCALE_NOT_DEFINED", "Default locale has not been defined.",
297
+ value !== undefined, {} );
298
+ };
299
+
300
+
301
+
302
+
303
+ var validateParameterPresence = function( value, name ) {
304
+ validate( "E_MISSING_PARAMETER", "Missing required parameter `{name}`.",
305
+ value !== undefined, { name: name });
306
+ };
307
+
308
+
309
+
310
+
311
+ /**
312
+ * range( value, name, minimum, maximum )
313
+ *
314
+ * @value [Number].
315
+ *
316
+ * @name [String] name of variable.
317
+ *
318
+ * @minimum [Number]. The lowest valid value, inclusive.
319
+ *
320
+ * @maximum [Number]. The greatest valid value, inclusive.
321
+ */
322
+ var validateParameterRange = function( value, name, minimum, maximum ) {
323
+ validate(
324
+ "E_PAR_OUT_OF_RANGE",
325
+ "Parameter `{name}` has value `{value}` out of range [{minimum}, {maximum}].",
326
+ value === undefined || value >= minimum && value <= maximum,
327
+ {
328
+ maximum: maximum,
329
+ minimum: minimum,
330
+ name: name,
331
+ value: value
332
+ }
333
+ );
334
+ };
335
+
336
+
337
+
338
+
339
+ var validateParameterType = function( value, name, check, expected ) {
340
+ validate(
341
+ "E_INVALID_PAR_TYPE",
342
+ "Invalid `{name}` parameter ({value}). {expected} expected.",
343
+ check,
344
+ {
345
+ expected: expected,
346
+ name: name,
347
+ value: value
348
+ }
349
+ );
350
+ };
351
+
352
+
353
+
354
+
355
+ var validateParameterTypeLocale = function( value, name ) {
356
+ validateParameterType(
357
+ value,
358
+ name,
359
+ value === undefined || typeof value === "string" || value instanceof Cldr,
360
+ "String or Cldr instance"
361
+ );
362
+ };
363
+
364
+
365
+
366
+
367
+ /**
368
+ * Function inspired by jQuery Core, but reduced to our use case.
369
+ */
370
+ var isPlainObject = function( obj ) {
371
+ return obj !== null && "" + obj === "[object Object]";
372
+ };
373
+
374
+
375
+
376
+
377
+ var validateParameterTypePlainObject = function( value, name ) {
378
+ validateParameterType(
379
+ value,
380
+ name,
381
+ value === undefined || isPlainObject( value ),
382
+ "Plain Object"
383
+ );
384
+ };
385
+
386
+
387
+
388
+
389
+ var alwaysCldr = function( localeOrCldr ) {
390
+ return localeOrCldr instanceof Cldr ? localeOrCldr : new Cldr( localeOrCldr );
391
+ };
392
+
393
+
394
+
395
+
396
+ // ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions?redirectlocale=en-US&redirectslug=JavaScript%2FGuide%2FRegular_Expressions
397
+ var regexpEscape = function( string ) {
398
+ return string.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1" );
399
+ };
400
+
401
+
402
+
403
+
404
+ var stringPad = function( str, count, right ) {
405
+ var length;
406
+ if ( typeof str !== "string" ) {
407
+ str = String( str );
408
+ }
409
+ for ( length = str.length; length < count; length += 1 ) {
410
+ str = ( right ? ( str + "0" ) : ( "0" + str ) );
411
+ }
412
+ return str;
413
+ };
414
+
415
+
416
+
417
+
418
+ function validateLikelySubtags( cldr ) {
419
+ cldr.once( "get", validateCldr );
420
+ cldr.get( "supplemental/likelySubtags" );
421
+ }
422
+
423
+ /**
424
+ * [new] Globalize( locale|cldr )
425
+ *
426
+ * @locale [String]
427
+ *
428
+ * @cldr [Cldr instance]
429
+ *
430
+ * Create a Globalize instance.
431
+ */
432
+ function Globalize( locale ) {
433
+ if ( !( this instanceof Globalize ) ) {
434
+ return new Globalize( locale );
435
+ }
436
+
437
+ validateParameterPresence( locale, "locale" );
438
+ validateParameterTypeLocale( locale, "locale" );
439
+
440
+ this.cldr = alwaysCldr( locale );
441
+
442
+ validateLikelySubtags( this.cldr );
443
+ }
444
+
445
+ /**
446
+ * Globalize.load( json, ... )
447
+ *
448
+ * @json [JSON]
449
+ *
450
+ * Load resolved or unresolved cldr data.
451
+ * Somewhat equivalent to previous Globalize.addCultureInfo(...).
452
+ */
453
+ Globalize.load = function() {
454
+
455
+ // validations are delegated to Cldr.load().
456
+ Cldr.load.apply( Cldr, arguments );
457
+ };
458
+
459
+ /**
460
+ * Globalize.locale( [locale|cldr] )
461
+ *
462
+ * @locale [String]
463
+ *
464
+ * @cldr [Cldr instance]
465
+ *
466
+ * Set default Cldr instance if locale or cldr argument is passed.
467
+ *
468
+ * Return the default Cldr instance.
469
+ */
470
+ Globalize.locale = function( locale ) {
471
+ validateParameterTypeLocale( locale, "locale" );
472
+
473
+ if ( arguments.length ) {
474
+ this.cldr = alwaysCldr( locale );
475
+ validateLikelySubtags( this.cldr );
476
+ }
477
+ return this.cldr;
478
+ };
479
+
480
+ /**
481
+ * Optimization to avoid duplicating some internal functions across modules.
482
+ */
483
+ Globalize._alwaysArray = alwaysArray;
484
+ Globalize._createError = createError;
485
+ Globalize._formatMessage = formatMessage;
486
+ Globalize._formatMessageToParts = formatMessageToParts;
487
+ Globalize._isPlainObject = isPlainObject;
488
+ Globalize._objectExtend = objectExtend;
489
+ Globalize._partsJoin = partsJoin;
490
+ Globalize._partsPush = partsPush;
491
+ Globalize._regexpEscape = regexpEscape;
492
+ Globalize._runtimeBind = runtimeBind;
493
+ Globalize._stringPad = stringPad;
494
+ Globalize._validate = validate;
495
+ Globalize._validateCldr = validateCldr;
496
+ Globalize._validateDefaultLocale = validateDefaultLocale;
497
+ Globalize._validateParameterPresence = validateParameterPresence;
498
+ Globalize._validateParameterRange = validateParameterRange;
499
+ Globalize._validateParameterTypePlainObject = validateParameterTypePlainObject;
500
+ Globalize._validateParameterType = validateParameterType;
501
+
502
+ return Globalize;
503
+
504
+
505
+
506
+
507
+ }));