@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 +0,0 @@
1
- {"version":3,"file":"icu-message-formatter.es.min.js","sources":["../source/utilities.js","../node_modules/@ultraq/array-utils/array-utils.es.js","../node_modules/@ultraq/function-utils/function-utils.es.js","../source/pluralTypeHandler.js","../source/MessageFormatter.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 2017, 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 * Flattens an array of arrays of infinite depth into a single-dimension array.\n * \n * > This is now natively in JavaScript as the `flat` method on an Array\n * > instance. [Check MDN for which browsers have access to this feature](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat).\n * > If you can't use `flat`, then this method will do the job 🙂\n * \n * @param {Array} array\n * @return {Array} Flattened array.\n */\nexport function flatten(array) {\n return array.reduce(function (accumulator, value) {\n return accumulator.concat(Array.isArray(value) ? flatten(value) : value);\n }, []);\n}\n/**\n * Creates an array of numbers from the starting value (inclusive) to the end\n * (exclusive), with an optional step (the gap between values).\n * \n * @param {Number} start\n * The value to start at, the first item in the returned array.\n * @param {Number} end\n * The value to end with, the last item in the returned array.\n * @param {Number} [step=1]\n * The increment/gap between values, defaults to 1.\n * @return {Array} An array encompassing the given range.\n */\n\nexport function range(start, end) {\n var step = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n return Array.apply(0, Array(Math.ceil((end - start) / step))).map(function (empty, index) {\n return index * step + start;\n });\n}\n/**\n * Remove and return the first item from `array` that matches the predicate\n * function.\n * \n * @param {Array} array\n * @param {Function} predicate\n * Invoked with the array item.\n * @return {Object} The matching item, or `null` if no match was found.\n */\n\nexport function remove(array, predicate) {\n return array.find(function (item, index) {\n if (predicate(item)) {\n array.splice(index, 1);\n return item;\n }\n });\n}\n\n//# sourceMappingURL=array-utils.es.js.map","/**\n * A higher-order function to apply [memoization](https://en.wikipedia.org/wiki/Memoization).\n * \n * If memoizing a recursive function, then memoize and define the function at\n * the same time so you can make a call to the memoized function, eg:\n * \n * ```javascript\n * const myFunction = memoize(() => myFunction());\n * ```\n * \n * @param {Function} func\n * @return {Function} \n */\nexport function memoize(func) {\n var cache = {};\n return function () {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n var key = args.length ? args.map(function (arg) {\n return arg === null ? 'null' : arg === undefined ? 'undefined' : typeof arg === 'function' ? arg.toString() : arg instanceof Date ? arg.toISOString() : JSON.stringify(arg);\n }).join('|') : '_(no-args)_';\n\n if (Object.prototype.hasOwnProperty.call(cache, key)) {\n return cache[key];\n }\n\n var result = func.apply(void 0, args);\n cache[key] = result;\n return result;\n };\n}\n\n//# sourceMappingURL=function-utils.es.js.map","/* \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 {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\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","flatten","array","reduce","value","concat","Array","isArray","memoize","func","cache","_len","arguments","_key","key","map","arg","undefined","toString","Date","toISOString","JSON","stringify","join","Object","prototype","hasOwnProperty","call","result","apply","pluralFormatter","MessageFormatter","locale","typeHandlers","message","values","_this","process","blockStartIndex","blockEndIndex","type","format","body","typeHandler","this","bind","keyCounter","replaceNumberSign","output","numBraces","numberValues","keyParam","pluralTypeHandler","matches","intValue","parseInt","forEach","startsWith","keywordPossibilities","Intl","resolvedOptions","PluralRules","pluralKeyword","select","keyword","selectTypeHandler"],"mappings":"24DA8BO,SAASA,EAAWC,WACpBC,EAAe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,GAAUV,GAA7D1E,IAAAA,SAAUsE,IAAAA,oBACXT,EAAO7D,SACVuD,GACAe,YAKC9C,EEtFO,SAAS6D,EAAkB7D,OAAOiD,yDAAU,GAAYlB,yCAAQM,2CAC5D1E,EAAWsF,GAArBhF,IAAAA,aAEJ+B,KAAS/B,EACLoE,EAAOpE,EAAM+B,GAAQ+B,GApBhB,UAsBK9D,EACVoE,EAAOpE,EAAK,MAAS8D,GAGtB/B"}
@@ -1,2 +0,0 @@
1
- var IcuMessageFormatter=function(r){"use strict";function e(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),t.push.apply(t,n)}return t}function t(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?e(Object(n),!0).forEach((function(e){i(r,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):e(Object(n)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}function n(r,e){if(!(r instanceof e))throw new TypeError("Cannot call a class as a function")}function o(r,e){for(var t=0;t<e.length;t++){var n=e[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,n.key,n)}}function i(r,e,t){return e in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function a(r,e){return function(r){if(Array.isArray(r))return r}(r)||function(r,e){var t=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null==t)return;var n,o,i=[],a=!0,u=!1;try{for(t=t.call(r);!(a=(n=t.next()).done)&&(i.push(n.value),!e||i.length!==e);a=!0);}catch(r){u=!0,o=r}finally{try{a||null==t.return||t.return()}finally{if(u)throw o}}return i}(r,e)||function(r,e){if(!r)return;if("string"==typeof r)return u(r,e);var t=Object.prototype.toString.call(r).slice(8,-1);"Object"===t&&r.constructor&&(t=r.constructor.name);if("Map"===t||"Set"===t)return Array.from(r);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return u(r,e)}(r,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function l(r){for(var e=function(r){return/\s/.test(r)},t=[],n={},o=0,i=null,a=!1,u=0;u<r.length;){if(a&&(e(r[u])||"{"===r[u]))a=!1,i=r.slice(o,u),"{"===r[u]&&u--;else if(!a&&!e(r[u])){var l="{"===r[u];if(i&&l){var c=s(r,u);if(-1===c)throw new Error('Unbalanced curly braces in string: "'.concat(r,'"'));n[i]=r.slice(u+1,c),u=c,i=null}else i&&(t.push(i),i=null),a=!0,o=u}u++}return a&&(i=r.slice(o)),i&&t.push(i),{args:t,cases:n}}function s(r,e){for(var t=0,n=e+1;n<r.length;n++){var o=r.charAt(n);if("}"===o){if(0===t)return n;t--}else"{"===o&&t++}return-1}function c(r){return f(r.slice(1,-1),",",3)}function f(r,e,t){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];if(!r)return n;if(1===t)return n.push(r),n;var o=r.indexOf(e);if(-1===o)return n.push(r),n;var i=r.substring(0,o).trim(),a=r.substring(o+e.length+1).trim();return n.push(i),f(a,e,t-1,n)}function v(r){return r.reduce((function(r,e){return r.concat(Array.isArray(e)?v(e):e)}),[])}function h(r){var e={};return function(){for(var t=arguments.length,n=new Array(t),o=0;o<t;o++)n[o]=arguments[o];var i=n.length?n.map((function(r){return null===r?"null":void 0===r?"undefined":"function"==typeof r?r.toString():r instanceof Date?r.toISOString():JSON.stringify(r)})).join("|"):"_(no-args)_";if(Object.prototype.hasOwnProperty.call(e,i))return e[i];var a=r.apply(void 0,n);return e[i]=a,a}}var p,g=function(){function r(e){var t=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};n(this,r),i(this,"format",h((function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return v(t.process(r,e)).join("")}))),this.locale=e,this.typeHandlers=o}var e,t,u;return e=r,t=[{key:"process",value:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r)return[];var t=r.indexOf("{");if(-1!==t){var n=s(r,t);if(-1===n)throw new Error('Unbalanced curly braces in string: "'.concat(r,'"'));var o=r.substring(t,n+1);if(o){var i=[],u=r.substring(0,t);u&&i.push(u);var l=c(o),f=a(l,3),v=f[0],h=f[1],p=f[2],g=e[v];null==g&&(g="");var y=h&&this.typeHandlers[h];i.push(y?y(g,p,this.locale,e,this.process.bind(this)):g);var b=r.substring(n+1);return b&&i.push(this.process(b,e)),i}}return[r]}}],t&&o(e.prototype,t),u&&o(e,u),r}(),y=0,b="other";function d(r,e){for(var t=0,n="",o=0,i={};t<r.length;){if("#"!==r[t]||o)n+=r[t];else{var a="__hashToken".concat(y++);n+="{".concat(a,", number}"),i[a]=e}"{"===r[t]?o++:"}"===r[t]&&o--,t++}return{caseBody:n,numberValues:i}}var O="other";return r.MessageFormatter=g,r.findClosingBracket=s,r.parseCases=l,r.pluralTypeHandler=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0,a=l(e),u=a.args,s=a.cases,c=parseInt(r);u.forEach((function(r){r.startsWith("offset:")&&(c-=parseInt(r.slice("offset:".length)))}));var f=[];if("PluralRules"in Intl){void 0!==p&&p.resolvedOptions().locale===n||(p=new Intl.PluralRules(n));var v=p.select(c);v!==b&&f.push(v)}1===c&&f.push("one"),f.push("=".concat(c),b);for(var h=0;h<f.length;h++){var g=f[h];if(g in s){var y=d(s[g],c),O=y.caseBody,m=y.numberValues;return i(O,t(t({},o),m))}}return r},r.selectTypeHandler=function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments.length>3?arguments[3]:void 0,n=arguments.length>4?arguments[4]:void 0,o=l(e),i=o.cases;return r in i?n(i[r],t):O in i?n(i.other,t):r},r.splitFormattedArgument=c,Object.defineProperty(r,"__esModule",{value:!0}),r}({});
2
- //# sourceMappingURL=icu-message-formatter.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"icu-message-formatter.min.js","sources":["../source/utilities.js","../node_modules/@ultraq/array-utils/array-utils.es.js","../node_modules/@ultraq/function-utils/function-utils.es.js","../source/pluralTypeHandler.js","../source/MessageFormatter.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 2017, 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 * Flattens an array of arrays of infinite depth into a single-dimension array.\n * \n * > This is now natively in JavaScript as the `flat` method on an Array\n * > instance. [Check MDN for which browsers have access to this feature](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat).\n * > If you can't use `flat`, then this method will do the job 🙂\n * \n * @param {Array} array\n * @return {Array} Flattened array.\n */\nexport function flatten(array) {\n return array.reduce(function (accumulator, value) {\n return accumulator.concat(Array.isArray(value) ? flatten(value) : value);\n }, []);\n}\n/**\n * Creates an array of numbers from the starting value (inclusive) to the end\n * (exclusive), with an optional step (the gap between values).\n * \n * @param {Number} start\n * The value to start at, the first item in the returned array.\n * @param {Number} end\n * The value to end with, the last item in the returned array.\n * @param {Number} [step=1]\n * The increment/gap between values, defaults to 1.\n * @return {Array} An array encompassing the given range.\n */\n\nexport function range(start, end) {\n var step = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;\n return Array.apply(0, Array(Math.ceil((end - start) / step))).map(function (empty, index) {\n return index * step + start;\n });\n}\n/**\n * Remove and return the first item from `array` that matches the predicate\n * function.\n * \n * @param {Array} array\n * @param {Function} predicate\n * Invoked with the array item.\n * @return {Object} The matching item, or `null` if no match was found.\n */\n\nexport function remove(array, predicate) {\n return array.find(function (item, index) {\n if (predicate(item)) {\n array.splice(index, 1);\n return item;\n }\n });\n}\n\n//# sourceMappingURL=array-utils.es.js.map","/**\n * A higher-order function to apply [memoization](https://en.wikipedia.org/wiki/Memoization).\n * \n * If memoizing a recursive function, then memoize and define the function at\n * the same time so you can make a call to the memoized function, eg:\n * \n * ```javascript\n * const myFunction = memoize(() => myFunction());\n * ```\n * \n * @param {Function} func\n * @return {Function} \n */\nexport function memoize(func) {\n var cache = {};\n return function () {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n\n var key = args.length ? args.map(function (arg) {\n return arg === null ? 'null' : arg === undefined ? 'undefined' : typeof arg === 'function' ? arg.toString() : arg instanceof Date ? arg.toISOString() : JSON.stringify(arg);\n }).join('|') : '_(no-args)_';\n\n if (Object.prototype.hasOwnProperty.call(cache, key)) {\n return cache[key];\n }\n\n var result = func.apply(void 0, args);\n cache[key] = result;\n return result;\n };\n}\n\n//# sourceMappingURL=function-utils.es.js.map","/* \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 {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\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","flatten","array","reduce","value","concat","Array","isArray","memoize","func","cache","_len","arguments","_key","key","map","arg","undefined","toString","Date","toISOString","JSON","stringify","join","Object","prototype","hasOwnProperty","call","result","apply","pluralFormatter","MessageFormatter","locale","typeHandlers","message","values","_this","process","blockStartIndex","blockEndIndex","type","format","body","typeHandler","this","bind","keyCounter","OTHER","replaceNumberSign","output","numBraces","numberValues","keyParam","matches","intValue","parseInt","forEach","startsWith","keywordPossibilities","Intl","resolvedOptions","PluralRules","pluralKeyword","select","keyword"],"mappings":"47DA8BO,SAASA,EAAWC,WACpBC,EAAe,SAAAC,SAAM,KAAKC,KAAKD,IAE/BE,EAAO,GACPC,EAAQ,GAEVC,EAAgB,EAChBC,EAAa,KACbC,GAAS,EAETC,EAAI,EACDA,EAAIT,EAAOU,QAAQ,IAErBF,IAAWP,EAAaD,EAAOS,KAAqB,MAAdT,EAAOS,IAChDD,GAAS,EACTD,EAAaP,EAAOW,MAAML,EAAeG,GAGvB,MAAdT,EAAOS,IACVA,SAKG,IAAKD,IAAWP,EAAaD,EAAOS,IAAK,KACvCG,EAAyB,MAAdZ,EAAOS,MAIpBF,GAAcK,EAAU,KACrBC,EAAiBC,EAAmBd,EAAQS,OAE1B,IAApBI,QACG,IAAIE,oDAA6Cf,QAGxDK,EAAME,GAAcP,EAAOW,MAAMF,EAAI,EAAGI,GAExCJ,EAAII,EACJN,EAAa,UAGTA,IACHH,EAAKY,KAAKT,GACVA,EAAa,MAGdC,GAAS,EACTF,EAAgBG,EAGlBA,WAGGD,IACHD,EAAaP,EAAOW,MAAML,IAGvBC,GACHH,EAAKY,KAAKT,GAGJ,CACNH,KAAAA,EACAC,MAAAA,GAaK,SAASS,EAAmBd,EAAQiB,WACtCC,EAAQ,EACHT,EAAIQ,EAAY,EAAGR,EAAIT,EAAOU,OAAQD,IAAK,KAC/CU,EAAOnB,EAAOoB,OAAOX,MACZ,MAATU,EAAc,IACH,IAAVD,SACIT,EAERS,QAEiB,MAATC,GACRD,WAGM,EAYF,SAASG,EAAuBC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MAEF1C,IAApBa,GAAiCA,EAAgB8B,kBAAkB5B,SAAWA,IACjFF,EAAkB,IAAI6B,KAAKE,YAAY7B,QAGlC8B,EAAgBhC,EAAgBiC,OAAOT,GAGzCQ,IAAkBf,GACrBW,EAAqB1E,KAAK8E,GAGX,IAAbR,GACHI,EAAqB1E,KAlFT,OAoFb0E,EAAqB1E,gBAASsE,GAAYP,OAErC,IAAItE,EAAI,EAAGA,EAAIiF,EAAqBhF,OAAQD,IAAK,KAC/CuF,EAAUN,EAAqBjF,MACjCuF,KAAW3F,EAAO,OACc2E,EAAkB3E,EAAM2F,GAAUV,GAA7D1E,IAAAA,SAAUuE,IAAAA,oBACXV,EAAO7D,SACVuD,GACAgB,YAKC/C,uBEtFO,SAA2BA,OAAOiD,yDAAU,GAAYlB,yCAAQM,2CAC5D1E,EAAWsF,GAArBhF,IAAAA,aAEJ+B,KAAS/B,EACLoE,EAAOpE,EAAM+B,GAAQ+B,GAEpBY,KAAS1E,EACVoE,EAAOpE,EAAK,MAAS8D,GAGtB/B"}
@@ -1,476 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
6
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
7
- var _createClass = require('@babel/runtime/helpers/createClass');
8
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
9
- var arrayUtils = require('@ultraq/array-utils');
10
- var functionUtils = require('@ultraq/function-utils');
11
-
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
15
- var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
16
- var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
17
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
18
-
19
- /*
20
- * Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/)
21
- *
22
- * Licensed under the Apache License, Version 2.0 (the "License");
23
- * you may not use this file except in compliance with the License.
24
- * You may obtain a copy of the License at
25
- *
26
- * http://www.apache.org/licenses/LICENSE-2.0
27
- *
28
- * Unless required by applicable law or agreed to in writing, software
29
- * distributed under the License is distributed on an "AS IS" BASIS,
30
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
- * See the License for the specific language governing permissions and
32
- * limitations under the License.
33
- */
34
-
35
- /**
36
- * Most branch-based type handlers are based around "cases".
37
- * For example, `select` and `plural` compare compare a value
38
- * to "case keys" to choose a subtranslation.
39
- *
40
- * This util splits "matches" portions provided to the aforementioned
41
- * handlers into case strings, and extracts any prepended arguments
42
- * (for example, `plural` supports an `offset:n` argument used for
43
- * populating the magic `#` variable).
44
- *
45
- * @param {String} string
46
- * @return {Object} The `cases` key points to a map of all cases.
47
- * The `arguments` key points to a list of prepended arguments.
48
- */
49
- function parseCases(string) {
50
- var isWhitespace = function isWhitespace(ch) {
51
- return /\s/.test(ch);
52
- };
53
-
54
- var args = [];
55
- var cases = {};
56
- var currTermStart = 0;
57
- var latestTerm = null;
58
- var inTerm = false;
59
- var i = 0;
60
-
61
- while (i < string.length) {
62
- // Term ended
63
- if (inTerm && (isWhitespace(string[i]) || string[i] === '{')) {
64
- inTerm = false;
65
- latestTerm = string.slice(currTermStart, i); // We want to process the opening char again so the case will be properly registered.
66
-
67
- if (string[i] === '{') {
68
- i--;
69
- }
70
- } // New term
71
- else if (!inTerm && !isWhitespace(string[i])) {
72
- var caseBody = string[i] === '{'; // If there's a previous term, we can either handle a whole
73
- // case, or add that as an argument.
74
-
75
- if (latestTerm && caseBody) {
76
- var branchEndIndex = findClosingBracket(string, i);
77
-
78
- if (branchEndIndex === -1) {
79
- throw new Error("Unbalanced curly braces in string: \"".concat(string, "\""));
80
- }
81
-
82
- cases[latestTerm] = string.slice(i + 1, branchEndIndex); // Don't include the braces
83
-
84
- i = branchEndIndex; // Will be moved up where needed at end of loop.
85
-
86
- latestTerm = null;
87
- } else {
88
- if (latestTerm) {
89
- args.push(latestTerm);
90
- latestTerm = null;
91
- }
92
-
93
- inTerm = true;
94
- currTermStart = i;
95
- }
96
- }
97
-
98
- i++;
99
- }
100
-
101
- if (inTerm) {
102
- latestTerm = string.slice(currTermStart);
103
- }
104
-
105
- if (latestTerm) {
106
- args.push(latestTerm);
107
- }
108
-
109
- return {
110
- args: args,
111
- cases: cases
112
- };
113
- }
114
- /**
115
- * Finds the index of the matching closing curly bracket, including through
116
- * strings that could have nested brackets.
117
- *
118
- * @param {String} string
119
- * @param {Number} fromIndex
120
- * @return {Number} The index of the matching closing bracket, or -1 if no
121
- * closing bracket could be found.
122
- */
123
-
124
- function findClosingBracket(string, fromIndex) {
125
- var depth = 0;
126
-
127
- for (var i = fromIndex + 1; i < string.length; i++) {
128
- var char = string.charAt(i);
129
-
130
- if (char === '}') {
131
- if (depth === 0) {
132
- return i;
133
- }
134
-
135
- depth--;
136
- } else if (char === '{') {
137
- depth++;
138
- }
139
- }
140
-
141
- return -1;
142
- }
143
- /**
144
- * Split a `{key, type, format}` block into those 3 parts, taking into account
145
- * nested message syntax that can exist in the `format` part.
146
- *
147
- * @param {String} block
148
- * @return {Array}
149
- * An array with `key`, `type`, and `format` items in that order, if present
150
- * in the formatted argument block.
151
- */
152
-
153
- function splitFormattedArgument(block) {
154
- return split(block.slice(1, -1), ',', 3);
155
- }
156
- /**
157
- * Like `String.prototype.split()` but where the limit parameter causes the
158
- * remainder of the string to be grouped together in a final entry.
159
- *
160
- * @private
161
- * @param {String} string
162
- * @param {String} separator
163
- * @param {Number} limit
164
- * @param {Array} [accumulator=[]]
165
- * @return {Array}
166
- */
167
-
168
- function split(string, separator, limit) {
169
- var accumulator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
170
-
171
- if (!string) {
172
- return accumulator;
173
- }
174
-
175
- if (limit === 1) {
176
- accumulator.push(string);
177
- return accumulator;
178
- }
179
-
180
- var indexOfDelimiter = string.indexOf(separator);
181
-
182
- if (indexOfDelimiter === -1) {
183
- accumulator.push(string);
184
- return accumulator;
185
- }
186
-
187
- var head = string.substring(0, indexOfDelimiter).trim();
188
- var tail = string.substring(indexOfDelimiter + separator.length + 1).trim();
189
- accumulator.push(head);
190
- return split(tail, separator, limit - 1, accumulator);
191
- }
192
-
193
- /**
194
- * The main class for formatting messages.
195
- *
196
- * @author Emanuel Rabina
197
- */
198
-
199
- var MessageFormatter = /*#__PURE__*/function () {
200
- /**
201
- * Creates a new formatter that can work using any of the custom type handlers
202
- * you register.
203
- *
204
- * @param {String} locale
205
- * @param {Object} [typeHandlers={}]
206
- * Optional object where the keys are the names of the types to register,
207
- * their values being the functions that will return a nicely formatted
208
- * string for the data and locale they are given.
209
- */
210
- function MessageFormatter(locale) {
211
- var _this = this;
212
-
213
- var typeHandlers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
214
-
215
- _classCallCheck__default["default"](this, MessageFormatter);
216
-
217
- _defineProperty__default["default"](this, "format", functionUtils.memoize(function (message) {
218
- var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
219
- return arrayUtils.flatten(_this.process(message, values)).join('');
220
- }));
221
-
222
- this.locale = locale;
223
- this.typeHandlers = typeHandlers;
224
- }
225
- /**
226
- * Formats an ICU message syntax string using `values` for placeholder data
227
- * and any currently-registered type handlers.
228
- *
229
- * @param {String} message
230
- * @param {Object} [values={}]
231
- * @return {String}
232
- */
233
-
234
-
235
- _createClass__default["default"](MessageFormatter, [{
236
- key: "process",
237
- value:
238
- /**
239
- * Process an ICU message syntax string using `values` for placeholder data
240
- * and any currently-registered type handlers. The result of this method is
241
- * an array of the component parts after they have been processed in turn by
242
- * their own type handlers. This raw output is useful for other renderers,
243
- * eg: React where components can be used instead of being forced to return
244
- * raw strings.
245
- *
246
- * This method is used by {@link MessageFormatter#format} where it acts as a
247
- * string renderer.
248
- *
249
- * @param {String} message
250
- * @param {Object} [values={}]
251
- * @return {Array}
252
- */
253
- function process(message) {
254
- var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
255
-
256
- if (!message) {
257
- return [];
258
- }
259
-
260
- var blockStartIndex = message.indexOf('{');
261
-
262
- if (blockStartIndex !== -1) {
263
- var blockEndIndex = findClosingBracket(message, blockStartIndex);
264
-
265
- if (blockEndIndex !== -1) {
266
- var block = message.substring(blockStartIndex, blockEndIndex + 1);
267
-
268
- if (block) {
269
- var result = [];
270
- var head = message.substring(0, blockStartIndex);
271
-
272
- if (head) {
273
- result.push(head);
274
- }
275
-
276
- var _splitFormattedArgume = splitFormattedArgument(block),
277
- _splitFormattedArgume2 = _slicedToArray__default["default"](_splitFormattedArgume, 3),
278
- key = _splitFormattedArgume2[0],
279
- type = _splitFormattedArgume2[1],
280
- format = _splitFormattedArgume2[2];
281
-
282
- var body = values[key];
283
-
284
- if (body === null || body === undefined) {
285
- body = '';
286
- }
287
-
288
- var typeHandler = type && this.typeHandlers[type];
289
- result.push(typeHandler ? typeHandler(body, format, this.locale, values, this.process.bind(this)) : body);
290
- var tail = message.substring(blockEndIndex + 1);
291
-
292
- if (tail) {
293
- result.push(this.process(tail, values));
294
- }
295
-
296
- return result;
297
- }
298
- } else {
299
- throw new Error("Unbalanced curly braces in string: \"".concat(message, "\""));
300
- }
301
- }
302
-
303
- return [message];
304
- }
305
- }]);
306
-
307
- return MessageFormatter;
308
- }();
309
-
310
- 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; }
311
-
312
- 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__default["default"](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; }
313
- var pluralFormatter;
314
- var keyCounter = 0; // All the special keywords that can be used in `plural` blocks for the various branches
315
-
316
- var ONE = 'one';
317
- var OTHER$1 = 'other';
318
- /**
319
- * @private
320
- * @param {String} caseBody
321
- * @param {Number} value
322
- * @return {Object} {caseBody: string, numberValues: object}
323
- */
324
-
325
- function replaceNumberSign(caseBody, value) {
326
- var i = 0;
327
- var output = '';
328
- var numBraces = 0;
329
- var numberValues = {};
330
-
331
- while (i < caseBody.length) {
332
- if (caseBody[i] === '#' && !numBraces) {
333
- var keyParam = "__hashToken".concat(keyCounter++);
334
- output += "{".concat(keyParam, ", number}");
335
- numberValues[keyParam] = value;
336
- } else {
337
- output += caseBody[i];
338
- }
339
-
340
- if (caseBody[i] === '{') {
341
- numBraces++;
342
- } else if (caseBody[i] === '}') {
343
- numBraces--;
344
- }
345
-
346
- i++;
347
- }
348
-
349
- return {
350
- caseBody: output,
351
- numberValues: numberValues
352
- };
353
- }
354
- /**
355
- * Handler for `plural` statements within ICU message syntax strings. Returns
356
- * a formatted string for the branch that closely matches the current value.
357
- *
358
- * See https://formatjs.io/docs/core-concepts/icu-syntax#plural-format for more
359
- * details on how the `plural` statement works.
360
- *
361
- * @param {String} value
362
- * @param {String} matches
363
- * @param {String} locale
364
- * @param {String} values
365
- * @param {Function} format
366
- * @return {String}
367
- */
368
-
369
-
370
- function pluralTypeHandler(value) {
371
- var matches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
372
- var locale = arguments.length > 2 ? arguments[2] : undefined;
373
- var values = arguments.length > 3 ? arguments[3] : undefined;
374
- var format = arguments.length > 4 ? arguments[4] : undefined;
375
-
376
- var _parseCases = parseCases(matches),
377
- args = _parseCases.args,
378
- cases = _parseCases.cases;
379
-
380
- var intValue = parseInt(value);
381
- args.forEach(function (arg) {
382
- if (arg.startsWith('offset:')) {
383
- intValue -= parseInt(arg.slice('offset:'.length));
384
- }
385
- });
386
- var keywordPossibilities = [];
387
-
388
- if ('PluralRules' in Intl) {
389
- // Effectively memoize because instantiation of `Int.*` objects is expensive.
390
- if (pluralFormatter === undefined || pluralFormatter.resolvedOptions().locale !== locale) {
391
- pluralFormatter = new Intl.PluralRules(locale);
392
- }
393
-
394
- var pluralKeyword = pluralFormatter.select(intValue); // Other is always added last with least priority, so we don't want to add it here.
395
-
396
- if (pluralKeyword !== OTHER$1) {
397
- keywordPossibilities.push(pluralKeyword);
398
- }
399
- }
400
-
401
- if (intValue === 1) {
402
- keywordPossibilities.push(ONE);
403
- }
404
-
405
- keywordPossibilities.push("=".concat(intValue), OTHER$1);
406
-
407
- for (var i = 0; i < keywordPossibilities.length; i++) {
408
- var keyword = keywordPossibilities[i];
409
-
410
- if (keyword in cases) {
411
- var _replaceNumberSign = replaceNumberSign(cases[keyword], intValue),
412
- caseBody = _replaceNumberSign.caseBody,
413
- numberValues = _replaceNumberSign.numberValues;
414
-
415
- return format(caseBody, _objectSpread(_objectSpread({}, values), numberValues));
416
- }
417
- }
418
-
419
- return value;
420
- }
421
-
422
- /*
423
- * Copyright 2019, Emanuel Rabina (http://www.ultraq.net.nz/)
424
- *
425
- * Licensed under the Apache License, Version 2.0 (the "License");
426
- * you may not use this file except in compliance with the License.
427
- * You may obtain a copy of the License at
428
- *
429
- * http://www.apache.org/licenses/LICENSE-2.0
430
- *
431
- * Unless required by applicable law or agreed to in writing, software
432
- * distributed under the License is distributed on an "AS IS" BASIS,
433
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
434
- * See the License for the specific language governing permissions and
435
- * limitations under the License.
436
- */
437
- var OTHER = 'other';
438
- /**
439
- * Handler for `select` statements within ICU message syntax strings. Returns
440
- * a formatted string for the branch that closely matches the current value.
441
- *
442
- * See https://formatjs.io/docs/core-concepts/icu-syntax#select-format for more
443
- * details on how the `select` statement works.
444
- *
445
- * @param {String} value
446
- * @param {String} matches
447
- * @param {String} locale
448
- * @param {String} values
449
- * @param {Function} format
450
- * @return {String}
451
- */
452
-
453
- function selectTypeHandler(value) {
454
- var matches = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
455
- var values = arguments.length > 3 ? arguments[3] : undefined;
456
- var format = arguments.length > 4 ? arguments[4] : undefined;
457
-
458
- var _parseCases = parseCases(matches),
459
- cases = _parseCases.cases;
460
-
461
- if (value in cases) {
462
- return format(cases[value], values);
463
- } else if (OTHER in cases) {
464
- return format(cases[OTHER], values);
465
- }
466
-
467
- return value;
468
- }
469
-
470
- exports.MessageFormatter = MessageFormatter;
471
- exports.findClosingBracket = findClosingBracket;
472
- exports.parseCases = parseCases;
473
- exports.pluralTypeHandler = pluralTypeHandler;
474
- exports.selectTypeHandler = selectTypeHandler;
475
- exports.splitFormattedArgument = splitFormattedArgument;
476
- //# sourceMappingURL=icu-message-formatter.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"icu-message-formatter.cjs.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","pluralKeyword","select","keyword","selectTypeHandler"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAT,CAAoBC,MAApB,EAA4B;AAClC,MAAMC,YAAY,GAAG,SAAfA,YAAe,CAAAC,EAAE;AAAA,WAAI,KAAKC,IAAL,CAAUD,EAAV,CAAJ;AAAA,GAAvB;;AAEA,MAAME,IAAI,GAAG,EAAb;AACA,MAAMC,KAAK,GAAG,EAAd;AAEA,MAAIC,aAAa,GAAG,CAApB;AACA,MAAIC,UAAU,GAAG,IAAjB;AACA,MAAIC,MAAM,GAAG,KAAb;AAEA,MAAIC,CAAC,GAAG,CAAR;;AACA,SAAOA,CAAC,GAAGT,MAAM,CAACU,MAAlB,EAA0B;AACzB;AACA,QAAIF,MAAM,KAAKP,YAAY,CAACD,MAAM,CAACS,CAAD,CAAP,CAAZ,IAA2BT,MAAM,CAACS,CAAD,CAAN,KAAc,GAA9C,CAAV,EAA8D;AAC7DD,MAAAA,MAAM,GAAG,KAAT;AACAD,MAAAA,UAAU,GAAGP,MAAM,CAACW,KAAP,CAAaL,aAAb,EAA4BG,CAA5B,CAAb,CAF6D;;AAK7D,UAAIT,MAAM,CAACS,CAAD,CAAN,KAAc,GAAlB,EAAuB;AACtBA,QAAAA,CAAC;AACD;AACD,KARD;AAAA,SAWK,IAAI,CAACD,MAAD,IAAW,CAACP,YAAY,CAACD,MAAM,CAACS,CAAD,CAAP,CAA5B,EAAyC;AAC7C,UAAMG,QAAQ,GAAGZ,MAAM,CAACS,CAAD,CAAN,KAAc,GAA/B,CAD6C;AAI7C;;AACA,UAAIF,UAAU,IAAIK,QAAlB,EAA4B;AAC3B,YAAMC,cAAc,GAAGC,kBA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