package/package.json000644 0000005215 3560116604 011551 0ustar00000000 000000 { "name": "is-callable", "version": "1.1.4", "author": { "name": "Jordan Harband", "email": "ljharb@gmail.com", "url": "http://ljharb.codes" }, "contributors": [ { "name": "Jordan Harband", "email": "ljharb@gmail.com", "url": "http://ljharb.codes" } ], "description": "Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.", "license": "MIT", "main": "index.js", "scripts": { "pretest": "npm run --silent lint", "test": "npm run --silent tests-only", "posttest": "npm run --silent security", "tests-only": "npm run --silent test:stock && npm run --silent test:staging", "test:stock": "node test.js", "test:staging": "node --es-staging test.js", "coverage": "npm run --silent istanbul", "covert": "covert test.js", "covert:quiet": "covert test.js --quiet", "istanbul": "npm run --silent istanbul:clean && npm run --silent istanbul:std && npm run --silent istanbul:harmony && npm run --silent istanbul:merge && istanbul check", "istanbul:clean": "rimraf coverage coverage-std coverage-harmony", "istanbul:merge": "istanbul-merge --out coverage/coverage.raw.json coverage-harmony/coverage.raw.json coverage-std/coverage.raw.json && istanbul report html", "istanbul:harmony": "node --harmony ./node_modules/istanbul/lib/cli.js cover test.js --dir coverage-harmony", "istanbul:std": "istanbul cover test.js --report html --dir coverage-std", "prelint": "editorconfig-tools check *", "lint": "npm run jscs && npm run eslint", "jscs": "jscs *.js", "eslint": "eslint *.js", "security": "nsp check" }, "repository": { "type": "git", "url": "git://github.com/ljharb/is-callable.git" }, "keywords": [ "Function", "function", "callable", "generator", "generator function", "arrow", "arrow function", "ES6", "toStringTag", "@@toStringTag" ], "dependencies": {}, "devDependencies": { "@ljharb/eslint-config": "^12.2.1", "covert": "^1.1.0", "editorconfig-tools": "^0.1.1", "eslint": "^4.19.1", "foreach": "^2.0.5", "istanbul": "1.1.0-alpha.1", "istanbul-merge": "^1.1.1", "jscs": "^3.0.7", "make-arrow-function": "^1.1.0", "make-generator-function": "^1.1.0", "nsp": "^3.2.1", "rimraf": "^2.6.2", "semver": "^5.5.0", "tape": "^4.9.1" }, "testling": { "files": "test.js", "browsers": [ "iexplore/6.0..latest", "firefox/3.0..6.0", "firefox/15.0..latest", "firefox/nightly", "chrome/4.0..10.0", "chrome/20.0..latest", "chrome/canary", "opera/10.0..latest", "opera/next", "safari/4.0..latest", "ipad/6.0..latest", "iphone/6.0..latest", "android-browser/4.2" ] }, "engines": { "node": ">= 0.4" } } package/.editorconfig000644 0000000436 3560116604 011740 0ustar00000000 000000 root = true [*] indent_style = tab indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true max_line_length = 150 [CHANGELOG.md] indent_style = space indent_size = 2 [*.json] max_line_length = off [Makefile] max_line_length = off package/.eslintrc000644 0000000231 3560116604 011100 0ustar00000000 000000 { "root": true, "extends": "@ljharb", "rules": { "id-length": 0, "max-statements": [2, 12], "max-statements-per-line": [2, { "max": 2 }] } } package/.istanbul.yml000644 0000001741 3560116604 011705 0ustar00000000 000000 verbose: false instrumentation: root: . extensions: - .js - .jsx default-excludes: true excludes: [] variable: __coverage__ compact: true preserve-comments: false complete-copy: false save-baseline: false baseline-file: ./coverage/coverage-baseline.raw.json include-all-sources: false include-pid: false es-modules: false auto-wrap: false reporting: print: summary reports: - html dir: ./coverage summarizer: pkg report-config: {} watermarks: statements: [50, 80] functions: [50, 80] branches: [50, 80] lines: [50, 80] hooks: hook-run-in-context: false post-require-hook: null handle-sigint: false check: global: statements: 100 lines: 100 branches: 100 functions: 100 excludes: [] each: statements: 100 lines: 100 branches: 100 functions: 100 excludes: [] package/.jscs.json000644 0000010040 3560116604 011166 0ustar00000000 000000 { "es3": true, "additionalRules": [], "requireSemicolons": true, "disallowMultipleSpaces": true, "disallowIdentifierNames": [], "requireCurlyBraces": { "allExcept": [], "keywords": ["if", "else", "for", "while", "do", "try", "catch"] }, "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"], "disallowSpaceAfterKeywords": [], "disallowSpaceBeforeComma": true, "disallowSpaceAfterComma": false, "disallowSpaceBeforeSemicolon": true, "disallowNodeTypes": [ "DebuggerStatement", "ForInStatement", "LabeledStatement", "SwitchCase", "SwitchStatement", "WithStatement" ], "requireObjectKeysOnNewLine": { "allExcept": ["sameLine"] }, "requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true }, "requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true }, "disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true }, "requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true }, "disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true }, "requireSpaceBetweenArguments": true, "disallowSpacesInsideParentheses": true, "disallowSpacesInsideArrayBrackets": true, "disallowQuotedKeysInObjects": { "allExcept": ["reserved"] }, "disallowSpaceAfterObjectKeys": true, "requireCommaBeforeLineBreak": true, "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], "requireSpaceAfterPrefixUnaryOperators": [], "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], "requireSpaceBeforePostfixUnaryOperators": [], "disallowSpaceBeforeBinaryOperators": [], "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], "disallowSpaceAfterBinaryOperators": [], "disallowImplicitTypeConversion": ["binary", "string"], "disallowKeywords": ["with", "eval"], "requireKeywordsOnNewLine": [], "disallowKeywordsOnNewLine": ["else"], "requireLineFeedAtFileEnd": true, "disallowTrailingWhitespace": true, "disallowTrailingComma": true, "excludeFiles": ["node_modules/**", "vendor/**"], "disallowMultipleLineStrings": true, "requireDotNotation": { "allExcept": ["keywords"] }, "requireParenthesesAroundIIFE": true, "validateLineBreaks": "LF", "validateQuoteMarks": { "escape": true, "mark": "'" }, "disallowOperatorBeforeLineBreak": [], "requireSpaceBeforeKeywords": [ "do", "for", "if", "else", "switch", "case", "try", "catch", "finally", "while", "with", "return" ], "validateAlignedFunctionParameters": { "lineBreakAfterOpeningBraces": true, "lineBreakBeforeClosingBraces": true }, "requirePaddingNewLinesBeforeExport": true, "validateNewlineAfterArrayElements": { "maximum": 1 }, "requirePaddingNewLinesAfterUseStrict": true, "disallowArrowFunctions": true, "disallowMultiLineTernary": true, "validateOrderInObjectKeys": "asc-insensitive", "disallowIdenticalDestructuringNames": true, "disallowNestedTernaries": { "maxLevel": 1 }, "requireSpaceAfterComma": { "allExcept": ["trailing"] }, "requireAlignedMultilineParams": false, "requireSpacesInGenerator": { "afterStar": true }, "disallowSpacesInGenerator": { "beforeStar": true }, "disallowVar": false, "requireArrayDestructuring": false, "requireEnhancedObjectLiterals": false, "requireObjectDestructuring": false, "requireEarlyReturn": false, "requireCapitalizedConstructorsNew": { "allExcept": ["Function", "String", "Object", "Symbol", "Number", "Date", "RegExp", "Error", "Boolean", "Array"] }, "requireImportAlphabetized": false, "requireSpaceBeforeObjectValues": true, "requireSpaceBeforeDestructuredValues": true, "disallowSpacesInsideTemplateStringPlaceholders": true, "disallowArrayDestructuringReturn": false, "requireNewlineBeforeSingleStatementsInIf": false, "disallowUnusedVariables": true, "requireSpacesInsideImportedObjectBraces": true, "requireUseStrict": true } package/.travis.yml000644 0000015122 3560116604 011372 0ustar00000000 000000 language: node_js os: - linux node_js: - "10.4" - "9.11" - "8.11" - "7.10" - "6.14" - "5.12" - "4.9" - "iojs-v3.3" - "iojs-v2.5" - "iojs-v1.8" - "0.12" - "0.10" - "0.8" before_install: - 'case "${TRAVIS_NODE_VERSION}" in 0.*) export NPM_CONFIG_STRICT_SSL=false ;; esac' - 'nvm install-latest-npm' install: - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' script: - 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi' - 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi' - 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi' - 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi' sudo: false env: - TEST=true matrix: fast_finish: true include: - node_js: "lts/*" env: PRETEST=true - node_js: "lts/*" env: POSTTEST=true - node_js: "4" env: COVERAGE=true - node_js: "10.3" env: TEST=true ALLOW_FAILURE=true - node_js: "10.2" env: TEST=true ALLOW_FAILURE=true - node_js: "10.1" env: TEST=true ALLOW_FAILURE=true - node_js: "10.0" env: TEST=true ALLOW_FAILURE=true - node_js: "9.10" env: TEST=true ALLOW_FAILURE=true - node_js: "9.9" env: TEST=true ALLOW_FAILURE=true - node_js: "9.8" env: TEST=true ALLOW_FAILURE=true - node_js: "9.7" env: TEST=true ALLOW_FAILURE=true - node_js: "9.6" env: TEST=true ALLOW_FAILURE=true - node_js: "9.5" env: TEST=true ALLOW_FAILURE=true - node_js: "9.4" env: TEST=true ALLOW_FAILURE=true - node_js: "9.3" env: TEST=true ALLOW_FAILURE=true - node_js: "9.2" env: TEST=true ALLOW_FAILURE=true - node_js: "9.1" env: TEST=true ALLOW_FAILURE=true - node_js: "9.0" env: TEST=true ALLOW_FAILURE=true - node_js: "8.10" env: TEST=true ALLOW_FAILURE=true - node_js: "8.9" env: TEST=true ALLOW_FAILURE=true - node_js: "8.8" env: TEST=true ALLOW_FAILURE=true - node_js: "8.7" env: TEST=true ALLOW_FAILURE=true - node_js: "8.6" env: TEST=true ALLOW_FAILURE=true - node_js: "8.5" env: TEST=true ALLOW_FAILURE=true - node_js: "8.4" env: TEST=true ALLOW_FAILURE=true - node_js: "8.3" env: TEST=true ALLOW_FAILURE=true - node_js: "8.2" env: TEST=true ALLOW_FAILURE=true - node_js: "8.1" env: TEST=true ALLOW_FAILURE=true - node_js: "8.0" env: TEST=true ALLOW_FAILURE=true - node_js: "7.9" env: TEST=true ALLOW_FAILURE=true - node_js: "7.8" env: TEST=true ALLOW_FAILURE=true - node_js: "7.7" env: TEST=true ALLOW_FAILURE=true - node_js: "7.6" env: TEST=true ALLOW_FAILURE=true - node_js: "7.5" env: TEST=true ALLOW_FAILURE=true - node_js: "7.4" env: TEST=true ALLOW_FAILURE=true - node_js: "7.3" env: TEST=true ALLOW_FAILURE=true - node_js: "7.2" env: TEST=true ALLOW_FAILURE=true - node_js: "7.1" env: TEST=true ALLOW_FAILURE=true - node_js: "7.0" env: TEST=true ALLOW_FAILURE=true - node_js: "6.13" env: TEST=true ALLOW_FAILURE=true - node_js: "6.12" env: TEST=true ALLOW_FAILURE=true - node_js: "6.11" env: TEST=true ALLOW_FAILURE=true - node_js: "6.10" env: TEST=true ALLOW_FAILURE=true - node_js: "6.9" env: TEST=true ALLOW_FAILURE=true - node_js: "6.8" env: TEST=true ALLOW_FAILURE=true - node_js: "6.7" env: TEST=true ALLOW_FAILURE=true - node_js: "6.6" env: TEST=true ALLOW_FAILURE=true - node_js: "6.5" env: TEST=true ALLOW_FAILURE=true - node_js: "6.4" env: TEST=true ALLOW_FAILURE=true - node_js: "6.3" env: TEST=true ALLOW_FAILURE=true - node_js: "6.2" env: TEST=true ALLOW_FAILURE=true - node_js: "6.1" env: TEST=true ALLOW_FAILURE=true - node_js: "6.0" env: TEST=true ALLOW_FAILURE=true - node_js: "5.11" env: TEST=true ALLOW_FAILURE=true - node_js: "5.10" env: TEST=true ALLOW_FAILURE=true - node_js: "5.9" env: TEST=true ALLOW_FAILURE=true - node_js: "5.8" env: TEST=true ALLOW_FAILURE=true - node_js: "5.7" env: TEST=true ALLOW_FAILURE=true - node_js: "5.6" env: TEST=true ALLOW_FAILURE=true - node_js: "5.5" env: TEST=true ALLOW_FAILURE=true - node_js: "5.4" env: TEST=true ALLOW_FAILURE=true - node_js: "5.3" env: TEST=true ALLOW_FAILURE=true - node_js: "5.2" env: TEST=true ALLOW_FAILURE=true - node_js: "5.1" env: TEST=true ALLOW_FAILURE=true - node_js: "5.0" env: TEST=true ALLOW_FAILURE=true - node_js: "4.8" env: TEST=true ALLOW_FAILURE=true - node_js: "4.7" env: TEST=true ALLOW_FAILURE=true - node_js: "4.6" env: TEST=true ALLOW_FAILURE=true - node_js: "4.5" env: TEST=true ALLOW_FAILURE=true - node_js: "4.4" env: TEST=true ALLOW_FAILURE=true - node_js: "4.3" env: TEST=true ALLOW_FAILURE=true - node_js: "4.2" env: TEST=true ALLOW_FAILURE=true - node_js: "4.1" env: TEST=true ALLOW_FAILURE=true - node_js: "4.0" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v3.2" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v3.1" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v3.0" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v2.4" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v2.3" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v2.2" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v2.1" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v2.0" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v1.7" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v1.6" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v1.5" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v1.4" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v1.3" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v1.2" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v1.1" env: TEST=true ALLOW_FAILURE=true - node_js: "iojs-v1.0" env: TEST=true ALLOW_FAILURE=true - node_js: "0.11" env: TEST=true ALLOW_FAILURE=true - node_js: "0.9" env: TEST=true ALLOW_FAILURE=true - node_js: "0.6" env: TEST=true ALLOW_FAILURE=true - node_js: "0.4" env: TEST=true ALLOW_FAILURE=true allow_failures: - os: osx - env: TEST=true ALLOW_FAILURE=true - env: COVERAGE=true package/CHANGELOG.md000644 0000003730 3560116604 011074 0ustar00000000 000000 1.1.4 / 2018-07-02 ================= * [Fix] improve `class` and arrow function detection (#30, #31) * [Tests] on all latest node minors; improve matrix * [Dev Deps] update all dev deps 1.1.3 / 2016-02-27 ================= * [Fix] ensure “class “ doesn’t screw up “class” detection * [Tests] up to `node` `v5.7`, `v4.3` * [Dev Deps] update to `eslint` v2, `@ljharb/eslint-config`, `jscs` 1.1.2 / 2016-01-15 ================= * [Fix] Make sure comments don’t screw up “class” detection (#4) * [Tests] up to `node` `v5.3` * [Tests] Add `parallelshell`, run both `--es-staging` and stock tests at once * [Dev Deps] update `tape`, `jscs`, `nsp`, `eslint`, `@ljharb/eslint-config` * [Refactor] convert `isNonES6ClassFn` into `isES6ClassFn` 1.1.1 / 2015-11-30 ================= * [Fix] do not throw when a non-function has a function in its [[Prototype]] (#2) * [Dev Deps] update `tape`, `eslint`, `@ljharb/eslint-config`, `jscs`, `nsp`, `semver` * [Tests] up to `node` `v5.1` * [Tests] no longer allow node 0.8 to fail. * [Tests] fix npm upgrades in older nodes 1.1.0 / 2015-10-02 ================= * [Fix] Some browsers report TypedArray constructors as `typeof object` * [New] return false for "class" constructors, when possible. * [Tests] up to `io.js` `v3.3`, `node` `v4.1` * [Dev Deps] update `eslint`, `editorconfig-tools`, `nsp`, `tape`, `semver`, `jscs`, `covert`, `make-arrow-function` * [Docs] Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG 1.0.4 / 2015-01-30 ================= * If @@toStringTag is not present, use the old-school Object#toString test. 1.0.3 / 2015-01-29 ================= * Add tests to ensure arrow functions are callable. * Refactor to aid optimization of non-try/catch code. 1.0.2 / 2015-01-29 ================= * Fix broken package.json 1.0.1 / 2015-01-29 ================= * Add early exit for typeof not "function" 1.0.0 / 2015-01-29 ================= * Initial release. package/index.js000644 0000002131 3560116604 010722 0ustar00000000 000000 'use strict'; var fnToStr = Function.prototype.toString; var constructorRegex = /^\s*class\b/; var isES6ClassFn = function isES6ClassFunction(value) { try { var fnStr = fnToStr.call(value); return constructorRegex.test(fnStr); } catch (e) { return false; // not a function } }; var tryFunctionObject = function tryFunctionToStr(value) { try { if (isES6ClassFn(value)) { return false; } fnToStr.call(value); return true; } catch (e) { return false; } }; var toStr = Object.prototype.toString; var fnClass = '[object Function]'; var genClass = '[object GeneratorFunction]'; var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; module.exports = function isCallable(value) { if (!value) { return false; } if (typeof value !== 'function' && typeof value !== 'object') { return false; } if (typeof value === 'function' && !value.prototype) { return true; } if (hasToStringTag) { return tryFunctionObject(value); } if (isES6ClassFn(value)) { return false; } var strClass = toStr.call(value); return strClass === fnClass || strClass === genClass; }; package/LICENSE000644 0000002072 3560116604 010266 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2015 Jordan Harband Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/Makefile000644 0000007372 3560116604 010731 0ustar00000000 000000 # Since we rely on paths relative to the makefile location, abort if make isn't being run from there. $(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in)) # The files that need updating when incrementing the version number. VERSIONED_FILES := *.js *.json README* # Add the local npm packages' bin folder to the PATH, so that `make` can find them, when invoked directly. # Note that rather than using `$(npm bin)` the 'node_modules/.bin' path component is hard-coded, so that invocation works even from an environment # where npm is (temporarily) unavailable due to having deactivated an nvm instance loaded into the calling shell in order to avoid interference with tests. export PATH := $(shell printf '%s' "$$PWD/node_modules/.bin:$$PATH") UTILS := semver # Make sure that all required utilities can be located. UTIL_CHECK := $(or $(shell PATH="$(PATH)" which $(UTILS) >/dev/null && echo 'ok'),$(error Did you forget to run `npm install` after cloning the repo? At least one of the required supporting utilities not found: $(UTILS))) # Default target (by virtue of being the first non '.'-prefixed in the file). .PHONY: _no-target-specified _no-target-specified: $(error Please specify the target to make - `make list` shows targets. Alternatively, use `npm test` to run the default tests; `npm run` shows all tests) # Lists all targets defined in this makefile. .PHONY: list list: @$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | command grep -v -e '^[^[:alnum:]]' -e '^$@$$command ' | sort # All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS). .PHONY: test test: @npm test .PHONY: _ensure-tag _ensure-tag: ifndef TAG $(error Please invoke with `make TAG= release`, where is either an increment specifier (patch, minor, major, prepatch, preminor, premajor, prerelease), or an explicit major.minor.patch version number) endif CHANGELOG_ERROR = $(error No CHANGELOG specified) .PHONY: _ensure-changelog _ensure-changelog: @ (git status -sb --porcelain | command grep -E '^( M|[MA] ) CHANGELOG.md' > /dev/null) || (echo no CHANGELOG.md specified && exit 2) # Ensures that the git workspace is clean. .PHONY: _ensure-clean _ensure-clean: @[ -z "$$((git status --porcelain --untracked-files=no || echo err) | command grep -v 'CHANGELOG.md')" ] || { echo "Workspace is not clean; please commit changes first." >&2; exit 2; } # Makes a release; invoke with `make TAG= release`. .PHONY: release release: _ensure-tag _ensure-changelog _ensure-clean @old_ver=`git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*'` || { echo "Failed to determine current version." >&2; exit 1; }; old_ver=$${old_ver#v}; \ new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \ if printf "$$new_ver" | command grep -q '^[0-9]'; then \ semver "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be major.minor.patch' >&2; exit 2; }; \ semver -r "> $$old_ver" "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be HIGHER than current one.' >&2; exit 2; } \ else \ new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \ fi; \ printf "=== Bumping version **$$old_ver** to **$$new_ver** before committing and tagging:\n=== TYPE 'proceed' TO PROCEED, anything else to abort: " && read response && [ "$$response" = 'proceed' ] || { echo 'Aborted.' >&2; exit 2; }; \ replace "$$old_ver" "$$new_ver" -- $(VERSIONED_FILES) && \ git commit -m "v$$new_ver" $(VERSIONED_FILES) CHANGELOG.md && \ git tag -a -m "v$$new_ver" "v$$new_ver" package/README.md000644 0000003672 3560116604 010547 0ustar00000000 000000 # is-callable [![Version Badge][2]][1] [![Build Status][3]][4] [![dependency status][5]][6] [![dev dependency status][7]][8] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][11]][1] [![browser support][9]][10] Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag. ## Example ```js var isCallable = require('is-callable'); var assert = require('assert'); assert.notOk(isCallable(undefined)); assert.notOk(isCallable(null)); assert.notOk(isCallable(false)); assert.notOk(isCallable(true)); assert.notOk(isCallable([])); assert.notOk(isCallable({})); assert.notOk(isCallable(/a/g)); assert.notOk(isCallable(new RegExp('a', 'g'))); assert.notOk(isCallable(new Date())); assert.notOk(isCallable(42)); assert.notOk(isCallable(NaN)); assert.notOk(isCallable(Infinity)); assert.notOk(isCallable(new Number(42))); assert.notOk(isCallable('foo')); assert.notOk(isCallable(Object('foo'))); assert.ok(isCallable(function () {})); assert.ok(isCallable(function* () {})); assert.ok(isCallable(x => x * x)); ``` ## Tests Simply clone the repo, `npm install`, and run `npm test` [1]: https://npmjs.org/package/is-callable [2]: http://versionbadg.es/ljharb/is-callable.svg [3]: https://travis-ci.org/ljharb/is-callable.svg [4]: https://travis-ci.org/ljharb/is-callable [5]: https://david-dm.org/ljharb/is-callable.svg [6]: https://david-dm.org/ljharb/is-callable [7]: https://david-dm.org/ljharb/is-callable/dev-status.svg [8]: https://david-dm.org/ljharb/is-callable#info=devDependencies [9]: https://ci.testling.com/ljharb/is-callable.png [10]: https://ci.testling.com/ljharb/is-callable [11]: https://nodei.co/npm/is-callable.png?downloads=true&stars=true [license-image]: http://img.shields.io/npm/l/is-callable.svg [license-url]: LICENSE [downloads-image]: http://img.shields.io/npm/dm/is-callable.svg [downloads-url]: http://npm-stat.com/charts.html?package=is-callable package/test.js000644 0000012645 3560116604 010605 0ustar00000000 000000 'use strict'; /* eslint no-magic-numbers: 1 */ var test = require('tape'); var isCallable = require('./'); var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol'; var genFn = require('make-generator-function'); var arrowFn = require('make-arrow-function')(); var weirdlyCommentedArrowFn; var asyncFn; var asyncArrowFn; try { /* eslint no-new-func: 0 */ weirdlyCommentedArrowFn = Function('return cl/*/**/=>/**/ass - 1;')(); asyncFn = Function('return async function foo() {};')(); asyncArrowFn = Function('return async () => {};')(); } catch (e) { /**/ } var forEach = require('foreach'); var noop = function () {}; var classFake = function classFake() { }; // eslint-disable-line func-name-matching var returnClass = function () { return ' class '; }; var return3 = function () { return 3; }; /* for coverage */ noop(); classFake(); returnClass(); return3(); /* end for coverage */ var invokeFunction = function invokeFunctionString(str) { var result; try { /* eslint-disable no-new-func */ var fn = Function(str); /* eslint-enable no-new-func */ result = fn(); } catch (e) {} return result; }; var classConstructor = invokeFunction('"use strict"; return class Foo {}'); var commentedClass = invokeFunction('"use strict"; return class/*kkk*/\n//blah\n Bar\n//blah\n {}'); var commentedClassOneLine = invokeFunction('"use strict"; return class/**/A{}'); var classAnonymous = invokeFunction('"use strict"; return class{}'); var classAnonymousCommentedOneLine = invokeFunction('"use strict"; return class/*/*/{}'); test('not callables', function (t) { t.test('non-number/string primitives', function (st) { st.notOk(isCallable(), 'undefined is not callable'); st.notOk(isCallable(null), 'null is not callable'); st.notOk(isCallable(false), 'false is not callable'); st.notOk(isCallable(true), 'true is not callable'); st.end(); }); t.notOk(isCallable([]), 'array is not callable'); t.notOk(isCallable({}), 'object is not callable'); t.notOk(isCallable(/a/g), 'regex literal is not callable'); t.notOk(isCallable(new RegExp('a', 'g')), 'regex object is not callable'); t.notOk(isCallable(new Date()), 'new Date() is not callable'); t.test('numbers', function (st) { st.notOk(isCallable(42), 'number is not callable'); st.notOk(isCallable(Object(42)), 'number object is not callable'); st.notOk(isCallable(NaN), 'NaN is not callable'); st.notOk(isCallable(Infinity), 'Infinity is not callable'); st.end(); }); t.test('strings', function (st) { st.notOk(isCallable('foo'), 'string primitive is not callable'); st.notOk(isCallable(Object('foo')), 'string object is not callable'); st.end(); }); t.test('non-function with function in its [[Prototype]] chain', function (st) { var Foo = function Bar() {}; Foo.prototype = noop; st.equal(true, isCallable(Foo), 'sanity check: Foo is callable'); st.equal(false, isCallable(new Foo()), 'instance of Foo is not callable'); st.end(); }); t.end(); }); test('@@toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (t) { var fakeFunction = { toString: function () { return String(return3); }, valueOf: return3 }; fakeFunction[Symbol.toStringTag] = 'Function'; t.equal(String(fakeFunction), String(return3)); t.equal(Number(fakeFunction), return3()); t.notOk(isCallable(fakeFunction), 'fake Function with @@toStringTag "Function" is not callable'); t.end(); }); var typedArrayNames = [ 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array' ]; test('Functions', function (t) { t.ok(isCallable(noop), 'function is callable'); t.ok(isCallable(classFake), 'function with name containing "class" is callable'); t.ok(isCallable(returnClass), 'function with string " class " is callable'); t.ok(isCallable(isCallable), 'isCallable is callable'); t.end(); }); test('Typed Arrays', function (st) { forEach(typedArrayNames, function (typedArray) { /* istanbul ignore if : covered in node 0.6 */ if (typeof global[typedArray] === 'undefined') { st.comment('# SKIP typed array "' + typedArray + '" not supported'); } else { st.ok(isCallable(global[typedArray]), typedArray + ' is callable'); } }); st.end(); }); test('Generators', { skip: !genFn }, function (t) { t.ok(isCallable(genFn), 'generator function is callable'); t.end(); }); test('Arrow functions', { skip: !arrowFn }, function (t) { t.ok(isCallable(arrowFn), 'arrow function is callable'); t.ok(isCallable(weirdlyCommentedArrowFn), 'weirdly commented arrow functions are callable'); t.end(); }); test('"Class" constructors', { skip: !classConstructor || !commentedClass || !commentedClassOneLine || !classAnonymous }, function (t) { t.notOk(isCallable(classConstructor), 'class constructors are not callable'); t.notOk(isCallable(commentedClass), 'class constructors with comments in the signature are not callable'); t.notOk(isCallable(commentedClassOneLine), 'one-line class constructors with comments in the signature are not callable'); t.notOk(isCallable(classAnonymous), 'anonymous class constructors are not callable'); t.notOk(isCallable(classAnonymousCommentedOneLine), 'anonymous one-line class constructors with comments in the signature are not callable'); t.end(); }); test('`async function`s', { skip: !asyncFn }, function (t) { t.ok(isCallable(asyncFn), '`async function`s are callable'); t.ok(isCallable(asyncArrowFn), '`async` arrow functions are callable'); t.end(); });