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 🙏

© 2026 – Pkg Stats / Ryan Hefner

kojak

v1.2.1

Published

Helper for managing settings objects in multiple environments

Readme

Kojak

(Named after an Irish Setter in a Stephen King novel, because all the better names are taken)

A simple configuration container class, designed for handling settings objects easily. Design considerations:

  • support environment-based property choices at any depth
  • provide a native interface for getting and setting (no special methods required)
  • support modification after creation
  • support environment-changes after creation

It's a known limitation that convoluted series of setting a mix of keys and objects may result in unintuitive results - things set directly take precedence over objects set afterwards due to internal design. For sanity, either always set things using objects, or only use objects during the constructor phase and thereafter set directly on keys (e.g. settings.foo = 'bar' instead of settings.set({foo: 'bar'} where possible)

API

new Kojak([one, [two, [...])

Creates a new settings object with optional properties provided during creation

.set(value, override = true)

Adds an object to the Kojak collection, making top-level keys from the value available as top-level keys on the Kojak object. override defines if the new data should take preccedence over existing data.

.set(path, value, override = true)

Adds the defined path to the Kojak collection. A path is either a simple key name or a dot-separated path. It uses Lodash _.set internally.

.get(path, default)

Returns the value at the provided path, or the default if it is undefined. It uses Lodash _.get internally.

.setEnv(name)

Changes the chosen environment for path-resolution.

.useEnv(options)

Imports properties from process.env according to provided options.

settings.useEnv({
    prefix: '', // prefix string
    requirePrefix: false, // only add keys which match the prefix
    stripPrefix: false, // remove the prefix from keys that start with it

    castNumbers: false, // should numeric values be cast as Numbers
    
    split: /__/, // regex for splitting keys into nested parameters
    filter: /.*/, // regex for filtering keys which are added
    override: true // whether to override, or only provide defaults,
})

Examples

Basic usage, with a nested environment branch

// NODE_ENV=development
let settings = new Kojak({
  color: {
    production: 'blue',
    development: 'green'
  }
});
console.log(settings.color) // 'green'

A top-level environment branch

// NODE_ENV=production
let settings = new Kojak({
    production: {
        color: 'blue'
    },
    development: {
        color: 'green'
    }
});
console.log(settings.color) // 'blue'

Importing parameters from envvars

// NODE_PORT=9182, NESTED__VALUE=hello
let settings = new Kojak();
settings.useEnv();
console.log(settings.node_port); // '9182'
console.log(settings.nested.value); // 'hello'

Importing some parameters from envvars

// NODE_PORT=9182, NESTED__VALUE=hello
let settings = new Kojak();
settings.useEnv({
    prefix: 'NODE_',
    requirePrefix: true,
    stripPrefix: true,
    castNumbers: true
});
console.log(settings.port); // 9182

Getting a nested value with a default

let settings = new Kojak();
settings.set({flagColor: {top: 'white', bottom: 'red'}})
console.log(settings.flagColor.top) // 'white'
console.log(settings.get('flagColor.left', 'blank')) // 'blank'

Setting default-values after other things

let settings = new Kojak({color: 'white'})

settings.set({color: 'blue', size: 'large'}, false); // false signifies it's a default
console.log(settings.color) // 'white'
console.log(settings.size) // 'large'

Setting default values during construction

let defaults = {color: 'white', size: 'large'};
let settings = new Kojak(defaults, {color: 'blue'}); // right-most values take precedence

console.log(settings.color) // 'blue'
console.log(settings.size) // 'large'