- Notifications
You must be signed in to change notification settings - Fork3
Releases: dphilipson/typescript-string-enums
v1.0.0
Assets2
Uh oh!
There was an error while loading.Please reload this page.
v0.3.4
Fixes sourcemaps by inlining sources.
Assets2
Uh oh!
There was an error while loading.Please reload this page.
v0.3.3
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){ ...}
Assets2
Uh oh!
There was an error while loading.Please reload this page.
v0.3.2
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`);}
Assets2
Uh oh!
There was an error while loading.Please reload this page.
v0.3.1
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)
Assets2
Uh oh!
There was an error while loading.Please reload this page.
v0.3.0
The artifact for this version is broken on npm. Please use 0.3.1 or later instead.
Assets2
Uh oh!
There was an error while loading.Please reload this page.
v0.2.0
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!
Assets2
Uh oh!
There was an error while loading.Please reload this page.