mirror of
https://github.com/denoland/deno.git
synced 2024-11-01 09:24:20 -04:00
a3c3a56ff7
* Rename MkdirOption interface to MkdirOptions It was hard to remember which Options interfaces were spelled in the singular and which in the plural (and anyway this one contained two options). Also added MkdirOptions to cli/js/deno.ts. All the analogous interfaces were exported there. * Rename RemoveOption interface to RemoveOptions This was the last remaining Option interface spelled in the singular. Easier to remember if they're all Option**s**; plus we may want to add extra options here later.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
import { sendSync, sendAsync } from "./dispatch_json.ts";
|
|
|
|
export interface RemoveOptions {
|
|
/** Defaults to `false`. If set to `true`, path will be removed even if
|
|
* it's a non-empty directory. */
|
|
recursive?: boolean;
|
|
}
|
|
|
|
/** Synchronously removes the named file or directory. Throws error if
|
|
* permission denied, path not found, or path is a non-empty directory and
|
|
* the `recursive` option isn't set to `true`.
|
|
*
|
|
* Deno.removeSync("/path/to/dir/or/file", { recursive: false });
|
|
*
|
|
* Requires `allow-write` permission. */
|
|
export function removeSync(path: string, options: RemoveOptions = {}): void {
|
|
sendSync("op_remove", { path, recursive: !!options.recursive });
|
|
}
|
|
|
|
/** Removes the named file or directory. Throws error if permission denied,
|
|
* path not found, or path is a non-empty directory and the `recursive`
|
|
* option isn't set to `true`.
|
|
*
|
|
* await Deno.remove("/path/to/dir/or/file", { recursive: false });
|
|
*
|
|
* Requires `allow-write` permission. */
|
|
export async function remove(
|
|
path: string,
|
|
options: RemoveOptions = {}
|
|
): Promise<void> {
|
|
await sendAsync("op_remove", { path, recursive: !!options.recursive });
|
|
}
|