mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
+ chokidar type defs including tests
This commit is contained in:
parent
0acdbea7fd
commit
ae81e340a9
41
chokidar/chokidar-tests.ts
Normal file
41
chokidar/chokidar-tests.ts
Normal file
@ -0,0 +1,41 @@
|
||||
/// <reference path="chokidar.d.ts" />
|
||||
|
||||
import fs = require('fs');
|
||||
import chokidar = require('chokidar');
|
||||
|
||||
var watcher = chokidar.watch('file, dir, or glob', {
|
||||
ignored: /[\/\\]\./, persistent: true
|
||||
});
|
||||
|
||||
var log = console.log.bind(console);
|
||||
|
||||
watcher
|
||||
.on('add', function(path:string) { log('File', path, 'has been added'); })
|
||||
.on('addDir', function(path:string) { log('Directory', path, 'has been added'); })
|
||||
.on('change', function(path:string) { log('File', path, 'has been changed'); })
|
||||
.on('unlink', function(path:string) { log('File', path, 'has been removed'); })
|
||||
.on('unlinkDir', function(path:string) { log('Directory', path, 'has been removed'); })
|
||||
.on('error', function(error:any) { log('Error happened', error); })
|
||||
.on('ready', function() { log('Initial scan complete. Ready for changes.'); })
|
||||
.on('raw', function(event:Event, path:string, details:any) { log('Raw event info:', event, path, details); })
|
||||
|
||||
// 'add', 'addDir' and 'change' events also receive stat() results as second
|
||||
// argument when available: http://nodejs.org/api/fs.html#fs_class_fs_stats
|
||||
watcher.on('change', function(path:string, stats:fs.Stats) {
|
||||
if (stats) console.log('File', path, 'changed size to', stats.size);
|
||||
});
|
||||
|
||||
// Watch new files.
|
||||
watcher.add('new-file');
|
||||
watcher.add(['new-file-2', 'new-file-3', '**/other-file*']);
|
||||
|
||||
// Un-watch some files.
|
||||
watcher.unwatch('new-file*');
|
||||
|
||||
// Only needed if watching is `persistent: true`.
|
||||
watcher.close();
|
||||
|
||||
// One-liner
|
||||
require('chokidar').watch('.', {ignored: /[\/\\]\./}).on('all', function(event:string, path:string) {
|
||||
console.log(event, path);
|
||||
});
|
||||
42
chokidar/chokidar.d.ts
vendored
Normal file
42
chokidar/chokidar.d.ts
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// Type definitions for chokidar 1.0.0
|
||||
// Project: https://github.com/paulmillr/chokidar
|
||||
// Definitions by: Stefan Steinhart <https://github.com/reppners/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module "fs"
|
||||
{
|
||||
interface FSWatcher
|
||||
{
|
||||
add(fileDirOrGlob:string):void;
|
||||
add(filesDirsOrGlobs:Array<string>):void;
|
||||
unwatch(fileDirOrGlob:string):void;
|
||||
unwatch(filesDirsOrGlobs:Array<string>):void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "chokidar"
|
||||
{
|
||||
interface WatchOptions
|
||||
{
|
||||
persistent?:boolean;
|
||||
ignored?:any;
|
||||
ignoreInitial?:boolean;
|
||||
followSymlinks?:boolean;
|
||||
cwd?:string;
|
||||
usePolling?:boolean;
|
||||
useFsEvents?:boolean;
|
||||
alwaysStat?:boolean;
|
||||
depth?:number;
|
||||
interval?:number;
|
||||
binaryInterval?:number;
|
||||
ignorePermissionErrors?:boolean;
|
||||
atomic?:boolean;
|
||||
}
|
||||
|
||||
import fs = require("fs");
|
||||
|
||||
function watch( fileDirOrGlob:string, options?:WatchOptions ):fs.FSWatcher;
|
||||
function watch( filesDirsOrGlobs:Array<string>, options?:WatchOptions ):fs.FSWatcher;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user