Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@critocrito/namefn

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@critocrito/namefn

Set the name property of a function.

  • 0.1.5
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

namefn

Set the name property of a function.

Synopsis

License: GPL v3 npm version Build Status Coverage Status

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.

Installation

npm install @critocrito/namefn

Usage

import namefn from "@critocrito/namefn";

const f = namefn("identity", x => x);
console.log(f.name); // identity
f; // [Function: identity]

Examples

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]

License

GPL 3.0 licensed

Keywords

FAQs

Package last updated on 06 Oct 2018

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc