{"id":17002020,"url":"https://github.com/sagiegurari/funcs-js","last_synced_at":"2025-04-12T06:21:43.783Z","repository":{"id":20340678,"uuid":"89642991","full_name":"sagiegurari/funcs-js","owner":"sagiegurari","description":"Function wrappers for enhanced behavior.","archived":false,"fork":false,"pushed_at":"2023-01-19T17:38:27.000Z","size":81,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T10:21:41.642Z","etag":null,"topics":["async","browser","delay","funcs-js","function","function-wrapper","functions","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sagiegurari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-27T21:47:27.000Z","updated_at":"2021-10-27T10:05:55.000Z","dependencies_parsed_at":"2023-02-11T13:15:30.372Z","dependency_job_id":null,"html_url":"https://github.com/sagiegurari/funcs-js","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Ffuncs-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Ffuncs-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Ffuncs-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sagiegurari%2Ffuncs-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sagiegurari","download_url":"https://codeload.github.com/sagiegurari/funcs-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525775,"owners_count":21118750,"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":["async","browser","delay","funcs-js","function","function-wrapper","functions","nodejs"],"created_at":"2024-10-14T04:26:52.319Z","updated_at":"2025-04-12T06:21:43.755Z","avatar_url":"https://github.com/sagiegurari.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# funcs-js\n\n[![NPM Version](http://img.shields.io/npm/v/funcs-js.svg?style=flat)](https://www.npmjs.org/package/funcs-js) [![CI](https://github.com/sagiegurari/funcs-js/workflows/CI/badge.svg?branch=master)](https://github.com/sagiegurari/funcs-js/actions) [![Coverage Status](https://coveralls.io/repos/sagiegurari/funcs-js/badge.svg)](https://coveralls.io/r/sagiegurari/funcs-js) [![Known Vulnerabilities](https://snyk.io/test/github/sagiegurari/funcs-js/badge.svg)](https://snyk.io/test/github/sagiegurari/funcs-js) [![Inline docs](http://inch-ci.org/github/sagiegurari/funcs-js.svg?branch=master)](http://inch-ci.org/github/sagiegurari/funcs-js) [![License](https://img.shields.io/npm/l/funcs-js.svg?style=flat)](https://github.com/sagiegurari/funcs-js/blob/master/LICENSE) [![Total Downloads](https://img.shields.io/npm/dt/funcs-js.svg?style=flat)](https://www.npmjs.org/package/funcs-js)\n\n\u003e Function wrappers for enhanced behavior.\n\n* [Overview](#overview)\n* [Usage](#usage)\n  * [once](#usage-once)\n  * [maxTimes](#usage-maxTimes)\n  * [async](#usage-async)\n  * [delay](#usage-delay)\n  * [isFunction](#usage-isFunction)\n  * [noop](#usage-noop)\n  * [ensure](#usage-ensure)\n* [Installation](#installation)\n* [API Documentation](docs/api.md)\n* [Contributing](.github/CONTRIBUTING.md)\n* [Release History](#history)\n* [License](#license)\n\n\u003ca name=\"overview\"\u003e\u003c/a\u003e\n## Overview\nThe funcs-js provides different utility functions which enable to wrap functions and modify their behavior.\n\nThis library requires no external dependencies, and it is supported for both browser and node.js environments.\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n## Usage\nIn order to use the library in browser, you first must add the relevant dependency:\n\n```html\n\u003cscript type=\"text/javascript\" src=\"funcs.js\"\u003e\u003c/script\u003e\n```\n\nWhen using an AMD loader (such as RequireJS) or CommonJS type loader, the funcs object is not automatically defined on the window scope.\n\nFor node.js, simply require the module as follows:\n\n````js\nvar funcs = require('funcs-js');\n````\n\n\u003ca name=\"usage-once\"\u003e\u003c/a\u003e\n\u003c!-- markdownlint-disable MD009 MD031 MD036 --\u003e\n### 'funcs.once(fn, [options]) ⇒ function'\nEnsures the provided function is invoked only once.\u003cbr\u003e\nThis is the same as calling funcs.maxTimes(fn, 1)\u003cbr\u003e\nThis function output can be chained with other funcs apis.\n\n**Example**  \n````js\nconst onlyOnceCallback = funcs.once(callback);\n\n//can also chain multiple modifications (chained functions do not require original function as argument)\nconst asyncOnceCallback = funcs.once(callback).async();\n````\n\u003c!-- markdownlint-enable MD009 MD031 MD036 --\u003e\n\n\u003ca name=\"usage-maxTimes\"\u003e\u003c/a\u003e\n\u003c!-- markdownlint-disable MD009 MD031 MD036 --\u003e\n### 'funcs.maxTimes(fn, times, [options]) ⇒ function'\nWraps the provided function and ensures it is invoked no more than the provided amount.\u003cbr\u003e\nThis function output can be chained with other funcs apis.\n\n**Example**  \n````js\nconst onlyOnceCallback = funcs.maxTimes(callback, 1);\n\n//can also chain multiple modifications (chained functions do not require original function as argument)\nconst delayedMaxTimesCallback = funcs.maxTimes(callback, 5).delay(500);\n````\n\u003c!-- markdownlint-enable MD009 MD031 MD036 --\u003e\n\n\u003ca name=\"usage-async\"\u003e\u003c/a\u003e\n\u003c!-- markdownlint-disable MD009 MD031 MD036 --\u003e\n### 'funcs.async(fn, [options]) ⇒ function'\nEnsures the function is invoked only in the next cycle.\u003cbr\u003e\nThis is the same as calling funcs.delay(fn, 0)\u003cbr\u003e\nThis function output can be chained with other funcs apis.\n\n**Example**  \n````js\nconst asyncCallback = funcs.async(callback);\n\n//can also chain multiple modifications (chained functions do not require original function as argument)\nconst asyncOnceCallback = funcs.async(callback).once();\n````\n\u003c!-- markdownlint-enable MD009 MD031 MD036 --\u003e\n\n\u003ca name=\"usage-delay\"\u003e\u003c/a\u003e\n\u003c!-- markdownlint-disable MD009 MD031 MD036 --\u003e\n### 'funcs.delay(fn, [delay], [options]) ⇒ function'\nTrigger the actual function only after the provided delay.\u003cbr\u003e\nThis function output can be chained with other funcs apis.\n\n**Example**  \n````js\nconst delayedCallback = funcs.delay(callback, 500);\n\n//can also chain multiple modifications (chained functions do not require original function as argument)\nconst delayedMaxTimesCallback = funcs.delay(callback, 500).maxTimes(5);\n````\n\u003c!-- markdownlint-enable MD009 MD031 MD036 --\u003e\n\n\u003ca name=\"usage-isFunction\"\u003e\u003c/a\u003e\n\u003c!-- markdownlint-disable MD009 MD031 MD036 --\u003e\n### 'funcs.isFunction([fn]) ⇒ Boolean'\nReturns true if the provided argument is a function.\n\n**Example**  \n````js\nconst isFn = funcs.isFunction(myFunction);\n\nfuncs.isFunction(function () {}); //true\nfuncs.isFunction(); //false\nfuncs.isFunction(5); //false\nfuncs.isFunction(true); //false\n````\n\u003c!-- markdownlint-enable MD009 MD031 MD036 --\u003e\n\n\u003ca name=\"usage-noop\"\u003e\u003c/a\u003e\n\u003c!-- markdownlint-disable MD009 MD031 MD036 --\u003e\n### 'funcs.noop() ⇒ undefined'\nEmpty function.\n\n\u003c!-- markdownlint-enable MD009 MD031 MD036 --\u003e\n\n\u003ca name=\"usage-ensure\"\u003e\u003c/a\u003e\n\u003c!-- markdownlint-disable MD009 MD031 MD036 --\u003e\n### 'funcs.ensure([fn]) ⇒ function'\nEnsures a return function.\u003cbr\u003e\nIf a function is provided, it will be returned, otherwise a noop function will be returned.\n\n**Example**  \n````js\nconst handler = funcs.ensure(maybeHandler);\n````\n\u003c!-- markdownlint-enable MD009 MD031 MD036 --\u003e\n\n\u003ca name=\"installation\"\u003e\u003c/a\u003e\n## Installation\nRun npm install in your project as follows:\n\n```sh\nnpm install --save funcs-js\n```\n\nOr if you are using bower, you can install it as follows:\n\n```sh\nbower install funcs-js --save\n```\n\n## API Documentation\nSee full docs at: [API Docs](docs/api.md)\n\n## Contributing\nSee [contributing guide](.github/CONTRIBUTING.md)\n\n\u003ca name=\"history\"\u003e\u003c/a\u003e\n## Release History\n\n| Date        | Version | Description |\n| ----------- | ------- | ----------- |\n| 2020-05-12  | v2.0.0  | Migrate to github actions, upgrade minimal node version and remove bower |\n| 2019-02-08  | v1.0.18 | Maintenance |\n| 2017-04-28  | v1.0.1  | Offical release |\n| 2017-04-28  | v0.0.6  | Docs |\n| 2017-04-28  | v0.0.5  | Rename package as funcs-js |\n| 2017-04-27  | v0.0.1  | Initial release |\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n## License\nDeveloped by Sagie Gur-Ari and licensed under the Apache 2 open source license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Ffuncs-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsagiegurari%2Ffuncs-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsagiegurari%2Ffuncs-js/lists"}