Skip to content

Compares two functions, are they equal? Checks their names, bodies and argument names. Powered by `parse-function`.

License

Notifications You must be signed in to change notification settings

tunnckoCore/function-equal

Compares two functions, are they equal? Checks their names, bodies and argument names. Powered by parse-function.

code climate standard code style travis build status coverage status dependency status

Install

npm i function-equal --save

Usage

For more use-cases see the tests

const functionEqual = require('function-equal')

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

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.

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

Compares two functions, are they equal? Checks their names, bodies and argument names. Powered by `parse-function`.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published