GithubHelp home page GithubHelp logo

ts-enum-util's People

Contributors

dependabot[bot] avatar uselesspickles 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ts-enum-util's Issues

fail push new version???

D:.
│  LICENSE
│  package.json
│  README.md
│
├─dist
│  └─types
│          index.d.ts
│          index.d.ts.map
│
└─src
        index.ts

forgot push or build js file??

Cannot find name Extract

I'm using ts-enum-util: "^3.1.0. The error occurs in index.d.ts and is as follows:

Error: ERROR in node_modules/ts-enum-util/dist/types/index.d.ts(15,23): error TS2304: Cannot find name 'Extract'.

Until now, I'm gonna stick to Object.Keys..

Problems using ts-enum-utils with typeorm and nestJS

Trying to use ts-enum-utils to describe types imported by typeorm.

The error I receive is

import { $enum } from 'ts-enum-util'
^^^^^^

SyntaxError: Cannot use import statement outside a module

The tsconfig.json file was generated by nestjs\cli and looks like this.

{ 
   {
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "resolveJsonModule": true
  },
  "exclude": ["node_modules", "dist"]
}

What am I doing wrong?

New feature: Get enums sorted by value

Motivation:
In numerous scenarios, the order of the values is more important than lexicographical keys.
for example:

import React, {PureComponent} from "react";
import { $enum } from "ts-enum-util";

enum Log {
    debug,
    info,
    warning,
    error
}

class LogSelector extends PureComponent{
    public render() {
        return <select>{$enum(Log).map((value, key) => <option key={value}>{key}</option>)}</select>;
    }
}

The select will have the options ordered debug, error, info, warning which is harder to understand than debug, info, warning, eror.

Maybe add something like $enum(Log, true) to order by value? or passing comparable?
Thanks

Invalid type (maybe invalid usage)

I have the following code

export enum DecisionType {
  DECISION = 'whatever,
  UNDEFINED = 'undef'
}

And I want to make sure I receive a string that is one of the legal value and return the correct key.
If I understand correctly, I should be doing this

export function DecisionTypeString (decisionStr: string): StringKeyOf<DecisionType> {
  let value = $enum(DecisionType).asValueOrDefault(decisionStr, DecisionType.UNDEFINED)
  let retval =  $enum(DecisionType).getKeyOrDefault(value, DecisionType.UNDEFINED)
  return retval
}

However, I get the following error message

CaseEnums.ts:15:3 - error TS2322: Type 'string' is not assignable to type '"toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | ... 29 more ... | "trimRight"'.

What am I doing wrong?

how to do asKeyOrDefault in case insensitive?

I want to get the proper key (mixing upper and lower cases) from a string (lower case).
How can I do without looping through the whole array?

Here is my current implementation. Any better like using asKeyOrDefault ?

enum Languages {
  'unknown',
  'en',
  'zh-TW',
  'zh-CN',
  'ja',
}

const key = $enum(Languages).getKeys().find(x => x.toLowerCase() === 'zh-tw')

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.