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

confiction

v0.7.0

Published

![build](https://github.com/leomeloxp/confiction/workflows/build/badge.svg?branch=master) [![npm version](http://img.shields.io/npm/v/confiction.svg)](https://www.npmjs.org/package/confiction)

Downloads

3

Readme

Confiction

build npm version

Manage your browser based environment configuration with conviction.

Confiction is inspired by Convict and Conf.

Usage

Firstly:

npm install confiction

Then define your schema somewhere within your project, eg:

// config.ts
import { Confiction, Schema } from '../dist';

const schema = {
  url: {
    doc: 'The api endpoint url.',
    format: 'string',
    default: 'http://localhost:3000',
  },
  token: {
    doc: 'An auth token to be sent alongside API requests.',
    format: 'string',
    default: '<TOKEN>',
  },
};
type Config = {
  [k in keyof typeof schema]: typeof schema[k]['default'];
};

type CID = Config['url'];

export const config = new Confiction(schema as Schema<Config>);

You can optionally override default config (eg, on page load) like so:

// index.ts
import { config } from './config';

fetch('/config.json').then(async (res) => {
  // Some config values that override default ones.
  const newConfig = await res.json();
  config.load(newConfig);
});

And to use your config store you can simply get the values from the exported config object:

// someFile.ts
import { config, Config } from './config';
// Type matching the config entry.
const api = config.get<Config, 'passwordRetries'>('passwordRetries');
// Casting the type of a config value.
const token = config.get<string>('token');

fetch(`${api}/me`, {
  headers: {
    authorization: `Bearer ${token}`,
  },
});

Roadmap

Confiction is in its early days still but I intend to improve it in the near future a number of new features so if you feel like something should be added into the library feel free to open an issue about it. A few things that I already plan on adding include:

The ability to load or set overriding config values to cookies and local storage.

This should allow for potentially interesting use cases such as feature flags, easter eggs or real time client side debugging.

Nested configs and . notation support

This should allow for a better grouping of configs and more complex schemas that would suite a larger number of use cases.

Better validation for schemas

Right now schema validation is done in a very naive way. In the future I intend to support more complex validation formats such as those present in Convict.