v8r
Version:
A command-line JSON, YAML and TOML validator that's on your wavelength
21 lines (18 loc) • 553 B
JavaScript
import fs from "node:fs";
import path from "node:path";
import isUrl from "is-url";
import { parseSchema } from "./parser.js";
async function getFromUrlOrFile(location, cache, base = null) {
if (isUrl(location)) {
return await cache.fetch(location);
} else {
if (base != null) {
return parseSchema(
await fs.promises.readFile(path.join(base, location), "utf8"),
path.join(base, location),
);
}
}
return parseSchema(await fs.promises.readFile(location, "utf8"), location);
}
export { getFromUrlOrFile };