A Proxy based alternative to json-watch module.

Overview

@webreflection/json-watch

build status Coverage Status

Social Media Photo by Andrik Langfield on Unsplash

A modern take at this 7yo json-watch module.

import watcher from '@webreflection/json-watch';

// returns a Proxy for an arrow function
const json = watcher('/path/to/file.json');
// {"any":"data"} as file content example

// the object reads the file only when accessed
// and only if there were no changes in between reads
json.any === 'data'; // true

// setting arbitrary data is OK too
json.other = 'stuff';

// but no write happens out of the box, however
// it is always possible to save the file again
import {writeFile} from 'node:fs';
writeFile('/path/to/file.json', JSON.stringify(json), _ => {
  // once written, all other watchers will have the latest
  // written version of the JSON object content
  console.log(json.other); // "stuff"
});

The default export watcher(path[, options]) accepts an optional object to configure the watch(path, options) node operation.

By default, the options object contains {persistent: false}. All options for watch are available.

What are the differences compared to the old module?

  • multiple paths can be observerd, not just one per time
  • the first read is lazy
  • Proxy is (imho) a better DX for this kind of utility / use case
  • the amount of consumed memory is fine-tuned to the minumum
  • the JSON can contain single line comments which, even if not allowed by specs, is practical for settings.json like config files and entries description (meaning, the .json file can also be a parsable .js file that preserve other .json rules)
  • it has 100% code coverage
  • it's a dual ESM / CJS module
You might also like...

A useful list of must-watch talks about JavaScript

Must-Watch JavaScript This is a collection of well-received talks about JavaScript, covering topics such as ES6/ES2015, JavaScript frameworks, client-

Jan 4, 2023

This project is made with the help of https://www.youtube.com/watch?v=LMagNcngvcU&t=897s

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Apr 24, 2022

This is a Netflix clone where you can watch movies or series

This is a Netflix clone where you can watch movies or series

Netlfix Clone This is a Netflix clone where you can watch movies or series. Visit Now ๐Ÿš€ Things I Implemented SignIn/SignUp Movie/Series Filter Watch

Dec 1, 2022

Do you wanna watch "Bad Apple!!" on your vim/neovim?

bad-apple.vim Let's watch Bad Apple!! on your vim/neovim! BadAppleVimShort.mov https://youtu.be/XezoLvr1dX0 Required denops.vim https://github.com/vim

Dec 28, 2022

Web app to search,get, watch animes (built with Nextjs, Tailwind)

Animeinfo An anime discovery, made with NextJs and TailwindCSS. Please deploy your own version of the site, by following the instructions. Please foll

May 24, 2022

Application for organizing, rating, and sharing TV series and movies that you are watching or would like to watch.

Application for organizing, rating, and sharing TV series and movies that you are watching or would like to watch.

Watch This! We're living in an age of virtually unlimited ntertainment options, and keeping up with it all can be a little overwhelming. Using the Wat

Jun 13, 2022

The idea is build an app that make me consult uber ride prices through my mi band or a smart watch.

The idea is build an app that make me consult uber ride prices through my mi band or a smart watch.

CanIGetHome? - Get uber prices The main idea is the possibility to me to get the estimate uber rides prices through my mi band 6. Get my current local

Nov 23, 2022

๐Ÿš€๐Ÿ‘ฉโ€๐Ÿš€This repo contains all the files to follow along and implement a MultiChain NFT MarketPlace! Be sure to watch my Youtube tutorials so you can learn and follow along!

๐Ÿš€๐Ÿ‘ฉโ€๐Ÿš€This repo contains all the files to follow along and implement a MultiChain NFT MarketPlace! Be sure to watch my Youtube tutorials so you can learn and follow along!

Multi-Chain NFT Marketplace ๐Ÿš€ ๐Ÿ‘ฉโ€๐Ÿš€ This repo contains all the files to follow along and implement a MultiChain NFT MarketPlace! Be sure to watch my

Jan 5, 2023

Run a command, watch the filesystem, stop the process on file change and then run the command again...

hubmon Run a command, watch the filesystem, stop the process on file change and then run the command again... Install You can install this command lin

Jul 30, 2022
Owner
Andrea Giammarchi
Web, Mobile, IoT and all Web & JS things since 00's
Andrea Giammarchi
Proxy but misspelled -- closed proxy for the internet

pyrox Proxy that runs on Cloudflare Workers. Setup Install wrangler2. npm install wrangler. Generate a public Ed25519 key, exported under SPKI mode wi

bots.gg 10 Sep 9, 2022
JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes

JSON Hash This package contains the following JSON utilties for Deno: digest.ts provides cryptographic hash digests of JSON trees. It guarantee that d

Hong Minhee (ๆดช ๆฐ‘ๆ†™) 13 Sep 2, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de crรฉer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
Userland module that implements the module path mapping that Node.js does with "exports" in package.json

exports-map Userland module that implements the module path mapping that Node.js does with "exports" in package.json npm install exports-map Usage co

Mathias Buus 9 May 31, 2022
An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

Snyk Labs 57 Dec 28, 2022
A serverless proxy for filtering JSON using node-jq

jqp jqp is a free serverless proxy that lets you request data from remote sources, filter it using node-jq, and receive the filtered response. How to

Abe Rubenstein 7 Dec 28, 2022
A faster alternative to legacy node:querystring module

fast-querystring Fast query-string parser and stringifier to replace the legacy node:querystring module. Installation npm i fast-querystring Features

Yagiz Nizipli 95 Dec 17, 2022
App that allows you to control and watch YouTube videos using hand gestures. Additionally, app that allows you to search for videos, playlists, and channels.

YouTube Alternative Interaction App An app I made with Edward Wu that allows you to search and watch videos from YouTube. Leverages Google's YouTube D

Aaron Lam 2 Dec 28, 2021
Bookmate - Watch changes in Chrome bookmarks, and use bookmarks as an append-only key-value store via an fs-like API.

?? Bookmate An append-only key-value store built on Chrome bookmarks, plus an asychronous stream of Bookmark changes. For NodeJS Actual production exa

Cris 6 Nov 8, 2022