{"id":21831347,"url":"https://github.com/nodef/extra-function","last_synced_at":"2026-02-26T08:02:22.327Z","repository":{"id":41808186,"uuid":"249692645","full_name":"nodef/extra-function","owner":"nodef","description":"A function is a set of statements that performs a task or calculates a value.","archived":false,"fork":false,"pushed_at":"2025-04-08T17:18:27.000Z","size":583,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T17:51:19.775Z","etag":null,"topics":["apply","arguments","attach","attach-right","bind","call","compare","compose","compose-right","contextify","curry","curry-right","debounce","debounce-early","extra","false","function","identity","noop","true"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/extra-function","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-24T11:41:20.000Z","updated_at":"2025-04-08T17:18:28.000Z","dependencies_parsed_at":"2025-03-08T08:11:33.290Z","dependency_job_id":null,"html_url":"https://github.com/nodef/extra-function","commit_stats":{"total_commits":101,"total_committers":1,"mean_commits":101.0,"dds":0.0,"last_synced_commit":"a9919178ed802621b04607fe05320a421024fdef"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodef%2Fextra-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodef%2Fextra-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodef%2Fextra-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodef%2Fextra-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodef","download_url":"https://codeload.github.com/nodef/extra-function/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054225,"owners_count":21039952,"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","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":["apply","arguments","attach","attach-right","bind","call","compare","compose","compose-right","contextify","curry","curry-right","debounce","debounce-early","extra","false","function","identity","noop","true"],"created_at":"2024-11-27T19:09:47.657Z","updated_at":"2026-02-26T08:02:17.095Z","avatar_url":"https://github.com/nodef.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"A **function** is a *set of statements* that *performs a task* or *calculates a value*.\u003cbr\u003e\n📦 [Node.js](https://www.npmjs.com/package/extra-function),\n🌐 [Web](https://www.npmjs.com/package/extra-function.web),\n📜 [Files](https://unpkg.com/extra-function/),\n📰 [JSDoc](https://nodef.github.io/extra-function/),\n📘 [Wiki](https://github.com/nodef/extra-function/wiki/).\n\nFunctions are one of the fundamental building blocks in JavaScript. It is\nsimilar to a procedure—a set of statements that performs a task or calculates a\nvalue [(1)]. It can accept some **parameters**, and may define some **local**\n**variables** necessary for performing the desired *operation*. These\n*parameters* and *local variables* are contained in the **scope of the**\n**function**, and *cannot* be accessed from the *outside*. However, a function can\naccess variables *external to itself* (as long as they are not *overridden*),\nsuch as *global variables* or *variables* in the scope this function is\n*encapsulated in*. A **nested function** can access *free variables* that\nare defined in *outer scopes*, even when it is being *invoked* **away** from\nwhere it is *defined*. It does this by **capturing** the *free variables* (by\n*reference*) into a **closure** [(1)]. *Closure*, *arrow functions*, and more,\nare *functional language features* based on [lambda calculus].\n\nThis package includes a number of methods to *transform functions*. This enables\nyou to obtain a desired function by transforming the behavior of existing\nfunctions (*without actually executing them*). The **result** of a function can\nbe manipulated with [negate]. In case a *pure* function is expensive, its\nresults can **cached** with [memoize]. **Parameters** of a function can be\nmanipulated with [reverse], [spread], [unspread]. [reverse] flips the order of\nparameters, [spread] spreads the first array parameter of a function, and\n[unspread] combines all parameters into the first parameter (array). If you want\nsome **functional** **behavior**, [compose], [composeRight], [curry], and\n[curryRight] can be used. [composeRight] is also known as [pipe-forward\noperator] or [function chaining]. If you are unfamiliar, [Haskell] is a great\npurely functional language, and there is great [haskell beginner guide] to learn\nfrom.\n\nTo control invocation **time** of a function, use [delay]. A function can be\n**rate controlled** with [restrict], [debounce], [debounceEarly], [throttle],\n[throttleEarly]. [debounce] and [debounceEarly] prevent the invocation of a\nfunction during **hot** periods (when there are too many calls), and can be used\nfor example to issue AJAX request after user input has stopped (for certain\ndelay time). [throttle] and [throttleEarly] can be used to limit the rate of\ninvocation of a function, and can be used for example to minimize system usage\nwhen a user is [constantly refreshing a webpage]. Except [restrict], all\n*rate/time control* methods can be *flushed* (`flush()`) to invoke the target\nfunction immediately, or *cleared* (`clear()`) to disable invocation of the\ntarget function.\n\nIn addition, [is], [isAsync], [isGenerator], [name], and [length] obtain\nmetadata (about) information on a function. To attach a `this` to a function,\nuse [bind]. A few generic functions are also included: [NOOP], [FALSE], [TRUE],\n[IDENTITY], [COMPARE], [ARGUMENTS].\n\nThis package is available in *Node.js* and *Web* formats. To use it on the web,\nsimply use the `extra_function` global variable after loading with a `\u003cscript\u003e`\ntag from the [jsDelivr CDN].\n\n[(1)]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions\n[lambda calculus]: https://en.wikipedia.org/wiki/Lambda_calculus\n[pipe-forward operator]: https://stackoverflow.com/questions/1457140/haskell-composition-vs-fs-pipe-forward-operator\n[function chaining]: https://www.npmjs.com/package/chain-function\n[Haskell]: https://www.haskell.org\n[haskell beginner guide]: http://learnyouahaskell.com\n[constantly refreshing a webpage]: https://tenor.com/view/social-network-mark-zuckerberg-refresh-movie-jesse-eisenberg-gif-12095762\n[jsDelivr CDN]: https://cdn.jsdelivr.net/npm/extra-function.web/index.js\n\n\u003e Stability: [Experimental](https://www.youtube.com/watch?v=L1j93RnIxEo).\n\n\u003cbr\u003e\n\n\n```javascript\nconst xfunction = require('extra-function');\n// import * as xfunction from \"extra-function\";\n// import * as xfunction from \"https://unpkg.com/extra-function/index.mjs\"; (deno)\n\nvar a = xfunction.composeRight(x =\u003e x*x, x =\u003e x+2);\na(10);\n// → 102\n\nvar a = xfunction.curry((x, y) =\u003e x+y);\na(2)(3);\n// → 7\n\nvar a = xfunction.unspread(Math.max);\na([2, 3, 1]);\n// → 1.25\n```\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\n## Index\n\n| Property | Description |\n|  ----  |  ----  |\n| [NOOP] | Do nothing. |\n| [FALSE] | Return false. |\n| [TRUE] | Return false. |\n| [IDENTITY] | Return the same (first) value. |\n| [COMPARE] | Compare two values. |\n| [ARGUMENTS] | Return the arguments passed as a array. |\n|  |  |\n| [name] | Get the name of a function. |\n| [length] | Get the number of parameters of a function. |\n|  |  |\n| [bind] | Bind this-object, and optional prefix arguments to a function. |\n|  |  |\n| [call] | Invoke a function with specified this-object, and arguments provided individually. |\n| [apply] | Invoke a function with specified this-object, and arguments provided as an array. |\n|  |  |\n| [is] | Check if value is a function. |\n| [isAsync] | Check if value is an async function. |\n| [isGenerator] | Check if value is a generator function. |\n|  |  |\n| [contextify] | Contextify a function by accepting the first parameter as this-object. |\n| [decontextify] | Decontextify a function by accepting this-object as the first argument. |\n|  |  |\n| [negate] | Generate a result-negated version of a function. |\n|  |  |\n| [memoize] | Generate result-cached version of a function. |\n|  |  |\n| [reverse] | Generate a parameter-reversed version of a function. |\n| [spread] | Generate a (first) parameter-spreaded version of a function. |\n| [unspread] | Generate a (first) parameter-collapsed version of a function. |\n| [attach] | Attach prefix arguments to leftmost parameters of a function. |\n| [attachRight] | Attach suffix arguments to rightmost parameters of a function. |\n|  |  |\n| [compose] | Compose functions together, in applicative order. |\n| [composeRight] | Compose functions together, such that result is piped forward. |\n| [curry] | Generate curried version of a function. |\n| [curryRight] | Generate right-curried version of a function. |\n|  |  |\n| [defer] | Generate deferred version of a function, that executes after the current stack has cleared. |\n| [delay] | Generate delayed version of a function. |\n|  |  |\n| [restrict] | Generate restricted-use version of a function. |\n| [restrictOnce] | Restrict a function to be used only once. |\n| [restrictBefore] | Restrict a function to be used only upto a certain number of calls. |\n| [restrictAfter] | Restrict a function to be used only after a certain number of calls. |\n|  |  |\n| [debounce] | Generate debounced version of a function. |\n| [debounceEarly] | Generate leading-edge debounced version of a function. |\n| [throttle] | Generate throttled version of a function. |\n| [throttleEarly] | Generate leading-edge throttled version of a function. |\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\n## References\n\n- [MDN Web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference)\n- [Lodash documentation](https://lodash.com/docs/4.17.15)\n- [Underscore.js documentation](https://underscorejs.org/)\n- [Function composition](https://en.wikipedia.org/wiki/Function_composition)\n- [Debouncing and Throttling Explained Through Examples by David Corbacho](https://css-tricks.com/debouncing-throttling-explained-examples/)\n- [Learn You a Haskell for Great Good!: Higher order functions by Miran Lipovaca](http://learnyouahaskell.com/higher-order-functions)\n- [How to know if a function is async?](https://stackoverflow.com/questions/38508420/how-to-know-if-a-function-is-async)\n- [Check if function is a generator](https://stackoverflow.com/questions/16754956/check-if-function-is-a-generator)\n- [Haskell composition (.) vs F#'s pipe forward operator (|\u003e)](https://stackoverflow.com/questions/1457140/haskell-composition-vs-fs-pipe-forward-operator)\n- [JavaScript Detect Async Function by David Walsh](https://davidwalsh.name/javascript-detect-async-function)\n- [is-function package by Stephen Sugden](https://www.npmjs.com/package/is-function)\n- [is-async-function package by Jordan Harband](https://www.npmjs.com/package/is-async-function)\n- [is-callback-function package by Charlike Mike Reagent](https://www.npmjs.com/package/is-callback-function)\n- [is-generator-fn package by Sindre Sorhus](https://www.npmjs.com/package/is-generator-fn)\n- [is-generator-function package by Jordan Harband](https://www.npmjs.com/package/is-generator-function)\n- [fn-name package by Sindre Sorhus](https://www.npmjs.com/package/fn-name)\n- [memoizee package by Mariusz Nowak](https://www.npmjs.com/package/memoizee)\n- [memoizerific package by @thinkloop](https://www.npmjs.com/package/memoizerific)\n- [compose-function package by Christoph Hermann](https://www.npmjs.com/package/compose-function)\n- [chain-function package by Jason Quense](https://www.npmjs.com/package/chain-function)\n- [@spudly/curry package by Stephen Sorensen](https://www.npmjs.com/package/@spudly/curry)\n- [one-time package by Arnout Kazemier](https://www.npmjs.com/package/one-time)\n- [onetime package by Sindre Sorhus](https://www.npmjs.com/package/onetime)\n- [once package by Isaac Z. Schlueter](https://www.npmjs.com/package/once)\n- [debounce package by @component](https://www.npmjs.com/package/debounce)\n- [throttle-debounce package by Ivan Nikolić](https://www.npmjs.com/package/throttle-debounce)\n- [throttleit package by @component](https://www.npmjs.com/package/throttleit)\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\n[![](https://img.youtube.com/vi/vzfy4EKwG_Y/maxresdefault.jpg)](https://www.youtube.com/watch?v=vzfy4EKwG_Y)\u003cbr\u003e\n[![ORG](https://img.shields.io/badge/org-nodef-green?logo=Org)](https://nodef.github.io)\n[![DOI](https://zenodo.org/badge/249692645.svg)](https://zenodo.org/badge/latestdoi/249692645)\n[![Coverage Status](https://coveralls.io/repos/github/nodef/extra-function/badge.svg?branch=master)](https://coveralls.io/github/nodef/extra-function?branch=master)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/4848d3e9557e4144c919/test_coverage)](https://codeclimate.com/github/nodef/extra-function/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/4848d3e9557e4144c919/maintainability)](https://codeclimate.com/github/nodef/extra-function/maintainability)\n![](https://ga-beacon.deno.dev/G-RC63DPBH3P:SH3Eq-NoQ9mwgYeHWxu7cw/github.com/nodef/extra-function)\n\n[NOOP]: https://github.com/nodef/extra-function/wiki/NOOP\n[FALSE]: https://github.com/nodef/extra-function/wiki/FALSE\n[TRUE]: https://github.com/nodef/extra-function/wiki/TRUE\n[IDENTITY]: https://github.com/nodef/extra-function/wiki/IDENTITY\n[COMPARE]: https://github.com/nodef/extra-function/wiki/COMPARE\n[ARGUMENTS]: https://github.com/nodef/extra-function/wiki/ARGUMENTS\n[is]: https://github.com/nodef/extra-function/wiki/is\n[isAsync]: https://github.com/nodef/extra-function/wiki/isAsync\n[isGenerator]: https://github.com/nodef/extra-function/wiki/isGenerator\n[name]: https://github.com/nodef/extra-function/wiki/name\n[bind]: https://github.com/nodef/extra-function/wiki/bind\n[negate]: https://github.com/nodef/extra-function/wiki/negate\n[memoize]: https://github.com/nodef/extra-function/wiki/memoize\n[reverse]: https://github.com/nodef/extra-function/wiki/reverse\n[spread]: https://github.com/nodef/extra-function/wiki/spread\n[unspread]: https://github.com/nodef/extra-function/wiki/unspread\n[compose]: https://github.com/nodef/extra-function/wiki/compose\n[composeRight]: https://github.com/nodef/extra-function/wiki/composeRight\n[curry]: https://github.com/nodef/extra-function/wiki/curry\n[curryRight]: https://github.com/nodef/extra-function/wiki/curryRight\n[delay]: https://github.com/nodef/extra-function/wiki/delay\n[debounce]: https://github.com/nodef/extra-function/wiki/debounce\n[debounceEarly]: https://github.com/nodef/extra-function/wiki/debounceEarly\n[throttle]: https://github.com/nodef/extra-function/wiki/throttle\n[throttleEarly]: https://github.com/nodef/extra-function/wiki/throttleEarly\n[restrict]: https://github.com/nodef/extra-function/wiki/restrict\n[length]: https://github.com/nodef/extra-function/wiki/length\n[call]: https://github.com/nodef/extra-function/wiki/call\n[apply]: https://github.com/nodef/extra-function/wiki/apply\n[contextify]: https://github.com/nodef/extra-function/wiki/contextify\n[decontextify]: https://github.com/nodef/extra-function/wiki/decontextify\n[attach]: https://github.com/nodef/extra-function/wiki/attach\n[attachRight]: https://github.com/nodef/extra-function/wiki/attachRight\n[defer]: https://github.com/nodef/extra-function/wiki/defer\n[restrictOnce]: https://github.com/nodef/extra-function/wiki/restrictOnce\n[restrictBefore]: https://github.com/nodef/extra-function/wiki/restrictBefore\n[restrictAfter]: https://github.com/nodef/extra-function/wiki/restrictAfter\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodef%2Fextra-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodef%2Fextra-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodef%2Fextra-function/lists"}