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

tp-config

v1.0.5

Published

Used to get the application configuration

Downloads

24

Readme

tp-config

Build Status Coverage Status npm version monthly downloads code style: prettier semantic-release UNPKG liense

Intro

The Config lets you configure your entire app.

Example

import Config from 'tp-config';

const config = new Config({
  testKey: testValue,
});

config.get('testKey') === 'testValue'; // true

Install

NPM Badge

API

config.get(key, fallbackValue)

Returns a single config value, given a key.

  • @param {string} [key] - the key for the config value
  • @param {any} [fallbackValue] - a fallback value to use when the config value was not found, or is config value is null. Fallback value defaults to null.
  • @return {any}
let config = new Config({
  testNum: 2,
  testFn: function (this: Config) {
    return `testFnReturnValue+${this.get("testNum")}`;
  }
});
expect(config.get("testNum")).toEqual(2);
expect(config.get("testFn")).toEqual("testFnReturnValue+2");

config.getBoolean(key, fallbackValue)

Same as get(), however always returns a boolean value. If the value from get() is null, then it'll return the fallbackValue which defaults to false. Otherwise, getBoolean() will return if the config value is truthy or not. It also returns true if the config value was the string value "true".

  • @param {string} [key] - the key for the config value
  • @param {boolean} [fallbackValue] - a fallback value to use when the config value was null. Fallback value defaults to false.
let config = new Config({
  key1: true,
  key2: false
});
expect(config.getBoolean("key1")).toEqual(true);
expect(config.getBoolean("key2")).toEqual(false);

config.getNumber(key, fallbackValue)

Same as get(), however always returns a number value. Uses parseFloat() on the value received from get(). If the result from the parse is NaN, then it will return the value passed to fallbackValue. If no fallback value was provided then it'll default to returning NaN when the result is not a valid number.

  • @param {string} [key] - the key for the config value
  • @param {number} [fallbackValue] - a fallback value to use when the config value turned out to be NaN. Fallback value defaults to NaN.
let config = new Config({
  key: 6
});
expect(config.getNumber("key")).toEqual(6);

config.set(key, value)

Sets a single config value.

  • @param {string} [key] - The key used to look up the value at a later point in time.
  • @param {string} [value] - The config value being stored.
let config = new Config(null);
config.set("name", "Doc Brown");
config.set("occupation", "Weather Man");

expect(config.get("name")).toEqual("Doc Brown");
expect(config.get("occupation")).toEqual("Weather Man");

config.settings()

Get all configs.

  • @return {object} - Return all configs.
let config = new Config({
  name: "Doc Brown",
  occupation: "Weather Man"
});

expect(config.settings()).toEqual({
  name: "Doc Brown",
  occupation: "Weather Man"
});

config.settings(configs)

Set(reset) all configs.

  • @param {object} [configs] - The configs object will be reset
  • @return {object} this - Return this value
let config = new Config();
config.settings({
  name: "Doc Brown",
  occupation: "Weather Man"
});

expect(config.get("name")).toEqual("Doc Brown");
expect(config.get("occupation")).toEqual("Weather Man");

Development

  • npm t: Run test suite
  • npm start: Run npm run build in watch mode
  • npm run test:watch: Run test suite in interactive watch mode
  • npm run test:prod: Run linting and generate coverage
  • npm run build: Generate bundles and typings, create docs
  • npm run lint: Lints code
  • npm run commit: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)

License

MIT