Skip to main content

@std/fs@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
default

Helpers for working with the filesystem.

Classes

c
SubdirectoryMoveError(
src: string | URL,
dest: string | URL
)

Error thrown in move or moveSync when the destination is a subdirectory of the source.

c
WalkError(
cause: unknown,
root: string
)

Error thrown in walk or walkSync during iteration.

  • root: string

    File path of the root that's being walked.

Functions

f
copy(
src: string | URL,
dest: string | URL,
options?: CopyOptions
): Promise<void>

Copy a file or directory. The directory can have contents. Like cp -r. Requires the --allow-read and --allow-write flag.

f
copySync(
src: string | URL,
dest: string | URL,
options?: CopyOptions
): void

Copy a file or directory. The directory can have contents. Like cp -r. Requires the --allow-read and --allow-write flag.

f
detect(content: string): EOL | null

Detect the EOL character for string input. returns null if no newline.

f
emptyDir(dir: string | URL): Promise<void>

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted. Requires the --allow-read and --allow-write flag.

f
emptyDirSync(dir: string | URL): void

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted. Requires the --allow-read and --allow-write flag.

f
ensureDir(dir: string | URL): Promise<void>

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p. Requires the --allow-read and --allow-write flag.

f
ensureDirSync(dir: string | URL): void

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p. Requires the --allow-read and --allow-write flag.

f
ensureFile(filePath: string | URL): Promise<void>

Ensures that the file exists. If the file that is requested to be created is in directories that do not exist. these directories are created. If the file already exists, it is NOTMODIFIED. Requires the --allow-read and --allow-write flag.

f
ensureFileSync(filePath: string | URL): void

Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is NOT MODIFIED. Requires the --allow-read and --allow-write flag.

f
ensureLinkSync(
src: string | URL,
dest: string | URL
): void

Ensures that the hard link exists. If the directory structure does not exist, it is created.

f
ensureSymlinkSync(
target: string | URL,
linkName: string | URL
): void

Ensures that the link exists, and points to a valid file. If the directory structure does not exist, it is created.

f
exists(
path: string | URL,
options?: ExistsOptions
): Promise<boolean>

Test whether or not the given path exists by checking with the file system. Please consider to check if the path is readable and either a file or a directory by providing additional options:

f
existsSync(
path: string | URL,
options?: ExistsOptions
): boolean

Test whether or not the given path exists by checking with the file system. Please consider to check if the path is readable and either a file or a directory by providing additional options:

f
expandGlob(
glob: string | URL,
unnamed 1?: ExpandGlobOptions
): AsyncIterableIterator<WalkEntry>

Expand the glob string from the specified root directory and yield each result as a WalkEntry object.

f
expandGlobSync(
glob: string | URL,
unnamed 1?: ExpandGlobOptions
): IterableIterator<WalkEntry>

Synchronous version of expandGlob().

f
format(
content: string,
eol: EOL
): string

Format the file to the targeted EOL.

f
move(
src: string | URL,
dest: string | URL,
unnamed 2?: MoveOptions
): Promise<void>

Moves a file or directory.

f
moveSync(
src: string | URL,
dest: string | URL,
unnamed 2?: MoveOptions
): void

Moves a file or directory synchronously.

f
walk(
root: string | URL,
unnamed 1?: WalkOptions
): AsyncIterableIterator<WalkEntry>

Walks the file tree rooted at root, yielding each file or directory in the tree filtered according to the given options.

f
walkSync(
root: string | URL,
unnamed 1?: WalkOptions
): IterableIterator<WalkEntry>

Same as walk but uses synchronous ops

Interfaces

I

Options for copy and copySync.

  • overwrite: boolean

    overwrite existing file or directory.

  • When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent.

I

Options for exists and existsSync.

  • isDirectory: boolean

    When true, will check if the path is a directory as well. Directory symlinks are included.

  • isFile: boolean

    When true, will check if the path is a file as well. File symlinks are included.

  • isReadable: boolean

    When true, will check if the path is readable by the user as well.

I

Options for expandGlob and expandGlobSync.

  • canonicalize: boolean

    Indicates whether the followed symlink's path should be canonicalized. This option works only if followSymlinks is not false.

  • exclude: string[]

    List of glob patterns to be excluded from the expansion.

  • Whether to follow symbolic links.

  • includeDirs: boolean

    Whether to include directories in entries.

  • root: string

    File path where to expand from.

I

Options for move and moveSync.

  • overwrite: boolean

    Whether the destination file should be overwritten if it already exists.

I

Walk entry for walk, walkSync, expandGlob and expandGlobSync.

  • path: string

    Full path of the entry.

I

Options for walk and walkSync.

  • canonicalize: boolean

    Indicates whether the followed symlink's path should be canonicalized. This option works only if followSymlinks is not false.

  • exts: string[]

    List of file extensions used to filter entries. If specified, entries without the file extension specified by this option are excluded.

  • Indicates whether symlinks should be resolved or not.

  • includeDirs: boolean

    Indicates whether directory entries should be included or not.

  • includeFiles: boolean

    Indicates whether file entries should be included or not.

  • Indicates whether symlink entries should be included or not. This option is meaningful only if followSymlinks is set to false.

  • match: RegExp[]

    List of regular expression patterns used to filter entries. If specified, entries that do not match the patterns specified by this option are excluded.

  • maxDepth: number

    The maximum depth of the file tree to be walked recursively.

  • skip: RegExp[]

    List of regular expression patterns used to filter entries. If specified, entries matching the patterns specified by this option are excluded.

Variables

v
CRLF: "\r\n"

End-of-line character for Windows platforms.

v
EOL: "\n" | "\r\n"

End-of-line character evaluated for the current platform.

v
LF: "\n"

End-of-line character for POSIX platforms such as macOS and Linux.

copy

Functions

f
copy(
src: string | URL,
dest: string | URL,
options?: CopyOptions
): Promise<void>

Copy a file or directory. The directory can have contents. Like cp -r. Requires the --allow-read and --allow-write flag.

f
copySync(
src: string | URL,
dest: string | URL,
options?: CopyOptions
): void

Copy a file or directory. The directory can have contents. Like cp -r. Requires the --allow-read and --allow-write flag.

Interfaces

I

Options for copy and copySync.

  • overwrite: boolean

    overwrite existing file or directory.

  • When true, will set last modification and access times to the ones of the original source files. When false, timestamp behavior is OS-dependent.

empty_dir

Functions

f
emptyDir(dir: string | URL): Promise<void>

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted. Requires the --allow-read and --allow-write flag.

f
emptyDirSync(dir: string | URL): void

Ensures that a directory is empty. Deletes directory contents if the directory is not empty. If the directory does not exist, it is created. The directory itself is not deleted. Requires the --allow-read and --allow-write flag.

ensure_dir

Functions

f
ensureDir(dir: string | URL): Promise<void>

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p. Requires the --allow-read and --allow-write flag.

f
ensureDirSync(dir: string | URL): void

Ensures that the directory exists. If the directory structure does not exist, it is created. Like mkdir -p. Requires the --allow-read and --allow-write flag.

ensure_file

Functions

f
ensureFile(filePath: string | URL): Promise<void>

Ensures that the file exists. If the file that is requested to be created is in directories that do not exist. these directories are created. If the file already exists, it is NOTMODIFIED. Requires the --allow-read and --allow-write flag.

f
ensureFileSync(filePath: string | URL): void

Ensures that the file exists. If the file that is requested to be created is in directories that do not exist, these directories are created. If the file already exists, it is NOT MODIFIED. Requires the --allow-read and --allow-write flag.

ensure_link
ensure_symlink
eol

Functions

f
detect(content: string): EOL | null

Detect the EOL character for string input. returns null if no newline.

f
format(
content: string,
eol: EOL
): string

Format the file to the targeted EOL.

Variables

v
CRLF: "\r\n"

End-of-line character for Windows platforms.

v
EOL: "\n" | "\r\n"

End-of-line character evaluated for the current platform.

v
LF: "\n"

End-of-line character for POSIX platforms such as macOS and Linux.

exists

Functions

f
exists(
path: string | URL,
options?: ExistsOptions
): Promise<boolean>

Test whether or not the given path exists by checking with the file system. Please consider to check if the path is readable and either a file or a directory by providing additional options:

f
existsSync(
path: string | URL,
options?: ExistsOptions
): boolean

Test whether or not the given path exists by checking with the file system. Please consider to check if the path is readable and either a file or a directory by providing additional options:

Interfaces

I

Options for exists and existsSync.

  • isDirectory: boolean

    When true, will check if the path is a directory as well. Directory symlinks are included.

  • isFile: boolean

    When true, will check if the path is a file as well. File symlinks are included.

  • isReadable: boolean

    When true, will check if the path is readable by the user as well.

expand_glob

Functions

f
expandGlob(
glob: string | URL,
unnamed 1?: ExpandGlobOptions
): AsyncIterableIterator<WalkEntry>

Expand the glob string from the specified root directory and yield each result as a WalkEntry object.

f
expandGlobSync(
glob: string | URL,
unnamed 1?: ExpandGlobOptions
): IterableIterator<WalkEntry>

Synchronous version of expandGlob().

Interfaces

I

Options for expandGlob and expandGlobSync.

  • canonicalize: boolean

    Indicates whether the followed symlink's path should be canonicalized. This option works only if followSymlinks is not false.

  • exclude: string[]

    List of glob patterns to be excluded from the expansion.

  • Whether to follow symbolic links.

  • includeDirs: boolean

    Whether to include directories in entries.

  • root: string

    File path where to expand from.

move

Classes

c
SubdirectoryMoveError(
src: string | URL,
dest: string | URL
)

Error thrown in move or moveSync when the destination is a subdirectory of the source.

Functions

f
move(
src: string | URL,
dest: string | URL,
unnamed 2?: MoveOptions
): Promise<void>

Moves a file or directory.

f
moveSync(
src: string | URL,
dest: string | URL,
unnamed 2?: MoveOptions
): void

Moves a file or directory synchronously.

Interfaces

I

Options for move and moveSync.

  • overwrite: boolean

    Whether the destination file should be overwritten if it already exists.

walk

Classes

c
WalkError(
cause: unknown,
root: string
)

Error thrown in walk or walkSync during iteration.

  • root: string

    File path of the root that's being walked.

Functions

f
walk(
root: string | URL,
unnamed 1?: WalkOptions
): AsyncIterableIterator<WalkEntry>

Walks the file tree rooted at root, yielding each file or directory in the tree filtered according to the given options.

f
walkSync(
root: string | URL,
unnamed 1?: WalkOptions
): IterableIterator<WalkEntry>

Same as walk but uses synchronous ops

Interfaces

I

Walk entry for walk, walkSync, expandGlob and expandGlobSync.

  • path: string

    Full path of the entry.

I

Options for walk and walkSync.

  • canonicalize: boolean

    Indicates whether the followed symlink's path should be canonicalized. This option works only if followSymlinks is not false.

  • exts: string[]

    List of file extensions used to filter entries. If specified, entries without the file extension specified by this option are excluded.

  • Indicates whether symlinks should be resolved or not.

  • includeDirs: boolean

    Indicates whether directory entries should be included or not.

  • includeFiles: boolean

    Indicates whether file entries should be included or not.

  • Indicates whether symlink entries should be included or not. This option is meaningful only if followSymlinks is set to false.

  • match: RegExp[]

    List of regular expression patterns used to filter entries. If specified, entries that do not match the patterns specified by this option are excluded.

  • maxDepth: number

    The maximum depth of the file tree to be walked recursively.

  • skip: RegExp[]

    List of regular expression patterns used to filter entries. If specified, entries matching the patterns specified by this option are excluded.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.