UNPKG

@neodx/vfs

Version:

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

78 lines (75 loc) 2.34 kB
import { m as VfsPlugin, B as BaseVfs } from '../_internal/types-BlKafAog.js'; import { ParseJsonParams, SerializeJsonParams } from '@neodx/fs'; interface JsonPluginApi { jsonFile<FileContents extends JSONValue | unknown = unknown>( path: string ): JsonFileApi<FileContents>; readJson<T extends JSONValue | unknown = unknown>( path: string, options?: ParseJsonParams ): Promise<T>; writeJson<T extends JSONValue | unknown = unknown>( path: string, json: T, options?: SerializeJsonParams ): Promise<void>; updateJson<T extends JSONValue | unknown = unknown>( path: string, updater: JsonUpdate<T>, options?: ParseJsonParams & SerializeJsonParams ): Promise<void>; } interface JsonFileApi<FileContents extends JSONValue | unknown = unknown> { read<T extends FileContents = FileContents>(options?: ParseJsonParams): Promise<T>; write<T extends FileContents = FileContents>( json: T, options?: SerializeJsonParams ): Promise<void>; update<T extends FileContents = FileContents>( updater: JsonUpdate<T>, options?: ParseJsonParams & SerializeJsonParams ): Promise<void>; } type JsonUpdate<T> = (json: T) => T | void | Promise<T | void>; declare function json(): VfsPlugin<JsonPluginApi>; declare function createJsonFileApi<FileContents extends JSONValue | unknown = unknown>( vfs: BaseVfs, path: string ): JsonFileApi<FileContents>; declare function readVfsJson<T extends JSONValue | unknown = unknown>( vfs: BaseVfs, path: string, options?: ParseJsonParams ): Promise<T>; declare function writeVfsJson<T extends JSONValue | unknown = unknown>( vfs: BaseVfs, path: string, json: T, options?: SerializeJsonParams ): Promise<void>; declare function updateVfsJson<T extends JSONValue | unknown = unknown>( vfs: BaseVfs, path: string, updater: JsonUpdate<T>, options?: ParseJsonParams & SerializeJsonParams ): Promise<void>; type JSONPrimitive = string | number | boolean | null; type JSONValue = JSONPrimitive | JSONObject | JSONArray; type JSONArray = JSONValue[]; interface JSONObject { [member: string]: JSONValue; } export { type JSONArray, type JSONObject, type JSONPrimitive, type JSONValue, type JsonFileApi, type JsonPluginApi, type JsonUpdate, createJsonFileApi, json, readVfsJson, updateVfsJson, writeVfsJson };