get-function-header

Zero-dependency get function header

Usage no npm install needed!

<script type="module">
  import getFunctionHeader from 'https://cdn.skypack.dev/get-function-header';
</script>

README

get-function-header npm GitHub license Build Status Coverage Status

Zero-dependency get function header

Installation

yarn add get-function-header

Usage

import getFunctionHeader from 'get-function-header'

async function sayHello(who, ...messages) {
  console.log(`${ who }: ${ messages.join() }`)
}

getFunctionHeader(sayHello.toString()).trim()
// async function sayHello(who, ...messages)

API

Table of Contents

getFunctionHeader

Get function header codeing from function string.

Parameters

  • code string The function string get from Function.prototype.toString
  • withComments boolean Return header with comments or not (optional, default false)

Returns string The function header string