From 27d05885ad4aa92e63ad6fb72d761ea89c30c5d4 Mon Sep 17 00:00:00 2001 From: Mizunashi Mana Date: Tue, 4 Oct 2016 07:57:46 +0900 Subject: [PATCH] Add touch type definition (#11555) --- touch/index.d.ts | 31 +++++++++++++++++++++++++++++++ touch/touch-tests.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ touch/tsconfig.json | 19 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 touch/index.d.ts create mode 100644 touch/touch-tests.ts create mode 100644 touch/tsconfig.json diff --git a/touch/index.d.ts b/touch/index.d.ts new file mode 100644 index 0000000000..5b848a91cd --- /dev/null +++ b/touch/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for touch +// Project: https://github.com/isaacs/node-touch +// Definitions by: Mizunashi Mana +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function touch(filename: string, cb: (err: any) => any): void; +declare function touch(filename: string, opts: touch.Options, cb: (err: any) => any): void; + +declare namespace touch { + export interface Options { + force?: boolean; + time?: Date | string | number; + atime?: boolean | Date; + mtime?: boolean | Date; + ref?: string; + nocreate?: boolean; + } + + export function sync(filename: string, opts?: touch.Options): void; + + export function ftouch(fd: number, cb: (err: any) => any): void; + export function ftouch(fd: number, opts: touch.Options, cb: (err: any) => any): void; + + export namespace ftouch { + export function sync(fd: number, opts?: touch.Options): void; + } + + export const ftouchSync: typeof ftouch.sync; +} + +export = touch; diff --git a/touch/touch-tests.ts b/touch/touch-tests.ts new file mode 100644 index 0000000000..485ead2eaa --- /dev/null +++ b/touch/touch-tests.ts @@ -0,0 +1,44 @@ +import * as touch from 'touch'; + +// type value definitions +const boolVal = true; +const numVal = 0; +const strVal = "string"; +const dateVal = new Date(); + +// Options tests +let opts: touch.Options = {}; + +opts.force = boolVal; + +opts.time = numVal; +opts.time = strVal; +opts.time = dateVal; + +opts.atime = boolVal; +opts.atime = dateVal; + +opts.mtime = boolVal; +opts.mtime = dateVal; + +opts.ref = strVal; + +opts.nocreate = boolVal; + +// touch API tests +touch(strVal, (e) => console.log(e)); +touch(strVal, opts, (e) => console.log(e)); + +touch.sync(strVal); +touch.sync(strVal, opts); + +// ftouch API tests +touch.ftouch(numVal, (e) => console.log(e)); +touch.ftouch(numVal, opts, (e) => console.log(e)); + +touch.ftouch.sync(numVal); +touch.ftouch.sync(numVal, opts); + +touch.ftouchSync(numVal); +touch.ftouchSync(numVal, opts); + diff --git a/touch/tsconfig.json b/touch/tsconfig.json new file mode 100644 index 0000000000..f3a8219e00 --- /dev/null +++ b/touch/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "touch-tests.ts" + ] +}