MCPcopy
hub / github.com/messageformat/messageformat / cases

Method cases

packages/messageformat/src/compiler.js:71–89  ·  view source on GitHub ↗
(token, pluralToken)

Source from the content-addressed store, hash-verified

69 }
70
71 cases(token, pluralToken) {
72 let needOther = true;
73 const r = token.cases.map(({ key, tokens }) => {
74 if (key === 'other') needOther = false;
75 const s = tokens.map(tok => this.token(tok, pluralToken));
76 return `${property(null, key)}: ${this.concatenate(s, false)}`;
77 });
78 if (needOther) {
79 const { type } = token;
80 const { cardinals, ordinals } = this.plural;
81 if (
82 type === 'select' ||
83 (type === 'plural' && cardinals.includes('other')) ||
84 (type === 'selectordinal' && ordinals.includes('other'))
85 )
86 throw new Error(`No 'other' form found in ${JSON.stringify(token)}`);
87 }
88 return `{ ${r.join(', ')} }`;
89 }
90
91 concatenate(tokens, root) {
92 const asValues = this.options.returnType === 'values';

Callers 1

tokenMethod · 0.95

Calls 2

tokenMethod · 0.95
concatenateMethod · 0.95

Tested by

no test coverage detected