lib/index.js
function FileWatcher(path, options, callback) {

    if (typeof options === "function") {
        callback = options;
    }

    if (typeof options === "boolean") {
        options = { once: options };
    }

    options = Ul.merge(options, {
        once: false
    });

    var watcher = null
      , newWatcher = false
      , check = function (cb) {
            var inter = setInterval(function() {
                    IsThere(path, function (exists) {
                        if (!--tries || exists) {
                            clearInterval(inter);
                        }

                        if (exists) {
                            cb();
                        }
                    });
                }, 500)
              , tries = 5
              ;
        }
      , handler = function (ev) {

            if (options.once) {
                watcher.off();
            }

            if (newWatcher) { return; }

            // Check the rename
            if (ev === "rename" && !options.once) {
                newWatcher = true;
                check(function () {
                    watcher.off();
                    watcher._ = FileWatcher(path, options, callback)._;
                });
            }

            callback.call(watcher, null, ev, watcher.a_path);
        }
      ;

    try {
        watcher = new Watcher(path, handler);
    } catch (e) {
        callback(e);
    }

    return watcher;
}
function FileWatcher(path, options, callback) {

    if (typeof options === "function") {
        callback = options;
    }

    if (typeof options === "boolean") {
        options = { once: options };
    }

    options = Ul.merge(options, {
        once: false
    });

    var watcher = null
      , newWatcher = false
      , check = function (cb) {
            var inter = setInterval(function() {
                    IsThere(path, function (exists) {
                        if (!--tries || exists) {
                            clearInterval(inter);
                        }

                        if (exists) {
                            cb();
                        }
                    });
                }, 500)
              , tries = 5
              ;
        }
      , handler = function (ev) {

            if (options.once) {
                watcher.off();
            }

            if (newWatcher) { return; }

            // Check the rename
            if (ev === "rename" && !options.once) {
                newWatcher = true;
                check(function () {
                    watcher.off();
                    watcher._ = FileWatcher(path, options, callback)._;
                });
            }

            callback.call(watcher, null, ev, watcher.a_path);
        }
      ;

    try {
        watcher = new Watcher(path, handler);
    } catch (e) {
        callback(e);
    }

    return watcher;
}
function FileWatcher ( path , options , callback ) { if ( typeof options === "function" ) { callback = options ; } if ( typeof options === "boolean" ) { options = { once : options } ; } options = Ul . merge ( options , { once : false } ) ; var watcher = null , newWatcher = false , check = function ( cb ) { var inter = setInterval ( function ( ) { IsThere ( path , function ( exists ) { if ( ! -- tries || exists ) { clearInterval ( inter ) ; } if ( exists ) { cb ( ) ; } } ) ; } , 500 ) , tries = 5 ; } , handler = function ( ev ) { if ( options . once ) { watcher . off ( ) ; } if ( newWatcher ) { return ; } // Check the rename if ( ev === "rename" && ! options . once ) { newWatcher = true ; check ( function ( ) { watcher . off ( ) ; watcher . _ = FileWatcher ( path , options , callback ) . _ ; } ) ; } callback . call ( watcher , null , ev , watcher . a_path ) ; } ; try { watcher = new Watcher ( path , handler ) ; } catch ( e ) { callback ( e ) ; } return watcher ; }
FileWatcher
Creates a new file watcher.

@name FileWatcher
@function
@param {String} path The path to the file.
@param {Boolean|Options} options A boolean value representing the `once`
value or an object containing the following fields:

- `once` (Boolean): If `true`, the handler is deleted after first event.

@param {Function} callback This function will be called when the file is
changed or renamed. The first parameter is the error, the second one is
the evenit name and the third one is the file path.
@return {Watcher} The watcher instance.
FileWatcher Creates a new file watcher .