17 lines
367 B
JavaScript
17 lines
367 B
JavaScript
import { readFileSync } from "node:fs";
|
|
|
|
const UTF8_BOM = "\uFEFF";
|
|
|
|
export const stripUtf8Bom = (value) => {
|
|
if (typeof value !== "string") {
|
|
return value;
|
|
}
|
|
|
|
return value.startsWith(UTF8_BOM) ? value.slice(1) : value;
|
|
};
|
|
|
|
export const readJsonFile = (filePath) => {
|
|
const raw = readFileSync(filePath, "utf8");
|
|
return JSON.parse(stripUtf8Bom(raw));
|
|
};
|