From cc8ac27940dd887f97e33579ee305aeb2dffb5bf Mon Sep 17 00:00:00 2001 From: is_gordeev Date: Wed, 23 Sep 2020 17:24:26 +0300 Subject: [PATCH 1/4] 71! --- LICENSE | 2 +- README.md | 4 +++- lib/micro-enum-DOCUMENTED.js | 28 +++++++++++----------------- lib/micro-enum.js | 2 +- package.json | 12 ------------ 5 files changed, 16 insertions(+), 32 deletions(-) delete mode 100644 package.json diff --git a/LICENSE b/LICENSE index 02517e2..1ceccb4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013 tolgaek +Copyright (c) 2020 hazer_hazer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index af3c84f..cabafb1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ Micro JS Enum ============= -A **94-byte** JavaScript enum implementation. +A **71-byte** JavaScript enum implementation. + +Based on `tolgaek` 94-byte JavaScript enum implementation. Documentation ------------- 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..cff6b40 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;} +Enum=(...e)=>{s={all:[],keys:e};e.map((l,i)=>s[l]=s.all[i]=i);return 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" -} From fac001b5b41f9bed1ef5925ba52a4925af38f974 Mon Sep 17 00:00:00 2001 From: is_gordeev Date: Wed, 10 Mar 2021 19:26:25 +0300 Subject: [PATCH 2/4] 67 chars --- lib/micro-enum.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/micro-enum.js b/lib/micro-enum.js index cff6b40..b5a767c 100644 --- a/lib/micro-enum.js +++ b/lib/micro-enum.js @@ -1 +1 @@ -Enum=(...e)=>{s={all:[],keys:e};e.map((l,i)=>s[l]=s.all[i]=i);return s} \ No newline at end of file +Enum=((...l)=>(s={all:[],keys:l},l.map((l,a)=>s[l]=s.all[a]=a),s)); \ No newline at end of file From 378c98455ea367834127ab8d1fba58b8d81066f6 Mon Sep 17 00:00:00 2001 From: is_gordeev Date: Wed, 10 Mar 2021 19:29:56 +0300 Subject: [PATCH 3/4] cleanup --- LICENSE | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index 1ceccb4..02517e2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 hazer_hazer +Copyright (c) 2013 tolgaek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index cabafb1..b1151b8 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ Micro JS Enum ============= -A **71-byte** JavaScript enum implementation. +A **67-byte** JavaScript enum implementation. -Based on `tolgaek` 94-byte JavaScript enum implementation. +Hazer-hazer version of `tolgaek` 94-byte JavaScript enum implementation. Documentation ------------- From 2cd600d721d76ead24e6ceaef85fea983ee4c423 Mon Sep 17 00:00:00 2001 From: is_gordeev Date: Wed, 10 Mar 2021 19:35:07 +0300 Subject: [PATCH 4/4] Support nodejs export --- index.js | 2 +- lib/micro-enum.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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.js b/lib/micro-enum.js index b5a767c..00e462f 100644 --- a/lib/micro-enum.js +++ b/lib/micro-enum.js @@ -1 +1 @@ -Enum=((...l)=>(s={all:[],keys:l},l.map((l,a)=>s[l]=s.all[a]=a),s)); \ No newline at end of file +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