MCPcopy
hub / github.com/loggerhead/json4u / readFileIfNeed

Function readFileIfNeed

__tests__/utils.ts:4–12  ·  view source on GitHub ↗
(fileNameOrText: string)

Source from the content-addressed store, hash-verified

2import path from "path";
3
4export function readFileIfNeed(fileNameOrText: string) {
5 if (/(\w+\/)*\w+\.(json|txt)/.test(fileNameOrText)) {
6 const baseDir = path.join(process.cwd(), "__tests__/fixtures");
7 const fullPath = path.join(baseDir, fileNameOrText);
8 return fs.readFileSync(fullPath, "utf8");
9 } else {
10 return fileNameOrText;
11 }
12}

Callers 4

expectEqFunction · 0.90
parse.test.tsFile · 0.90
jsonpath.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected