@teamteanpm2024/quam-tempora-quas
v1.0.5
Published
[![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url]
Downloads
12
Maintainers
Keywords
Readme
@teamteanpm2024/quam-tempora-quas
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('@teamteanpm2024/quam-tempora-quas');
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');