From b9683a0460472046b74e79b6f7ab61654e086c3b Mon Sep 17 00:00:00 2001 From: Gabe Scholz Date: Mon, 28 Aug 2017 22:19:21 -0700 Subject: [PATCH] Update klaw-sync type definition --- types/klaw-sync/index.d.ts | 54 ++++++++++++++++-------------- types/klaw-sync/klaw-sync-tests.ts | 12 +++---- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/types/klaw-sync/index.d.ts b/types/klaw-sync/index.d.ts index 23eb661174..1bdd409dfc 100644 --- a/types/klaw-sync/index.d.ts +++ b/types/klaw-sync/index.d.ts @@ -5,32 +5,36 @@ /// -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 -export function klawSync(root: string, options?: Options): ReadonlyArray +export = klawSync diff --git a/types/klaw-sync/klaw-sync-tests.ts b/types/klaw-sync/klaw-sync-tests.ts index 5c2b806108..4808146882 100644 --- a/types/klaw-sync/klaw-sync-tests.ts +++ b/types/klaw-sync/klaw-sync-tests.ts @@ -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)