UNPKG

@intlayer/core

Version:

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

28 lines (26 loc) 887 B
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); //#region src/interpreter/getCondition.ts /** * Picks content based on a boolean condition. * * @param conditionContent - A map with 'true', 'false', and optionally 'fallback' keys. * @param state - The boolean state to match. * @returns The matching content. * * @example * ```ts * const content = getCondition({ * 'true': 'The condition is validated', * 'false': 'The condition is not validated', * }, true); * // '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