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

Function createJsoncLoader

packages/cli/src/cli/loaders/jsonc.ts:318–357  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

316}
317
318export default function createJsoncLoader(): ILoader<
319 string,
320 Record<string, any>
321> {
322 return createLoader({
323 pull: async (locale, input) => {
324 const jsoncString = input || "{}";
325 const errors: ParseError[] = [];
326 const result = parse(jsoncString, errors, {
327 allowTrailingComma: true,
328 disallowComments: false,
329 allowEmptyContent: true,
330 });
331
332 if (errors.length > 0) {
333 throw new Error(`Failed to parse JSONC: ${errors[0].error}`);
334 }
335
336 return result || {};
337 },
338 push: async (locale, data) => {
339 // JSONC parser's stringify preserves formatting but doesn't add comments
340 // We'll use standard JSON.stringify with pretty formatting for output
341 const serializedData = JSON.stringify(data, null, 2);
342 return serializedData;
343 },
344 pullHints: async (input) => {
345 if (!input || typeof input !== "string") {
346 return {};
347 }
348
349 try {
350 return extractCommentsFromJsonc(input);
351 } catch (error) {
352 console.warn("Failed to extract comments from JSONC:", error);
353 return {};
354 }
355 },
356 });
357}

Callers 2

createBucketLoaderFunction · 0.85
jsonc.spec.tsFile · 0.85

Calls 4

createLoaderFunction · 0.90
parseFunction · 0.85
extractCommentsFromJsoncFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected