forked from daren.hsu/line_push
update
This commit is contained in:
+6
@@ -12,9 +12,15 @@ max_line_length = 150
|
||||
[CHANGELOG.md]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
max_line_length = off
|
||||
|
||||
[*.json]
|
||||
max_line_length = off
|
||||
|
||||
[Makefile]
|
||||
max_line_length = off
|
||||
|
||||
[coverage*/**/*]
|
||||
indent_style = off
|
||||
indent_size = off
|
||||
max_line_length = off
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
coverage/
|
||||
+10
-1
@@ -5,8 +5,17 @@
|
||||
|
||||
"rules": {
|
||||
"id-length": 0,
|
||||
"max-statements": [2, 12],
|
||||
"max-statements": [2, 14],
|
||||
"max-statements-per-line": [2, { "max": 2 }],
|
||||
"operator-linebreak": [2, "before"],
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"files": "test/**",
|
||||
"rules": {
|
||||
"no-throw-literal": 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
+33
@@ -1,3 +1,36 @@
|
||||
1.2.4 / 2021-08-05
|
||||
=================
|
||||
* [Fix] use `has-tostringtag` approach to behave correctly in the presence of symbol shams
|
||||
* [readme] fix repo URLs
|
||||
* [readme] add actions and codecov badges
|
||||
* [readme] remove defunct badges
|
||||
* [meta] ignore eclint checking coverage output
|
||||
* [meta] use `prepublishOnly` script for npm 7+
|
||||
* [actions] use `node/install` instead of `node/run`; use `codecov` action
|
||||
* [actions] remove unused workflow file
|
||||
* [Tests] run `nyc` on all tests; use `tape` runner
|
||||
* [Tests] use `available-typed-arrays`, `for-each`, `has-symbols`, `object-inspect`
|
||||
* [Dev Deps] update `available-typed-arrays`, `eslint`, `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape`
|
||||
|
||||
1.2.3 / 2021-01-31
|
||||
=================
|
||||
* [Fix] `document.all` is callable (do not use `document.all`!)
|
||||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape`
|
||||
* [Tests] migrate tests to Github Actions
|
||||
* [actions] add "Allow Edits" workflow
|
||||
* [actions] switch Automatic Rebase workflow to `pull_request_target` event
|
||||
|
||||
1.2.2 / 2020-09-21
|
||||
=================
|
||||
* [Fix] include actual fix from 579179e
|
||||
* [Dev Deps] update `eslint`
|
||||
|
||||
1.2.1 / 2020-09-09
|
||||
=================
|
||||
* [Fix] phantomjs‘ Reflect.apply does not throw properly on a bad array-like
|
||||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`
|
||||
* [meta] fix eclint error
|
||||
|
||||
1.2.0 / 2020-06-02
|
||||
=================
|
||||
* [New] use `Reflect.apply`‑based callability detection
|
||||
|
||||
+14
-15
@@ -1,6 +1,7 @@
|
||||
# is-callable <sup>[![Version Badge][2]][1]</sup>
|
||||
|
||||
[![Build Status][3]][4]
|
||||
[![github actions][actions-image]][actions-url]
|
||||
[![coverage][codecov-image]][codecov-url]
|
||||
[![dependency status][5]][6]
|
||||
[![dev dependency status][7]][8]
|
||||
[![License][license-image]][license-url]
|
||||
@@ -8,8 +9,6 @@
|
||||
|
||||
[![npm badge][11]][1]
|
||||
|
||||
[![browser support][9]][10]
|
||||
|
||||
Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.
|
||||
|
||||
## Example
|
||||
@@ -52,17 +51,17 @@ npm install is-callable
|
||||
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
|
||||
[2]: https://versionbadg.es/inspect-js/is-callable.svg
|
||||
[5]: https://david-dm.org/inspect-js/is-callable.svg
|
||||
[6]: https://david-dm.org/inspect-js/is-callable
|
||||
[7]: https://david-dm.org/inspect-js/is-callable/dev-status.svg
|
||||
[8]: https://david-dm.org/inspect-js/is-callable#info=devDependencies
|
||||
[11]: https://nodei.co/npm/is-callable.png?downloads=true&stars=true
|
||||
[license-image]: http://img.shields.io/npm/l/is-callable.svg
|
||||
[license-image]: https://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
|
||||
[downloads-image]: https://img.shields.io/npm/dm/is-callable.svg
|
||||
[downloads-url]: https://npm-stat.com/charts.html?package=is-callable
|
||||
[codecov-image]: https://codecov.io/gh/inspect-js/is-callable/branch/main/graphs/badge.svg
|
||||
[codecov-url]: https://app.codecov.io/gh/inspect-js/is-callable/
|
||||
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/is-callable
|
||||
[actions-url]: https://github.com/inspect-js/is-callable/actions
|
||||
|
||||
+10
-2
@@ -12,8 +12,12 @@ if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'func
|
||||
}
|
||||
});
|
||||
isCallableMarker = {};
|
||||
// eslint-disable-next-line no-throw-literal
|
||||
reflectApply(function () { throw 42; }, null, badArrayLike);
|
||||
} catch (_) {
|
||||
reflectApply = null;
|
||||
if (_ !== isCallableMarker) {
|
||||
reflectApply = null;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reflectApply = null;
|
||||
@@ -41,10 +45,13 @@ var tryFunctionObject = function tryFunctionToStr(value) {
|
||||
var toStr = Object.prototype.toString;
|
||||
var fnClass = '[object Function]';
|
||||
var genClass = '[object GeneratorFunction]';
|
||||
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
|
||||
var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag; // better: use `has-tostringtag`
|
||||
/* globals document: false */
|
||||
var documentDotAll = typeof document === 'object' && typeof document.all === 'undefined' && document.all !== undefined ? document.all : {};
|
||||
|
||||
module.exports = reflectApply
|
||||
? function isCallable(value) {
|
||||
if (value === documentDotAll) { return true; }
|
||||
if (!value) { return false; }
|
||||
if (typeof value !== 'function' && typeof value !== 'object') { return false; }
|
||||
if (typeof value === 'function' && !value.prototype) { return true; }
|
||||
@@ -56,6 +63,7 @@ module.exports = reflectApply
|
||||
return !isES6ClassFn(value);
|
||||
}
|
||||
: function isCallable(value) {
|
||||
if (value === documentDotAll) { return true; }
|
||||
if (!value) { return false; }
|
||||
if (typeof value !== 'function' && typeof value !== 'object') { return false; }
|
||||
if (typeof value === 'function' && !value.prototype) { return true; }
|
||||
|
||||
+30
-38
@@ -1,40 +1,40 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"is-callable@1.2.0",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"is-callable@1.2.4",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "is-callable@1.2.0",
|
||||
"_id": "is-callable@1.2.0",
|
||||
"_from": "is-callable@1.2.4",
|
||||
"_id": "is-callable@1.2.4",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-pyVD9AaGLxtg6srb2Ng6ynWJqkHU9bEM087AKck0w8QwDarTfNcpIYoU8x8Hv2Icm8u6kFJM18Dag8lyqGkviw==",
|
||||
"_integrity": "sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w==",
|
||||
"_location": "/is-callable",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "is-callable@1.2.0",
|
||||
"raw": "is-callable@1.2.4",
|
||||
"name": "is-callable",
|
||||
"escapedName": "is-callable",
|
||||
"rawSpec": "1.2.0",
|
||||
"rawSpec": "1.2.4",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.2.0"
|
||||
"fetchSpec": "1.2.4"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/es-abstract",
|
||||
"/es-to-primitive"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz",
|
||||
"_spec": "1.2.0",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.4.tgz",
|
||||
"_spec": "1.2.4",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Jordan Harband",
|
||||
"email": "ljharb@gmail.com",
|
||||
"url": "http://ljharb.codes"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/ljharb/is-callable/issues"
|
||||
"url": "https://github.com/inspect-js/is-callable/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
@@ -43,23 +43,24 @@
|
||||
"url": "http://ljharb.codes"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"description": "Is this JS value callable? Works with Functions and GeneratorFunctions, despite ES6 @@toStringTag.",
|
||||
"devDependencies": {
|
||||
"@ljharb/eslint-config": "^17.1.0",
|
||||
"aud": "^1.1.2",
|
||||
"covert": "^1.1.1",
|
||||
"@ljharb/eslint-config": "^17.6.0",
|
||||
"aud": "^1.1.5",
|
||||
"available-typed-arrays": "^1.0.4",
|
||||
"eclint": "^2.8.1",
|
||||
"eslint": "^7.1.0",
|
||||
"foreach": "^2.0.5",
|
||||
"istanbul": "1.1.0-alpha.1",
|
||||
"istanbul-merge": "^1.1.1",
|
||||
"es-value-fixtures": "^1.2.1",
|
||||
"eslint": "^7.32.0",
|
||||
"for-each": "^0.3.3",
|
||||
"has-tostringtag": "^1.0.0",
|
||||
"make-arrow-function": "^1.2.0",
|
||||
"make-async-function": "^1.0.0",
|
||||
"make-generator-function": "^2.0.0",
|
||||
"nyc": "^10.3.2",
|
||||
"object-inspect": "^1.11.0",
|
||||
"rimraf": "^2.7.1",
|
||||
"safe-publish-latest": "^1.1.4",
|
||||
"tape": "^5.0.1"
|
||||
"tape": "^5.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
@@ -72,7 +73,7 @@
|
||||
"rimraf"
|
||||
]
|
||||
},
|
||||
"homepage": "https://github.com/ljharb/is-callable#readme",
|
||||
"homepage": "https://github.com/inspect-js/is-callable#readme",
|
||||
"keywords": [
|
||||
"Function",
|
||||
"function",
|
||||
@@ -90,26 +91,17 @@
|
||||
"name": "is-callable",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/ljharb/is-callable.git"
|
||||
"url": "git://github.com/inspect-js/is-callable.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "npm run --silent istanbul",
|
||||
"covert": "covert test",
|
||||
"covert:quiet": "covert test --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:harmony": "node --harmony ./node_modules/istanbul/lib/cli.js cover test --dir 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:std": "istanbul cover test --report html --dir coverage-std",
|
||||
"lint": "eslint .",
|
||||
"posttest": "npx aud --production",
|
||||
"posttest": "aud --production",
|
||||
"prelint": "eclint check *",
|
||||
"prepublish": "safe-publish-latest",
|
||||
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||
"prepublishOnly": "safe-publish-latest",
|
||||
"pretest": "npm run --silent lint",
|
||||
"test": "npm run --silent tests-only",
|
||||
"test:staging": "node --es-staging test",
|
||||
"test:stock": "node test",
|
||||
"tests-only": "npm run --silent test:stock && npm run --silent test:staging"
|
||||
"test": "npm run tests-only --",
|
||||
"tests-only": "nyc tape 'test/**/*.js'"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/index.js",
|
||||
@@ -129,5 +121,5 @@
|
||||
"android-browser/4.2"
|
||||
]
|
||||
},
|
||||
"version": "1.2.0"
|
||||
"version": "1.2.4"
|
||||
}
|
||||
|
||||
+36
-49
@@ -5,7 +5,11 @@
|
||||
|
||||
var test = require('tape');
|
||||
var isCallable = require('../');
|
||||
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
|
||||
var hasToStringTag = require('has-tostringtag/shams')();
|
||||
var v = require('es-value-fixtures');
|
||||
var forEach = require('for-each');
|
||||
var inspect = require('object-inspect');
|
||||
var typedArrayNames = require('available-typed-arrays')();
|
||||
var generators = require('make-generator-function')();
|
||||
var arrows = require('make-arrow-function').list();
|
||||
var asyncs = require('make-async-function').list();
|
||||
@@ -15,7 +19,6 @@ try {
|
||||
weirdlyCommentedArrowFn = Function('return cl/*/**/=>/**/ass - 1;')();
|
||||
/* eslint-enable no-new-func */
|
||||
} catch (e) { /**/ }
|
||||
var forEach = require('foreach');
|
||||
|
||||
var noop = function () {};
|
||||
var classFake = function classFake() { }; // eslint-disable-line func-name-matching
|
||||
@@ -63,46 +66,32 @@ 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(), 'implicit undefined is not callable');
|
||||
|
||||
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();
|
||||
forEach(v.nonFunctions.concat([
|
||||
Object(42),
|
||||
Object('foo'),
|
||||
NaN,
|
||||
[],
|
||||
/a/g,
|
||||
new RegExp('a', 'g'),
|
||||
new Date()
|
||||
]), function (nonFunction) {
|
||||
t.equal(isCallable(nonFunction), false, inspect(nonFunction) + ' is not callable');
|
||||
});
|
||||
|
||||
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.equal(isCallable(Foo), true, 'sanity check: Foo is callable');
|
||||
st.equal(isCallable(new Foo()), false, 'instance of Foo is not callable');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('@@toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (t) {
|
||||
test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
|
||||
var fakeFunction = {
|
||||
toString: function () { return String(return3); },
|
||||
valueOf: return3
|
||||
@@ -114,18 +103,6 @@ test('@@toStringTag', { skip: !hasSymbols || !Symbol.toStringTag }, function (t)
|
||||
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');
|
||||
@@ -134,14 +111,9 @@ test('Functions', function (t) {
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Typed Arrays', function (st) {
|
||||
test('Typed Arrays', { skip: typedArrayNames.length === 0 }, 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.ok(isCallable(global[typedArray]), typedArray + ' is callable');
|
||||
});
|
||||
st.end();
|
||||
});
|
||||
@@ -181,3 +153,18 @@ test('proxies of functions', { skip: !proxy }, function (t) {
|
||||
t.ok(isCallable(proxy), 'proxies of functions are callable');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('throwing functions', function (t) {
|
||||
t.plan(1);
|
||||
|
||||
var thrower = function (a) { return a.b; };
|
||||
t.ok(isCallable(thrower), 'a function that throws is callable');
|
||||
});
|
||||
|
||||
/* globals document: false */
|
||||
test('document.all', { skip: typeof document !== 'object' }, function (t) {
|
||||
t.notOk(isCallable(document), 'document is not callable');
|
||||
t.ok(isCallable(document.all), 'document.all is callable');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user