
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@critocrito/namefn
Advanced tools
namefnSet the name property of a function.
When programmatically generating functions in JavaScript, they often lack a
name. This reduces the usability of using those functions in a REPL. namefn
is a little helper to set the names of functions at construction time.
npm install @critocrito/namefn
import namefn from "@critocrito/namefn";
const f = namefn("identity", x => x);
console.log(f.name); // identity
f; // [Function: identity]
import namefn from "@critocrito/namefn";
const f = x => () => x;
const g = f(23);
console.log(g.name); // ""
g; // ""
const constant23 = namefn("constant23", f(23));
console.log(constant23.name); // "constant23"
constant23; // "[Function: constant23]"
The following example implements a curry function, and includes the number
of missing arguments in the function name.
import namefn from "@critocrito/namefn";
const curry = n => {
const localCurry = (name, f, ...args) => {
const g = (...largs) => {
const rest = args.concat(largs);
if (rest.length < n) return localCurry(name, f, ...rest);
return f(...rest);
};
return namefn(`${name}-${n - args.length}`, g);
};
return namefn(`curry${n}`, localCurry);
};
const curry2 = curry(2);
const map = curry2("map", (f, xs) => xs.map(f));
map; // [Function: map-2]
const addOne = map(i => i + 1);
addOne; // [Function: map-1]
FAQs
Set the name property of a function.
We found that @critocrito/namefn demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.