npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

enumr8

v1.1.0

Published

A javascript module for defining custom enum types and generating instances of that type.

Downloads

4

Readme

enumr8

A javascript module for defining custom enum types and generating instances of that type.

##How to use

const createEnumType = require('enumr8');



//DAYS OF THE WEEK EXAMPLE/////////////////////////////////////////////////////

//define an enum type consisting of the days of the week
let Weekday = createEnumType(['Sunday',
                              'Monday',
                              'Tuesday',
                              'Wednesday',
                              'Thursday',
                              'Friday',
                              'Saturday']);

//retrieve first and last                               
console.log(Weekday.eFirst());
console.log(Weekday.eLast());

//retrieve the value of Friday
console.log(Weekday.Friday);

//get number of days in the week
console.log(Weeday.eLength)




let today = Weekday.eCreate('Tuesday');
console.log(today.getValue()); //Tuesday

today.increment();
console.log(today.getValue()); //Wednesday

today.add(3);
console.log(today.getValue()); //Saturday

today.add(2);
console.log("Today is now " + today.getValue());      //Monday

console.log("Yesterday was " + today.getPrevious());  //Sunday
console.log("Tomorrow is " + today.getNext());        //Tuesday

today.decrement();
console.log("Today is now " + today.getValue()); //Sunday

today.decrement();
console.log("Today is now " + today.getValue()); //Saturday

today.setByValue(Weekday.Thursday);
console.log("Today is now " + today.getValue()); //Thursday


//HEXADECIMAL EXAMPLE//////////////////////////////////////////////////////////

//define an enum type consisting of the symbols for hexadecimal
let HexadecimalDigit = createEnumType({   "0" : 0,
                                          "1" : 1,
                                          "2" : 2,
                                          "3" : 3,
                                          "4" : 4,
                                          "5" : 5,
                                          "6" : 6,
                                          "7" : 7,
                                          "8" : 8,
                                          "9" : 9,
                                          "a" : 10,
                                          "b" : 11,
                                          "c" : 12,
                                          "d" : 13,
                                          "e" : 14,
                                          "f" : 15}, "Hexadecimal", true);

let HexadecimalNumber =

function hexParser(hexString){

}

//TELLING TIME/////////////////////////////////////////////////////////////////

let Period = createEnumType(["AM", "PM"]);

let Hour = createEnumType(["12","1","2","3","4","5","6","7","8","9","10","11"]);

let Minute = createEnumType(["00","01","02","03","04","05","06","07","08","09",
                            "10","11","12","13","14","15","16","17","18","19",
                            "20","21","22","23","24","25","26","27","28","29",
                            "30","31","32","33","34","35","36","37","38","39",
                            "40","41","42","43","44","45","46","47","48","49",
                            "50","51","52","53","54","55","56","57","58","59"]);

let time = { "hour": Hour.eCreate(4),
             "minute": Minute.eCreate(20),
             "period": Period.eCreate("AM")
           };

//INCHES, FEET, YARDS/////////////////////////////////////////////////////////

let Inch = createEnumType({ "": 0,
                            "1 inch": 1,
                            "2 inches": 2,
                            "3 inches": 3,
                            "4 inches" : 4,
                            "5 inches" : 5,
                            "6 inches": 6,
                            "7 inches": 7,
                            "8 inches" : 8,
                            "9 inches" : 9,
                            "10 inches": 10,
                            "11 inches": 11
                          });
let Foot = createEnumType({ "": 0,
                            "1 foot": 1,
                            "2 feet": 2,
                          });



//DICE////////////////////////////////////////////////////////////////////////

let Dice = createEnumType({"One":1,"Two":2,"Three":3,"Four":4,"Five":5,"Six":6});

let blueDie = Dice.eCreate();
let greenDie = Dice.eCreate();

const SIX_CUBED = Math.pow(6,3);

function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min)) + min;
}

function rollDie(die){
  die.setByIndex(getRandomInt(0,SIX_CUBED));
}

function printDiceTotal(die1, die2){
  console.log("Dice total is " + (die1.getValue() + die2.getValue()));
}

console.log(blueDie.getLabel()); //"One"
console.log(greenDie.getLabel()); //"One"

greenDie.increment();
console.log(greenDie.getLabel()); //"Two"

//roll Dice
rollDie(blueDie);
rollDie(greenDie);

console.log("The blue die is now " blueDie.getLabel() + ".");
console.log("The green die is now " greenDie.getLabel() + ".");

printDiceTotal(blueDie, greenDie);


//Caesar Cipher////////////////////////////////////////////////////////////////

let Alphabet = createEnumType(["a","b","c","d","e","f","g","h","i","j","k",
                              "l","m","n","o","p","q","r","s","t","u","v",
                              "w","x","y","z"]);

//functional cypher
function convertStrToEnum(str){


  return enum;
}

function convertEnumToStr(enum){

  return str;
}

function shiftMsg(enum, integer){

    return enum;
}

function cyphon(str, shiftVal){
  return convertEnumToStr(shiftMsg(converStrToEnum(str), shiftVal));
}

//Testing...
let encodedMsg = cyphon("Time flies like an arrow.", 4);
console.log(encodedMsg);


//object-oriented cypher
function cypher(message){
  let cyph = {}
  let enum = convertStringToEnum(message);
  let msg = message

  function getOriginalMessage(){
    return msg;
  }

  function shift(n){
      shiftMsg(enum, n);
  }

  function getEncryptedMessage(){
    return convertEnumToStr(enum);
  }

  cyph.getOriginalMessage = getOriginalMessage;
  cyph.shift = shift;
  cyph.getEncryptedMessage = getEncryptedMessage;

  return cyph;
}



let c = cypher("When all you have is a hammer, everything looks like a nail.");
console.log(c.getOriginalMessage());

c.shift(-27);
console.log(c.getEncryptedMessage());
console.log(c.getOriginalMessage());


##API