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

renum

v1.0.5

Published

Simple enum using frozen object.

Downloads

6

Readme

renum npm package Travis Coveralls

renum is a small library to create frozen objects in javascript from multiple sources.

Getting started

Install renum using npm:

npm install renum --save

Then using ES6

import renum from 'renum';

export default renum(
  'INCREMENT',
  'DECREMENT'
);

Using ES5

const renum = require('renum');

module.exports = renum(
  'INCREMENT',
  'DECREMENT'
);

Usage

From primitive arguments

Strings

renum('1', '2', '3') //=> {1: '1', 2: '2', 3: '3'}

String

renum('1 2 3') //=> {1: '1', 2: '2', 3: '3'}

Template String

renum(`
  1
  2
  3
`) //=> {1: '1', 2: '2', 3: '3'}

Numbers

renum(1, 2, 3) //=> {1: 1, 2: 2, 3: 3}

Boolean

renum(true, false, true) //=> {true: true, false: false}

Empty values

renum(null, undefined) //=> {}

Symbol

renum(Symbol(1), Symbol(f => f + 1)) //=> {Symbol(1): Symbol(1), Symbol(f => f + 1): 'Symbol(f => f + 1)'}

From Objects

Array

renum(['1', 2, true]) //=> {1: '1', 2: 2, true: true}

Pairs

renum([
  ['INCREMENT', n => n + 1],
  ['DECREMENT', n => n - 1],
]) //=> {INCREMENT: [Function], DECREMENT: [Function]}

Map

renum(new Map({INCREMENT: '+', DECREMENT: '-'})) //=> {INCREMENT: '+', DECREMENT: '-'}

Set

renum(new Set([1, 2, 3])) //=> {1: 1, 2: 2, 3: 3}

Inception

renum(1, renum(2, renum(3))) //=> {1: 1, 2: 2, 3: 3}

Extending renum

In order to let you use renum with other libraries, you can implement your own translator.

Example for immutable:

// renum-immutable.js
import R from 'ramda';
import Immutable from 'immutable';

export default [
  [Immutable.List.isList, R.invoker(0, 'toArray')],
  [Immutable.Map.isMap, R.invoker(0, 'toObject')],
  [Immutable.Stack.isStack, R.invoker(0, 'toJS')],
];

And then:

import R from 'ramda';
import renum from 'renum';
import renumImmutable from './renum-immutable';

// from a list of pairs
renum.extend(renumImmutable);

// or from arguments directly
renum.extend(R.isEmpty, R.always({}));

Extend functions are called in priority first pass, then a second pass will be done with the default included predicates/transforms. It mean you actually can return another type rather than a frozen Object, and renum will convert it properly.

Typescript

renum Typescript type declarations are available, you just need to add a reference:

///<reference path='./node_modules/renum/type-definitions/renum.d.ts'/>

You can also read this file in order to better understand how renum works.

Testing

npm test

Benchmark

npm run bench

Motivations

  • Firstly designed to create immutable action types from redux based projects and easily be able to merge each other.
  • Learning Functional Programming.