UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

33 lines (31 loc) 889 B
//#region src/interpreter/getCondition.ts /** * Allow to pick a content based on a condition. * * Usage: * * ```ts * const content = getCondition({ * 'true': 'The condition is validated', * 'false': 'The condition is not validated', * }, true); * // 'The condition is validated' * ``` * * The last key provided will be used as the fallback value. * * ```ts * const content = getCondition({ * 'false': 'The condition is not validated', * 'true': 'The condition is validated', * }, undefined); * // 'The condition is validated' */ const getCondition = (conditionContent, state) => { const stateList = Object.keys(conditionContent); const fallbackState = stateList[stateList.length - 1]; return conditionContent[`${state}`] ?? conditionContent.fallback ?? conditionContent[fallbackState]; }; //#endregion exports.getCondition = getCondition; //# sourceMappingURL=getCondition.cjs.map