@augment-vir/node
Version:
A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.
51 lines (50 loc) • 1.89 kB
TypeScript
import { type JsonCompatibleArray, type JsonCompatibleObject, type JsonCompatibleValue } from '@augment-vir/common';
import { type PartialWithUndefined } from '@augment-vir/core';
/**
* Read a file and also parse its contents as JSON.
*
* @category Node : File
* @category JSON : Node
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
* @see
* - {@link writeJsonFile}
* - {@link appendJsonFile}
*/
export declare function readJsonFile(path: string): Promise<JsonCompatibleValue | undefined>;
/**
* Options for {@link writeJsonFile}.
*
* @category Node : File
* @category JSON : Node
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
*/
export type WriteJsonOptions = PartialWithUndefined<{
includeTrailingNewLine: boolean;
}>;
/**
* Write to a file and stringify `data` as JSON before doing so.
*
* @category Node : File
* @category JSON : Node
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
* @see
* - {@link readJsonFile}
* - {@link appendJsonFile}
*/
export declare function writeJsonFile(path: string, data: JsonCompatibleValue, options?: WriteJsonOptions): Promise<void>;
/**
* Append the given `newData` to the contents of the existing JSON file. If the file does not yet
* exist, `newData` is written as its only JSON contents.
*
* @category Node : File
* @category JSON : Node
* @category Package : @augment-vir/node
* @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node)
* @see
* - {@link readJsonFile}
* - {@link writeJsonFile}
*/
export declare function appendJsonFile(path: string, newData: JsonCompatibleObject | JsonCompatibleArray, options?: WriteJsonOptions): Promise<void>;