npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@push.rocks/smartchok

v1.0.34

Published

A smart wrapper for chokidar to facilitate file watching with enhanced features.

Downloads

248

Readme

@push.rocks/smartchok

smart wrapper for chokidar

Install

Install the package by running the following command in your terminal:

npm install @push.rocks/smartchok --save

This command adds @push.rocks/smartchok to your project's dependencies, ensuring that your project can use its functionality and that it will be installed when running npm install in your project root.

Usage

The @push.rocks/smartchok package provides a convenient and smart wrapper around the popular chokidar library for file watching with enhanced features such as observable support for filesystem events. This guide will introduce you to the usage of @push.rocks/smartchok, leveraging TypeScript for type safety and better developer experience.

Setting Up Your Project

To use @push.rocks/smartchok, ensure your project is set up to use TypeScript and ECMAScript modules (ESM). You need to have a tsconfig.json file at the root of your project with the following minimum settings:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "declaration": true,
    "outDir": "./dist",
    "strict": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "dist"]
}

This configuration enables TypeScript compilation targeting the latest ECMAScript standards and includes all TypeScript files (*.ts) in your src directory.

Basic Setup

To start using smartchok, first import it into your TypeScript file:

import { Smartchok } from '@push.rocks/smartchok';

Initializing Smartchok

Create an instance of Smartchok by specifying an array of glob patterns to watch:

const smartchokInstance = new Smartchok([
  './src/**/*.ts',          // Watch all TypeScript files in the src directory
  './public/assets/**/*'    // Watch all files in the public/assets directory
]);

Adding and Removing Files Dynamically

You can dynamically add and remove paths from being watched by using the add and remove methods:

// Add additional files or patterns
smartchokInstance.add(['./tests/**/*.spec.ts']);

// Remove specific patterns from watch
smartchokInstance.remove('./src/**/*.test.ts');

Handling Filesystem Events

smartchok leverages RxJS observables to notify about filesystem events. This allows you to respond to various events such as file additions, changes, and deletions with ease.

First, start the watcher:

await smartchokInstance.start();

Then, subscribe to an event:

const changeObservable = await smartchokInstance.getObservableFor('change');

changeObservable.subscribe({
  next: ([path, stats]) => {
    console.log(`File changed: ${path}`);
  },
  error: (err) => {
    console.error(`An error occurred: ${err}`);
  }
});

Supported events include 'add', 'change', 'unlink' (for deletions), and others. Refer to the chokidar documentation for a full list of events.

Stopping the Watcher

To stop watching for file changes, simply call:

await smartchokInstance.stop();

Advanced Usage

Beyond the basics, smartchok allows for more complex monitoring scenarios, such as debounced notifications for rapid changes, filtering events, and integrating with other observables for complex asynchronous workflows.

Conclusion

@push.rocks/smartchok provides a robust, observable-based wrapper around chokidar, making it an excellent choice for projects requiring efficient and flexible file monitoring. Its integration with RxJS opens up a wide array of possibilities for handling file system events in a reactive manner, making your code more concise, readable, and maintainable.

By following the guidelines provided in this document, you should now be equipped to integrate @push.rocks/smartchok into your TypeScript project, enhancing its capabilities with efficient file system monitoring.

License and Legal Information

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at [email protected].

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.