UNPKG

@neodx/vfs

Version:

Simple virtual file system - working dir context, lazy changes, different modes, integrations and moreover

38 lines (37 loc) 1.03 kB
var e = require('@neodx/fs'), r = require('../_internal/create-vfs-plugin-Bg0LL_-h.cjs'); function n(e, r) { return { read: n => t(e, r, n), write: (n, t) => s(e, r, n, t), update: (n, t) => a(e, r, n, t) }; } async function t(r, n, t) { try { return e.parseJson(await r.read(n, 'utf-8'), t); } catch (e) { throw Error(`Cannot parse ${n}: ${e.message}`); } } async function s(r, n, t, s) { return await r.write(n, e.serializeJson(t, s)); } async function a(e, r, n, a) { let o = await t(e, r, a); return await s(e, r, (await n(o)) ?? o, a); } (exports.createJsonFileApi = n), (exports.json = function () { return r.createVfsPlugin( 'json', e => ( (e.jsonFile = r => n(e, r)), (e.readJson = (r, n) => t(e, r, n)), (e.writeJson = (r, n, t) => s(e, r, n, t)), (e.updateJson = (r, n, t) => a(e, r, n, t)), e ) ); }), (exports.readVfsJson = t), (exports.updateVfsJson = a), (exports.writeVfsJson = s); //# sourceMappingURL=json.cjs.map