Socket
Socket
Sign inDemoInstall

node-watch

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-watch - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

16

lib/watch.js

@@ -169,8 +169,15 @@ /**

return function() {
var args = [].slice.call(arguments);
var args = [].slice.call(arguments);
if (Object.prototype.toString.call(args[1]) === '[object Function]') {
args[2] = args[1];
}
if (!Array.isArray(args[0])) {
args[0] = [args[0]];
}
//overwrite default options
args[1] = mixin(defaultOptions, args[1]);
return origin.apply(null, args);
//handle multiple files.
args[0].forEach(function(item) {
origin.apply(null, [item].concat(args.slice(1)));
});
}

@@ -199,3 +206,2 @@ };

function watch(fpath, options, cb) {
if (is.sym(fpath)

@@ -206,3 +212,2 @@ && !(options.followSymLinks

}
// Due to the unstalbe fs.watch(), if the `fpath` is a file then

@@ -230,3 +235,2 @@ // switch to watch its parent directory instead of watch it directly.

}
};

@@ -241,4 +245,4 @@

, followSymLinks: false
, maxSymLevel: 3
, maxSymLevel: 1
});
{
"name": "node-watch"
, "version": "0.3.0"
, "version": "0.3.1"
, "description": "fs.watch() wrapper of Nodejs "

@@ -5,0 +5,0 @@ , "url": "https://github.com/yuanchuan/node-watch"

#Node-watch
A [fs.watch](http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener) wrapper to watch files or directories(recursively by default).
This module will watch a directory **recursively** by default while trying to solve several problems when using the native [fs.watch()](http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener):
1. When modifying a file inside a watched directory, the callback function will be triggered multiple times caused by junkie files generated by the editor;
2. when modifying a watched single file, the callback function will only be triggered one time and then it is unwatched.
In current version it does not differentiate event like "rename" or "delete". Once there is a change, the callback function will be triggered.
### Installation

@@ -16,2 +11,4 @@

### Example

@@ -25,6 +22,20 @@

});
```
```
### Options
### Why fs.watch wrapper
* Some editors will generate temporary files which will cause the callback function to trigger multiple times.
* when watching a single file, the callback function will only be triggered one time and then the file is unwatched.
* Missing an option to watch a directory recursively.
### The difference
This module **currently** does not differentiate event like `rename` or `delete`. Once there is a change, the callback function will be triggered.
## Options
`recursive`:Watch it recursively or not (defaults to **true**).

@@ -34,7 +45,5 @@

`maxSymLevel`: The max number of following symbolic links, in order to prevent circular links (defaults to **3**).
`maxSymLevel`: The max number of following symbolic links, in order to prevent circular links (defaults to **1**).
#### Usage
```js

@@ -45,1 +54,31 @@ watch('somedir', { recursive: false, followSymLinks: true }, function(filename) {

```
##FAQ
### 1. How to watch mutiple files or directories.
```js
watch(['file1', 'file2'], function(file) {
//
});
```
### 2. How to filter files
Write your own filter function as a high order function. For example:
```js
var filter = function(pattern, fn) {
return function(filename) {
if (pattern.test(filename)) {
fn(filename):
}
}
}
// only watch for js files
watch('mydir', filter(/\.js$/, function(filename) {
}));
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc