( path: string | URL, data: string, options?: WriteFileOptions, )
| 76 | * @param options Options for writing files. See {@linkcode WriteFileOptions}. |
| 77 | */ |
| 78 | export function writeTextFileSync( |
| 79 | path: string | URL, |
| 80 | data: string, |
| 81 | options?: WriteFileOptions, |
| 82 | ): void { |
| 83 | if (isDeno) { |
| 84 | Deno.writeTextFileSync(path, data, { ...options }); |
| 85 | } else { |
| 86 | const { |
| 87 | append = false, |
| 88 | create = true, |
| 89 | createNew = false, |
| 90 | mode, |
| 91 | } = options ?? {}; |
| 92 | |
| 93 | const flag = getWriteFsFlag({ append, create, createNew }); |
| 94 | try { |
| 95 | getNodeFs().writeFileSync(path, data, { encoding: "utf-8", flag }); |
| 96 | if (mode != null) { |
| 97 | getNodeFs().chmodSync(path, mode); |
| 98 | } |
| 99 | } catch (error) { |
| 100 | throw mapError(error); |
| 101 | } |
| 102 | } |
| 103 | } |
no test coverage detected