fs#WriteFileOptions TypeScript Examples
The following examples show how to use
fs#WriteFileOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: fs.ts From gitmars with GNU General Public License v3.0 | 6 votes |
/**
* 写入json文件内容
*
* @example
* ```ts
* import { writeJSON } from '@jssj/node'
* writeJSON('/path/of/file', 'test data', { encoding: 'utf8 })
* ```
* @param args - Parameters<typeof writeFileSync>
* @param args.path - Path to file
* @param args.data - data
* @param args.options - options
*/
export function writeJSON(
file: PathOrFileDescriptor,
data: Record<string, unknown> | Parameters<typeof writeFileSync>[1],
options?: WriteFileOptions
): void {
if (typeof data === 'object') {
data = (data && JSON.stringify(data, null, 4)) || ''
}
writeFileSync(file, data, options)
}