MCPcopy
hub / github.com/lingodotdev/lingo.dev / createNormalizeLoader

Function createNormalizeLoader

packages/cli/src/cli/loaders/flat.ts:93–114  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

91}
92
93function createNormalizeLoader(): ILoader<
94 DenormalizeResult,
95 Record<string, string>
96> {
97 return createLoader({
98 pull: async (locale, input) => {
99 const normalized = normalizeObjectKeys(input.denormalized);
100 return normalized;
101 },
102 push: async (locale, data, originalInput) => {
103 const keysMap = originalInput?.keysMap ?? {};
104 const input = mapDenormalizedKeys(data, keysMap);
105 const denormalized: Record<string, any> = unflatten(input, {
106 delimiter: "/",
107 transformKey(key) {
108 return decodeURIComponent(String(key));
109 },
110 });
111 return { denormalized, keysMap: keysMap || {} };
112 },
113 });
114}
115
116export function buildDenormalizedKeysMap(obj: Record<string, string>) {
117 if (!obj) return {};

Callers 1

createFlatLoaderFunction · 0.85

Calls 3

createLoaderFunction · 0.90
normalizeObjectKeysFunction · 0.85
mapDenormalizedKeysFunction · 0.85

Tested by

no test coverage detected