JavaScript enums using proxies.

Overview

enum-xyz

JavaScript enums using proxies.

Based on this tweet

Install

$ npm install enum-xyz --save

Usage

Strings

import Enum from 'enum-xyz'

const { Summer, Autumn, Winter, Spring } = Enum.String

console.log(Summer) // 'Summer'
console.log(Autumn) // 'Autumn'
console.log(Winter) // 'Winter'
console.log(Spring) // 'Spring'

Strings (lowercased)

import Enum from 'enum-xyz'

const { Summer, Autumn, Winter, Spring } = Enum.StringLower

console.log(Summer) // 'summer'
console.log(Autumn) // 'autumn'
console.log(Winter) // 'winter'
console.log(Spring) // 'spring'

Numeric

import Enum from 'enum-xyz'

const { A, B, C, D } = Enum.Numeric

console.log(A) // 0
console.log(B) // 1
console.log(C) // 2
console.log(D) // 3

Numeric Starting at Index

import Enum from 'enum-xyz'

const { A, B, C, D } = Enum.NumericAt(1)

console.log(A) // 1
console.log(B) // 2
console.log(C) // 3
console.log(D) // 4
You might also like...

Simple Library implemented using HTML, CSS and JavaScript. This is a simple implementation of JavaScript Modules of ES6.

Awesome-books A single page project with the porpuse of storing books' titles and authors. Built With CSS, HTML & Javascript. How to run in your local

Feb 21, 2022

This is a project that allows users to add/remove books from a list. we accomplish this by using a JavaScript object. Built with JavaScript, Html and CSS.

Awesome-book This is a project that allows users to add/remove book from a list. we accomplish this by usig javascript oject. Built With HTML5 CSS3 Ja

May 27, 2022

Custom alert box using javaScript and css. This plugin will provide the functionality to customize the default JavaScript alert box.

customAlertBoxPlugin Custom Alert Box Plugin Using JavaScript and CSS Author: Suraj Aswal Must Include CSS Code/Default Custom Alert Box Class: /* mus

Sep 10, 2022

Device.js is a JavaScript library to detect device, viewport, and browser information using plain JavaScript.

Device.js Device.js is a JavaScript library to detect device, viewport, and browser information using plain JavaScript. Compatibility Works with all m

Dec 16, 2022

This is my to-do list website built with html, css and JavaScript. In this project I used Webpack to bundle JavaScript and ES6 modules to write modular JavaScript.

This is my to-do list website built with html, css and JavaScript. In this project I used Webpack to bundle JavaScript and ES6 modules to write modular JavaScript.

To-Do-List App This is my to-do list website built with html, css and JavaScript. In this project I used Webpack to bundle JavaScript and ES6 modules

Sep 20, 2022

This repo contains instructions on how to create your NFT in Solana(using Metaplex and Candy Machine) and mint it using your custom front-end Dapp

This repo contains instructions on how to create your NFT in Solana(using Metaplex and Candy Machine) and mint it using your custom front-end Dapp

Solana-NFT minting Dapp Create your own NFT's on Solana, and mint them from your custom front-end Dapp. Tools used Metaplex - Metaplex is the NFT sta

Nov 2, 2022

Using decentralized identities with Web 2 to create a no login required website. Built using the Handshake blockchain.

Blending Web 2/3, is this Web .666? ( •̀ᴗ•́ )و ̑̑ Learn more by joining the Handshake Discord Community applause is a platform I built using centraliz

Mar 3, 2022

Tip Tweet is a hybrid dApp that provides a simple way to tip a tweet using Ethereum. Authors can claim their tips using their Twitter account. You only need the tweet URL to tip. 🚀 😎

Tip Tweet Table of Contents About Folder Structure Contract Deveopment Starting the App Usage Contributing About Tip Tweet is hybrid dApp that allows

Nov 15, 2022

This is a fully functional DAO, a Web3 project made using Solidity, Hardhat, JS, Next.js, Openzeppelin, CSS, HTML, using the Rinkerby network!

My First DAO! This is made for a DAO-Tutorial via learnweb3.io This is a DAO, a decentralised autonomous organisation, essentially a more collective a

Jun 20, 2022
Comments
  • Refactor

    Refactor

    Proposed changes

    1. Abstracts Proxy boilerplate
    2. Combines Integers using default startIndex
    3. Reduces runtime complexity using Map
    4. Tweaks naming for unqualified import
    5. Adopts EcmaScript module syntax
    6. Adds JSDoc annotations to generate .d.ts
    7. Formatted with Prettier

    Remaining changes if accepted

    • [x] Add Prettier config and script (f9130c36116e10093bff16063e5f56b6e8ac75d6)
    • [x] Add tsconfig.json (d04cde59feb283b32e4a8a24d06ca3cfd999dfdb)
    • [x] Generate *.d.ts from JSDoc (also d04cde59feb283b32e4a8a24d06ca3cfd999dfdb)
    • [x] Deprecate previous names (65fdac18b1e210426d280ccda29e264063e12f7b)
    • [x] Update tests to use EcmaScript modules (1289066425359b2ef2c2fefa7fea5ec02893dbe0)
    • [x] Add ActionCreators in extras module (4e327765629f2f3907fe6a196611ea7a91274877)
    • [x] Add apply trap (originally 7b7df53cbd5d179dcaac33b3e31dcc2991bdcf46)
    • [ ] Add more tests
    • [ ] Add colors in extras module
    • [ ] Update changelog

    Followup PR

    • [ ] Update readme
    • [ ] Add custom use cases in examples section
    opened by texastoland 30
  • Flexible and hetergenous enums

    Flexible and hetergenous enums

    With the current syntax, there is no way to create an enum with say a key of foo, but a value of bar. There is also no way to create heterogenous enums (although those cases are much more rare). It might make sense to have an enum that could support this and also lends itself to being more easily exportable (as discussed here) if a developer chooses to use this syntax. Caveat being, there should be a way for the destructured syntax to also access these methods even if the syntax is more clunky (developer choice...or they may start one way in a single file and later expand on it and need more functionality).

    Example syntax could be:

    const ENVIRONMENTS = Enum.set({
      DEV: 'development',
      PROD: 'production'
    })
    
    // Could have methods of this later e.g. ENVIRONMENTS.keys()
    

    Later methods accessible from this will show the value of this over an object. And could also internally freeze the values for more benefits over an object.

    enhancement 
    opened by chasefleming 1
  • Method for listing keys and values of enum

    Method for listing keys and values of enum

    Currently there is no way to access keys or values of an enum. This ties somewhat back to the exporting issue in that there needs to be a way to group enum items together in order to access methods off of them.

    Ideal solution would include methods for:

    • .keys()
    • .values()
    enhancement 
    opened by chasefleming 0
  • Exporting enums under names

    Exporting enums under names

    Currently, if you export like this:

    // enums.js
    export const { Summer, Autumn, Winter, Spring } = Enum.String
    

    Importing would then require you to import

    // other file
    import { Summer, Autumn, Winter, Spring } from './enums.js'
    

    If you have many enums, this could be tedious and you may want to scope them to a name like Seasons which you could then call each item on. Ideally, it would look something like this:

    import { Seasons } from './enums.js'
    Seasons.Summer // 'Summer'
    

    This may take some design changes. Curious to spark a conversation here on approach.

    enhancement 
    opened by chasefleming 6
Releases(0.1.0)
Owner
Chase Fleming
Chase Fleming
A TypeScript namespace declaration for KeyboardEvent.key strings, just in case your code is allergic to enums.

ts-key-namespace A TypeScript namespace declaration for KeyboardEvent.key strings, just in case you prefer namespaces to enums. Largely based on ts-ke

Daniel Soohan Park 3 Apr 5, 2022
Small TS library to type and safely handle `serde` JSON serializations of Rust enums.

rustie-ts TypeScript library with helper types and functions to type-safely handle Rust's serde JSON serialization of Enums. It can also be used stand

Kelvin Steiner Santos 4 Jul 17, 2022
NodeJS library without any external dependencies to check if free HTTP/SOCKS4/SOCKS5 proxies are working/up

free-proxy_checker NodeJS library WITHOUT any external dependencies to: download free proxies; check if free HTTP/SOCKS4/SOCKS5 proxies are working/up

antoine vastel 15 Nov 6, 2022
🚀 A Node.js server that automaticaly finds and checks proxies for you.

Proxi A Node.js app that automaticaly finds and checks proxies for you and shows them on a dashboard. Install & Setup ## Download git clone https://gi

Jareer Abdullah 8 Jul 7, 2022
JavaScript project for the Leaderboard list app, using Webpack and ES6 features, notably modules. this app consume the Leaderboard API using JavaScript async and await and add some styling.

Leaderboard Project JavaScript project for the Leaderboard list app, using Webpack and ES6 features, notably modules. this app consume the Leaderboard

bizimungu pascal 4 May 20, 2022
Web-pack based Todo-List Website built using HTML, CSS and JavaScript. Tested Using Jest.

To-DO List Live Link Additional description about the project and its features: Built With HTML and CSS Javascript HTML & CSS3 & JavaScript Linters Gi

Saadat Ali 8 Mar 31, 2022
Awesome Books project with ES6 is an application that was built using Vanilla JavaScript with ES6 features like using arrow functions. This application allows you to keep records of your favorite books.

Javascript Project Awesome Books with ES6 Using Javascript to create a simple Awesome Books project. Populating the books list and then removing one b

Ghazanfar Ali 8 Sep 28, 2022
Emem Ekpo 7 Sep 9, 2022
Harrison Njuguna 5 Nov 11, 2022
Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked. Desktop view Mobile v

Ellis 2 Feb 16, 2021