@stryke/fs
Version:
A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.
50 lines (49 loc) • 1.89 kB
TypeScript
import type { JsonParseOptions, JsonSerializeOptions } from "@stryke/json/types";
export interface JsonReadOptions extends JsonParseOptions {
/**
* mutable field recording whether JSON ends with new line
*
* @defaultValue false
*/
endsWithNewline?: boolean;
}
/**
* 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
*/
export declare function readJsonFileSync<T extends object = any>(path: string, options?: JsonReadOptions): 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
*/
export declare function readJsonFile<T extends object = any>(path: string, options?: JsonReadOptions): Promise<T>;
export 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
*/
export 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
*/
export declare function writeJsonFile<T extends object = object>(path: string, data: T, options?: JsonWriteOptions): Promise<void>;