@ultraq/icu-message-formatter 0.12.0 → 0.14.0

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 (32) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +5 -6
  3. package/dist/icu-message-formatter.browser.es.min.js +2 -0
  4. package/dist/icu-message-formatter.browser.es.min.js.map +1 -0
  5. package/dist/icu-message-formatter.browser.min.js +2 -0
  6. package/dist/icu-message-formatter.browser.min.js.map +1 -0
  7. package/dist/icu-message-formatter.cjs +473 -0
  8. package/dist/icu-message-formatter.cjs.map +1 -0
  9. package/dist/icu-message-formatter.d.cts +153 -0
  10. package/dist/icu-message-formatter.d.ts +153 -0
  11. package/dist/icu-message-formatter.js +466 -0
  12. package/dist/icu-message-formatter.js.map +1 -0
  13. package/package.json +43 -26
  14. package/dist/icu-message-formatter.es.min.js +0 -2
  15. package/dist/icu-message-formatter.es.min.js.map +0 -1
  16. package/dist/icu-message-formatter.min.js +0 -2
  17. package/dist/icu-message-formatter.min.js.map +0 -1
  18. package/lib/icu-message-formatter.cjs.js +0 -476
  19. package/lib/icu-message-formatter.cjs.js.map +0 -1
  20. package/lib/icu-message-formatter.es.js +0 -460
  21. package/lib/icu-message-formatter.es.js.map +0 -1
  22. package/rollup.config.dist.js +0 -37
  23. package/rollup.config.js +0 -35
  24. package/source/IcuMessageFormatter.js +0 -9
  25. package/source/MessageFormatter.js +0 -112
  26. package/source/MessageFormatter.test.js +0 -153
  27. package/source/pluralTypeHandler.js +0 -122
  28. package/source/pluralTypeHandler.test.js +0 -188
  29. package/source/selectTypeHandler.js +0 -46
  30. package/source/selectTypeHandler.test.js +0 -59
  31. package/source/utilities.js +0 -166
  32. package/source/utilities.test.js +0 -123
@@ -1,460 +0,0 @@
1
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
- import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
3
- import _createClass from '@babel/runtime/helpers/createClass';
4
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
5
- import { flatten } from '@ultraq/array-utils';
6
- import { memoize } from '@ultraq/function-utils';
7
-
8
- /*
9
- * Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/)
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- /**
25
- * Most branch-based type handlers are based around "cases".
26
- * For example, `select` and `plural` compare compare a value
27
- * to "case keys" to choose a subtranslation.
28
- *
29
- * This util splits "matches" portions provided to the aforementioned
30
- * handlers into case strings, and extracts any prepended arguments
31
- * (for example, `plural` supports an `offset:n` argument used for
32
- * populating the magic `#` variable).
33
- *
34
- * @param {String} string
35
- * @return {Object} The `cases` key points to a map of all cases.
36
- * The `arguments` key points to a list of prepended arguments.
37
- */
38
- function parseCases(string) {
39
- var isWhitespace = function isWhitespace(ch) {
40
- return /\s/.test(ch);
41
- };
42
-
43
- var args = [];
44
- var cases = {};
45
- var currTermStart = 0;
46
- var latestTerm = null;
47
- var inTerm = false;
48
- var i = 0;
49
-
50
- while (i < string.length) {
51
- // Term ended
52
- if (inTerm && (isWhitespace(string[i]) || string[i] === '{')) {
53
- inTerm = false;
54
- latestTerm = string.slice(currTermStart, i); // We want to process the opening char again so the case will be properly registered.
55
-
56
- if (string[i] === '{') {
57
- i--;
58
- }
59
- } // New term
60
- else if (!inTerm && !isWhitespace(string[i])) {
61
- var caseBody = string[i] === '{'; // If there's a previous term, we can either handle a whole
62
- // case, or add that as an argument.
63
-
64
- if (latestTerm && caseBody) {
65
- var branchEndIndex = findClosingBracket(string, i);
66
-
67
- if (branchEndIndex === -1) {
68
- throw new Error("Unbalanced curly braces in string: \"".concat(string, "\""));
69
- }
70
-
71
- cases[latestTerm] = string.slice(i + 1, branchEndIndex); // Don't include the braces
72
-
73
- i = branchEndIndex; // Will be moved up where needed at end of loop.
74
-
75
- latestTerm = null;
76
- } else {
77
- if (latestTerm) {
78
- args.push(latestTerm);
79
- latestTerm = null;
80
- }
81
-
82
- inTerm = true;
83
- currTermStart = i;
84
- }
85
- }
86
-
87
- i++;
88
- }
89
-
90
- if (inTerm) {
91
- latestTerm = string.slice(currTermStart);
92
- }
93
-
94
- if (latestTerm) {
95
- args.push(latestTerm);
96
- }
97
-
98
- return {
99
- args: args,
100
- cases: cases
101
- };
102
- }
103
- /**
104
- * Finds the index of the matching closing curly bracket, including through
105
- * strings that could have nested brackets.
106
- *
107
- * @param {String} string
108
- * @param {Number} fromIndex
109
- * @return {Number} The index of the matching closing bracket, or -1 if no
110
- * closing bracket could be found.
111
- */
112
-
113
- function findClosingBracket(string, fromIndex) {
114
- var depth = 0;
115
-
116
- for (var i = fromIndex + 1; i < string.length; i++) {
117
- var char = string.charAt(i);
118
-
119
- if (char === '}') {
120
- if (depth === 0) {
121
- return i;
122
- }
123
-
124
- depth--;
125
- } else if (char === '{') {
126
- depth++;
127
- }
128
- }
129
-
130
- return -1;
131
- }
132
- /**
133
- * Split a `{key, type, format}` block into those 3 parts, taking into account
134
- * nested message syntax that can exist in the `format` part.
135
- *
136
- * @param {String} block
137
- * @return {Array}
138
- * An array with `key`, `type`, and `format` items in that order, if present
139
- * in the formatted argument block.
140
- */
141
-
142
- function splitFormattedArgument(block) {
143
- return split(block.slice(1, -1), ',', 3);
144
- }
145
- /**
146
- * Like `String.prototype.split()` but where the limit parameter causes the
147
- * remainder of the string to be grouped together in a final entry.
148
- *
149
- * @private
150
- * @param {String} string
151
- * @param {String} separator
152
- * @param {Number} limit
153
- * @param {Array} [accumulator=[]]
154
- * @return {Array}
155
- */
156
-
157
- function split(string, separator, limit) {
158
- var accumulator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
159
-
160
- if (!string) {
161
- return accumulator;
162
- }
163
-
164
- if (limit === 1) {
165
- accumulator.push(string);
166
- return accumulator;
167
- }
168
-
169
- var indexOfDelimiter = string.indexOf(separator);
170
-
171
- if (indexOfDelimiter === -1) {
172
- accumulator.push(string);
173
- return accumulator;
174
- }
175
-
176
- var head = string.substring(0, indexOfDelimiter).trim();
177
- var tail = string.substring(indexOfDelimiter + separator.length + 1).trim();
178
- accumulator.push(head);
179
- return split(tail, separator, limit - 1, accumulator);
180
- }
181
-
182
- /**
183
- * The main class for formatting messages.
184
- *
185
- * @author Emanuel Rabina
186
- */
187
-
188
- var MessageFormatter = /*#__PURE__*/function () {
189
- /**
190
- * Creates a new formatter that can work using any of the custom type handlers
191
- * you register.
192
- *
193
- * @param {String} locale
194
- * @param {Object} [typeHandlers={}]
195
- * Optional object where the keys are the names of the types to register,
196
- * their values being the functions that will return a nicely formatted
197
- * string for the data and locale they are given.
198
- */
199
- function MessageFormatter(locale) {
200
- var _this = this;
201
-
202
- var typeHandlers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
203
-
204
- _classCallCheck(this, MessageFormatter);
205
-
206
- _defineProperty(this, "format", memoize(function (message) {
207
- var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
208
- return flatten(_this.process(message, values)).join('');
209
- }));
210
-
211
- this.locale = locale;
212
- this.typeHandlers = typeHandlers;
213
- }
214
- /**
215
- * Formats an ICU message syntax string using `values` for placeholder data
216
- * and any currently-registered type handlers.
217
- *
218
- * @param {String} message
219
- * @param {Object} [values={}]
220
- * @return {String}
221
- */
222
-
223
-
224
- _createClass(MessageFormatter, [{
225
- key: "process",
226
- value:
227
- /**
228
- * Process an ICU message syntax string using `values` for placeholder data
229
- * and any currently-registered type handlers. The result of this method is
230
- * an array of the component parts after they have been processed in turn by
231
- * their own type handlers. This raw output is useful for other renderers,
232
- * eg: React where components can be used instead of being forced to return
233
- * raw strings.
234
- *
235
- * This method is used by {@link MessageFormatter#format} where it acts as a
236
- * string renderer.
237
- *
238
- * @param {String} message
239
- * @param {Object} [values={}]
240
- * @return {Array}
241
- */
242
- function process(message) {
243
- var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
244
-
245
- if (!message) {
246
- return [];
247
- }
248
-
249
- var blockStartIndex = message.indexOf('{');
250
-
251
- if (blockStartIndex !== -1) {
252
- var blockEndIndex = findClosingBracket(message, blockStartIndex);
253
-
254
- if (blockEndIndex !== -1) {
255
- var block = message.substring(blockStartIndex, blockEndIndex + 1);
256
-
257
- if (block) {
258
- var result = [];
259
- var head = message.substring(0, blockStartIndex);
260
-
261
- if (head) {
262
- result.push(head);
263
- }
264
-
265
- var _splitFormattedArgume = splitFormattedArgument(block),
266
- _splitFormattedArgume2 = _slicedToArray(_splitFormattedArgume, 3),
267
- key = _splitFormattedArgume2[0],
268
- type = _splitFormattedArgume2[1],
269
- format = _splitFormattedArgume2[2];
270
-
271
- var body = values[key];
272
-
273
- if (body === null || body === undefined) {
274
- body = '';
275
- }
276
-
277
- var typeHandler = type && this.typeHandlers[type];
278
- result.push(typeHandler ? typeHandler(body, format, this.locale, values, this.process.bind(this)) : body);
279
- var tail = message.substring(blockEndIndex + 1);
280
-
281
- if (tail) {
282
- result.push(this.process(tail, values));
283
- }
284
-
285
- return result;
286
- }
287
- } else {
288
- throw new Error("Unbalanced curly braces in string: \"".concat(message, "\""));
289
- }
290
- }
291
-
292
- return [message];
293
- }
294
- }]);
295
-
296
- return MessageFormatter;
297
- }();
298
-
299
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
300
-
301
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
302
- var pluralFormatter;
303
- var keyCounter = 0; // All the special keywords that can be used in `plural` blocks for the various branches
304
-
305
- var ONE = 'one';
306
- var OTHER$1 = 'other';
307
- /**
308
- * @private
309
- * @param {String} caseBody
310
- * @param {Number} value
311
- * @return {Object} {caseBody: string, numberValues: object}
312
- */
313
-
314
- function replaceNumberSign(caseBody, value) {
315
- var i = 0;
316
- var output = '';
317
- var numBraces = 0;
318
- var numberValues = {};
319
-
320
- while (i < caseBody.length) {
321
- if (caseBody[i] === '#' && !numBraces) {
322
- var keyParam = "__hashToken".concat(keyCounter++);
323
- output += "{".concat(keyParam, ", number}");
324
- numberValues[keyParam] = value;
325
- } else {
326
- output += caseBody[i];
327
- }
328
-
329
- if (caseBody[i] === '{') {
330
- numBraces++;
331
- } else if (caseBody[i] === '}') {
332
- numBraces--;
333
- }
334
-
335
- i++;
336
- }
337
-
338
- return {
339
- caseBody: output,
340
- numberValues: numberValues
341
- };
342
- }
343
- /**
344
- * Handler for `plural` statements within ICU message syntax strings. Returns
345
- * a formatted string for the branch that closely matches the current value.
346
- *
347
- * See https://formatjs.io/docs/core-concepts/icu-syntax#plural-format for more
348
- * details on how the `plural` statement works.
349
- *
350
- * @param {String} value
351
- * @param {String} matches
352
- * @param {String} locale
353
- * @param {String} values
354
- * @param {Function} format
355
- * @return {String}
356
- */
357
-
358
-
359
- function pluralTypeHandler(value) {
360
- var matches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
361
- var locale = arguments.length > 2 ? arguments[2] : undefined;
362
- var values = arguments.length > 3 ? arguments[3] : undefined;
363
- var format = arguments.length > 4 ? arguments[4] : undefined;
364
-
365
- var _parseCases = parseCases(matches),
366
- args = _parseCases.args,
367
- cases = _parseCases.cases;
368
-
369
- var intValue = parseInt(value);
370
- args.forEach(function (arg) {
371
- if (arg.startsWith('offset:')) {
372
- intValue -= parseInt(arg.slice('offset:'.length));
373
- }
374
- });
375
- var keywordPossibilities = [];
376
-
377
- if ('PluralRules' in Intl) {
378
- // Effectively memoize because instantiation of `Int.*` objects is expensive.
379
- if (pluralFormatter === undefined || pluralFormatter.resolvedOptions().locale !== locale) {
380
- pluralFormatter = new Intl.PluralRules(locale);
381
- }
382
-
383
- var pluralKeyword = pluralFormatter.select(intValue); // Other is always added last with least priority, so we don't want to add it here.
384
-
385
- if (pluralKeyword !== OTHER$1) {
386
- keywordPossibilities.push(pluralKeyword);
387
- }
388
- }
389
-
390
- if (intValue === 1) {
391
- keywordPossibilities.push(ONE);
392
- }
393
-
394
- keywordPossibilities.push("=".concat(intValue), OTHER$1);
395
-
396
- for (var i = 0; i < keywordPossibilities.length; i++) {
397
- var keyword = keywordPossibilities[i];
398
-
399
- if (keyword in cases) {
400
- var _replaceNumberSign = replaceNumberSign(cases[keyword], intValue),
401
- caseBody = _replaceNumberSign.caseBody,
402
- numberValues = _replaceNumberSign.numberValues;
403
-
404
- return format(caseBody, _objectSpread(_objectSpread({}, values), numberValues));
405
- }
406
- }
407
-
408
- return value;
409
- }
410
-
411
- /*
412
- * Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/)
413
- *
414
- * Licensed under the Apache License, Version 2.0 (the "License");
415
- * you may not use this file except in compliance with the License.
416
- * You may obtain a copy of the License at
417
- *
418
- * http://www.apache.org/licenses/LICENSE-2.0
419
- *
420
- * Unless required by applicable law or agreed to in writing, software
421
- * distributed under the License is distributed on an "AS IS" BASIS,
422
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
423
- * See the License for the specific language governing permissions and
424
- * limitations under the License.
425
- */
426
- var OTHER = 'other';
427
- /**
428
- * Handler for `select` statements within ICU message syntax strings. Returns
429
- * a formatted string for the branch that closely matches the current value.
430
- *
431
- * See https://formatjs.io/docs/core-concepts/icu-syntax#select-format for more
432
- * details on how the `select` statement works.
433
- *
434
- * @param {String} value
435
- * @param {String} matches
436
- * @param {String} locale
437
- * @param {String} values
438
- * @param {Function} format
439
- * @return {String}
440
- */
441
-
442
- function selectTypeHandler(value) {
443
- var matches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
444
- var values = arguments.length > 3 ? arguments[3] : undefined;
445
- var format = arguments.length > 4 ? arguments[4] : undefined;
446
-
447
- var _parseCases = parseCases(matches),
448
- cases = _parseCases.cases;
449
-
450
- if (value in cases) {
451
- return format(cases[value], values);
452
- } else if (OTHER in cases) {
453
- return format(cases[OTHER], values);
454
- }
455
-
456
- return value;
457
- }
458
-
459
- export { MessageFormatter, findClosingBracket, parseCases, pluralTypeHandler, selectTypeHandler, splitFormattedArgument };
460
- //# sourceMappingURL=icu-message-formatter.es.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"icu-message-formatter.es.js","sources":["../source/utilities.js","../source/MessageFormatter.js","../source/pluralTypeHandler.js","../source/selectTypeHandler.js"],"sourcesContent":["/* \n * Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Most branch-based type handlers are based around \"cases\".\n * For example, `select` and `plural` compare compare a value\n * to \"case keys\" to choose a subtranslation.\n * \n * This util splits \"matches\" portions provided to the aforementioned\n * handlers into case strings, and extracts any prepended arguments\n * (for example, `plural` supports an `offset:n` argument used for\n * populating the magic `#` variable).\n * \n * @param {String} string\n * @return {Object} The `cases` key points to a map of all cases.\n * The `arguments` key points to a list of prepended arguments.\n */\nexport function parseCases(string) {\n\tconst isWhitespace = ch => /\\s/.test(ch);\n\n\tconst args = [];\n\tconst cases = {};\n\n\tlet currTermStart = 0;\n\tlet latestTerm = null;\n\tlet inTerm = false;\n\n\tlet i = 0;\n\twhile (i < string.length) {\n\t\t// Term ended\n\t\tif (inTerm && (isWhitespace(string[i]) || string[i] === '{')) {\n\t\t\tinTerm = false;\n\t\t\tlatestTerm = string.slice(currTermStart, i);\n\n\t\t\t// We want to process the opening char again so the case will be properly registered.\n\t\t\tif (string[i] === '{') {\n\t\t\t\ti--;\n\t\t\t}\n\t\t}\n\n\t\t// New term\n\t\telse if (!inTerm && !isWhitespace(string[i])) {\n\t\t\tconst caseBody = string[i] === '{';\n\n\t\t\t// If there's a previous term, we can either handle a whole\n\t\t\t// case, or add that as an argument.\n\t\t\tif (latestTerm && caseBody) {\n\t\t\t\tconst branchEndIndex = findClosingBracket(string, i);\n\n\t\t\t\tif (branchEndIndex === -1) {\n\t\t\t\t\tthrow new Error(`Unbalanced curly braces in string: \"${string}\"`);\n\t\t\t\t}\n\n\t\t\t\tcases[latestTerm] = string.slice(i + 1, branchEndIndex); // Don't include the braces\n\n\t\t\t\ti = branchEndIndex; // Will be moved up where needed at end of loop.\n\t\t\t\tlatestTerm = null;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (latestTerm) {\n\t\t\t\t\targs.push(latestTerm);\n\t\t\t\t\tlatestTerm = null;\n\t\t\t\t}\n\n\t\t\t\tinTerm = true;\n\t\t\t\tcurrTermStart = i;\n\t\t\t}\n\t\t}\n\t\ti++;\n\t}\n\n\tif (inTerm) {\n\t\tlatestTerm = string.slice(currTermStart);\n\t}\n\n\tif (latestTerm) {\n\t\targs.push(latestTerm);\n\t}\n\n\treturn {\n\t\targs,\n\t\tcases\n\t};\n}\n\n/**\n * Finds the index of the matching closing curly bracket, including through\n * strings that could have nested brackets.\n * \n * @param {String} string\n * @param {Number} fromIndex\n * @return {Number} The index of the matching closing bracket, or -1 if no\n * closing bracket could be found.\n */\nexport function findClosingBracket(string, fromIndex) {\n\tlet depth = 0;\n\tfor (let i = fromIndex + 1; i < string.length; i++) {\n\t\tlet char = string.charAt(i);\n\t\tif (char === '}') {\n\t\t\tif (depth === 0) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t\tdepth--;\n\t\t}\n\t\telse if (char === '{') {\n\t\t\tdepth++;\n\t\t}\n\t}\n\treturn -1;\n}\n\n/**\n * Split a `{key, type, format}` block into those 3 parts, taking into account\n * nested message syntax that can exist in the `format` part.\n * \n * @param {String} block\n * @return {Array}\n * An array with `key`, `type`, and `format` items in that order, if present\n * in the formatted argument block.\n */\nexport function splitFormattedArgument(block) {\n\treturn split(block.slice(1, -1), ',', 3);\n}\n\n/**\n * Like `String.prototype.split()` but where the limit parameter causes the\n * remainder of the string to be grouped together in a final entry.\n * \n * @private\n * @param {String} string\n * @param {String} separator\n * @param {Number} limit\n * @param {Array} [accumulator=[]]\n * @return {Array}\n */\nfunction split(string, separator, limit, accumulator = []) {\n\tif (!string) {\n\t\treturn accumulator;\n\t}\n\tif (limit === 1) {\n\t\taccumulator.push(string);\n\t\treturn accumulator;\n\t}\n\tlet indexOfDelimiter = string.indexOf(separator);\n\tif (indexOfDelimiter === -1) {\n\t\taccumulator.push(string);\n\t\treturn accumulator;\n\t}\n\tlet head = string.substring(0, indexOfDelimiter).trim();\n\tlet tail = string.substring(indexOfDelimiter + separator.length + 1).trim();\n\taccumulator.push(head);\n\treturn split(tail, separator, limit - 1, accumulator);\n}\n","/* \n * Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {findClosingBracket, splitFormattedArgument} from './utilities.js';\n\nimport {flatten} from '@ultraq/array-utils';\nimport {memoize} from '@ultraq/function-utils';\n\n/**\n * The main class for formatting messages.\n * \n * @author Emanuel Rabina\n */\nexport default class MessageFormatter {\n\n\t/**\n\t * Creates a new formatter that can work using any of the custom type handlers\n\t * you register.\n\t * \n\t * @param {String} locale\n\t * @param {Object} [typeHandlers={}]\n\t * Optional object where the keys are the names of the types to register,\n\t * their values being the functions that will return a nicely formatted\n\t * string for the data and locale they are given.\n\t */\n\tconstructor(locale, typeHandlers = {}) {\n\n\t\tthis.locale = locale;\n\t\tthis.typeHandlers = typeHandlers;\n\t}\n\n\t/**\n\t * Formats an ICU message syntax string using `values` for placeholder data\n\t * and any currently-registered type handlers.\n\t * \n\t * @param {String} message\n\t * @param {Object} [values={}]\n\t * @return {String}\n\t */\n\tformat = memoize((message, values = {}) => {\n\n\t\treturn flatten(this.process(message, values)).join('');\n\t})\n\n\t/**\n\t * Process an ICU message syntax string using `values` for placeholder data\n\t * and any currently-registered type handlers. The result of this method is\n\t * an array of the component parts after they have been processed in turn by\n\t * their own type handlers. This raw output is useful for other renderers,\n\t * eg: React where components can be used instead of being forced to return\n\t * raw strings.\n\t * \n\t * This method is used by {@link MessageFormatter#format} where it acts as a\n\t * string renderer.\n\t * \n\t * @param {String} message\n\t * @param {Object} [values={}]\n\t * @return {Array}\n\t */\n\tprocess(message, values = {}) {\n\n\t\tif (!message) {\n\t\t\treturn [];\n\t\t}\n\n\t\tlet blockStartIndex = message.indexOf('{');\n\t\tif (blockStartIndex !== -1) {\n\t\t\tlet blockEndIndex = findClosingBracket(message, blockStartIndex);\n\t\t\tif (blockEndIndex !== -1) {\n\t\t\t\tlet block = message.substring(blockStartIndex, blockEndIndex + 1);\n\t\t\t\tif (block) {\n\t\t\t\t\tlet result = [];\n\t\t\t\t\tlet head = message.substring(0, blockStartIndex);\n\t\t\t\t\tif (head) {\n\t\t\t\t\t\tresult.push(head);\n\t\t\t\t\t}\n\t\t\t\t\tlet [key, type, format] = splitFormattedArgument(block);\n\t\t\t\t\tlet body = values[key];\n\t\t\t\t\tif (body === null || body === undefined) {\n\t\t\t\t\t\tbody = '';\n\t\t\t\t\t}\n\t\t\t\t\tlet typeHandler = type && this.typeHandlers[type];\n\t\t\t\t\tresult.push(typeHandler ?\n\t\t\t\t\t\ttypeHandler(body, format, this.locale, values, this.process.bind(this)) :\n\t\t\t\t\t\tbody);\n\t\t\t\t\tlet tail = message.substring(blockEndIndex + 1);\n\t\t\t\t\tif (tail) {\n\t\t\t\t\t\tresult.push(this.process(tail, values));\n\t\t\t\t\t}\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new Error(`Unbalanced curly braces in string: \"${message}\"`);\n\t\t\t}\n\t\t}\n\t\treturn [message];\n\t}\n}\n","/* \n * Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {parseCases} from './utilities.js';\n\nlet pluralFormatter;\n\nlet keyCounter = 0;\n\n// All the special keywords that can be used in `plural` blocks for the various branches\nconst ONE = 'one';\nconst OTHER = 'other';\n\n/**\n * @private\n * @param {String} caseBody\n * @param {Number} value\n * @return {Object} {caseBody: string, numberValues: object}\n */\nfunction replaceNumberSign(caseBody, value) {\n\tlet i = 0;\n\tlet output = '';\n\tlet numBraces = 0;\n\tconst numberValues = {};\n\n\twhile (i < caseBody.length) {\n\t\tif (caseBody[i] === '#' && !numBraces) {\n\t\t\tlet keyParam = `__hashToken${keyCounter++}`;\n\t\t\toutput += `{${keyParam}, number}`;\n\t\t\tnumberValues[keyParam] = value;\n\t\t}\n\t\telse {\n\t\t\toutput += caseBody[i];\n\t\t}\n\n\t\tif (caseBody[i] === '{') {\n\t\t\tnumBraces++;\n\t\t}\n\t\telse if (caseBody[i] === '}') {\n\t\t\tnumBraces--;\n\t\t}\n\n\t\ti++;\n\t}\n\n\treturn {\n\t\tcaseBody: output,\n\t\tnumberValues\n\t};\n}\n\n/**\n * Handler for `plural` statements within ICU message syntax strings. Returns\n * a formatted string for the branch that closely matches the current value.\n * \n * See https://formatjs.io/docs/core-concepts/icu-syntax#plural-format for more\n * details on how the `plural` statement works.\n * \n * @param {String} value\n * @param {String} matches\n * @param {String} locale\n * @param {String} values\n * @param {Function} format\n * @return {String}\n */\nexport default function pluralTypeHandler(value, matches = '', locale, values, format) {\n\tconst { args, cases } = parseCases(matches);\n\n\tlet intValue = parseInt(value);\n\n\targs.forEach((arg) => {\n\t\tif (arg.startsWith('offset:')) {\n\t\t\tintValue -= parseInt(arg.slice('offset:'.length));\n\t\t}\n\t});\n\n\tconst keywordPossibilities = [];\n\n\tif ('PluralRules' in Intl) {\n\t\t// Effectively memoize because instantiation of `Int.*` objects is expensive.\n\t\tif (pluralFormatter === undefined || pluralFormatter.resolvedOptions().locale !== locale) {\n\t\t\tpluralFormatter = new Intl.PluralRules(locale);\n\t\t}\n\n\t\tconst pluralKeyword = pluralFormatter.select(intValue);\n\n\t\t// Other is always added last with least priority, so we don't want to add it here.\n\t\tif (pluralKeyword !== OTHER) {\n\t\t\tkeywordPossibilities.push(pluralKeyword);\n\t\t}\n\t}\n\tif (intValue === 1) {\n\t\tkeywordPossibilities.push(ONE);\n\t}\n\tkeywordPossibilities.push(`=${intValue}`, OTHER);\n\n\tfor (let i = 0; i < keywordPossibilities.length; i++) {\n\t\tconst keyword = keywordPossibilities[i];\n\t\tif (keyword in cases) {\n\t\t\tconst { caseBody, numberValues } = replaceNumberSign(cases[keyword], intValue);\n\t\t\treturn format(caseBody, {\n\t\t\t\t...values,\n\t\t\t\t...numberValues\n\t\t\t});\n\t\t}\n\t}\n\n\treturn value;\n}\n","/* \n * Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {parseCases} from './utilities.js';\n\nconst OTHER = 'other';\n\n/**\n * Handler for `select` statements within ICU message syntax strings. Returns\n * a formatted string for the branch that closely matches the current value.\n * \n * See https://formatjs.io/docs/core-concepts/icu-syntax#select-format for more\n * details on how the `select` statement works.\n * \n * @param {String} value\n * @param {String} matches\n * @param {String} locale\n * @param {String} values\n * @param {Function} format\n * @return {String}\n */\nexport default function selectTypeHandler(value, matches = '', locale, values, format) {\n\tconst { cases } = parseCases(matches);\n\n\tif (value in cases) {\n\t\treturn format(cases[value], values);\n\t}\n\telse if (OTHER in cases) {\n\t\treturn format(cases[OTHER], values);\n\t}\n\n\treturn value;\n}\n"],"names":["parseCases","string","isWhitespace","ch","test","args","cases","currTermStart","latestTerm","inTerm","i","length","slice","caseBody","branchEndIndex","findClosingBracket","Error","push","fromIndex","depth","char","charAt","splitFormattedArgument","block","split","separator","limit","accumulator","indexOfDelimiter","indexOf","head","substring","trim","tail","MessageFormatter","locale","typeHandlers","memoize","message","values","flatten","process","join","blockStartIndex","blockEndIndex","result","key","type","format","body","undefined","typeHandler","bind","pluralFormatter","keyCounter","ONE","OTHER","replaceNumberSign","value","output","numBraces","numberValues","keyParam","pluralTypeHandler","matches","intValue","parseInt","forEach","arg","startsWith","keywordPossibilities","Intl","resolvedOptions","PluralRules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A;AACA;AACA;AACA;AACA;AACA;;AACe,SAASqB,iBAAT,CAA2BnB,KAA3B,EAAwE;AAAA,MAAtCM,OAAsC,uEAA5B,EAA4B;AAAA,MAAhBzB,MAAgB;AAAA,MAARS,MAAQ;;AACtF,oBAAkBhD,UAAU,CAACgE,OAAD,CAA5B;AAAA,MAAQ1D,KAAR,eAAQA,KAAR;;AAEA,MAAIoD,KAAK,IAAIpD,KAAb,EAAoB;AACnB,WAAO0C,MAAM,CAAC1C,KAAK,CAACoD,KAAD,CAAN,EAAenB,MAAf,CAAb;AACA,GAFD,MAGK,IAAIiB,KAAK,IAAIlD,KAAb,EAAoB;AACxB,WAAO0C,MAAM,CAAC1C,KAAK,CAACkD,KAAD,CAAN,EAAejB,MAAf,CAAb;AACA;;AAED,SAAOmB,KAAP;AACA;;;;"}
@@ -1,37 +0,0 @@
1
-
2
- import babel from '@rollup/plugin-babel';
3
- import commonjs from '@rollup/plugin-commonjs';
4
- import nodeResolve from '@rollup/plugin-node-resolve';
5
- import {terser} from 'rollup-plugin-terser';
6
-
7
- export default {
8
- input: 'source/IcuMessageFormatter.js',
9
- output: [
10
- {
11
- file: 'dist/icu-message-formatter.min.js',
12
- format: 'iife',
13
- name: 'IcuMessageFormatter',
14
- sourcemap: true
15
- },
16
- {
17
- file: 'dist/icu-message-formatter.es.min.js',
18
- format: 'es',
19
- name: 'IcuMessageFormatter',
20
- sourcemap: true
21
- }
22
- ],
23
- plugins: [
24
- commonjs(),
25
- babel({
26
- babelHelpers: 'bundled',
27
- skipPreflightCheck: true // See: https://github.com/rollup/plugins/issues/381#issuecomment-627215009
28
- }),
29
- nodeResolve({
30
- browser: true
31
- }),
32
- terser()
33
- ],
34
- treeshake: {
35
- moduleSideEffects: false
36
- }
37
- };
package/rollup.config.js DELETED
@@ -1,35 +0,0 @@
1
-
2
- import babel from '@rollup/plugin-babel';
3
- import commonjs from '@rollup/plugin-commonjs';
4
- import nodeResolve from '@rollup/plugin-node-resolve';
5
-
6
- export default {
7
- input: 'source/IcuMessageFormatter.js',
8
- output: [
9
- {
10
- file: `lib/icu-message-formatter.cjs.js`,
11
- format: 'cjs',
12
- sourcemap: true
13
- },
14
- {
15
- file: `lib/icu-message-formatter.es.js`,
16
- format: 'es',
17
- sourcemap: true
18
- }
19
- ],
20
- plugins: [
21
- commonjs(),
22
- babel({
23
- babelHelpers: 'runtime'
24
- }),
25
- nodeResolve()
26
- ],
27
- external: [
28
- /@babel\/runtime/,
29
- '@ultraq/array-utils',
30
- '@ultraq/function-utils'
31
- ],
32
- treeshake: {
33
- moduleSideEffects: false
34
- }
35
- };
@@ -1,9 +0,0 @@
1
-
2
- export {default as MessageFormatter} from './MessageFormatter.js';
3
- export {default as pluralTypeHandler} from './pluralTypeHandler.js';
4
- export {default as selectTypeHandler} from './selectTypeHandler.js';
5
- export {
6
- findClosingBracket,
7
- parseCases,
8
- splitFormattedArgument
9
- } from './utilities.js';