GithubHelp home page GithubHelp logo

enum-xyz's People

Contributors

chasefleming avatar gregsantos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

moeyc gregsantos

enum-xyz's Issues

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()

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.

Numeric enums do not reset their index for separate declarations

When creating multiple numeric enums consecutively, the index does not reset to zero for the new enum. This leads to unexpected behavior where the new enum starts from where the previous one left off.

Reproduction Steps

Declare a numeric enum:

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

Declare another numeric enum:

const { D, E } = Enum.Numeric;

Expected Behavior:
D should have a value of 0.

Actual Behavior:
D starts from where C left off.

Setup CI

  • Run tests on pull request
  • Run build on pull request

Get ESM running with Jest

Files are currently using CommonJS for Jest. Convert to ES Modules and get Jest running with them.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.