1.0.2 • Published 6 years ago

is-bound-func v1.0.2

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

is-bound-func

Check if given function is bound or not.

npm install is-bound-func

API

index.d.ts

isBoundFunc<T extends Function>(fn: T, chkLevel = 2)

demo

const isBoundFunc = require('is-bound-func')
import isBoundFunc from 'is-bound-func';
import * as isBoundFunc from 'is-bound-func';

demo.ts

[
	() => {},
	function (){},
	function a(){},
	parseInt,
	parseInt.bind(null),
].forEach(fn =>
{
	// when fn not bound will return null, else will return a number

	console.dir({
		name: fn.name,
		fn,
	});
	console.dir([isBoundFunc(fn), isBoundFunc(fn.bind(null))]);
});

output

{ name: '', fn: [Function] }
[ null, 2 ]
{ name: '', fn: [Function] }
[ null, 2 ]
{ name: 'a', fn: [Function: a] }
[ null, 2 ]
{ name: 'parseInt', fn: [Function: parseInt] }
[ null, 2 ]
{ name: 'bound parseInt', fn: [Function: bound parseInt] }
[ 2, 2 ]