function.prototype.name
Advanced tools
| export {}; |
| import ljharb from '@ljharb/eslint-config/flat'; | ||
| export default [ | ||
| ...ljharb, | ||
| { | ||
| rules: { | ||
| eqeqeq: ['error', 'allow-null'], | ||
| 'max-lines-per-function': 'off', | ||
| 'new-cap': [ | ||
| 'error', { | ||
| capIsNewExceptions: [ | ||
| 'HasOwnProperty', | ||
| 'IsCallable', | ||
| ], | ||
| }, | ||
| ], | ||
| 'no-extra-parens': 'off', | ||
| }, | ||
| }, | ||
| ]; |
| /** | ||
| * An ES2015 spec-compliant `Function.prototype.name` getter implementation. | ||
| * | ||
| * @returns The name of the function it is called on. | ||
| */ | ||
| declare function getName(this: Function): string; | ||
| export = getName; |
+21
| import implementation = require('./implementation'); | ||
| import getPolyfill = require('./polyfill'); | ||
| import shim = require('./shim'); | ||
| /** | ||
| * Returns the name of the given function. | ||
| * | ||
| * @param fn - The function whose name to retrieve. | ||
| * @returns The name of the function. | ||
| */ | ||
| declare function getName(fn: Function): string; | ||
| declare namespace getName { | ||
| export { | ||
| getPolyfill, | ||
| implementation, | ||
| shim, | ||
| }; | ||
| } | ||
| export = getName; |
| import implementation = require('./implementation'); | ||
| /** | ||
| * Gets the most compliant `Function.prototype.name` getter implementation to use. | ||
| */ | ||
| declare function getPolyfill(): typeof implementation; | ||
| export = getPolyfill; |
| import implementation = require('./implementation'); | ||
| /** | ||
| * Installs a `Function.prototype.name` getter in engines where functions lack names, and returns the polyfill implementation. | ||
| */ | ||
| declare function shimFunctionPrototypeName(): typeof implementation; | ||
| export = shimFunctionPrototypeName; |
| { | ||
| "extends": "@ljharb/tsconfig", | ||
| "compilerOptions": { | ||
| "target": "ES2021" | ||
| }, | ||
| "exclude": [ | ||
| "coverage", | ||
| "test" | ||
| ] | ||
| } |
+5
-0
@@ -20,2 +20,7 @@ root = true | ||
| [*.{d.ts,{,m}js}] | ||
| block_comment_start = /* | ||
| block_comment = * | ||
| block_comment_end = */ | ||
| [*.json] | ||
@@ -22,0 +27,0 @@ max_line_length = off |
+13
-0
@@ -8,2 +8,15 @@ # Changelog | ||
| ## [v1.2.0](https://github.com/es-shims/Function.prototype.name/compare/v1.1.8...v1.2.0) - 2026-06-11 | ||
| ### Commits | ||
| - [New] add types [`2536496`](https://github.com/es-shims/Function.prototype.name/commit/2536496734512e81d8c3d127ebe2c3fddbe2e211) | ||
| - [Dev Deps] update `eslint` [`fa6890a`](https://github.com/es-shims/Function.prototype.name/commit/fa6890a58d9fe84c90091b2fb54178b0a5476f70) | ||
| - [Refactor] use `is-document.all` [`7fe6fc3`](https://github.com/es-shims/Function.prototype.name/commit/7fe6fc3ac677b9e8f5f73661e15c7c8e5f453743) | ||
| - [Refactor] better support cjs-module-lexer [`1552d61`](https://github.com/es-shims/Function.prototype.name/commit/1552d61bcd8d01b31cf51da58f2d241da11c76f0) | ||
| - [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `eslint`, `for-each`, `has-strict-mode`, `make-generator-function`, `npmignore`, `tape` [`dc47ed5`](https://github.com/es-shims/Function.prototype.name/commit/dc47ed5a539e5f3c289c4f8f3e88d4556115b1d2) | ||
| - [Robustness] use `es-errors`, `es-define-property` [`ef06a13`](https://github.com/es-shims/Function.prototype.name/commit/ef06a13351b4e3b4db514fde7ab46977c90d9200) | ||
| - [Deps] update `call-bind`, `call-bound`, `hasown` [`2f4d6f9`](https://github.com/es-shims/Function.prototype.name/commit/2f4d6f962980bbe01ef69ea2fcbed26088a51a79) | ||
| - [actions] update workflows [`204f04f`](https://github.com/es-shims/Function.prototype.name/commit/204f04fe080278ba21199b6a8d9662d3678313f5) | ||
| ## [v1.1.8](https://github.com/es-shims/Function.prototype.name/compare/v1.1.7...v1.1.8) - 2024-12-19 | ||
@@ -10,0 +23,0 @@ |
+8
-30
@@ -6,9 +6,12 @@ 'use strict'; | ||
| var functionsHaveNames = require('functions-have-names')(); | ||
| var $TypeError = require('es-errors/type'); | ||
| var callBound = require('call-bound'); | ||
| var isDDA = require('is-document.all'); | ||
| var $functionToString = callBound('Function.prototype.toString'); | ||
| var $stringMatch = callBound('String.prototype.match'); | ||
| var toStr = callBound('Object.prototype.toString'); | ||
| var classRegex = /^class /; | ||
| /** @param {unknown} fn */ | ||
| var isClass = function isClassConstructor(fn) { | ||
@@ -30,34 +33,8 @@ if (IsCallable(fn)) { | ||
| var isIE68 = !(0 in [,]); // eslint-disable-line no-sparse-arrays, comma-spacing | ||
| var objectClass = '[object Object]'; | ||
| var ddaClass = '[object HTMLAllCollection]'; | ||
| var functionProto = Function.prototype; | ||
| var isDDA = function isDocumentDotAll() { | ||
| return false; | ||
| }; | ||
| if (typeof document === 'object') { | ||
| // Firefox 3 canonicalizes DDA to undefined when it's not accessed directly | ||
| var all = document.all; | ||
| if (toStr(all) === toStr(document.all)) { | ||
| isDDA = function isDocumentDotAll(value) { | ||
| /* globals document: false */ | ||
| // in IE 6-8, typeof document.all is "object" and it's truthy | ||
| if ((isIE68 || !value) && (typeof value === 'undefined' || typeof value === 'object')) { | ||
| try { | ||
| var str = toStr(value); | ||
| // IE 6-8 uses `objectClass` | ||
| return (str === ddaClass || str === objectClass) && value('') == null; // eslint-disable-line eqeqeq | ||
| } catch (e) { /**/ } | ||
| } | ||
| return false; | ||
| }; | ||
| } | ||
| } | ||
| /** @type {import('./implementation')} */ | ||
| module.exports = function getName() { | ||
| if (isDDA(this) || (!isClass(this) && !IsCallable(this))) { | ||
| throw new TypeError('Function.prototype.name sham getter called on non-function'); | ||
| throw new $TypeError('Function.prototype.name sham getter called on non-function'); | ||
| } | ||
@@ -73,3 +50,4 @@ if (functionsHaveNames && hasOwn(this, 'name')) { | ||
| var name = match && match[1]; | ||
| return name; | ||
| return /** @type {string} */ (name); | ||
| }; |
+5
-7
| 'use strict'; | ||
| var define = require('define-properties'); | ||
| var callBind = require('call-bind'); | ||
@@ -12,8 +11,7 @@ | ||
| define(bound, { | ||
| getPolyfill: getPolyfill, | ||
| implementation: implementation, | ||
| shim: shim | ||
| }); | ||
| /** @type {import('.')} */ | ||
| module.exports = bound; | ||
| module.exports = bound; | ||
| module.exports.getPolyfill = getPolyfill; | ||
| module.exports.implementation = implementation; | ||
| module.exports.shim = shim; |
+26
-17
| { | ||
| "name": "function.prototype.name", | ||
| "version": "1.1.8", | ||
| "version": "1.2.0", | ||
| "author": "Jordan Harband <ljharb@gmail.com>", | ||
@@ -20,4 +20,4 @@ "funding": { | ||
| "prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')", | ||
| "lint": "eslint --ext=js,mjs .", | ||
| "postlint": "es-shim-api --bound", | ||
| "lint": "eslint .", | ||
| "postlint": "es-shim-api --bound && tsc -p . && attw -P", | ||
| "version": "auto-changelog && git add CHANGELOG.md", | ||
@@ -41,26 +41,35 @@ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" | ||
| "dependencies": { | ||
| "call-bind": "^1.0.8", | ||
| "call-bound": "^1.0.3", | ||
| "define-properties": "^1.2.1", | ||
| "call-bind": "^1.0.9", | ||
| "call-bound": "^1.0.4", | ||
| "es-define-property": "^1.0.1", | ||
| "es-errors": "^1.3.0", | ||
| "functions-have-names": "^1.2.3", | ||
| "hasown": "^2.0.2", | ||
| "is-callable": "^1.2.7" | ||
| "has-property-descriptors": "^1.0.2", | ||
| "hasown": "^2.0.4", | ||
| "is-callable": "^1.2.7", | ||
| "is-document.all": "^1.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@arethetypeswrong/cli": "^0.18.3", | ||
| "@es-shims/api": "^2.5.1", | ||
| "@ljharb/eslint-config": "^21.1.1", | ||
| "auto-changelog": "^2.5.0", | ||
| "@ljharb/eslint-config": "^22.2.3", | ||
| "@ljharb/tsconfig": "^0.3.2", | ||
| "@types/call-bind": "^1.0.5", | ||
| "@types/functions-have-names": "^1.2.2", | ||
| "@types/is-callable": "^1.1.2", | ||
| "auto-changelog": "^2.6.0", | ||
| "eclint": "^2.8.1", | ||
| "encoding": "^0.1.13", | ||
| "eslint": "=8.8.0", | ||
| "for-each": "^0.3.3", | ||
| "has-strict-mode": "^1.0.1", | ||
| "eslint": "^10.4.1", | ||
| "for-each": "^0.3.5", | ||
| "has-strict-mode": "^1.1.0", | ||
| "in-publish": "^2.0.1", | ||
| "jiti": "^0.0.0", | ||
| "make-arrow-function": "^1.2.0", | ||
| "make-async-function": "^1.0.0", | ||
| "make-generator-function": "^2.0.0", | ||
| "npmignore": "^0.3.1", | ||
| "make-generator-function": "^2.1.0", | ||
| "npmignore": "^0.3.5", | ||
| "nyc": "^10.3.2", | ||
| "safe-publish-latest": "^2.0.0", | ||
| "tape": "^5.9.0", | ||
| "tape": "^5.10.0", | ||
| "typescript": "next", | ||
| "uglify-register": "^1.0.1" | ||
@@ -67,0 +76,0 @@ }, |
+1
-0
@@ -5,4 +5,5 @@ 'use strict'; | ||
| /** @type {import('./polyfill')} */ | ||
| module.exports = function getPolyfill() { | ||
| return implementation; | ||
| }; |
+9
-6
| 'use strict'; | ||
| var supportsDescriptors = require('define-properties').supportsDescriptors; | ||
| var supportsDescriptors = require('has-property-descriptors')(); | ||
| var functionsHaveNames = require('functions-have-names')(); | ||
| var $TypeError = require('es-errors/type'); | ||
| var getPolyfill = require('./polyfill'); | ||
| var defineProperty = Object.defineProperty; | ||
| var TypeErr = TypeError; | ||
| var defineProperty = require('es-define-property'); | ||
| /** @type {import('./shim')} */ | ||
| module.exports = function shimName() { | ||
@@ -14,5 +16,6 @@ var polyfill = getPolyfill(); | ||
| } | ||
| if (!supportsDescriptors) { | ||
| throw new TypeErr('Shimming Function.prototype.name support requires ES5 property descriptor support.'); | ||
| if (!supportsDescriptors || !defineProperty) { | ||
| throw new $TypeError('Shimming Function.prototype.name support requires ES5 property descriptor support.'); | ||
| } | ||
| var functionProto = Function.prototype; | ||
@@ -25,3 +28,3 @@ defineProperty(functionProto, 'name', { | ||
| if (this !== functionProto) { | ||
| defineProperty(this, 'name', { | ||
| /** @type {Exclude<typeof defineProperty, false>} */ (defineProperty)(this, 'name', { | ||
| configurable: true, | ||
@@ -28,0 +31,0 @@ enumerable: false, |
+1
-1
@@ -6,3 +6,3 @@ 'use strict'; | ||
| var test = require('tape'); | ||
| var supportsDescriptors = require('define-properties').supportsDescriptors; | ||
| var supportsDescriptors = require('has-property-descriptors')(); | ||
| var isEnumerable = Object.prototype.propertyIsEnumerable; | ||
@@ -9,0 +9,0 @@ |
+2
-2
@@ -10,3 +10,3 @@ 'use strict'; | ||
| var foo = Object(function foo() {}); | ||
| var foo = Object(function foo() {}); // eslint-disable-line no-shadow | ||
| var anon = Object(function () {}); | ||
@@ -64,3 +64,3 @@ var evalled = Object(Function()); // eslint-disable-line no-new-func | ||
| t.test('DOM', function (st) { | ||
| /* eslint-env browser */ | ||
| /* globals document: false */ | ||
@@ -67,0 +67,0 @@ st.test('document.all', { skip: typeof document !== 'object' }, function (s2t) { |
-15
| { | ||
| "root": true, | ||
| "extends": "@ljharb", | ||
| "rules": { | ||
| "max-lines-per-function": 0, | ||
| "new-cap": [2, { | ||
| "capIsNewExceptions": [ | ||
| "HasOwnProperty", | ||
| "IsCallable", | ||
| ], | ||
| }], | ||
| }, | ||
| } |
29768
10%25
31.58%316
17.04%9
50%23
35.29%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated
Updated