{"_id":"messageformat-runtime","_rev":"289747","name":"messageformat-runtime","description":"Runtime components of messageformat","dist-tags":{"latest":"3.0.0-beta.1","next":"3.0.0-beta.1"},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"}],"time":{"modified":"2021-06-03T18:47:59.000Z","created":"2019-10-15T18:12:09.233Z","3.0.0-beta.1":"2020-04-12T13:10:04.300Z","3.0.0-beta.0":"2019-10-15T18:12:09.233Z"},"users":{},"author":{"name":"Eemeli Aro","email":"eemeli@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/messageformat/messageformat.git","directory":"packages/runtime"},"versions":{"3.0.0-beta.1":{"name":"messageformat-runtime","version":"3.0.0-beta.1","description":"Runtime components of messageformat","keywords":["i18n","icu","messageformat","internationalization"],"author":{"name":"Eemeli Aro","email":"eemeli@gmail.com"},"license":"MIT","homepage":"https://messageformat.github.io/messageformat/v3/","repository":{"type":"git","url":"git+https://github.com/messageformat/messageformat.git","directory":"packages/runtime"},"main":"lib/runtime","sideEffects":false,"scripts":{"build:cjs":"MODULE_TYPE=cjs babel src -d lib","build:mjs":"MODULE_TYPE=mjs babel src -d lib --keep-file-extension","build":"npm run build:cjs && npm run build:mjs","docs":"jsdoc2md -c jsdoc.config.json -f src/messages.mjs > README.md","prepublishOnly":"npm run build && npm run docs"},"dependencies":{"make-plural":"^6.2.1"},"browserslist":["last 1 version","> 1%","maintained node versions","not dead"],"eslintConfig":{"env":{"browser":true,"es6":true},"parserOptions":{"sourceType":"module"}},"gitHead":"dd10833d8d39155b005ea2ba6ec7a87f4daf0cd2","readmeFilename":"README.md","bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"_id":"messageformat-runtime@3.0.0-beta.1","_nodeVersion":"13.10.1","_npmVersion":"lerna/3.20.2/node@v13.10.1+x64 (darwin)","dist":{"shasum":"fdfe1abcf1e298fb8c99b68cc1a1c4d822fde4e2","size":9836,"noattachment":false,"key":"/messageformat-runtime/-/messageformat-runtime-3.0.0-beta.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/messageformat-runtime/download/messageformat-runtime-3.0.0-beta.1.tgz"},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"}],"_npmUser":{"name":"eemeli","email":"eemeli@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/messageformat-runtime_3.0.0-beta.1_1586697004097_0.1919114374972153"},"_hasShrinkwrap":false,"publish_time":1586697004300,"_cnpm_publish_time":1586697004300},"3.0.0-beta.0":{"name":"messageformat-runtime","version":"3.0.0-beta.0","description":"Runtime components of messageformat","keywords":["i18n","icu","messageformat","internationalization"],"author":{"name":"Eemeli Aro","email":"eemeli@gmail.com"},"license":"MIT","homepage":"https://messageformat.github.io/","repository":{"type":"git","url":"git+https://github.com/messageformat/messageformat.git"},"main":"lib/runtime","sideEffects":false,"scripts":{"build:cjs":"MODULE_TYPE=cjs babel src -d lib","build:mjs":"MODULE_TYPE=mjs babel src -d lib --keep-file-extension","build":"npm run build:cjs && npm run build:mjs","docs":"jsdoc2md -c jsdoc.config.json -f src/messages.mjs > README.md","prepublishOnly":"npm run build && npm run docs"},"dependencies":{"make-plural":"^6.0.0-beta.3"},"browserslist":["last 1 version","> 1%","maintained node versions","not dead"],"eslintConfig":{"env":{"browser":true,"es6":true},"parserOptions":{"sourceType":"module"}},"gitHead":"b154a6f0d58e133a61fa6c5aa0bec51e08e98be7","bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"_id":"messageformat-runtime@3.0.0-beta.0","_nodeVersion":"10.16.3","_npmVersion":"lerna/3.17.0/node@v10.16.3+x64 (darwin)","dist":{"shasum":"3cde9405de1f94585b7183cda67c30ad9874166f","size":8781,"noattachment":false,"key":"/messageformat-runtime/-/messageformat-runtime-3.0.0-beta.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/messageformat-runtime/download/messageformat-runtime-3.0.0-beta.0.tgz"},"maintainers":[{"name":"eemeli","email":"eemeli@gmail.com"}],"_npmUser":{"name":"eemeli","email":"eemeli@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/messageformat-runtime_3.0.0-beta.0_1571163129126_0.03355476491943166"},"_hasShrinkwrap":false,"publish_time":1571163129233,"_cnpm_publish_time":1571163129233}},"readme":"<a name=\"module_messageformat-runtime/messages\"></a>\n\n## messageformat-runtime/messages\nAccessor class for compiled message functions generated by [messageformat](https://www.npmjs.com/package/messageformat)\n\n```js\nimport Messages from 'messageformat-runtime/messages'\n```\n\n\n* [messageformat-runtime/messages](#module_messageformat-runtime/messages)\n    * [module.exports](#exp_module_messageformat-runtime/messages--module.exports) ⏏\n        * [new module.exports(msgData, [defaultLocale])](#new_module_messageformat-runtime/messages--module.exports_new)\n        * [.availableLocales](#module_messageformat-runtime/messages--module.exports+availableLocales) : <code>Array.&lt;string&gt;</code>\n        * [.locale](#module_messageformat-runtime/messages--module.exports+locale) : <code>string</code> \\| <code>null</code>\n        * [.defaultLocale](#module_messageformat-runtime/messages--module.exports+defaultLocale) : <code>string</code> \\| <code>null</code>\n        * [.addMessages(data, [lc], [keypath])](#module_messageformat-runtime/messages--module.exports+addMessages) ⇒ <code>Messages</code>\n        * [.resolveLocale(lc)](#module_messageformat-runtime/messages--module.exports+resolveLocale) ⇒ <code>string</code> \\| <code>null</code>\n        * [.getFallback([lc])](#module_messageformat-runtime/messages--module.exports+getFallback) ⇒ <code>Array.&lt;string&gt;</code>\n        * [.setFallback(lc, fallback)](#module_messageformat-runtime/messages--module.exports+setFallback) ⇒ <code>Messages</code>\n        * [.hasMessage(key, [lc], [fallback])](#module_messageformat-runtime/messages--module.exports+hasMessage) ⇒ <code>boolean</code>\n        * [.hasObject(key, [lc], [fallback])](#module_messageformat-runtime/messages--module.exports+hasObject) ⇒ <code>boolean</code>\n        * [.get(key, [props], [lc])](#module_messageformat-runtime/messages--module.exports+get) ⇒ <code>string</code> \\| <code>Object.&lt;string, (function()\\|object)&gt;</code>\n\n<a name=\"exp_module_messageformat-runtime/messages--module.exports\"></a>\n\n### module.exports ⏏\n**Kind**: Exported class  \n<a name=\"new_module_messageformat-runtime/messages--module.exports_new\"></a>\n\n#### new module.exports(msgData, [defaultLocale])\n\n| Param | Type | Description |\n| --- | --- | --- |\n| msgData | <code>object</code> | A map of locale codes to their function objects |\n| [defaultLocale] | <code>string</code> | If not defined, default and initial locale is the first entry of `locales` |\n\n**Example**  \n```js\n// build.js\nimport fs from 'fs';\nimport MessageFormat from 'messageformat';\n\nconst mf = new MessageFormat(['en', 'fi']);\nconst msgSet = {\n  en: {\n    a: 'A {TYPE} example.',\n    b: 'This has {COUNT, plural, one{one user} other{# users}}.',\n    c: {\n      d: 'We have {P, number, percent} code coverage.'\n    }\n  },\n  fi: {\n    b: 'Tällä on {COUNT, plural, one{yksi käyttäjä} other{# käyttäjää}}.',\n    e: 'Minä puhun vain suomea.'\n  }\n};\nfs.writeFileSync('messages.js', String(mf.compile(msgSet)));\n```\n\n```js\n// runtime.js\nimport Messages from 'messageformat-runtime/messages';\nimport msgData from './messages';\n\nconst messages = new Messages(msgData, 'en');\n\nmessages.hasMessage('a')                // true\nmessages.hasObject('c')                 // true\nmessages.get('b', { COUNT: 3 })         // 'This has 3 users.'\nmessages.get(['c', 'd'], { P: 0.314 })  // 'We have 31% code coverage.'\n\nmessages.get('e')                       // 'e'\nmessages.setFallback('en', ['foo', 'fi'])\nmessages.get('e')                       // 'Minä puhun vain suomea.'\n\nmessages.locale = 'fi'\nmessages.hasMessage('a')                // false\nmessages.hasMessage('a', 'en')          // true\nmessages.hasMessage('a', null, true)    // true\nmessages.hasObject('c')                 // false\nmessages.get('b', { COUNT: 3 })         // 'Tällä on 3 käyttäjää.'\nmessages.get('c').d({ P: 0.628 })       // 'We have 63% code coverage.'\n```\n<a name=\"module_messageformat-runtime/messages--module.exports+availableLocales\"></a>\n\n#### module.exports.availableLocales : <code>Array.&lt;string&gt;</code>\nList of available locales\n\n**Kind**: instance property of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n**Read only**: true  \n<a name=\"module_messageformat-runtime/messages--module.exports+locale\"></a>\n\n#### module.exports.locale : <code>string</code> \\| <code>null</code>\nCurrent locale\n\nOne of Messages#availableLocales or `null`. Partial matches of language tags\nare supported, so e.g. with an `en` locale defined, it will be selected by\n`messages.locale = 'en-US'` and vice versa.\n\n**Kind**: instance property of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n<a name=\"module_messageformat-runtime/messages--module.exports+defaultLocale\"></a>\n\n#### module.exports.defaultLocale : <code>string</code> \\| <code>null</code>\nDefault fallback locale\n\nOne of Messages#availableLocales or `null`. Partial matches of language tags\nare supported, so e.g. with an `en` locale defined, it will be selected by\n`messages.defaultLocale = 'en-US'` and vice versa.\n\n**Kind**: instance property of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n<a name=\"module_messageformat-runtime/messages--module.exports+addMessages\"></a>\n\n#### module.exports.addMessages(data, [lc], [keypath]) ⇒ <code>Messages</code>\nAdd new messages to the accessor; useful if loading data dynamically\n\nThe locale code `lc` should be an exact match for the locale being updated,\nor empty to default to the current locale. Use [#resolveLocale](#resolveLocale) for\nresolving partial locale strings.\n\nIf `keypath` is empty, adds or sets the complete message object for the\ncorresponding locale. If any keys in `keypath` do not exist, a new object\nwill be created at that key.\n\n**Kind**: instance method of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n**Returns**: <code>Messages</code> - The Messages instance, to allow for chaining  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| data | <code>function</code> \\| <code>object</code> | Hierarchical map of keys to functions, or a   single message function |\n| [lc] | <code>string</code> | If empty or undefined, defaults to `this.locale` |\n| [keypath] | <code>Array.&lt;string&gt;</code> | The keypath being added |\n\n<a name=\"module_messageformat-runtime/messages--module.exports+resolveLocale\"></a>\n\n#### module.exports.resolveLocale(lc) ⇒ <code>string</code> \\| <code>null</code>\nResolve `lc` to the key of an available locale or `null`, allowing for\npartial matches. For example, with an `en` locale defined, it will be\nselected by `messages.defaultLocale = 'en-US'` and vice versa.\n\n**Kind**: instance method of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| lc | <code>string</code> | Locale code |\n\n<a name=\"module_messageformat-runtime/messages--module.exports+getFallback\"></a>\n\n#### module.exports.getFallback([lc]) ⇒ <code>Array.&lt;string&gt;</code>\nGet the list of fallback locales\n\n**Kind**: instance method of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| [lc] | <code>string</code> | If empty or undefined, defaults to `this.locale` |\n\n<a name=\"module_messageformat-runtime/messages--module.exports+setFallback\"></a>\n\n#### module.exports.setFallback(lc, fallback) ⇒ <code>Messages</code>\nSet the fallback locale or locales for `lc`\n\nTo disable fallback for the locale, use `setFallback(lc, [])`.\nTo use the default fallback, use `setFallback(lc, null)`.\n\n**Kind**: instance method of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n**Returns**: <code>Messages</code> - The Messages instance, to allow for chaining  \n\n| Param | Type |\n| --- | --- |\n| lc | <code>string</code> | \n| fallback | <code>Array.&lt;string&gt;</code> \\| <code>null</code> | \n\n<a name=\"module_messageformat-runtime/messages--module.exports+hasMessage\"></a>\n\n#### module.exports.hasMessage(key, [lc], [fallback]) ⇒ <code>boolean</code>\nCheck if `key` is a message function for the locale\n\n`key` may be a `string` for functions at the root level, or `string[]` for\naccessing hierarchical objects. If an exact match is not found and `fallback`\nis true, the fallback locales are checked for the first match.\n\n**Kind**: instance method of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| key | <code>string</code> \\| <code>Array.&lt;string&gt;</code> |  | The key or keypath being sought |\n| [lc] | <code>string</code> |  | If empty or undefined, defaults to `this.locale` |\n| [fallback] | <code>boolean</code> | <code>false</code> | If true, also checks fallback locales |\n\n<a name=\"module_messageformat-runtime/messages--module.exports+hasObject\"></a>\n\n#### module.exports.hasObject(key, [lc], [fallback]) ⇒ <code>boolean</code>\nCheck if `key` is a message object for the locale\n\n`key` may be a `string` for functions at the root level, or `string[]` for\naccessing hierarchical objects. If an exact match is not found and `fallback`\nis true, the fallback locales are checked for the first match.\n\n**Kind**: instance method of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| key | <code>string</code> \\| <code>Array.&lt;string&gt;</code> |  | The key or keypath being sought |\n| [lc] | <code>string</code> |  | If empty or undefined, defaults to `this.locale` |\n| [fallback] | <code>boolean</code> | <code>false</code> | If true, also checks fallback locales |\n\n<a name=\"module_messageformat-runtime/messages--module.exports+get\"></a>\n\n#### module.exports.get(key, [props], [lc]) ⇒ <code>string</code> \\| <code>Object.&lt;string, (function()\\|object)&gt;</code>\nGet the message or object corresponding to `key`\n\n`key` may be a `string` for functions at the root level, or `string[]` for\naccessing hierarchical objects. If an exact match is not found, the fallback\nlocales are checked for the first match.\n\nIf `key` maps to a message function, it will be called with `props`. If it\nmaps to an object, the object is returned directly.\n\n**Kind**: instance method of [<code>module.exports</code>](#exp_module_messageformat-runtime/messages--module.exports)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| key | <code>string</code> \\| <code>Array.&lt;string&gt;</code> | The key or keypath being sought |\n| [props] | <code>object</code> | Optional properties passed to the function |\n| [lc] | <code>string</code> | If empty or undefined, defaults to `this.locale` |\n\n","_attachments":{},"readmeFilename":"README.md","homepage":"https://messageformat.github.io/messageformat/v3/","bugs":{"url":"https://github.com/messageformat/messageformat/issues"},"license":"MIT"}