Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Releases: dphilipson/typescript-string-enums

v1.0.0

27 Feb 01:08

Choose a tag to compare

No changes, but committing to a stable release.

Assets2
Loading

v0.3.4

30 May 00:42

Choose a tag to compare

Fixes sourcemaps by inlining sources.

Loading

v0.3.3

22 May 10:36

Choose a tag to compare

IntroducesEnum.ofKeys function. As described in the README:

Enum.ofKeys(object)

Creates a new enum with the same keys as the provided enum or object and whose values are equal to
its keys. This is most useful if for some reason it is necessary to do string comparisons against
the keys of an enum rather than the values. For example:

constErrorColor=Enum({OK:"green",ERROR:"red"});typeErrorColor=Enum<typeofErrorColor>;constErrorLevel=Enum.ofKeys(ErrorColor);consterrorLevel=getErrorLevel();if(errorLevel===ErrorLevel.ERROR){    ...}
Loading

v0.3.2

20 Apr 21:39

Choose a tag to compare

AddsEnum.isType(), a type-checking function that can be used as a guard.

Sample usage:

constColor=Enum("RED","GREEN","BLUE","PUCE");typeColor=Enum<typeofColor>;letselectedColor:Color;constcolorString=getUserInputString();// Unsanitized string.if(Enum.isType(Color,colorString)){// Allowed because within type guard.selectedColor=colorString;}else{thrownewError(`${colorString} is not a valid color`);}
Loading

v0.3.1

23 Mar 23:47

Choose a tag to compare

IntroduceEnum.keys() andEnum.values(), which resembleObject.keys()
andObject.values() but provide strict typing in their return type:

constFileType=Enum({PDF:"application/pdf",Text:"text/plain",JPEG:"image/jpeg",});typeFileType=Enum<typeofFileType>;constkeys=Enum.keys(FileType);// Inferred type: ("PDF" | "Text" | "JPEG")[]// Return value: ["PDF", "Text", "JPEG"] (not necessarily in that order)constvalues=Enum.values(FileType);// Inferred type: ("application/pdf" | "text/plain" | "image/jpeg")[]// Return value: ["application/pdf", "text/plain", "image/jpeg"] (not necessarily in that order)

Thanks again to@kourge for his contribution!

(This release fixes a publishing issue in 0.3.0)

Loading

v0.3.0

23 Mar 21:51

Choose a tag to compare

The artifact for this version is broken on npm. Please use 0.3.1 or later instead.

Loading

v0.2.0

23 Mar 19:09

Choose a tag to compare

Enums can now be created with keys that differ from their string values. Additionally, these entries may have JSDoc comments. For example,

exportconstStatus=Enum({/**     * Everything is fine.     *     * Hovering over Status.RUNNING in an IDE will show this comment.     */RUNNING:"running",/**     * All is lost.     */STOPPED:"stopped",});exporttypeStatus=Enum<typeofStatus>;console.log(Status.RUNNING);// -> "running"

Thanks to@kourge for contributing!

Loading

[8]ページ先頭

©2009-2025 Movatter.jp