Determine if a value is a function
npm install @primitive/is-function[license-shield-url]: https://img.shields.io/github/license/primitive-js/is-function.svg?style=flat-square
[license-url]: https://github.com/Primitive-JS/is-function/blob/master/LICENSE
[npm-downloads-shield-url]: https://img.shields.io/npm/dt/@primitive/is-function.svg?style=flat-square
[npm-version-shield-url]: https://img.shields.io/npm/v/@primitive/is-function.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/@primitive/is-function
[unpkg-shield-url]: https://img.shields.io/badge/unpkg-up--to--date-brightgreen.svg?style=flat-square
[unpkg-url]: https://unpkg.com/@primitive/is-function/dist/index.min.js
[![NPM][npm-version-shield-url]][npm-url]
[![NPM][npm-downloads-shield-url]][npm-url]
[![CDN][unpkg-shield-url]][unpkg-url]
[![LICENSE][license-shield-url]][license-url]
Determine if a value is a function.
A value is a function if it is a literal function, or is an instance of typeFunction.
``shell`
npm install @primitive/is-function --save # Install package via NPM
yarn add @primitive/is-function # Install package via Yarn
`javascript
import { expect } from "chai";
import isFunction from "@primitive/is-function";
expect(isFunction(function () {})).to.be.true;
expect(isFunction(() => {})).to.be.true;
expect(isFunction(new Function())).to.be.true;
expect(isFunction(undefined)).to.be.false;
expect(isFunction(null)).to.be.false;
expect(isFunction(42).to.be.false;
`
This package contains TypeScript type declarations. Furthermore, the package
uses TypeScript type guards to allow type inference to influence intellisense.
`typescriptx
if (isFunction(x)) {
// IntelliSense now knows is a function.`
let y: Function = x;
}
This package can be imported via unpkg as demonstrated
below.
`html`
This package uses Gulp for building, and Chai
and Mocha for testing.
`shell`
npm install # Installs dependencies.
npm run build # Build the project.
npm test # Run tests.
Refer to the LICENSE` file for license information.