import { writeLines } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/fs.js";
Writes multiple lines of content to the file.
This function will automatically detect the line ending of the current content and use it to write the new lines. If the file is empty or does not exists (will be created automatically), it will use the system's default line ending to separate lines.
This function will append a new line at the end of the final content, in appending mode, it will also prepend a line ending before the input lines if the current content doesn't ends with one.
Examples
Example 1
Example 1
// with the default storage
import { writeLines } from "@ayonli/jsext/fs";
await writeLines("/path/to/file.txt", ["Hello", "World"]);
Example 2
Example 2
// with a user-selected directory as root (Chromium only)
import { writeLines } from "@ayonli/jsext/fs";
const root = await window.showDirectoryPicker();
await writeLines("/path/to/file.txt", ["Hello", "World"], { root });
Example 3
Example 3
// append the lines to the file
import { writeLines } from "@ayonli/jsext/fs";
await writeLines("/path/to/file.txt", ["Hello", "World"], { append: true });