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

sane

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sane

Sane aims to be fast, small, and reliable file system watcher.

  • 4.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

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

Keywords

FAQs

Package last updated on 15 Mar 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc