source: imaps-frontend/node_modules/set-function-name/index.js@ 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: 744 bytes
Line 
1'use strict';
2
3var define = require('define-data-property');
4var hasDescriptors = require('has-property-descriptors')();
5var functionsHaveConfigurableNames = require('functions-have-names').functionsHaveConfigurableNames();
6
7var $TypeError = require('es-errors/type');
8
9/** @type {import('.')} */
10module.exports = function setFunctionName(fn, name) {
11 if (typeof fn !== 'function') {
12 throw new $TypeError('`fn` is not a function');
13 }
14 var loose = arguments.length > 2 && !!arguments[2];
15 if (!loose || functionsHaveConfigurableNames) {
16 if (hasDescriptors) {
17 define(/** @type {Parameters<define>[0]} */ (fn), 'name', name, true, true);
18 } else {
19 define(/** @type {Parameters<define>[0]} */ (fn), 'name', name);
20 }
21 }
22 return fn;
23};
Note: See TracBrowser for help on using the repository browser.