Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Created August 5, 2019 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathansmith/f7526912713689f83c6fd4113ecd8b24 to your computer and use it in GitHub Desktop.
Save nathansmith/f7526912713689f83c6fd4113ecd8b24 to your computer and use it in GitHub Desktop.
Get method names, from object or class instance.
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