IP_Malafeev_KrutieLabi/lab3/node_modules/set-function-name
2024-01-11 00:20:49 +04:00
..
.github lab_3 2024-01-11 00:20:49 +04:00
.eslintrc lab_3 2024-01-11 00:20:49 +04:00
CHANGELOG.md lab_3 2024-01-11 00:20:49 +04:00
index.js lab_3 2024-01-11 00:20:49 +04:00
LICENSE lab_3 2024-01-11 00:20:49 +04:00
package.json lab_3 2024-01-11 00:20:49 +04:00
README.md lab_3 2024-01-11 00:20:49 +04:00

set-function-name Version Badge

github actions coverage License Downloads

npm badge

Set a functions name.

Arguments:

  • fn: the function
  • name: the new name
  • loose: 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');