source: imaps-frontend/node_modules/set-function-name/README.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.3 KB
Line 
1# set-function-name <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
3[![github actions][actions-image]][actions-url]
4[![coverage][codecov-image]][codecov-url]
5[![License][license-image]][license-url]
6[![Downloads][downloads-image]][downloads-url]
7
8[![npm badge][npm-badge-png]][package-url]
9
10Set a function’s name.
11
12Arguments:
13 - `fn`: the function
14 - `name`: the new name
15 - `loose`: Optional. If true, and the name fails to be set, do not throw. Default false.
16
17Returns `fn`.
18
19## Usage
20
21```javascript
22var setFunctionName = require('set-function-name');
23var assert = require('assert');
24
25const obj = {
26 concise() {},
27 arrow: () => {},
28 named: function named() {},
29 anon: function () {},
30};
31assert.equal(obj.concise.name, 'concise');
32assert.equal(obj.arrow.name, 'arrow');
33assert.equal(obj.named.name, 'named');
34assert.equal(obj.anon.name, 'anon');
35
36assert.equal(setFunctionName(obj.concise, 'brief'), obj.concise);
37assert.equal(setFunctionName(obj.arrow, 'pointy'), obj.arrow);
38assert.equal(setFunctionName(obj.named, ''), obj.named);
39assert.equal(setFunctionName(obj.anon, 'anonymous'), obj.anon);
40
41assert.equal(obj.concise.name, 'brief');
42assert.equal(obj.arrow.name, 'pointy');
43assert.equal(obj.named.name, '');
44assert.equal(obj.anon.name, 'anonymous');
45```
46
47[package-url]: https://npmjs.org/package/set-function-name
48[npm-version-svg]: https://versionbadg.es/ljharb/set-function-name.svg
49[deps-svg]: https://david-dm.org/ljharb/set-function-name.svg
50[deps-url]: https://david-dm.org/ljharb/set-function-name
51[dev-deps-svg]: https://david-dm.org/ljharb/set-function-name/dev-status.svg
52[dev-deps-url]: https://david-dm.org/ljharb/set-function-name#info=devDependencies
53[npm-badge-png]: https://nodei.co/npm/set-function-name.png?downloads=true&stars=true
54[license-image]: https://img.shields.io/npm/l/set-function-name.svg
55[license-url]: LICENSE
56[downloads-image]: https://img.shields.io/npm/dm/set-function-name.svg
57[downloads-url]: https://npm-stat.com/charts.html?package=set-function-name
58[codecov-image]: https://codecov.io/gh/ljharb/set-function-name/branch/main/graphs/badge.svg
59[codecov-url]: https://app.codecov.io/gh/ljharb/set-function-name/
60[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/set-function-name
61[actions-url]: https://github.com/ljharb/set-function-name/actions
Note: See TracBrowser for help on using the repository browser.