UNPKG

@intlayer/chokidar

Version:

Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.

29 lines (28 loc) 1.11 kB
//#region src/reduceDictionaryContent/applyMask.ts const applyMask = (full, mask) => { if (mask === true) return full; if (Array.isArray(mask) && Array.isArray(full)) return mask.map((m, i) => applyMask(full[i], m)); if (full && typeof full === "object" && "nodeType" in full) { if (mask && typeof mask === "object") return full; return full; } if (mask && typeof mask === "object" && full && typeof full === "object") { const out = {}; const maskEntries = Object.entries(mask); const allChildrenAreArrays = maskEntries.every(([, value]) => Array.isArray(value)); for (const [k, m] of maskEntries) { const fullValue = full[k]; if (Array.isArray(m) && Array.isArray(fullValue)) { const isTranslationNode = (val) => !!val && typeof val === "object" && "nodeType" in val; const isArrayOfTranslationNodes = fullValue.every((item) => isTranslationNode(item)); if (!allChildrenAreArrays && !isArrayOfTranslationNodes) continue; } out[k] = applyMask(fullValue, m); } return out; } return full; }; //#endregion export { applyMask }; //# sourceMappingURL=applyMask.mjs.map