package/package.json000644 000765 000024 0000002160 12371730162013016 0ustar00000000 000000 { "name": "is-arrow-function", "version": "1.0.2", "description": "Determine if a function is an ES6 arrow function or not.", "main": "index.js", "scripts": { "test": "node --harmony test/index.js", "coverage": "covert test/index.js", "coverage-quiet": "covert test/index.js --quiet" }, "repository": { "type": "git", "url": "git://github.com/ljharb/node-is-arrow-function.git" }, "keywords": [ "arrow", "arrow function", "es6", "fat", "fat arrow", "function", "=>" ], "author": "Jordan Harband", "license": "MIT", "bugs": { "url": "https://github.com/ljharb/node-is-arrow-function/issues" }, "dependencies": {}, "devDependencies": { "tape": "~2.14.0", "covert": "~0.4.0" }, "testling": { "files": "test/index.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/.npmignore000644 000765 000024 0000000143 12214515400012516 0ustar00000000 000000 lib-cov *.seed *.log *.csv *.dat *.out *.pid *.gz pids logs results npm-debug.log node_modules/ package/README.md000644 000765 000024 0000002353 12236370636012021 0ustar00000000 000000 #is-arrow-function [![Version Badge][2]][1] [![Build Status][3]][4] [![dependency status][5]][6] [![dev dependency status][7]][8] [![npm badge][11]][1] [![browser support][9]][10] npm module to determine if a function is an ES6 arrow function or not. NOTE: Only works in Firefox at the moment. ## Example ```js var isArrowFunction = require('is-arrow-function'); assert(!isArrowFunction(function () {})); assert(!isArrowFunction(null)); assert(isArrowFunction((a, b) => a * b)); ``` ## Tests Simply clone the repo, `npm install`, and run `npm test` [1]: https://npmjs.org/package/is-arrow-function [2]: http://vb.teelaun.ch/ljharb/node-is-arrow-function.svg [3]: https://travis-ci.org/ljharb/node-is-arrow-function.png [4]: https://travis-ci.org/ljharb/node-is-arrow-function [5]: https://david-dm.org/ljharb/node-is-arrow-function.png [6]: https://david-dm.org/ljharb/node-is-arrow-function [7]: https://david-dm.org/ljharb/node-is-arrow-function/dev-status.png [8]: https://david-dm.org/ljharb/node-is-arrow-function#info=devDependencies [9]: https://ci.testling.com/ljharb/node-is-arrow-function.png [10]: https://ci.testling.com/ljharb/node-is-arrow-function [11]: https://nodei.co/npm/is-arrow-function.png?downloads=true&stars=true package/LICENSE000644 000765 000024 0000002071 12214511051011524 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2013 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/index.js000644 000765 000024 0000000437 12257224614012205 0ustar00000000 000000 var toStr = Object.prototype.toString; var fnToStr = Function.prototype.toString; var isFnRegex = /^\s*function/; module.exports = function isArrowFunction(fn) { "use strict"; var fnStr = toStr.call(fn); return fnStr === '[object Function]' && !isFnRegex.test(fnToStr.call(fn)); }; package/.nvmrc000644 000765 000024 0000000006 12313521356011652 0ustar00000000 000000 0.11 package/.travis.yml000644 000765 000024 0000000466 12321443517012650 0ustar00000000 000000 language: node_js node_js: - "0.11" - "0.10" - "0.9" - "0.8" - "0.6" - "0.4" before_install: - '[ "${TRAVIS_NODE_VERSION}" == "0.6" ] || npm install -g npm@~1.4.6' matrix: fast_finish: true allow_failures: - node_js: "0.11" - node_js: "0.9" - node_js: "0.6" - node_js: "0.4" package/test/index.js000644 000765 000024 0000003423 12311254261013152 0ustar00000000 000000 "use strict"; var test = require('tape'); var isArrowFunction = require('../index'); var arrowFunc = require('../test/make-arrow-fn'); var forEach = function (arr, func) { var i; for (i = 0; i < arr.length; ++i) { func(arr[i], i, arr); } }; test('returns false for non-functions', function (t) { var nonFuncs = [ true, false, null, undefined, {}, [], /a/g, 'string', 42, new Date() ]; t.plan(nonFuncs.length); forEach(nonFuncs, function (nonFunc) { t.notOk(isArrowFunction(nonFunc), nonFunc + ' is not a function'); }); t.end(); }); test('returns false for non-arrow functions', function (t) { var func = function () {}; t.notOk(isArrowFunction(func), 'anonymous function is not an arrow function'); var namedFunc = function foo() {}; t.notOk(isArrowFunction(namedFunc), 'named function is not an arrow function'); if (typeof window !== 'undefined') { t.notOk(isArrowFunction(window.alert), 'window.alert is not an arrow function'); } else { t.skip('window.alert is not an arrow function'); } t.end(); }); test('returns false for non-arrow function with faked toString', function (t) { var func = function () {}; func.toString = function () { return 'ARROW'; }; t.notEqual(String(func), Function.prototype.toString.call(func), 'test function has faked toString that is different from default toString'); t.notOk(isArrowFunction(func), 'anonymous function with faked toString is not an arrow function'); t.end(); }); test('returns true for arrow functions', function (t) { if (arrowFunc) { t.ok(isArrowFunction(arrowFunc), 'arrow function is arrow function'); } else { t.skip('arrow function is arrow function - this environment does not support ES6 arrow functions. Please run `node --harmony`, or use a supporting browser.'); } t.end(); }); package/test/make-arrow-fn.js000644 000765 000024 0000000315 12255635316014521 0ustar00000000 000000 "use strict"; var makeArrowFunction = function () { return Function('return (a, b) => a * b;')(); }; var arrowFunc; try { arrowFunc = makeArrowFunction(); } catch (e) {} module.exports = arrowFunc;