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

@bitchcraft/keyconst

v1.0.1

Published

Creates a keymirrored Object from an Array of string keys

Downloads

8

Readme

@bitchcraft/keyconst

Create an object where values are identical to its key names. Inspired by keymirror and Facebook’s react/lib/keyMirror, keyconst reduces the amount of code to create new key constants in objects.

Instead of

const Actions = keymirror({ BUY_ICECREAM: null })

you can now simplify this to

const Actions = keyconst([ 'BUY_ICECREAM' ])

Installation

$ yarn add @bitchcraft/keyconst
$ npm install -P @bitchcraft/keyconst

Usage

ES6 example

import keyconst from '@bitchcraft/keyconst';

const Events = keyconst([
    'AUTH_SUCCESS',
    'AUTH_FAILURE',
    'AUTH_LOADING',
]);

function reducer(state = Map(), event) {
    const { payload, type } = event;

    switch (type){
        case Events.AUTH_LOADING:
            return state.set('loading', true);

        case Events.AUTH_SUCCESS:
            return state.set('loading', false)
                .set('user', payload.user);

        case Events.AUTH_FAILURE:
            return state.set('loading', false)
                .set('error', payload.error)
                .delete('user');
    }
    return state;
}

ES5 example

var keyconst = require('@bitchcraft/keyconst');

var Events = keyconst([
    'AUTH_SUCCESS',
    'AUTH_FAILURE',
    'AUTH_LOADING',
]);

function reducer(state, event) {
    if (typeof state !== 'object') state = {};
    var payload = event.payload;
    var type = event.type;

    switch (type){
        case Events.AUTH_LOADING:
            state.loading = true;
            break;

        case Events.AUTH_SUCCESS:
            state.loading = false;
            state.user = payload.user;
            break;

        case Events.AUTH_FAILURE:
            state.loading = false;
            state.error = payload.error;
            delete state.loading;
            break;
    }
    return state;
}

ES2015+ import with flow types

// babel: env, stage-0, flow
import keyconst from '@bitchcraft/keyconst/src/keyconst';

Bundle size

Gzipped size is around 1KB. You can check out the bundle analytics for the non-minified bundle.

Help and feedback

Please file issues in Github

Contribute

We are open for PRs. Please respect to the linting rules.

License

Keyconst is free software und the BSD-3-Clause (see LICENSE.md).

Contributors