@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
36 lines (34 loc) • 1.05 kB
JavaScript
import { getIntlayer } from "./getIntlayer.mjs";
//#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 = 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
export { getNesting };
//# sourceMappingURL=getNesting.mjs.map