Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
engines:
duplication:
enabled: true
config:
languages:
- javascript
eslint:
enabled: true
fixme:
enabled: true
nodesecurity:
enabled: false
ratings:
paths:
- "src/**"
- "configs/**"
- "./*.js"
exclude_paths:
- "dist/**/*"
- "build/**/*"
- "tests/**/*"
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/**
build/**
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ logs
*.log
node_modules
bower_components
build
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v5.0.0
88 changes: 78 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
EnumJS
======
A simple way to create an immutable list of enums in ES5.
A simple way to create an immutable enumerable list aka enum.
Still a WIP use at your own risk

[![Codacy Badge](https://www.codacy.com/project/badge/392d48a4b14f43f3853d534e34bbdd87)](https://www.codacy.com/public/RyanBogle/EnumJS)
Expand All @@ -9,22 +9,90 @@ Still a WIP use at your own risk

Usage
======
ES6
```javascript
import $enum { assign, assignTo } from 'enumjs';

var myEnum = $enum( 'a', 'b', 'c' );
```

NodeJS
```javascript
var Enum = require('Enum').Enum;
var $enum = require( 'enumjs' );

$enum
// { [Function: $enum] assign: [Function: assign], assignTo: [Function: assignTo] }

var myEnum = $enum( 'one', 'two', 'three' );
```

As a browser script
```javascript
// $enum will exist on the window object after the script is loaded
var myEnum = $enum(['one', 'two', 'three']);
```

var myEnumFromAry = new Enum(['one', 'two', 'three']);
OR
var myEnumFromObj = new Enum({one:1, two:2, three:3});
Constructor Patterns
======
There are several ways to create an enum, as described below
```javascript
/**
* possible argument signatures
* $enum( ...names )
* $enum([ names ])
* $enum({ name:value })
* $enum( startIndex, [ names ])
**/
```

ES5 Compatible Browsers

### As an argument list ###
#### `$enum( ...names );` ####

```javascript
// Enum will exist on the window object after the script is loaded
var myEnumFromAry = new Enum(['one', 'two', 'three']);
OR
var myEnumFromObj = new Enum({one:1, two:2, three:3});
var myEnum = $enum( 'zero', 'one', 'two' );

console.log( myEnum );
// -> Enum { zero: 0, one: 1, two: 2 }
```

### As an array ###
#### `$enum([ names ]);` ####

```javascript
var myEnum = $enum([ 'zero', 'one', 'two' ]);

console.log( myEnum );
// -> Enum { zero: 0, one: 1, two: 2 }
```

### As an object of own keys ###
#### `$enum({ key:value });` ####

```javascript
var myEnum = $enum({
PLAY: 'play',
STOP: 'stop',
SKIP: 'next'
});

console.log( myEnum );
// -> Enum { PLAY: 'play', STOP: 'stop', SKIP: 'next' }
```

### As a starting index and array of names ###
#### `$enum( startIndex, [ names ]);` ####

```javascript
var myEnum = $enum( 1, [ 'one', 'two', 'three' ]);

console.log( myEnum );
// -> Enum Enum { one: 1, two: 2, three: 3 }
```

Assign Functions
======
TODO

Come back for more updates!

22 changes: 0 additions & 22 deletions bower.json

This file was deleted.

12 changes: 12 additions & 0 deletions configs/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import babel from 'rollup-plugin-babel';

export default {
// exports: 'auto',
moduleName: '$enum',
sourceMap: true,
plugins: [
babel()
]
};

8 changes: 8 additions & 0 deletions configs/rollup.es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import config from './rollup.config';

config.entry = 'src/api.js';
config.format = 'es6';
config.dest = 'dist/enum.js';

export default config;
12 changes: 12 additions & 0 deletions configs/rollup.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import multiEntry, { entry } from 'rollup-plugin-multi-entry';
import config from './rollup.config';

config.entry = entry;
config.format = 'cjs';
config.dest = 'build/enum.tests.js';
config.external = [ 'tape' ];

config.plugins.push( multiEntry( 'tests/**/*.js' ));

export default config;
8 changes: 8 additions & 0 deletions configs/rollup.umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import config from './rollup.config';

config.entry = 'src/api.es5.js';
config.format = 'umd';
config.dest = 'dist/enum.umd.js';

export default config;
Loading