{"id":22031629,"url":"https://github.com/bsara/call-if","last_synced_at":"2026-04-15T19:32:06.226Z","repository":{"id":57192959,"uuid":"103968412","full_name":"bsara/call-if","owner":"bsara","description":null,"archived":false,"fork":false,"pushed_at":"2018-10-09T23:48:22.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T20:55:16.386Z","etag":null,"topics":["isc","javascript","micro-library"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsara.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":"2017-09-18T17:11:45.000Z","updated_at":"2018-10-09T23:48:23.000Z","dependencies_parsed_at":"2022-09-01T03:40:24.324Z","dependency_job_id":null,"html_url":"https://github.com/bsara/call-if","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/bsara/call-if","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsara%2Fcall-if","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsara%2Fcall-if/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsara%2Fcall-if/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsara%2Fcall-if/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsara","download_url":"https://codeload.github.com/bsara/call-if/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsara%2Fcall-if/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269390832,"owners_count":24409504,"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-08T02:00:09.200Z","response_time":72,"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":["isc","javascript","micro-library"],"created_at":"2024-11-30T08:19:29.042Z","updated_at":"2026-04-15T19:32:01.193Z","avatar_url":"https://github.com/bsara.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# call-if [![NPM Package](https://img.shields.io/npm/v/call-if.svg?style=flat-square)][npm]\n\n![ISC License](https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square)\n\n\u003e A micro-library of functions that call a given function if a given condition is met.\n\u003e\n\u003e This library was created for both convenience purposes and for the cleaner code that\n\u003e can be produced by using its provided functions.\n\n\u003e **NOTE:** Compatible with ES4+ browsers, AMD, CommonJS, ES6 Imports, and HTML\n\u003e script references.\n\n[Changelog](https://github.com/bsara/call-if/blob/master/CHANGELOG.md)\n\n\n\n## Install\n\n```bash\n$ npm i --save call-if\n```\n\n\n## Usage\n\n```js\nimport { callIf, callIfOrNull } from 'call-if';\n\n\nfunction myFunc(valueToPrint, valueToReturn) {\n  console.log(valueToPrint);\n\n  return valueToReturn;\n}\n\n\ncallIf(true, myFunc, \"Fish fingers and custard\", 42);  // Prints \"Fish fingers and custard\" \u0026 returns 42\ncallIf(false, myFunc, \"Fish fingers and custard\", 42); // Prints nothing and returns `undefined`\n\ncallIfOrNull(true, myFunc, \"Fish fingers and custard\", 42);  // Prints \"Fish fingers and custard\" \u0026 returns 42\ncallIfOrNull(false, myFunc, \"Fish fingers and custard\", 42); // Prints nothing and returns `null`\n\n```\n\n\n## API\n\n### callIf(condition, func, *[...funcParams]*)\n\nReturns the result of calling `func` if given `condition` evaluates to `true`; otherwise,\nreturns `undefined`.\n\n- **condition** `?Boolean`\n\n  Condition used to determine whether to call end return the result of `func` or `undefined`.\n\n- **func** `Function`\n\n  Function to be called if `condition` evaluates to `true`.\n\n- **...funcParams** `?...*`\n\n  Parameters to be passed to `func`, if called.\n\n\n\u003cbr/\u003e\n\n\n### callIfOrNull(condition, func, *[...funcParams]*)\n\nReturns the result of calling `func` if given `condition` evaluates to `true`; otherwise,\nreturns `null`.\n\n- **condition** `?Boolean`\n\n  Condition used to determine whether to call end return the result of `func` or `null`.\n\n- **func** `Function`\n\n  Function to be called if `condition` evaluates to `true`.\n\n- **...funcParams** `?...*`\n\n  Parameters to be passed to `func`, if called.\n\n\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n\n# License\n\nISC License (ISC)\n\nCopyright (c) 2018, Brandon D. Sara (http://bsara.pro/)\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted, provided that the above\ncopyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n\n\n\n[license]: https://github.com/bsara/call-if/blob/master/LICENSE \"License\"\n[npm]:     https://www.npmjs.com/package/call-if                \"NPM Package: call-if\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsara%2Fcall-if","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsara%2Fcall-if","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsara%2Fcall-if/lists"}