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

dacho

v2.0.1

Published

Utility of generating key/value object with a prefixed value

Downloads

4

Readme

dacho

NPM version NPM downloads Build Status Coverage Status Dependency Status DevDependency Status License

Utility of generating key/value object with a prefixed value.

For example, it is convenient to define ActionTypes for Flux, Redux and the like. Besides, it prevent from defining same value. It throws Error if you registered already defined value.

dacho is named after Dacho Club that is Japanese comedy group. They perform patterned reaction by the simple rules every time, but it is unique...

Installation

npm install --save dacho

Usage

Basic

It generate key/value object with a prefixed value.

// constants/nettoActionTypes.js
import {reaction} from 'dacho';

export default reaction([
  'IN',
  'OUT',
  'PUSH'
], 'NETTO/')

// OR using Object.
//
// export default reaction({
//   IN: null,
//   OUT: null,
//   PUSH: null
// }, 'NETTO/');
// constants/odenActionTypes.js
import {reaction} from 'dacho';

export default reaction([
  'IN',
  'OUT',
  'PUSH',
  'SHOWER',
], 'ODEN/')

// OR using Object.
//
// export default reaction({
//   IN: null,
//   OUT: null,
//   PUSH: null
//   SHOWER: null
// }, 'ODEN/');
// actionCreator.js
import nettoActionTypes from './constants/nettoActionTypes';
import odenActionTypes from './constants/odenActionTypes';


function rejectBathing() {
  return {
    type: nettoActionTypes.PUSH,  // 'NETTO/PUSH'
    payload: {member: 'UESHIMA'}
  };
}

function rejectEating() {
  return {
    type: odenActionTypes.PUSH,  // 'ODEN/PUSH'
    payload: {member: 'UESHIMA'}
  };
}

// assert.deepEqual(nettoActionTypes, {
//   IN: 'NETTO/IN',
//   OUT: 'NETTO/OUT',
//   PUSH: 'NETTO/PUSH'
// });

// assert.deepEqual(odenActionTypes, {
//   IN: 'ODEN/IN',
//   OUT: 'ODEN/OUT',
//   PUSH: 'ODEN/PUSH'
//   SHOWER: 'ODEN/SHOWER'
// });

It throws Error when you create same value object.

// ./constants/nettoActionTypes2.js
import {reaction} from 'dacho';

export default reaction([
  'IN'
], 'NETTO/');

// -> throw Error because 'NETTO/IN' is already defined.

With Global Prefix

It generate object with global prefix.

// ./singletons/reaction.js
import {createReaction} from 'dacho';

export default createReaction('DEGAWA/')
// ./constants/degawaNettoActionTypes.js
import reaction from './singletons/reaction';

export default reaction([
  'IN',
  'OUT',
  'PUSH'
], 'NETTO/');

// import degawaNettoActionTypes from './constants/degawaNettoActionTypes';
//
// assert.deepEqual(degawaNettoActionTypes, {
//   IN: 'DEGAWA/NETTO/IN',
//   OUT: 'DEGAWA/NETTO/OUT',
//   PUSH: 'DEGAWA/NETTO/PUSH'
// });

Tips

Testing

Despite collect values, It may raise Errors (key is already registered) when executing unit tests. One of solution of this problem is to use clear-require.

Example is here.

Flow

dacho can use together with Flow annotation. But, Flow version is 0.19 or higher.