You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

set-function-name

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

set-function-name

Set a function's name property


Version published
Weekly downloads
19M
decreased by-17.86%
Maintainers
2
Install size
219 kB
Created
Weekly downloads
 

Package description

What is set-function-name?

The `set-function-name` npm package allows developers to dynamically change the name of a function at runtime. This can be particularly useful for debugging purposes or when working with higher-order functions where maintaining a clear and meaningful stack trace is important. The package provides a straightforward and easy-to-use API for renaming functions.

What are set-function-name's main functionalities?

Setting a function's name

This feature allows you to set a new name for an existing function. The code sample demonstrates how to use `set-function-name` to change a function's name from 'originalFunction' to 'newFunctionName'.

const setFunctionName = require('set-function-name');

function originalFunction() {}
console.log(originalFunction.name); // 'originalFunction'

const renamedFunction = setFunctionName(originalFunction, 'newFunctionName');
console.log(renamedFunction.name); // 'newFunctionName'

Other packages similar to set-function-name

Changelog

Source

v2.0.2 - 2024-02-19

Commits

  • [meta] add types ae747cd
  • [Dev Deps] update aud, npmignore, object-inspect, tape 01aafcb
  • [Deps] update define-data-property, has-property-descriptors 0ef6338
  • [Refactor] use es-errors 0b23e87

Readme

Source

set-function-name Version Badge

github actions coverage License Downloads

npm badge

Set a function’s 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');

Keywords

FAQs

Package last updated on 20 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc