functionalscript
Version:
FunctionalScript is a purely functional subset of JavaScript
34 lines (33 loc) • 1.11 kB
JavaScript
import { at } from "../../types/ordered_map/module.f.js";
export const createVirtualIo = (files) => ({
console: {
log: (..._d) => { },
error: (..._d) => { }
},
fs: {
writeFileSync: (_file, _data) => { },
readFileSync: (path, _options) => { return at(path)(files); },
existsSync: (path) => { return at(path)(files) !== null; },
promises: {
readdir: (_path) => Promise.resolve([]),
readFile: (_path, _options) => Promise.resolve(''),
writeFile: (_path, _data, _options) => Promise.resolve(),
rm: (_path, _options) => Promise.resolve(),
mkdir: (_path, _options) => Promise.resolve(undefined),
copyFile: (_src, _dest) => Promise.resolve(),
}
},
process: {
argv: [],
env: {},
exit: n => { throw n; },
cwd: () => '',
},
asyncImport: () => Promise.reject(),
performance: {
now: () => 0,
},
fetch: () => Promise.reject(),
tryCatch: f => ['ok', f()],
asyncTryCatch: async (f) => ['ok', await f()],
});