@stryke/fs
Version:
A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.
46 lines (45 loc) • 1.8 kB
text/typescript
import { JsonParseOptions, JsonSerializeOptions } from "@stryke/json/types";
//#region src/json.d.ts
/**
* Reads a JSON file and returns the object the JSON content represents.
*
* @param path - A path to a file.
* @param options - JSON parse options
* @returns Object the JSON content of the file represents
*/
declare function readJsonFileSync<T extends object = any>(path: string, options?: JsonParseOptions): T;
/**
* Reads a JSON file and returns the object the JSON content represents.
*
* @param path - A path to a file.
* @param options - JSON parse options
* @returns Object the JSON content of the file represents
*/
declare function readJsonFile<T extends object = any>(path: string, options?: JsonParseOptions): Promise<T>;
interface JsonWriteOptions extends JsonSerializeOptions {
/**
* whether to append new line at the end of JSON file
*
* @defaultValue false
*/
appendNewLine?: boolean;
}
/**
* Serializes the given data to JSON and writes it to a file.
*
* @param path - A path to a file.
* @param data - data which should be serialized to JSON and written to the file
* @param options - JSON serialize options
*/
declare function writeJsonFileSync<T extends object = object>(path: string, data: T, options?: JsonWriteOptions): void;
/**
* Serializes the given data to JSON and writes it to a file asynchronously.
*
* @param path - A path to a file.
* @param data - data which should be serialized to JSON and written to the file
* @param options - JSON serialize options
*/
declare function writeJsonFile<T extends object = object>(path: string, data: T, options?: JsonWriteOptions): Promise<void>;
//#endregion
export { JsonWriteOptions, readJsonFile, readJsonFileSync, writeJsonFile, writeJsonFileSync };
//# sourceMappingURL=json.d.cts.map