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,326 @@
1
+ /**
2
+ * Globalize Runtime 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 Runtime v1.7.0 2021-08-02T11:53Z 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
+ /**
118
+ * Pushes part to parts array, concat two consecutive parts of the same type.
119
+ */
120
+ var partsPush = function( parts, type, value ) {
121
+
122
+ // Concat two consecutive parts of same type
123
+ if ( parts.length && parts[ parts.length - 1 ].type === type ) {
124
+ parts[ parts.length - 1 ].value += value;
125
+ return;
126
+ }
127
+
128
+ parts.push( { type: type, value: value } );
129
+ };
130
+
131
+
132
+
133
+
134
+ /**
135
+ * formatMessage( message, data )
136
+ *
137
+ * @message [String] A message with optional {vars} to be replaced.
138
+ *
139
+ * @data [Array or JSON] Object with replacing-variables content.
140
+ *
141
+ * Return the formatted message. For example:
142
+ *
143
+ * - formatMessage( "{0} second", [ 1 ] );
144
+ * > [{type: "variable", value: "1", name: "0"}, {type: "literal", value: " second"}]
145
+ *
146
+ * - formatMessage( "{0}/{1}", ["m", "s"] );
147
+ * > [
148
+ * { type: "variable", value: "m", name: "0" },
149
+ * { type: "literal", value: " /" },
150
+ * { type: "variable", value: "s", name: "1" }
151
+ * ]
152
+ */
153
+ var formatMessageToParts = function( message, data ) {
154
+
155
+ var lastOffset = 0,
156
+ parts = [];
157
+
158
+ // Create parts.
159
+ message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( nameIncludingBrackets, offset ) {
160
+ var name = nameIncludingBrackets.slice( 1, -1 );
161
+ partsPush( parts, "literal", message.slice( lastOffset, offset ));
162
+ partsPush( parts, "variable", data[ name ] );
163
+ parts[ parts.length - 1 ].name = name;
164
+ lastOffset += offset + nameIncludingBrackets.length;
165
+ });
166
+
167
+ // Skip empty ones such as `{ type: 'literal', value: '' }`.
168
+ return parts.filter(function( part ) {
169
+ return part.value !== "";
170
+ });
171
+ };
172
+
173
+
174
+
175
+
176
+ /**
177
+ * Returns joined parts values.
178
+ */
179
+ var partsJoin = function( parts ) {
180
+ return parts.map( function( part ) {
181
+ return part.value;
182
+ }).join( "" );
183
+ };
184
+
185
+
186
+
187
+
188
+ var runtimeStringify = function( args ) {
189
+ return JSON.stringify( args, function( _key, value ) {
190
+ if ( value && value.runtimeKey ) {
191
+ return value.runtimeKey;
192
+ }
193
+ return value;
194
+ } );
195
+ };
196
+
197
+
198
+
199
+
200
+ // Based on http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
201
+ var stringHash = function( str ) {
202
+ return [].reduce.call( str, function( hash, i ) {
203
+ var chr = i.charCodeAt( 0 );
204
+ hash = ( ( hash << 5 ) - hash ) + chr;
205
+ return hash | 0;
206
+ }, 0 );
207
+ };
208
+
209
+
210
+
211
+
212
+ var runtimeKey = function( fnName, locale, args, argsStr ) {
213
+ var hash;
214
+ argsStr = argsStr || runtimeStringify( args );
215
+ hash = stringHash( fnName + locale + argsStr );
216
+ return hash > 0 ? "a" + hash : "b" + Math.abs( hash );
217
+ };
218
+
219
+
220
+
221
+
222
+ var validate = function( code, message, check, attributes ) {
223
+ if ( !check ) {
224
+ throw createError( code, message, attributes );
225
+ }
226
+ };
227
+
228
+
229
+
230
+
231
+ var validateParameterPresence = function( value, name ) {
232
+ validate( "E_MISSING_PARAMETER", "Missing required parameter `{name}`.",
233
+ value !== undefined, { name: name });
234
+ };
235
+
236
+
237
+
238
+
239
+ var validateParameterType = function( value, name, check, expected ) {
240
+ validate(
241
+ "E_INVALID_PAR_TYPE",
242
+ "Invalid `{name}` parameter ({value}). {expected} expected.",
243
+ check,
244
+ {
245
+ expected: expected,
246
+ name: name,
247
+ value: value
248
+ }
249
+ );
250
+ };
251
+
252
+
253
+
254
+
255
+ var validateParameterTypeString = function( value, name ) {
256
+ validateParameterType(
257
+ value,
258
+ name,
259
+ value === undefined || typeof value === "string",
260
+ "a string"
261
+ );
262
+ };
263
+
264
+
265
+
266
+
267
+ // ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions?redirectlocale=en-US&redirectslug=JavaScript%2FGuide%2FRegular_Expressions
268
+ var regexpEscape = function( string ) {
269
+ return string.replace( /([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1" );
270
+ };
271
+
272
+
273
+
274
+
275
+ var stringPad = function( str, count, right ) {
276
+ var length;
277
+ if ( typeof str !== "string" ) {
278
+ str = String( str );
279
+ }
280
+ for ( length = str.length; length < count; length += 1 ) {
281
+ str = ( right ? ( str + "0" ) : ( "0" + str ) );
282
+ }
283
+ return str;
284
+ };
285
+
286
+
287
+
288
+
289
+ function Globalize( locale ) {
290
+ if ( !( this instanceof Globalize ) ) {
291
+ return new Globalize( locale );
292
+ }
293
+
294
+ validateParameterPresence( locale, "locale" );
295
+ validateParameterTypeString( locale, "locale" );
296
+
297
+ this._locale = locale;
298
+ }
299
+
300
+ Globalize.locale = function( locale ) {
301
+ validateParameterTypeString( locale, "locale" );
302
+
303
+ if ( arguments.length ) {
304
+ this._locale = locale;
305
+ }
306
+ return this._locale;
307
+ };
308
+
309
+ Globalize._createError = createError;
310
+ Globalize._formatMessage = formatMessage;
311
+ Globalize._formatMessageToParts = formatMessageToParts;
312
+ Globalize._partsJoin = partsJoin;
313
+ Globalize._partsPush = partsPush;
314
+ Globalize._regexpEscape = regexpEscape;
315
+ Globalize._runtimeKey = runtimeKey;
316
+ Globalize._stringPad = stringPad;
317
+ Globalize._validateParameterPresence = validateParameterPresence;
318
+ Globalize._validateParameterTypeString = validateParameterTypeString;
319
+ Globalize._validateParameterType = validateParameterType;
320
+
321
+ return Globalize;
322
+
323
+
324
+
325
+
326
+ }));