{"id":16628872,"url":"https://github.com/critocrito/namefn","last_synced_at":"2025-08-23T03:33:23.733Z","repository":{"id":57104475,"uuid":"132669113","full_name":"critocrito/namefn","owner":"critocrito","description":"Set the name property of a function.","archived":false,"fork":false,"pushed_at":"2019-11-07T22:11:58.000Z","size":1302,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-04T05:18:21.868Z","etag":null,"topics":["functional-programming","functions","javascript","repl"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/critocrito.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-08T21:52:07.000Z","updated_at":"2020-07-30T12:52:24.000Z","dependencies_parsed_at":"2022-08-20T17:10:39.779Z","dependency_job_id":null,"html_url":"https://github.com/critocrito/namefn","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/critocrito/namefn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fnamefn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fnamefn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fnamefn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fnamefn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/critocrito","download_url":"https://codeload.github.com/critocrito/namefn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/critocrito%2Fnamefn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271737470,"owners_count":24812126,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-programming","functions","javascript","repl"],"created_at":"2024-10-12T04:37:53.020Z","updated_at":"2025-08-23T03:33:23.708Z","avatar_url":"https://github.com/critocrito.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `namefn`\n\nSet the name property of a function.\n\n## Synopsis\n\n[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![npm version](https://img.shields.io/npm/v/@critocrito/namefn.svg?style=flat)](https://www.npmjs.com/package/@critocrito/namefn) [![Build Status](https://travis-ci.org/critocrito/namefn.svg?branch=master)](https://travis-ci.org/critocrito/namefn) [![Coverage Status](https://coveralls.io/repos/github/critocrito/namefn/badge.svg)](https://coveralls.io/github/critocrito/namefn) [![Greenkeeper badge](https://badges.greenkeeper.io/critocrito/namefn.svg)](https://greenkeeper.io/)\n\nWhen programmatically generating functions in JavaScript, they often lack a\nname. This reduces the usability of using those functions in a REPL. `namefn`\nis a little helper to set the names of functions at construction time.\n\n## Installation\n\n```sh\nnpm install @critocrito/namefn\n```\n\n## Usage\n\n```js\nimport namefn from \"@critocrito/namefn\";\n\nconst f = namefn(\"identity\", x =\u003e x);\nconsole.log(f.name); // identity\nf; // [Function: identity]\n```\n\n## Examples\n\n```js\nimport namefn from \"@critocrito/namefn\";\n\nconst f = x =\u003e () =\u003e x;\n\nconst g = f(23);\nconsole.log(g.name); // \"\"\ng; // \"\"\n\nconst constant23 = namefn(\"constant23\", f(23));\nconsole.log(constant23.name); // \"constant23\"\nconstant23; // \"[Function: constant23]\"\n```\n\nThe following example implements a `curry` function, and includes the number\nof missing arguments in the function name.\n\n```js\nimport namefn from \"@critocrito/namefn\";\n\nconst curry = n =\u003e {\n  const localCurry = (name, f, ...args) =\u003e {\n    const g = (...largs) =\u003e {\n      const rest = args.concat(largs);\n\n      if (rest.length \u003c n) return localCurry(name, f, ...rest);\n      return f(...rest);\n    };\n    return namefn(`${name}-${n - args.length}`, g);\n  };\n\n  return namefn(`curry${n}`, localCurry);\n};\nconst curry2 = curry(2);\n\nconst map = curry2(\"map\", (f, xs) =\u003e xs.map(f));\nmap; // [Function: map-2]\n\nconst addOne = map(i =\u003e i + 1);\naddOne; // [Function: map-1]\n```\n\n## License\n\n[GPL 3.0 licensed](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcritocrito%2Fnamefn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcritocrito%2Fnamefn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcritocrito%2Fnamefn/lists"}