UNPKG

1.81 kBTypeScriptView Raw
1import { ScriptedFlushable } from "../internal/common/Flushable";
2/**
3 * Operations common to all File interfaces
4 */
5export interface FileCore {
6 /**
7 * Return file name, excluding path
8 *
9 * @property {string} name
10 */
11 readonly name: string;
12 /**
13 * Return file path, with forward slashes
14 *
15 * @property {string} path
16 */
17 readonly path: string;
18}
19/**
20 * @deprecated
21 * Convenient way to defer File operations with fluent API
22 */
23export interface FileScripting extends ScriptedFlushable<File> {
24}
25export interface FileAsync extends FileCore {
26 setContent(content: string): Promise<this>;
27 rename(name: string): Promise<this>;
28 getContent(): Promise<string>;
29 replace(re: RegExp, replacement: string): Promise<this>;
30 replaceAll(oldLiteral: string, newLiteral: string): Promise<this>;
31 setPath(path: string): Promise<this>;
32 isExecutable(): Promise<boolean>;
33 isReadable(): Promise<boolean>;
34 isBinary(): Promise<boolean>;
35}
36export interface FileNonBlocking extends FileScripting, FileAsync {
37}
38/**
39 * Sychronous file operations. Use with care as they can limit concurrency.
40 * Following the conventions of node fs library, they use a "sync" suffix.
41 */
42export interface FileSync extends FileCore {
43 /**
44 * Return content. Blocks: use inputStream by preference.
45 *
46 * @property {string} content
47 */
48 getContentSync(): string;
49 setContentSync(content: string): this;
50}
51/**
52 * Abstraction for a File. Similar to Project abstraction,
53 * broken into three distinct styles of usage.
54 */
55export interface File extends FileScripting, FileSync, FileAsync {
56 /**
57 * Extension or the empty string if no extension can be determined
58 */
59 extension: string;
60}
61export declare function isFile(a: any): a is File;