Skip to content

Instantly share code, notes, and snippets.

@MNBuyskih
Created May 30, 2016 08:33
Show Gist options
  • Save MNBuyskih/c193f7ab8f634ad25a3706f9e5e829a0 to your computer and use it in GitHub Desktop.
Save MNBuyskih/c193f7ab8f634ad25a3706f9e5e829a0 to your computer and use it in GitHub Desktop.
function shareEnum(enu:any):string[] {
return Object.keys(enu)
.filter((key:string) => {
let value = parseInt(key);
return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
})
.reduce((result:string[], key:string) => {
result[key] = enu[key];
return result;
}, []);
}
@MNBuyskih
Copy link
Author

Example:

enum Example {One=1, Two, Three};
console.log(shareEnum(Example)); // => [undefined,'One', 'Two', 'Tree']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment