node-readfiles
Version:
A lightweight Node.js module to recursively read files in a directory using ES6 Promises
115 lines (114 loc) • 3.75 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
declare module "src/build-filter" {
export const buildFilter: (filtersParam: string | string[]) => RegExp;
}
declare module "src/build-filters.spec" { }
declare module "src/consts" {
export enum FilenameFormat {
RELATIVE = 0,
FULL_PATH = 1,
FILENAME = 2
}
}
declare module "src/readfiles" {
import * as fs from 'fs';
import { FilenameFormat } from "src/consts";
export interface ReadfilesOptions {
async?: boolean;
filter?: string | string[];
rejectOnError?: boolean;
reverse?: boolean;
hidden?: boolean;
depth?: number;
filenameFormat?: FilenameFormat;
readContents?: boolean;
encoding?: BufferEncoding;
}
type AsyncFunction = (done: () => void) => void;
export type ReadfilesCallback = (err: Error | null, relativeFilename: string, content: string | null, stat: fs.Stats) => void | AsyncFunction;
export function readfiles(dir: string): Promise<string[]>;
export function readfiles(dir: string, callback?: ReadfilesCallback): Promise<string[]>;
export function readfiles(dir: string, options?: ReadfilesOptions, callback?: ReadfilesCallback): Promise<string[]>;
}
declare module "src/index" {
export * from "src/consts";
export * from "src/readfiles";
export { readfiles as default } from "src/readfiles";
}
declare module "test/fixtures" {
export const flatPathFixture: {
'/path/to/dir': {
'abc.txt': string;
'def.dat': string;
'test123.txt': string;
'test456.dat': string;
};
};
export const deepPathFixture: {
'/path/to/dir': {
'.system': string;
'def.dat': string;
'abc.txt': string;
'abc123.txt': string;
subdir: {
'.dot': string;
'test456.dat': string;
'test789.txt': string;
'test123.txt': string;
'abc123.txt': string;
subsubdir: {
'.hidden': string;
'abc123.dat': string;
'def456.dat': string;
};
};
otherdir: {
'.other': string;
'test789.txt': string;
'test123.txt': string;
subsubdir: {
'.hidden': string;
'abc123.txt': string;
'def456.txt': string;
};
};
};
};
export const badDeepPathFixture: {
'/path/to/dir': {
'.system': string;
'def.dat': string;
'abc.txt': string;
'abc123.txt': string;
subdir: {
'.dot': string;
'error-file.dat': boolean;
'test456.dat': string;
'test789.txt': string;
'test123.txt': string;
'abc123.txt': string;
subsubdir: {
'.hidden': string;
'abc123.dat': string;
'def456.dat': string;
};
};
otherdir: {
'.other': string;
'error-file.dat': boolean;
'test789.txt': string;
'test123.txt': string;
subsubdir: {
'.hidden': string;
'abc123.txt': string;
'def456.txt': string;
};
};
};
};
}
declare module "test/fs-helper" {
export const mockFs: (fixture: Record<string, any>) => void;
}
declare module "src/readfiles.spec" { }