generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 178
/
Copy pathliterals.js
23 lines (22 loc) · 911 Bytes
/
literals.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Defaults } from './defaults.js';
import { equalsCaseInsensitive } from './external.js';
/**
* Method resolves price literals for the given language from the group of price literals.
* That group is either imported from json file or it is received as a parameter (in case of unit tests).
*
* @param settings
* @param priceLiterals
*/
export async function getPriceLiterals(settings, priceLiterals) {
//we are expecting an array of objects with lang and literals
const { data } = priceLiterals ? priceLiterals : await import('../price-literals.json');
if (Array.isArray(data)) {
const find = (language) =>
data.find((candidate) =>
equalsCaseInsensitive(candidate.lang, language),
);
const literals = find(settings.language) ?? find(Defaults.language);
if (literals) return Object.freeze(literals);
}
return {};
}