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

@rngnrs/figurecon

v1.2.0

Published

Simple real-time updating configuration module

Downloads

8

Readme

figurecon

Simple configuration module with real-time updates

install size open issues GitHub license

Description

This module is designed as a simple ES6-based advanced config module.

WARNING: Be sure not to use this package in production.

It is unreliable because not tested properly.

Any method can be changed/removed in any time, so use it carefully!

Features

  • Updates values on-the-fly (though it can be disabled)
  • May use defaults if there is no such value in main config
  • Supports update subscriptions (hooks)

Installation

npm i @rngnrs/figurecon

yarn add @rngnrs/figurecon

Usage

Import the module

[modern style] With config object, ES6 modules

import Figurecon from '@rngnrs/figurecon';

const configObject = {
  'key': 'value'
}

const defaults = {
  'your.config.here': true
};

const config = new Figurecon(configObject, defaults);
// ...

[modern style] With config file, ES6 modules

import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path';
import Figurecon from '@rngnrs/figurecon';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const defaults = {
  'your.config.here': true
};

const config = new Figurecon(resolve(__dirname, "./config.json"), defaults);
// ...

With config file

const path = require('path');
const Figurecon = require('@rngnrs/figurecon');
const defaults = {
  'your.config.here': true
};

const config = new Figurecon(path.resolve(__dirname, "./config.json"), defaults);
// ...

With config object

const Figurecon = require('@rngnrs/figurecon');

const configObject = {
  'key': 'value'
}

const defaults = {
  'your.config.here': true
};

const config = new Figurecon(configObject, defaults);
// ...

Get a value

Breaking: Versions below 1.0.0 could get a value via config(key, defaults). Due to ES6 class rewrite, Figurecon does not support this behaviour: use config.get(key, defaults) instead.

//...
let value1 = config.get('your.config.here'); // => true
let value2 = config.get('non.existent.key', 'default'); // => 'default'
let value3 = config.get('non.existent.key'); // => undefined

Set a value

// ...
let isSet1 = config.set('non.existent.key'); // => true, because `undefined` is value too
let isSet2 = config.set('non.existent.key', 111); // => true
let isSet3 = config.set('non.existent.key', 111); // => false, because already has this value
let isSet4 = config.set('non.existent.key', 222); // => true, because another value

Subcriptions (hooks)

// ...
let func = () => { /* ... */ };

// Subscribe to `key` updates
let hook = config.on('key', func);

// Usually it is an update from config file...
// but now we create it directly
config.set('key', true);

// Unsubscribe
// Also you could use `hook` because it returns `func`
config.off('key', func);

Use watcher for real-time updates

Figurecon uses real-time updates via tiny package called node-watch by default. If you want change a library, just use a wrapper that implements such interface:

// ...
let WatchLib = require('node-watch'); // or any other
let watcher = function (fileName, callback = async (eventType = "update", fileName) => {}) {
  return WatchLib(fileName, callback);
};
config.watch(watcher);
// when you do not need it, use .unwatch for correct process exiting:
config.unwatch();

If watcher already has this interface, just use this:

let WatchLib = require('node-watch');
const config = new Figurecon(configObject, defaults, {
  watch: true, // now by default!
  watcher: WatchLib
});

Otherwise, use config.reload() to do this job manually.

Disable watcher (completely)

If you want to disable updates, put { watch: false } in options:

const config = new Figurecon(configObject, defaults, {
  watch: false
});