Skip to content

Instantly share code, notes, and snippets.

@DDzia
Created April 19, 2019 19:45
Show Gist options
  • Save DDzia/258c21b84cbecc9d3aefd482c34e721b to your computer and use it in GitHub Desktop.
Save DDzia/258c21b84cbecc9d3aefd482c34e721b to your computer and use it in GitHub Desktop.
/**
* Get all keys from enumeration.
*/
public static keys(enumType: object) {
const members = Object.keys(enumType);<br /> let keys: string[];
if (!EnumHelpers.isNumeral(enumType)) {
keys = members;
} else {
keys = [];
members.forEach(x => {
const parsedValue = parseInt(x, 10);
if (Number.isNaN(parsedValue)) {
keys.push(x);
}
});
}
// key of enumeration can't be number
return keys.filter(x => Number.isNaN(parseInt(x, 10)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment