Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/fs.ts>writeLines

A JavaScript extension package for building strong and modern applications.
Latest
function writeLines
import { writeLines } from "https://deno.land/x/ayonli_jsext@v0.9.72/fs.ts";

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

// with the default storage
import { writeLines } from "@ayonli/jsext/fs";

await writeLines("/path/to/file.txt", ["Hello", "World"]);

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

// append the lines to the file
import { writeLines } from "@ayonli/jsext/fs";

await writeLines("/path/to/file.txt", ["Hello", "World"], { append: true });

Parameters

target: string | FileSystemFileHandle
lines: string[]
optional
options: WriteFileOptions = [UNSUPPORTED]

Returns

Promise<void>