@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
37 lines (36 loc) • 1.01 kB
JavaScript
//#region src/interpreter/getGender.ts
const getGenderEntry = (gender) => {
if (gender === "m" || gender === "male") return "male";
if (gender === "f" || gender === "female") return "female";
return "fallback";
};
/**
* Allow to pick a content based on a gender.
*
* Usage:
*
* ```ts
* const content = getGender({
* 'true': 'The gender is validated',
* 'false': 'The gender is not validated',
* }, true);
* // 'The gender is validated'
* ```
*
* The last key provided will be used as the fallback value.
*
* ```ts
* const content = getGender({
* 'false': 'The gender is not validated',
* 'true': 'The gender is validated',
* }, undefined);
* // 'The gender is validated'
*/
const getGender = (genderContent, gender) => {
const stateList = Object.keys(genderContent);
const fallbackState = stateList[stateList.length - 1];
return genderContent[getGenderEntry(gender)] ?? genderContent.fallback ?? genderContent[fallbackState];
};
//#endregion
export { getGender };
//# sourceMappingURL=getGender.mjs.map