Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.5.2 to 0.5.3

6

lib/is.js

@@ -11,2 +11,8 @@ var fs = require('fs');

},
regExp: function(item) {
return Object.prototype.toString.call(item) == '[object RegExp]';
},
string: function(item) {
return typeof item === 'string';
},
func: function(item) {

@@ -13,0 +19,0 @@ return typeof item === 'function';

12

lib/watch.js

@@ -49,3 +49,7 @@ var fs = require('fs');

if (fn(arg)) action();
} else {
}
else if (is.regExp(fn)) {
if (fn.test(arg)) action();
}
else {
action();

@@ -121,3 +125,3 @@ }

const deprecateWarning = util.deprecate(
var deprecationWarning = util.deprecate(
function() {},

@@ -252,3 +256,3 @@ '(node-watch) First param in callback function\

if (is.func(fn)) {
if (fn.length == 1) deprecateWarning();
if (fn.length == 1) deprecationWarning();
this.on('change', fn);

@@ -275,3 +279,3 @@ }

if (is.func(fn)) {
if (fn.length == 1) deprecateWarning();
if (fn.length == 1) deprecationWarning();
self.on('change', fn);

@@ -278,0 +282,0 @@ }

{
"description": "A neat fs.watch wrapper",
"description": "A wrapper and enhancements for fs.watch",
"license": "MIT",

@@ -14,3 +14,3 @@ "name": "node-watch",

],
"version": "0.5.2",
"version": "0.5.3",
"bugs": {

@@ -21,3 +21,3 @@ "url": "https://github.com/yuanchuan/node-watch/issues"

"author": "yuanchuan <yuanchuan23@gmail.com> (http://yuanchuan.name)",
"main": "./lib/watch.js",
"main": "./index.js",
"homepage": "https://github.com/yuanchuan/node-watch#readme",

@@ -24,0 +24,0 @@ "scripts": {

# node-watch [![Status](https://travis-ci.org/yuanchuan/node-watch.svg?branch=master)](https://travis-ci.org/yuanchuan/node-watch "See test builds")
A neat [fs.watch](http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener) wrapper.
A wrapper and enhancements for [fs.watch](http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener) (with 0 dependencies).

@@ -8,3 +8,3 @@ [![NPM](https://nodei.co/npm/node-watch.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/node-watch.png/)

### Installation
## Installation

@@ -15,3 +15,3 @@ ```bash

### Example
## Example

@@ -21,4 +21,4 @@ ```js

watch('somedir_or_somefile', { recursive: true }, function(evt, name) {
console.log(name, ' changed.');
watch('file_or_dir', { recursive: true }, function(evt, name) {
console.log('%s changed.', name);
});

@@ -28,3 +28,3 @@ ```

This is a completely rewritten version, **much faster** and in a more **memory-efficient** way.
So with recent nodejs versions under OS X or Windows you can do something like this:
So with recent nodejs under OS X or Windows you can do something like this:

@@ -37,3 +37,3 @@ ```js

### Why?
## Why?

@@ -46,10 +46,11 @@ * Some editors will generate temporary files which will cause the callback function to be triggered multiple times.

### Changelog
## Changelog
* The `filter` option can be of either Function or RegExp type since **v0.5.3**.
* The `recursive` option is default to be `false` since **v0.5.0**.
* The callback function will always provide a event name since **v0.5.0**.
* The callback function will always provide an event name since **v0.5.0**.
* Returns a [fs.FSWatcher](https://nodejs.org/api/fs.html#fs_class_fs_fswatcher) like object since **v0.4.0**.
### Events
## Events

@@ -72,3 +73,3 @@ The events provided by the callback function would be either `update` or `remove`.

### Watcher object
## Watcher object

@@ -92,18 +93,20 @@ `watch` function returns a [fs.FSWatcher](https://nodejs.org/api/fs.html#fs_class_fs_fswatcher) like object as the same as `fs.watch` (>= v0.4.0).

### Extra options
* `filter` Filter files or directories or skip to watch them.
## Extra options
* `filter <RegExp>` as a regular expression for filtering with ease
* `filter <Function>` as a function to filter files
```js
var options = {
// watch only for json files
watch('./', { filter: /\.json$/ }, console.log);
// ignore node_modules
watch('./', {
recursive: true,
filter : function(name) {
filter: function(name) {
return !/node_modules/.test(name);
}
};
// ignore node_modules
watch('./', options, console.log);
}, console.log);
```
### Known bugs
## Known issues

@@ -115,5 +118,5 @@ **Windows, node < v4.2.5**

### Misc
## Misc
##### 1. Watch multiple files or directories in one place
#### 1. Watch multiple files or directories in one place
```js

@@ -123,3 +126,3 @@ watch(['file1', 'file2'], console.log);

##### 2. Other ways to filter
#### 2. Other ways to filter

@@ -152,7 +155,24 @@ *a)* filtering directly inside the callback function:

#### 3. customize watch command line tool
```js
#!/usr/bin/env node
### License
Licensed under MIT
// https://github.com/nodejs/node-v0.x-archive/issues/3211
require('epipebomb')();
var watcher = require('node-watch')(
process.argv[2] || './', { recursive: true }, console.log
);
process.on('SIGINT', watcher.close);
```
Monitoring chrome from disk:
```bash
$ watch / | grep -i chrome
```
## License
MIT
Copyright (c) 2012-2017 [yuanchuan](https://github.com/yuanchuan)

@@ -21,4 +21,4 @@ var assert = require('assert');

describe('watch for files', function() {
it('should watch a single file and keep watching', function(done) {
this.timeout(3000);
var times = 1;

@@ -33,5 +33,5 @@ var file = 'home/a/file1';

});
tree.modify(file);
tree.modify(file, 400);
tree.modify(file, 800);
tree.modify(file, 100);
tree.modify(file, 500);
tree.modify(file, 900);
});

@@ -166,3 +166,3 @@

tree.modify('home/b/file1', 200);
tree.modify('home/node_modules/ma/file1', 200);
tree.modify('home/node_modules/ma/file1', 500);

@@ -173,3 +173,3 @@ setTimeout(function() {

done();
}, 600);
}, 900);
});

@@ -197,6 +197,28 @@

tree.modify(file1);
tree.modify(file2, 200);
tree.modify(file1, 200);
tree.modify(file2, 400);
});
it('should be able to filter with regexp', function(done) {
var dir = tree.getPath('home/a');
var file1 = 'home/a/file1';
var file2 = 'home/a/file2';
var options = {
filter: /file2/
}
var times = 0;
watcher = watch(dir, options, function(evt, name) {
times++;
if (name == tree.getPath(file2)) {
assert(times, 1, 'home/a/file1 should be ignored.');
done();
}
});
tree.modify(file1, 200);
tree.modify(file2, 400);
});
});

@@ -203,0 +225,0 @@ });

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