UNPKG

2.34 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 * Convenient way to defer File operations with fluent API
21 */
22export interface FileScripting extends ScriptedFlushable<File> {
23 /**
24 * Set entire file content to new string
25 *
26 * @param newContent {string} The content to set the file to
27 */
28 recordSetContent(newContent: string): this;
29 recordRename(name: string): this;
30 recordSetPath(name: string): this;
31 /**
32 * Replace all occurrences of the given regular expression with
33 * @param re
34 * @param replacement
35 */
36 recordReplace(re: RegExp, replacement: string): this;
37 recordReplaceAll(oldLiteral: string, newLiteral: string): this;
38}
39export interface FileAsync extends FileCore {
40 setContent(content: string): Promise<this>;
41 rename(name: string): Promise<this>;
42 getContent(): Promise<string>;
43 replace(re: RegExp, replacement: string): Promise<this>;
44 replaceAll(oldLiteral: string, newLiteral: string): Promise<this>;
45 setPath(path: string): Promise<this>;
46 isExecutable(): Promise<boolean>;
47 isReadable(): Promise<boolean>;
48 isBinary(): Promise<boolean>;
49}
50export interface FileNonBlocking extends FileScripting, FileAsync {
51}
52/**
53 * Sychronous file operations. Use with care as they can limit concurrency.
54 * Following the conventions of node fs library, they use a "sync" suffix.
55 */
56export interface FileSync extends FileCore {
57 /**
58 * Return content. Blocks: use inputStream by preference.
59 *
60 * @property {string} content
61 */
62 getContentSync(): string;
63 setContentSync(content: string): this;
64}
65/**
66 * Abstraction for a File. Similar to Project abstraction,
67 * broken into three distinct styles of usage.
68 */
69export interface File extends FileScripting, FileSync, FileAsync {
70 /**
71 * Extension or the empty string if no extension can be determined
72 */
73 extension: string;
74}
75export declare function isFile(a: any): a is File;
76//# sourceMappingURL=File.d.ts.map
\No newline at end of file