Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(
readonly _id: string,
readonly _tag: LanguageTag,
readonly strings: string[],
readonly exceptions: string[],
readonly index: ExceptionIndex,
readonly _spellout: any
) {
const language = _tag.language();
this._languageRegion = `${language}-${_tag.region()}`;
this._languageScript = `${language}-${_tag.script()}`;
this._plurals = pluralRules.get(language, _tag.region());
// When bundle is constructed, see if there are unicode extensions for
// number and calendar systems.
for (const subtag of _tag.extensionSubtags('u')) {
if (subtag.startsWith('nu-')) {
this._numberSystem = subtag.substring(3);
} else if (subtag.startsWith('ca-')) {
this._calendarSystem = subtag.substring(3);
}
}
}
import { Decimal } from '@phensley/decimal';
import { pluralRules, PluralRules } from '@phensley/plurals';
import { algorithmicNumbering } from './autogen.names';
import { rbnfRulesets } from './autogen.rbnf';
import { RBNF, RBNFDecimalFormatter, RBNFSet, RBNFSymbols } from './rbnf';
const U = undefined;
const ROOT = new RBNF(pluralRules.get('root'), rbnfRulesets);
const RBNFROOT = ROOT.get('root')!;
export class AlgorithmicNumberingSystems {
readonly rbnfset: RBNFSet | undefined;
readonly rulenames: string[] = [];
constructor(plurals: PluralRules, spellout: any, ...ids: string[]) {
const rbnf = new RBNF(plurals, spellout);
// Find the first defined system. This lets us check if a region-specific
// system exists, falling back to the language-script.
for (const id of ids) {
this.rbnfset = rbnf.get(id);
if (this.rbnfset) {
this.rulenames = this.rbnfset.pubnames;
constructor(options: MessageFormatterOptions = { }) {
this.formatters = options.formatters || {};
this.plurals = options.plurals || pluralRules.get(options.language || 'root', options.region);
const size = options.cacheSize || DEFAULT_CACHE_SIZE;
this.matcher = buildMessageMatcher(Object.keys(this.formatters));
this.cache = new Cache(s => parseMessagePattern(s, this.matcher), size);
}
} from '@phensley/messageformat';
export const messageSuite: Suite = makeSuite('message');
const FORMATTERS = {
foo: (args: MessageArg[], options: string[]) =>
options[0] === 'upper' ? args[0].toUpperCase() : args[0].toLowerCase()
};
const MESSAGE = 'foo bar {0 plural one {# item} other {# items}} {1}';
const MATCHER = buildMessageMatcher(Object.keys(FORMATTERS));
const CODE = parseMessagePattern(MESSAGE, MATCHER);
const FORMATTER = new MessageFormatter({ language: 'en', formatters: FORMATTERS });
const PLURALS = pluralRules.get('en');
messageSuite.add('parse', () => {
parseMessagePattern(MESSAGE, MATCHER);
});
messageSuite.add('eval', () => {
new MessageEngine(PLURALS, FORMATTERS, CODE).evaluate([12, 'hello']);
});
messageSuite.add('formatter', () => {
FORMATTER.format(MESSAGE, [12, 'hello'], {});
});
const plurals = (language: string, region?: string) =>
pluralRules.get(language, region);