UNPKG

@intlayer/core

Version:

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

37 lines (35 loc) 1.49 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_runtime = require('../../_virtual/_rolldown/runtime.cjs'); const require_transpiler_insertion_getInsertionValues = require('./getInsertionValues.cjs'); let _intlayer_types_nodeType = require("@intlayer/types/nodeType"); //#region src/transpiler/insertion/insertion.ts /** * Function intended to be used to build intlayer dictionaries. * * Allow to identify insertions inside a content. * * Usage: * * ```ts * insertion('Hi, my name is {{name}} and I am {{age}} years old.') * ``` * */ const insertion = (content) => { const getInsertions = () => { if (typeof content === "string") return require_transpiler_insertion_getInsertionValues.getInsertionValues(content); let stringContent; if (typeof content === "function") stringContent = content(); else if (typeof content.then === "function") stringContent = async () => require_transpiler_insertion_getInsertionValues.getInsertionValues(await content); if (typeof stringContent === "string") return require_transpiler_insertion_getInsertionValues.getInsertionValues(stringContent); try { return require_transpiler_insertion_getInsertionValues.getInsertionValues(JSON.stringify(content)); } catch (_e) { return []; } }; return (0, _intlayer_types_nodeType.formatNodeType)(_intlayer_types_nodeType.INSERTION, content, { fields: getInsertions() }); }; //#endregion exports.insert = insertion; //# sourceMappingURL=insertion.cjs.map