set-function-name (2.0.2)
Published 2026-02-24 14:04:58 +00:00 by atheaadmin
Installation
registry=npm install set-function-name@2.0.2"set-function-name": "2.0.2"About this package
set-function-name 
Set a function’s name.
Arguments:
fn: the functionname: the new nameloose: Optional. If true, and the name fails to be set, do not throw. Default false.
Returns fn.
Usage
var setFunctionName = require('set-function-name');
var assert = require('assert');
const obj = {
concise() {},
arrow: () => {},
named: function named() {},
anon: function () {},
};
assert.equal(obj.concise.name, 'concise');
assert.equal(obj.arrow.name, 'arrow');
assert.equal(obj.named.name, 'named');
assert.equal(obj.anon.name, 'anon');
assert.equal(setFunctionName(obj.concise, 'brief'), obj.concise);
assert.equal(setFunctionName(obj.arrow, 'pointy'), obj.arrow);
assert.equal(setFunctionName(obj.named, ''), obj.named);
assert.equal(setFunctionName(obj.anon, 'anonymous'), obj.anon);
assert.equal(obj.concise.name, 'brief');
assert.equal(obj.arrow.name, 'pointy');
assert.equal(obj.named.name, '');
assert.equal(obj.anon.name, 'anonymous');
Dependencies
Dependencies
| ID | Version |
|---|---|
| define-data-property | ^1.1.4 |
| es-errors | ^1.3.0 |
| functions-have-names | ^1.2.3 |
| has-property-descriptors | ^1.0.2 |
Development Dependencies
| ID | Version |
|---|---|
| @ljharb/eslint-config | ^21.1.0 |
| @types/call-bind | ^1.0.5 |
| @types/define-properties | ^1.1.5 |
| @types/es-value-fixtures | ^1.4.4 |
| @types/for-each | ^0.3.3 |
| @types/function.prototype.name | ^1.1.3 |
| @types/functions-have-names | ^1.2.2 |
| @types/has-property-descriptors | ^1.0.3 |
| @types/make-arrow-function | ^1.2.2 |
| @types/make-async-function | ^1.0.2 |
| @types/make-async-generator-function | ^1.0.3 |
| @types/make-generator-function | ^2.0.3 |
| @types/object-inspect | ^1.8.4 |
| @types/tape | ^5.6.4 |
| aud | ^2.0.4 |
| auto-changelog | ^2.4.0 |
| es-value-fixtures | ^1.4.2 |
| eslint | =8.8.0 |
| evalmd | ^0.0.19 |
| for-each | ^0.3.3 |
| function.prototype.name | ^1.1.6 |
| in-publish | ^2.0.1 |
| make-arrow-function | ^1.2.0 |
| make-async-function | ^1.0.0 |
| make-async-generator-function | ^1.0.0 |
| make-generator-function | ^2.0.0 |
| npmignore | ^0.3.1 |
| object-inspect | ^1.13.1 |
| safe-publish-latest | ^2.0.0 |
| tape | ^5.7.5 |
| typescript | next |
Keywords
set
assign
function
name
function.name
