Created
August 5, 2019 21:25
-
-
Save nathansmith/f7526912713689f83c6fd4113ecd8b24 to your computer and use it in GitHub Desktop.
Get method names, from object or class instance.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getMethodNames( | |
apiObject: object = {} | |
): string[] { | |
// Assume class instance. | |
let list = Object.getOwnPropertyNames( | |
Object.getPrototypeOf(apiObject) | |
); | |
// Detect plain object. | |
if (list.includes('__proto__')) { | |
list = Object.keys(apiObject); | |
} | |
list = list.filter( | |
s => s !== 'constructor' | |
); | |
list = list.sort(); | |
// Expose array. | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment