@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
29 lines (27 loc) • 727 B
JavaScript
import { getIntlayer } from "./getIntlayer.mjs";
//#region src/interpreter/getNesting.ts
/**
* Allow to extract the content of another dictionary.
*
* Usage:
* ```ts
* const content = getNesting("dictionaryKey", "path.to.content");
* // 'Example content'
* ```
*/
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