@beenotung/tslib
Version:
utils library in Typescript
52 lines (51 loc) • 2.15 kB
TypeScript
import { Result } from './result';
export declare function exist(filename: string): Promise<boolean>;
export declare function hasFile(filename: string): Promise<boolean>;
export declare function hasDirectory(filename: string): Promise<boolean>;
export declare function scanRecursively(args: {
entryPath: string;
onFile?: (filename: string, basename: string) => Result<void>;
onDir?: (dirname: string, basename: string) => Result<void>;
onComplete?: () => Result<void>;
dereferenceSymbolicLinks?: boolean;
skipDir?: (dirname: string, basename: string) => boolean;
}): Promise<void>;
export declare function scanRecursivelySync(args: {
entryPath: string;
onFile?: (filename: string, basename: string) => void;
onDir?: (dirname: string, basename: string) => void;
onComplete?: () => void;
dereferenceSymbolicLinks?: boolean;
skipDir?: (dirname: string, basename: string) => boolean;
}): void;
export declare function readJsonFile(file: string): Promise<any>;
export declare function readJsonFileSync(file: string): any;
export declare function writeJsonFile(file: string, value: any, options?: {
format?: boolean;
}): Promise<void>;
export declare function writeJsonFileSync(file: string, value: any, options?: {
format?: boolean;
}): void;
export type IterateFileByLineOptions = {
encoding?: BufferEncoding;
batchSize?: number;
close?: () => void;
};
/**
* linefeed "\n" is omitted from the yielded value
* but "\r" if exists is preserved as is
* */
export declare function iterateFileByLine(file: string, options?: IterateFileByLineOptions): Generator<string>;
export declare function verboseWriteFileSync(file: string, content: string | Buffer): void;
/**
* @description skip metadata files, e.g. .DS_Store
*/
export declare function getDirFilenamesSync(dir: string): string[];
/**
* @description skip metadata files, e.g. .DS_Store
*/
export declare function getDirFilenames(dir: string): Promise<string[]>;
/**
* @description check for metadata files, e.g. .DS_Store, *.swp, *.swo, .~lock.*#, *.ext~
*/
export declare function isMetadataFilename(filename: string): boolean;