Socket
Socket
Sign inDemoInstall

sane

Package Overview
Dependencies
6
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sane

Sane aims to be fast, small, and reliable file system watcher. No bells and whistles, just change events.


Version published
Weekly downloads
5M
decreased by-1.6%
Maintainers
1
Install size
129 kB
Created
Weekly downloads
 

Package description

What is sane?

The 'sane' npm package is a file watcher that provides a simple and efficient way to monitor file changes in a directory. It is particularly useful for development workflows where you need to automatically trigger actions when files are modified, added, or deleted.

What are sane's main functionalities?

Basic File Watching

This feature allows you to watch a directory for changes to specific file types. The code sample demonstrates how to set up a watcher for JavaScript and CSS files, and how to handle events for file changes, additions, and deletions.

const sane = require('sane');
const watcher = sane('./path/to/dir', {glob: ['**/*.js', '**/*.css']});

watcher.on('ready', () => { console.log('Ready to watch files'); });
watcher.on('change', (filepath, root, stat) => { console.log('File changed:', filepath); });
watcher.on('add', (filepath, root, stat) => { console.log('File added:', filepath); });
watcher.on('delete', (filepath, root) => { console.log('File deleted:', filepath); });

Custom Watcher Options

This feature allows you to customize the behavior of the file watcher. The code sample shows how to enable polling with a specific interval, which can be useful in environments where native file watching is not reliable.

const sane = require('sane');
const watcher = sane('./path/to/dir', {
  glob: ['**/*.js'],
  poll: true,
  interval: 1000
});

watcher.on('ready', () => { console.log('Ready to watch files with custom options'); });
watcher.on('change', (filepath, root, stat) => { console.log('File changed:', filepath); });

Ignoring Files and Directories

This feature allows you to ignore specific files or directories from being watched. The code sample demonstrates how to ignore the 'node_modules' directory and any JavaScript test files.

const sane = require('sane');
const watcher = sane('./path/to/dir', {
  ignored: ['node_modules', '**/*.test.js']
});

watcher.on('ready', () => { console.log('Ready to watch files, ignoring specified patterns'); });
watcher.on('change', (filepath, root, stat) => { console.log('File changed:', filepath); });

Other packages similar to sane

Readme

Source

sane

I've been driven to insanity by node filesystem watcher wrappers. Sane aims to be fast, small, and reliable file system watcher. No bells and whistles, just change events.

API

sane(dir, globs)

Shortcut for new sane.Watcher(files, {globs: globs})

var watcher = sane('path/to/dir', ['**/*.js, '**/*.css']);
watcher.on('ready', function () { console.log('ready') });
watcher.on('change', function (filepath) { console.log('file changed', filepath); });
// close
watcer.close();

sane.Watcher(dir, options)

options:

  • persistent: boolean indicating that the process shouldn't die while we're watching files.
  • glob: a single string glob pattern or an array of them.

For the glob pattern documentation, see minimatch.

sane.Watcher#close

Stops watching.

License

MIT

Keywords

FAQs

Last updated on 25 Feb 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc