functionsIn
object
Creates an array of function property names from own and inherited enumerable properties of object.
Installation
Import
import { functionsIn } from '@tulx/utils';Source Code
Implementation
/**
* Creates an array of function property names from own and inherited enumerable properties of object.
*
* @param object - The object to inspect.
* @returns Returns the function names.
*
* @example
* ```ts
* function Foo() {
* this.a = () => 'a';
* this.b = () => 'b';
* }
* Foo.prototype.c = () => 'c';
* functionsIn(new Foo()); // ['a', 'b', 'c']
* ```
*/
export function functionsIn(object: Record<string, unknown>): string[] {
const result: string[] = [];
for (const key in object) {
if (typeof object[key] === 'function') {
result.push(key);
}
}
return result;
}
Example
import { functionsIn } from '@tulx/utils';
function Foo() {
this.a = () => 'a';
this.b = () => 'b';
}
Foo.prototype.c = () => 'c';
functionsIn(new Foo()); // ['a', 'b', 'c']Related Functions
assign
Assigns own enumerable string keyed properties of source objects to the destination object.
assignIn
This method is like assign except that it iterates over own and inherited source properties.
assignInWith
This method is like assignIn except that it accepts customizer which is invoked to produce the assigned values.
assignWith
This method is like assign except that it accepts customizer which is invoked to produce the assigned values.
at
Creates an array of values corresponding to paths of object.
create
Creates an object that inherits from the prototype object.