mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
feat(types): Add types for the «readdir-enhanced» package (#23022)
This commit is contained in:
parent
2267e573cb
commit
6fe162ecd9
72
types/readdir-enhanced/index.d.ts
vendored
Normal file
72
types/readdir-enhanced/index.d.ts
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
// Type definitions for readdir-enhanced 2.2
|
||||
// Project: https://github.com/bigstickcarpet/readdir-enhanced
|
||||
// Definitions by: mrmlnc <https://github.com/mrmlnc>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import fs = require('fs');
|
||||
|
||||
declare namespace re {
|
||||
interface Entry extends fs.Stats {
|
||||
path: string;
|
||||
depth: number;
|
||||
}
|
||||
|
||||
type FilterFunction = (stat: Entry) => boolean;
|
||||
type Callback<T> = (err: NodeJS.ErrnoException, result: T) => void;
|
||||
type CallbackString = Callback<string[]>;
|
||||
type CallbackEntry = Callback<Entry[]>;
|
||||
|
||||
interface FileSystem {
|
||||
readdir?: (path: string, callback: Callback<string[]>) => void;
|
||||
lstat?: (path: string, callback: Callback<fs.Stats>) => void;
|
||||
stat?: (path: string, callback: Callback<fs.Stats>) => void;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
filter?: string | RegExp | FilterFunction;
|
||||
deep?: boolean | number | RegExp | FilterFunction;
|
||||
sep?: string;
|
||||
basePath?: string;
|
||||
fs?: FileSystem;
|
||||
}
|
||||
|
||||
function stat(root: string, options?: Options): Promise<Entry[]>;
|
||||
function stat(root: string, callback: CallbackEntry): void;
|
||||
function stat(root: string, options: Options, callback: CallbackEntry): void;
|
||||
|
||||
function async(root: string, options?: Options): Promise<string[]>;
|
||||
function async(root: string, callback: CallbackString): void;
|
||||
function async(root: string, options: Options, callback: CallbackString): void;
|
||||
|
||||
function readdirAsyncStat(root: string, options?: Options): Promise<Entry[]>;
|
||||
function readdirAsyncStat(root: string, callback: CallbackEntry): void;
|
||||
function readdirAsyncStat(root: string, options: Options, callback: CallbackEntry): void;
|
||||
|
||||
namespace async {
|
||||
function stat(root: string, options?: Options): Promise<Entry[]>;
|
||||
function stat(root: string, callback: CallbackEntry): void;
|
||||
function stat(root: string, options: Options, callback: CallbackEntry): void;
|
||||
}
|
||||
|
||||
function stream(root: string, options?: Options): NodeJS.ReadableStream;
|
||||
function readdirStreamStat(root: string, options?: Options): NodeJS.ReadableStream;
|
||||
|
||||
namespace stream {
|
||||
function stat(root: string, options?: Options): NodeJS.ReadableStream;
|
||||
}
|
||||
|
||||
function sync(root: string, options?: Options): string[];
|
||||
function readdirSyncStat(root: string, options?: Options): Entry[];
|
||||
|
||||
namespace sync {
|
||||
function stat(root: string, options?: Options): Entry[];
|
||||
}
|
||||
}
|
||||
|
||||
declare function re(root: string, options?: re.Options): Promise<string[]>;
|
||||
declare function re(root: string, callback: re.CallbackString): void;
|
||||
declare function re(root: string, options: re.Options, callback: re.CallbackString): void;
|
||||
|
||||
export = re;
|
||||
85
types/readdir-enhanced/readdir-enhanced-tests.ts
Normal file
85
types/readdir-enhanced/readdir-enhanced-tests.ts
Normal file
@ -0,0 +1,85 @@
|
||||
import fs = require('fs');
|
||||
|
||||
import re = require('readdir-enhanced');
|
||||
|
||||
const reFs: re.FileSystem = {
|
||||
stat: fs.stat,
|
||||
lstat: fs.lstat,
|
||||
readdir: fs.readdir
|
||||
};
|
||||
|
||||
const reOptions: re.Options = {
|
||||
basePath: '',
|
||||
fs: reFs,
|
||||
sep: '/'
|
||||
};
|
||||
|
||||
reOptions.deep = true;
|
||||
reOptions.deep = 2;
|
||||
reOptions.deep = /regexp/;
|
||||
reOptions.deep = () => true;
|
||||
|
||||
reOptions.deep = () => 0; // $ExpectError
|
||||
reOptions.deep = ''; // $ExpectError
|
||||
|
||||
reOptions.filter = '';
|
||||
reOptions.filter = /regexp/;
|
||||
reOptions.filter = () => true;
|
||||
|
||||
reOptions.filter = () => 0; // $ExpectError
|
||||
reOptions.filter = 1; // $ExpectError
|
||||
|
||||
const callbackString: re.CallbackString = (err, result) => { };
|
||||
const callbackEntry: re.CallbackEntry = (err, result) => { };
|
||||
|
||||
re('root', callbackString); // $ExpectType void
|
||||
re('root', reOptions, callbackString); // $ExpectType void
|
||||
re('root'); // $ExpectType Promise<string[]>
|
||||
re('root', reOptions); // $ExpectType Promise<string[]>
|
||||
|
||||
re.stat('root', callbackEntry); // $ExpectType void
|
||||
re.stat('root', reOptions, callbackEntry); // $ExpectType void
|
||||
re.stat('root'); // $ExpectType Promise<Entry[]>
|
||||
re.stat('root', reOptions); // $ExpectType Promise<Entry[]>
|
||||
|
||||
re.readdirAsyncStat('root', callbackEntry); // $ExpectType void
|
||||
re.readdirAsyncStat('root', reOptions, callbackEntry); // $ExpectType void
|
||||
re.readdirAsyncStat('root'); // $ExpectType Promise<Entry[]>
|
||||
re.readdirAsyncStat('root', reOptions); // $ExpectType Promise<Entry[]>
|
||||
|
||||
re.async('root', callbackString); // $ExpectType void
|
||||
re.async('root', reOptions, callbackString); // $ExpectType void
|
||||
re.async('root'); // $ExpectType Promise<string[]>
|
||||
re.async('root', reOptions); // $ExpectType Promise<string[]>
|
||||
|
||||
re.async.stat('root', callbackEntry); // $ExpectType void
|
||||
re.async.stat('root', reOptions, callbackEntry); // $ExpectType void
|
||||
re.async.stat('root'); // $ExpectType Promise<Entry[]>
|
||||
re.async.stat('root', reOptions); // $ExpectType Promise<Entry[]>
|
||||
|
||||
re.stream('root'); // $ExpectType ReadableStream
|
||||
re.stream('root', reOptions); // $ExpectType ReadableStream
|
||||
|
||||
re.stream.stat('root'); // $ExpectType ReadableStream
|
||||
re.stream.stat('root', reOptions); // $ExpectType ReadableStream
|
||||
|
||||
re.readdirStreamStat('root'); // $ExpectType ReadableStream
|
||||
re.readdirStreamStat('root', reOptions); // $ExpectType ReadableStream
|
||||
|
||||
re.sync('root'); // $ExpectType string[]
|
||||
re.sync('root', reOptions); // $ExpectType string[]
|
||||
|
||||
re.sync.stat('root'); // $ExpectType Entry[]
|
||||
re.sync.stat('root', reOptions); // $ExpectType Entry[]
|
||||
|
||||
re.readdirSyncStat('root'); // $ExpectType Entry[]
|
||||
re.readdirSyncStat('root', reOptions); // $ExpectType Entry[]
|
||||
|
||||
// Entry
|
||||
re.sync('root'); // $ExpectType string[]
|
||||
|
||||
const entries = re.sync.stat('root'); // $ExpectType Entry[]
|
||||
|
||||
entries[0]; // $ExpectType Entry
|
||||
entries[0].path; // $ExpectType string
|
||||
entries[0].depth; // $ExpectType number
|
||||
23
types/readdir-enhanced/tsconfig.json
Normal file
23
types/readdir-enhanced/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"readdir-enhanced-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/readdir-enhanced/tslint.json
Normal file
1
types/readdir-enhanced/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user