Awesome
function-equal
Compares two functions, are they equal? Checks their names, bodies and argument names. Powered by
parse-function
.
Install
npm i function-equal --save
Usage
For more use-cases see the tests
const functionEqual = require('function-equal')
functionEqual
Check two functions are strictly the same.
Params
a
{Function}b
{Function}returns
{Boolean}
Example
var fnEqual = require('function-equal')
// returns true
console.log(fnEqual(fnEqual, fnEqual))
console.log(fnEqual(console.log, console.log))
console.log(fnEqual(function a (b, c) { return b + c }, function a (b, c) { return b + c }))
console.log(fnEqual(console.log, console.dir)) // => false
console.log(fnEqual(function a (foo) {}, function c (foo) {})) // => false
console.log(fnEqual(function a (foo) {}, function a (foo) {})) // => true
console.log(fnEqual(function a (foo) {return foo}, function a (foo) {return foo})) // => true
console.log(fnEqual(function a (foo) {}, function a (bar) {})) // => false
Related
- error-base: Create custom Error classes. | homepage
- is-empty-function: Check that given string, function or arrow function have empty body,… more | homepage
- kind-error: Base class for easily creating meaningful and quiet by default Error… more | homepage
- kind-of: Get the native type of a value. | homepage
- parse-function: Parse a function, arrow function or string to object with name,… more | homepage
- useful-error: Enhanced Error class for creating meaningful and customizable error classes. Adds… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.