pax_global_header00006660000000000000000000000064135356734460014532gustar00rootroot0000000000000052 comment=b21aef2631b9e32d3173e9181e11c5d841a4ad15 fn-name-3.0.0/000077500000000000000000000000001353567344600130535ustar00rootroot00000000000000fn-name-3.0.0/.editorconfig000066400000000000000000000002571353567344600155340ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 fn-name-3.0.0/.gitattributes000066400000000000000000000000231353567344600157410ustar00rootroot00000000000000* text=auto eol=lf fn-name-3.0.0/.github/000077500000000000000000000000001353567344600144135ustar00rootroot00000000000000fn-name-3.0.0/.github/funding.yml000066400000000000000000000000531353567344600165660ustar00rootroot00000000000000github: sindresorhus tidelift: npm/fn-name fn-name-3.0.0/.github/security.md000066400000000000000000000002631353567344600166050ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. fn-name-3.0.0/.gitignore000066400000000000000000000000271353567344600150420ustar00rootroot00000000000000node_modules yarn.lock fn-name-3.0.0/.npmrc000066400000000000000000000000231353567344600141660ustar00rootroot00000000000000package-lock=false fn-name-3.0.0/.travis.yml000066400000000000000000000000651353567344600151650ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' fn-name-3.0.0/index.js000066400000000000000000000003311353567344600145150ustar00rootroot00000000000000'use strict'; module.exports = fn => { if (typeof fn !== 'function') { throw new TypeError('Expected a function'); } return fn.displayName || fn.name || (/function ([^(]+)?\(/.exec(fn.toString()) || [])[1]; }; fn-name-3.0.0/license000066400000000000000000000021251353567344600144200ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) 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. fn-name-3.0.0/package.json000066400000000000000000000007511353567344600153440ustar00rootroot00000000000000{ "name": "fn-name", "version": "3.0.0", "description": "Get the name of a named function", "license": "MIT", "repository": "sindresorhus/fn-name", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "function", "func", "fn", "name" ], "devDependencies": { "ava": "^2.3.0", "xo": "^0.24.0" } } fn-name-3.0.0/readme.md000066400000000000000000000017741353567344600146430ustar00rootroot00000000000000# fn-name [![Build Status](https://travis-ci.org/sindresorhus/fn-name.svg?branch=master)](https://travis-ci.org/sindresorhus/fn-name) > Get the name of a named function There is a [`name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) property on functions, but it's not supported in all browsers. This module tries that property then falls back to extracting the name from the function source. ## Install ``` $ npm install fn-name ``` ## Usage ```js const fnName = require('fn-name'); fnName(function foo() {}); //=> 'foo' ``` ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
fn-name-3.0.0/test.js000066400000000000000000000015051353567344600143710ustar00rootroot00000000000000import test from 'ava'; import fnName from '.'; test('named', t => { t.is(fnName(function foo() {}), 'foo'); // eslint-disable-line func-names }); test('anonymous', t => { t.is(fnName(function() {}), undefined); // eslint-disable-line prefer-arrow-callback, space-before-function-paren t.is(fnName(function () {}), undefined); // eslint-disable-line prefer-arrow-callback }); test('arrow', t => { t.is(fnName(() => {}), undefined); }); test('nested', t => { t.is( fnName(function () { // eslint-disable-line prefer-arrow-callback function nested() {} nested(); }), undefined ); }); test('nested callback', t => { function call(fn) { fn(); } t.is( fnName(function () { // eslint-disable-line prefer-arrow-callback call(function callback() {}); // eslint-disable-line func-names }), undefined ); });