UNPKG

relative-time-format

Version:
58 lines (46 loc) 2.16 kB
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } // Importing `PluralRule` polyfill from a separate package // results in a bundle that is larger by 1kB for some reason. // export { default as default } from 'intl-plural-rules-polyfill/cardinal' import PluralRuleFunctions from "./PluralRuleFunctions"; import getPluralRulesLocale from "./getPluralRulesLocale"; /** * `Intl.PluralRules` polyfill. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules */ var PluralRules = /*#__PURE__*/ function () { function PluralRules(locale, options) { _classCallCheck(this, PluralRules); var locales = PluralRules.supportedLocalesOf(locale); if (locales.length === 0) { throw new RangeError("Unsupported locale: " + locale); } if (options && options.type !== "cardinal") { throw new RangeError("Only \"cardinal\" \"type\" is supported"); } this.$ = PluralRuleFunctions[getPluralRulesLocale(locales[0])]; } _createClass(PluralRules, [{ key: "select", value: function select(number) { return this.$(number); } }], [{ key: "supportedLocalesOf", value: function supportedLocalesOf(locales) { if (typeof locales === "string") { locales = [locales]; } return locales.filter(function (locale) { return PluralRuleFunctions[getPluralRulesLocale(locale)]; }); } }]); return PluralRules; }(); export { PluralRules as default }; //# sourceMappingURL=PluralRules.js.map