/** * @file JSON writers that match the wire-format conventions a tool ecosystem * expects: configurable indentation, configurable EOL, trailing newline by * default. The `stringify` helper is exported so callers that already have an * `fs` handle can render a buffer without round-tripping through this * module's writers. */ import type { PathLike } from 'node:fs'; import type { JsonReviver } from '../json/types.js'; import type { WriteJsonOptions } from './types.js'; /** * Stringify JSON with custom formatting options. Formats JSON with configurable * line endings and indentation. * * @param json - Value to stringify. * @param options - Formatting options. * @param options.EOL - End-of-line sequence. * @param options.finalEOL - Whether to add final newline. * @param options.replacer - JSON replacer function. * @param options.spaces - Indentation spaces or string. * * @returns Formatted JSON string */ export declare function stringify(json: unknown, options?: { EOL?: string | undefined; finalEOL?: boolean | undefined; replacer?: JsonReviver | undefined; spaces?: number | string | undefined; } | undefined): string; /** * Write JSON content to a file asynchronously with formatting. Stringifies the * value with configurable indentation and line endings. Automatically adds a * final newline by default for POSIX compliance. * * @example * ;```ts * // Write formatted JSON with default 2-space indentation * await writeJson('./data.json', { name: 'example', version: '1.0.0' }) * * // Write with custom indentation * await writeJson('./config.json', config, { spaces: 4 }) * * // Write with tabs instead of spaces * await writeJson('./data.json', data, { spaces: '\t' }) * * // Write without final newline * await writeJson('./inline.json', obj, { finalEOL: false }) * * // Write with Windows line endings * await writeJson('./win.json', data, { EOL: '\r\n' }) * ``` * * @param filepath - Path to write to. * @param jsonContent - Value to stringify and write. * @param options - Write options including formatting and encoding. * * @returns Promise that resolves when write completes */ export declare function writeJson(filepath: PathLike, jsonContent: unknown, options?: WriteJsonOptions | string | undefined): Promise; /** * Write JSON content to a file synchronously with formatting. Stringifies the * value with configurable indentation and line endings. Automatically adds a * final newline by default for POSIX compliance. * * @example * ;```ts * // Write formatted JSON with default 2-space indentation * writeJsonSync('./package.json', pkg) * * // Write with custom indentation * writeJsonSync('./tsconfig.json', tsconfig, { spaces: 4 }) * * // Write with tabs for indentation * writeJsonSync('./data.json', data, { spaces: '\t' }) * * // Write compacted (no indentation) * writeJsonSync('./compact.json', data, { spaces: 0 }) * ``` * * @param filepath - Path to write to. * @param jsonContent - Value to stringify and write. * @param options - Write options including formatting and encoding. */ export declare function writeJsonSync(filepath: PathLike, jsonContent: unknown, options?: WriteJsonOptions | string | undefined): void;