renum
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
; 'INCREMENT' 'DECREMENT';
Using ES5
const renum = ; moduleexports = ;
Usage
From primitive arguments
Strings
//=> {1: '1', 2: '2', 3: '3'}
String
//=> {1: '1', 2: '2', 3: '3'}
Template String
//=> {1: '1', 2: '2', 3: '3'}
Numbers
//=> {1: 1, 2: 2, 3: 3}
Boolean
//=> {true: true, false: false}
Empty values
//=> {}
Symbol
//=> {Symbol(1): Symbol(1), Symbol(f => f + 1): 'Symbol(f => f + 1)'}
From Objects
Array
//=> {1: '1', 2: 2, true: true}
Pairs
//=> {INCREMENT: [Function], DECREMENT: [Function]}
Map
//=> {INCREMENT: '+', DECREMENT: '-'}
Set
//=> {1: 1, 2: 2, 3: 3}
Inception
//=> {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;; ImmutableListisList R ImmutableMapisMap R ImmutableStackisStack R;
And then:
;;; // from a list of pairsrenum; // or from arguments directlyrenum;
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
fromredux
based projects and easily be able to merge each other. - Learning Functional Programming.