diff --git a/README.md b/README.md index af3c84f..b1151b8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ Micro JS Enum ============= -A **94-byte** JavaScript enum implementation. +A **67-byte** JavaScript enum implementation. + +Hazer-hazer version of `tolgaek` 94-byte JavaScript enum implementation. Documentation ------------- diff --git a/index.js b/index.js index 704f8a8..dcffd22 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -module.exports = require('./lib/micro-enum.js'); +module.exports=require('./lib/micro-enum.js'); \ No newline at end of file diff --git a/lib/micro-enum-DOCUMENTED.js b/lib/micro-enum-DOCUMENTED.js index c700aac..13f20dd 100644 --- a/lib/micro-enum-DOCUMENTED.js +++ b/lib/micro-enum-DOCUMENTED.js @@ -73,21 +73,15 @@ * @version 1.0.0 */ -var Enum = // the name of the "class" - function() // this is what the arguments are passed to - { - var values = arguments; // get the varargs and save them to a 'values' variable. - var self = { // prepare a 'self' object to return, so we work with an object instead of a function - all : [], // prepare a list of all indices - keys : values // create the list of all keys - }; - - for(var i = 0; i < values.length; i++) // for all enum names given - { - self[values[i]] = i; // add the variable to this object - self.all[i] = i; // add the index to the list of all indices - } - - return self; // return the 'self' object, instead of this function +const Enum = (...elements) => { + const s = { + all: [], + keys: elements } -; \ No newline at end of file + + elements.map((el, i) => { + s[el] = s.all[i] = i + }) + + return s +} diff --git a/lib/micro-enum.js b/lib/micro-enum.js index fdf7d86..00e462f 100644 --- a/lib/micro-enum.js +++ b/lib/micro-enum.js @@ -1 +1 @@ -Enum=function(){let v=arguments,s={all:[],keys:v};for(let i=v.length;i--;)s[v[i]]=s.all[i]=i;return s;} +module.exports=Enum=((...l)=>(s={all:[],keys:l},l.map((l,a)=>s[l]=s.all[a]=a),s)); \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index 85fb3ba..0000000 --- a/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "simple-enum", - "version": "1.0.0", - "description": "A very, very tiny JavaScript enum implementation", - "main": "index.js", - "repository": { - "type": "git", - "url": "https://github.com/tolgaek/node-enum" - }, - "author": "Tolga Ekmen ", - "license": "MIT" -}