MCPcopy Create free account
hub / github.com/asg017/observable-prerender / valueOfFile

Function valueOfFile

bin/utils.js:126–161  ·  view source on GitHub ↗
(path, format)

Source from the content-addressed store, hash-verified

124
125// read the file found at path with the given format
126async function valueOfFile(path, format) {
127 switch (format) {
128 case "csv":
129 return csvParse(rw.readFileSync(path));
130 case "ndjson":
131 let data = [];
132 return await new Promise((resolve, reject) => {
133 readline
134 .createInterface({
135 input: rw.createReadStream(path),
136 output: null,
137 })
138 .on("line", (line) => {
139 try {
140 data.push(JSON.parse(line));
141 } catch (error) {
142 reject(error);
143 }
144 })
145 .on("close", () => {
146 resolve(data);
147 });
148 }).catch((error) => {
149 console.error(`SyntaxError when reading ${path} as ndjson: `);
150 console.error(error.message);
151 process.exit(1);
152 });
153 case "json":
154 return JSON.parse(rw.readFileSync(path, "utf8"));
155 case "string":
156 return rw.readFileSync(path, "utf8");
157 default:
158 console.error(`Unknown format passed in: ${format}`);
159 process.exit(1);
160 }
161}
162
163// parse list of --redefine flags
164function parseArgRedefines(argRedefines) {

Callers 1

runRedefinesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected