UNPKG

@mikezimm/fps-core-v7

Version:

Library of reusable core interfaces, types and constants migrated from fps-library-v2

36 lines 1.64 kB
import { HandleBarsRegex } from "./HandleBarsRegex"; /** * Could be replaced with replaceHTMLHandleBars src\logic\Strings\handleBarsHTML.tsx * * @param item * @param handleBarString * @param emptyIfSubEmpty * @returns */ export function replaceHandleBarsValues(item, handleBarString, emptyIfSubEmpty) { var _a, _b; if (typeof handleBarString !== 'string') { return handleBarString; } else { let returnEmpty = false; // Get array of strings by splitting the string by any {{ or }} const linkSplits = handleBarString.split(HandleBarsRegex); // Replace first handlebars instance if (linkSplits.length > 2) { const part1 = (_a = linkSplits[1]) === null || _a === void 0 ? void 0 : _a.trim().replace('/', ''); //Get column name, removing / from lookup values linkSplits[1] = item[part1] ? item[part1] : emptyIfSubEmpty === true ? '' : `${part1}`; if (!linkSplits[1] && emptyIfSubEmpty === true) returnEmpty = true; } // Replace second handlebars instance if (linkSplits.length > 4) { const part3 = (_b = linkSplits[3]) === null || _b === void 0 ? void 0 : _b.trim().replace('/', ''); //Get column name, removing / from lookup values linkSplits[3] = item[part3] ? item[part3] : emptyIfSubEmpty === true ? '' : `${part3}`; if (!linkSplits[3] && emptyIfSubEmpty === true) returnEmpty = true; } return returnEmpty === true ? '' : linkSplits.join(''); } } //# sourceMappingURL=handleBarsSub.js.map