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

@cazoo/toggles

v4.0.0

Published

Standardised API for feature toggling

Downloads

32

Readme

Toggles

CircleCI

Simple wrapper on top of environment variables to standardise feature toggling.

This is a universal package for both the browser and node.

At this point this package is more about estabilishing a convention rather being super useful. In the future this can be extended with pluggable Providers, like cookies or any service that stores key-value pairs.

Installation

npm install @cazoo/toggles --save

Basic usage

features

Given:

process.env = {
    FEATURE_LASER: 'on',
    FEATURE_DEATH_STAR: 'off'
}

Then:

import toggles from '@cazoo/toggles';

const { featureIsEnabled } = toggles.create();

...

if (featureIsEnabled('LASER')) {
    // use laser
} else {
    // don't use laser
}

market-specific features

When a feature toggle value is a stringified object, this object's keys are treated as markets and its values - as toggle values for each market.

It is possible to declare also a default value that will be used for markets where the toggle is not explicitly set.

Given:

process.env = {
    FEATURE_LASER: '{"gb":"off","default":"on"}',
    FEATURE_DEATH_STAR: 'on'
}

Then:

featureIsEnabled('LASER', 'gb')
// false

featureIsEnabled('LASER', 'fr')
// true - because the default value is set to 'on'

featureIsEnabled('LASER')
// true - the default value is used also when queried without a market 

featureIsEnabled('DEATH_STAR', 'gb')
// true - 'on' is equivalent to '{"default":"on"}'

treatments

Given:

process.env = {
    EXPERIMENT_LASER: JSON.stringify( {treatment: "on"} );
    EXPERIMENT_DEATH_STAR: JSON.stringify( {treatment: "off", config: JSON.stringify({luke: "I'm your father"}) );
}

Then:

import toggles from '@cazoo/toggles';

const { getTreatment, getAllExperiments } = toggles.create();

...

if (getTreatment('LASER').treatment === "on") {
    // use laser
} else {
    // don't use laser
}

//declare your config interface
interface config {
    luke : string
}

if(toggle.getTreatment("DEATH_STAR").config as config) {
    // if config is defined
}

const abSetup = getAllExperiments();
// array of experiments e.g.
// [
//     {
//         testName: "LASER",
//         treatment: "on"
//     },
//     {
//         testName: "DEATH_STAR",
//         treatment: "off",
//         config: {luke: "I'm your father"}
//     }
// ]

More usages

Please, refer to the integration.test.ts and integration.browser.test.ts for all the usages. They are intended to be a living documentation for the user.

Release

Releases are created by semantic-release, which checks all the commit messages since the last release to determine what the new version number should be.

Commit messages

To trigger a release, your commits need to follow the Angular Commit Message Conventions, meaning they need to be written in this pattern:

type(context): message

Type

Commits using the types feat, fix or perf will appear in the changelogs. However, any commit with BREAKING CHANGE in the body will also appear in the changelog, regardless of the type.

| Type | Release type | Description | | - | - | - | | feat | Minor (0.X.0) | A new feature | | fix | Patch (0.0.X) | A bug fix | | perf | Patch (0.0.X) | A code change that improves performance | | refactor | - | A code change that neither fixes a bug nor adds a feature | | test | - | Adding missing tests or correcting existing tests | | docs | - | Documentation only changes | | ci | - | Changes to our CI configuration files and scripts (example: CircleCI, BrowserStack, SauceLabs) | | build | - | Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) |

Context

For the context, we add the Jira ticket number. It's optional but good to have since the release logs are generated from the commits.

Examples

| Commit message | Release type | | - | - | | perf(DR-4567): remove graphiteWidth option from PencilBREAKING CHANGE: The graphiteWidth option has been removed.The default graphite width of 10mm is always used for performance reasons. | Major (X.0.0) | | feat(DR-4567): add 'graphiteWidth' option to Pencil | Minor (0.X.0) | | fix(DR-4567): stop graphite breaking when too much pressure applied to Pencil | Patch (0.0.X) |

💡 To add a body to your commit message, you can use git commit -m "TITLE" -m "BODY"