Files
klz-cables.com/.pnpm-store/v10/files/12/fc2c47e9a39b109af88de953b49848e91848463977861154d049defe81f906951089ab9bd0c3e81bbb1983de31c10b2d05f0c5a836e6a5b433d0b918e19d89
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

65 lines
1.8 KiB
Plaintext

import { ParserError } from "../util/errors.js";
import type { FileInfo } from "../types/index.js";
import type { Plugin } from "../types/index.js";
export default {
/**
* The order that this parser will run, in relation to other parsers.
*/
order: 100,
/**
* Whether to allow "empty" files. This includes zero-byte files, as well as empty JSON objects.
*/
allowEmpty: true,
/**
* Determines whether this parser can parse a given file reference.
* Parsers that match will be tried, in order, until one successfully parses the file.
* Parsers that don't match will be skipped, UNLESS none of the parsers match, in which case
* every parser will be tried.
*/
canParse: ".json",
/**
* Allow JSON files with byte order marks (BOM)
*/
allowBOM: true,
/**
* Parses the given file as JSON
*/
async parse(file: FileInfo): Promise<object | undefined> {
let data = file.data;
if (Buffer.isBuffer(data)) {
data = data.toString();
}
if (typeof data === "string") {
if (data.trim().length === 0) {
return; // This mirrors the YAML behavior
} else {
try {
return JSON.parse(data);
} catch (e: any) {
if (this.allowBOM) {
try {
// find the first curly brace
const firstCurlyBrace = data.indexOf("{");
// remove any characters before the first curly brace
data = data.slice(firstCurlyBrace);
return JSON.parse(data);
} catch (e: any) {
throw new ParserError(e.message, file.url);
}
}
throw new ParserError(e.message, file.url);
}
}
} else {
// data is already a JavaScript value (object, array, number, null, NaN, etc.)
return data as object;
}
},
} as Plugin;