{"id":21004676,"url":"https://github.com/flaque/stop-if","last_synced_at":"2025-10-24T19:09:35.343Z","repository":{"id":80716174,"uuid":"97290877","full_name":"Flaque/stop-if","owner":"Flaque","description":"An assert statement that turns off in production","archived":false,"fork":false,"pushed_at":"2017-10-01T19:22:49.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T10:13:53.582Z","etag":null,"topics":["assertion-library","javascript","npm-package"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Flaque.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-15T03:57:29.000Z","updated_at":"2017-07-15T05:30:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"07ba7f78-bb0d-40ea-b0a7-659c83cb1c91","html_url":"https://github.com/Flaque/stop-if","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flaque%2Fstop-if","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flaque%2Fstop-if/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flaque%2Fstop-if/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flaque%2Fstop-if/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Flaque","download_url":"https://codeload.github.com/Flaque/stop-if/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243419466,"owners_count":20287895,"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":["assertion-library","javascript","npm-package"],"created_at":"2024-11-19T08:37:27.833Z","updated_at":"2025-10-24T19:09:30.321Z","avatar_url":"https://github.com/Flaque.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hey You! Don't use this library \n\nIt already exists in the form of [invariant](https://github.com/zertosh/invariant). Didn't realize that at the time. \n\n----\n\n# stop-if\n\n`stop-if` is a tiny function that fills the need of an assert statement in javascript. However, if the function is run in a production environment:\n\n``` js\nprocess.env.NODE_ENV === \"production\"\n```\n\nthen `stop-if` will do nothing. \n\nThe goal of `stop-if` is to catch bugs early without ever risking uncaught production errors. \n\n## Install\n\nWith npm\n``` bash\n$ npm install --save stop-if\n```\n\nWith yarn\n``` bash \n$ yarn add stop-if\n```\n\n## Example\n\n``` js\nimport stopIf from 'stop-if';\n\nfunction addToList(item) {\n    stopIf(list === undefined)\n    list.add(item)\n}\n```\n\nYou can also add a message if you would like:\n\n``` js \nstopIf(foo, \"Fee fi fo fum, I smell the code of a hum-ity-dum.\");\n```\n\n## Why is this not called `assert`?\n\nJavascript testing frameworks frequently use terms like `assert` or `expect` to prove a statement. `stopIf` is named differently to avoid any confusion with these sorts of statements.\n\n## When should I use `stop-if`? \n\nStop-if, as with all assert statements, should be used as a way of expressing original intent of a function. It should be used to prove pre or post conditions or to standardize a way a function should be used. \n\n## When should I not use `stop-if`? \n\nYou should not use `stop-if` as a regular `throw` statement. A regular throw statement should only be used in `except`tional circumstances that are theoretically possible in the function, but not desired. For example, opening a file and then noticing that it doesn't exist would be an exception that you should use a regular `throw` statement.\n\nIt follows that you should not ever attempt to `catch` a `stopIf` function. The function will not run in production and therefore your catch is entirely useless.\n\nNever do this:\n\n``` js \ntry { // no \n  stopIf(true); // no\n} catch (Error e) { // no \n  console.error(e); // no \n} // no wtf no\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaque%2Fstop-if","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflaque%2Fstop-if","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaque%2Fstop-if/lists"}