Update klaw-sync module interface from v1.0 to v2.0.0 + (#25134)

*  commit 'Update `klaw-sync` module interface to v2.0.0 +

[v2.0.0 apis](https://github.com/manidlou/node-klaw-sync/tree/v2.0.0) [v3.0.2 apis](https://github.com/manidlou/node-klaw-sync/tree/v3.0.2)

* Update `klaw-sync` module interface from v1.0 to v2.0.0 +

* Update `klaw-sync` module interface from v1.0 to v2.0.0 +

* Change `klaw-sync` types version from `3.0` to `2.0` and remove ignore parameter.

* Update test case.

* Improve the test case of `options.filter`.

* Add definitions of `klaw-sync`

* Remove `Colin Luo` from `klaw-sync` Difinitions.
This commit is contained in:
Colin Luo
2018-04-25 07:05:35 +08:00
committed by Wesley Wigham
parent af589d355f
commit 3363dfb20e
2 changed files with 49 additions and 31 deletions

View File

@@ -1,4 +1,4 @@
// Type definitions for klaw-sync 1.1
// Type definitions for klaw-sync 2.0
// Project: https://github.com/manidlou/node-klaw-sync
// Definitions by: Brendan Forster <https://github.com/shiftkey>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -6,35 +6,50 @@
/// <reference types="node" />
import * as fs from 'fs'
declare namespace klawSync {
interface Item {
path: string
stats: fs.Stats
}
interface Item {
path: string
stats: fs.Stats
}
interface Options {
/**
* any paths or `micromatch` patterns to ignore.
*
* For more information on micromatch patterns: https://github.com/jonschlinkert/micromatch#features
*/
ignore?: string | string[]
/**
* True to only return files (ignore directories).
*
* Defaults to false if not specified.
*/
nodir?: boolean
/**
* True to only return directories (ignore files).
*
* Defaults to false if not specified.
*/
nofile?: boolean
}
type Filter = (item: Item) => boolean
interface Options {
/**
* @description True to only return files (ignore directories).
* Defaults to false if not specified.
* @default false
*/
nodir?: boolean
/**
* @description True to only return directories (ignore files).
* Defaults to false if not specified.
* @default false
*/
nofile?: boolean
/**
* @description when filter function is used, the default behavior is to read all directories even
* if they don't pass the filter function (won't be included but still will be traversed).
* If you set true, there will be neither inclusion nor traversal for directories that
* don't pass the filter function
* @since v2.0.0
*/
noRecurseOnFailedFilter?: boolean
/**
* @description function that gets one argument fn({path: '', stats: {}}) and returns true to include
* or false to exclude the item
* @since v2.0.0
*/
filter?: Filter
}
}
declare function klawSync(root: string, options?: klawSync.Options): ReadonlyArray<klawSync.Item>
declare function klawSync(
root: string,
options?: klawSync.Options,
): ReadonlyArray<klawSync.Item>
export = klawSync

View File

@@ -2,7 +2,7 @@ import * as path from 'path'
import klawSync = require('klaw-sync')
const outputMessage = (result: klawSync.Item) => {
console.log(`file: ${result.path} has size '${result.stats.size}'`)
console.log(`file: ${result.path} has size '${result.stats.size}'`)
}
klawSync('/some/dir').forEach(outputMessage)
@@ -12,9 +12,12 @@ const defaultOptions = {}
klawSync('/some/dir', defaultOptions).forEach(outputMessage)
const options = {
ignore: ['.exe'],
nodir: true,
nofile: false,
nodir: true,
nofile: false,
noRecurseOnFailedFilter: false,
filter(item: klawSync.Item) {
return item.path.indexOf('node_modules') < 0
},
}
klawSync('/some/dir', options).forEach(outputMessage)