1.0.0 • Published 3 years ago

@mkmod-ts/ts-get-exported-function v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

@mkmod-ts/ts-get-exported-function

Uses typescript to get any exported function from a .ts file:

const getExportedFunction = require("@mkmod-ts/ts-get-exported-function")

const code = `
export default function(s: string, n: number) {

}
`

console.log(
	getExportedFunction(code, "default")
)

Result is in the following format:

{
	parameters: [{
		name: "name of parameter",
		text: "textual representation of parameter",
		type: "type of parameter"
	}, ...],
	returnType: "the return type of the function",
	declarationWithFunctionName(name) {
		// returns declaration with a user set name like:
		return "<name>(<params>):<returnType>"
	}
}

or null if function was not found.