Skip to content

67 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

67 #5

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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This downplays the original creators. It'd be kinder to say that @tolgaek and I originally wrote this, and you improved upon it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)


Documentation
-------------
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/micro-enum.js');
module.exports=require('./lib/micro-enum.js');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used on the developer side, right? So the user doesn't download this, if I understand correctly. What do these whitespace removals improve?

28 changes: 11 additions & 17 deletions lib/micro-enum-DOCUMENTED.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
;

elements.map((el, i) => {
s[el] = s.all[i] = i
})

return s
}
2 changes: 1 addition & 1 deletion lib/micro-enum.js
Original file line number Diff line number Diff line change
@@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome!

Can you help me understand why you reassign module.exports here as well as in index.js?

12 changes: 0 additions & 12 deletions package.json

This file was deleted.