MCPcopy Index your code
hub / github.com/messageformat/messageformat / convertData

Function convertData

packages/convert/index.js:13–32  ·  view source on GitHub ↗
(data, locale, options)

Source from the content-addressed store, hash-verified

11};
12
13const convertData = (data, locale, options) => {
14 if (!data) return '';
15 if (Array.isArray(data))
16 return data.map(d => convertData(d, locale, options));
17 if (typeof data !== 'object') return applyReplacements(data, options);
18 const pluralMsg =
19 options.pluralVariable && getPluralMessage(data, locale, options);
20 if (pluralMsg) return pluralMsg;
21
22 return Object.keys(data).reduce((res, key) => {
23 const { includeLocales: il, verbose } = options;
24 const isLcKey = (!il || il.includes(key)) && pluralCategories[key];
25 if (isLcKey) {
26 options._lc[key] = true;
27 if (verbose) console.log(`messageformat-convert: Found locale ${key}`);
28 }
29 res[key] = convertData(data[key], isLcKey ? key : locale, options);
30 return res;
31 }, {});
32};
33
34const convert = (data, options) => {
35 if (data.length === 1) data = data[0];

Callers 1

convertFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected