Merge pull request #19410 from garbles/patch-2

Update klaw-sync type definition
This commit is contained in:
Mine Starks
2017-08-29 13:24:47 -07:00
committed by GitHub
2 changed files with 35 additions and 31 deletions

View File

@@ -5,32 +5,36 @@
/// <reference types="node" />
import * as fs from "fs"
import * as fs from 'fs'
export interface Item {
path: string
stats: fs.Stats
declare namespace klawSync {
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
}
}
export 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
}
declare function klawSync(root: string, options?: klawSync.Options): ReadonlyArray<klawSync.Item>
export function klawSync(root: string, options?: Options): ReadonlyArray<Item>
export = klawSync

View File

@@ -1,20 +1,20 @@
import { klawSync, Item } from "klaw-sync"
import * as path from "path"
import * as path from 'path'
import klawSync = require('klaw-sync')
const outputMessage = (result: Item) => {
const outputMessage = (result: klawSync.Item) => {
console.log(`file: ${result.path} has size '${result.stats.size}'`)
}
klawSync('/some/dir').forEach(outputMessage)
const defaultOptions = { }
const defaultOptions = {}
klawSync('/some/dir', defaultOptions).forEach(outputMessage)
const options = {
ignore: [ '.exe' ],
ignore: ['.exe'],
nodir: true,
nofile: false
nofile: false,
}
klawSync('/some/dir', options).forEach(outputMessage)