Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
MessageEngine,
MessageFormatter,
} 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'], {});
});
messageFormatter(options?: MessageFormatterOptions): MessageFormatter {
const plurals = this._bundle.plurals();
return new MessageFormatter({ ...options, plurals });
}