Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
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?
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]
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
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"
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.
glum
Create an issue to add yours!
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!
FAQs
JS enums with type safety
We found that glum demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.