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

glum

v0.2.2

Published

JS enums with type safety

Downloads

4

Readme

glum

styled with prettier Travis Coveralls Dev Dependencies Donate

Summary

glum is a super lightweight Enum library that makes use of Symbols to achieve type-safety.

What if my environment doesn't support ES6?

If you're in a browser, use a polyfill. If you're running in Node, chances are that Symbols are supported: they're supported in all versions after 5.12.0.

Why use Glum?

  • Type-safety. When you declare an Enum, members are unique and can't be mimicked by strings, numbers, etc.
  • Allows for passing in polyfills
  • Don't reinvent the wheel

:scroll: Docs

Installation

npm install glum

Or, if in a browser,

<script crossorigin src="https://cdn.jsdelivr.net/npm/glum"></script>

[Note: this will create a global variable called Glum]

Usage

We distribute a UMD build, so you can use it with ES modules, CommonJS, AMD, or in the browser

import Enum from 'glum'
// or var Enum = require 'glum'

let FRUIT = new Enum('APPLE', 'ORANGE', 'PEAR')

function nameFruit (fruit) {
  if ((fruit = FRUIT.APPLE)) {
    console.log("It's an apple")
  }
}

console.log(FRUIT.getName(FRUIT.APPLE)) // APPLE

API

new Enum(... enumNames, [symbolPolyfill])

Create a new Enum. Ex. let fruits = new Enum("APPLE", "ORANGE", "PEAR") Ex. with polyfill let fruits = new Enum("APPLE", "ORANGE", "PEAR", function(name) {return '@@\_Symbol:' + name})

Enum.has(member)

Check if a member is part of an enum. Note: this will primarily be used to accept function parameters, variables, etc. that must be a member of a certain enum. Ex.

let fruits = new Enum('APPLE', 'ORANGE', 'PEAR')
fruits.has(fruits.APPLE) // true
fruits.has(fruits.HI) // false

Enum.getName(member)

Get the name of an enum member. Note: this is usually used to get the name of an Enum member passed as a parameter, variable, etc. Ex.

let fruits = new Enum('APPLE', 'ORANGE', 'PEAR')
fruits.getName(fruits.APPLE) // "APPLE"

:heavy_check_mark: Tests

Tests can be run with npm test. Multiple tests check that things return expected results, formatting follows guidelines, and code coverage is at the expected level.

Projects using glum

Create an issue to add yours!

Credits

Made with :heart: by @nebrelbug and all these wonderful contributors (emoji key):

This project follows the all-contributors specification. Contributions of any kind are welcome!