-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TypeScript definition #81
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {IOptions as GlobOptions} from 'glob'; | ||
|
||
interface Options extends Readonly<GlobOptions> { | ||
/** | ||
* Allow deleting the current working directory and outside. | ||
* | ||
* @default false | ||
*/ | ||
readonly force?: boolean; | ||
|
||
/** | ||
* See what would be deleted. | ||
* | ||
* @default false | ||
* | ||
* @example | ||
* | ||
* const del = require('del'); | ||
* | ||
* (async () => { | ||
* const deletedPaths = await del(['tmp/*.js'], {dryRun: true}); | ||
* | ||
* console.log('Files and folders that would be deleted:\n', deletedPaths.join('\n')); | ||
* })(); | ||
*/ | ||
readonly dryRun?: boolean; | ||
|
||
/** | ||
* Concurrency limit. Minimum: `1`. | ||
* | ||
* @default Infinity | ||
*/ | ||
readonly concurrency?: number; | ||
} | ||
|
||
/** | ||
* Delete files and folders using glob patterns. | ||
* | ||
* @param patterns - See supported minimatch [patterns](https://github.com/isaacs/minimatch#usage). | ||
* - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) | ||
* - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) | ||
* @param options - See the [`glob` options](https://github.com/isaacs/node-glob#options). | ||
* @returns A promise for an array of deleted paths. | ||
*/ | ||
export default function del( | ||
patterns: string | ReadonlyArray<string>, | ||
options?: Options | ||
): Promise<string[]>; | ||
|
||
/** | ||
* Synchronously delete files and folders using glob patterns. | ||
* | ||
* @param patterns - See supported minimatch [patterns](https://github.com/isaacs/minimatch#usage). | ||
* - [Pattern examples with expected matches](https://github.com/sindresorhus/multimatch/blob/master/test/test.js) | ||
* - [Quick globbing pattern overview](https://github.com/sindresorhus/multimatch#globbing-patterns) | ||
* @param options - See the [`glob` options](https://github.com/isaacs/node-glob#options). | ||
* @returns An array of deleted paths. | ||
*/ | ||
export function sync( | ||
patterns: string | ReadonlyArray<string>, | ||
options?: Options | ||
): string[]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {expectType} from 'tsd-check'; | ||
import del, {sync as delSync} from '.'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I the only one that finds this ugly? Should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of default imports. They're always kinda ugly, everyone names the thing differently and the tooling has hard times determining what you actually want to import. It's much easier with named exports. |
||
|
||
let paths = ['tmp/*.js', '!tmp/unicorn.js']; | ||
|
||
// Del | ||
expectType<Promise<string[]>>(del('tmp/*.js')); | ||
expectType<Promise<string[]>>(del(paths)); | ||
|
||
expectType<Promise<string[]>>(del(paths, {force: true})); | ||
expectType<Promise<string[]>>(del(paths, {dryRun: true})); | ||
expectType<Promise<string[]>>(del(paths, {concurrency: 20})); | ||
expectType<Promise<string[]>>(del(paths, {cwd: ''})); | ||
|
||
// Del (sync) | ||
expectType<string[]>(delSync('tmp/*.js')); | ||
expectType<string[]>(delSync(paths)); | ||
|
||
expectType<string[]>(delSync(paths, {force: true})); | ||
expectType<string[]>(delSync(paths, {dryRun: true})); | ||
expectType<string[]>(delSync(paths, {concurrency: 20})); | ||
expectType<string[]>(delSync(paths, {cwd: ''})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
import
syntax. This is supposed to be a TS usage example.