UNPKG

@intlayer/core

Version:

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

37 lines (35 loc) 1.18 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_interpreter_getIntlayer = require('./getIntlayer.cjs'); //#region src/interpreter/getNesting.ts /** * Extracts content from another dictionary by its key and an optional path. * * This allows for reusing content across different dictionaries. * * @param dictionaryKey - The key of the dictionary to nest. * @param path - Optional dot-separated path to a specific field within the nested dictionary. * @param props - Optional properties like locale and plugins. * @returns The nested content. * * @example * ```ts * const content = getNesting("common", "buttons.save"); * // 'Save' * ``` */ const getNesting = (dictionaryKey, path, props) => { const dictionary = require_interpreter_getIntlayer.getIntlayer(dictionaryKey, props?.locale, props?.plugins); if (typeof path === "string") { const pathArray = path.split("."); let current = dictionary; for (const key of pathArray) { current = current?.[key]; if (current === void 0) return dictionary; } return current; } return dictionary; }; //#endregion exports.getNesting = getNesting; //# sourceMappingURL=getNesting.cjs.map