Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
messageSuite.add('parse', () => {
parseMessagePattern(MESSAGE, MATCHER);
});
parseMessagePattern,
MessageArg,
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'], {});
});