{"id":41171518,"url":"https://github.com/open-draft/outvariant","last_synced_at":"2026-01-22T19:43:16.871Z","repository":{"id":40778613,"uuid":"381859356","full_name":"open-draft/outvariant","owner":"open-draft","description":"Type-safe implementation of invariant with positionals.","archived":false,"fork":false,"pushed_at":"2024-07-05T10:11:40.000Z","size":158,"stargazers_count":55,"open_issues_count":0,"forks_count":4,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-20T11:45:07.702Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npm.im/outvariant","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/open-draft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-06-30T23:44:12.000Z","updated_at":"2025-10-18T02:56:36.000Z","dependencies_parsed_at":"2023-12-14T11:57:52.593Z","dependency_job_id":"196e3879-0faa-432e-8bc7-877dce621ef1","html_url":"https://github.com/open-draft/outvariant","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"c89e86d824ae7cb58cb81b320aeb87f5a7528b58"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/open-draft/outvariant","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-draft%2Foutvariant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-draft%2Foutvariant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-draft%2Foutvariant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-draft%2Foutvariant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-draft","download_url":"https://codeload.github.com/open-draft/outvariant/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-draft%2Foutvariant/sbom","scorecard":{"id":708304,"data":{"date":"2025-08-11","repo":{"name":"github.com/open-draft/outvariant","commit":"20bee3177d4b01e5fc66bdea43099ae0116870c3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.2,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":1,"reason":"Found 3/29 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/open-draft/outvariant/main.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/open-draft/outvariant/main.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/open-draft/outvariant/main.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/open-draft/outvariant/main.yml/main?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 13 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":3,"reason":"7 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T07:24:04.149Z","repository_id":40778613,"created_at":"2025-08-22T07:24:04.149Z","updated_at":"2025-08-22T07:24:04.149Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27996293,"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-12-24T02:00:07.193Z","response_time":83,"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":[],"created_at":"2026-01-22T19:43:16.342Z","updated_at":"2026-01-22T19:43:16.859Z","avatar_url":"https://github.com/open-draft.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `outvariant`\n\nType-safe implementation of invariant with positionals.\n\n## Motivation\n\n### Type-safely\n\nThis implementation asserts the given predicate expression so it's treated as non-nullable after the `invariant` call:\n\n```ts\n// Regular invariant:\ninvariant(user, 'Failed to fetch')\nuser?.firstName // \"user\" is possibly undefined\n\n// Outvariant:\ninvariant(user, 'Failed to fetch')\nuser.firstName // OK, \"invariant\" ensured the \"user\" exists\n```\n\n### Positionals support\n\nThis implementation uses [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) to support dynamic number of positionals:\n\n```js\ninvariant(predicate, 'Expected %s but got %s', 'one', false)\n```\n\n## What is this for?\n\nInvariant is a shorthand function that asserts a given predicate and throws an error if that predicate is false.\n\nCompare these two pieces of code identical in behavior:\n\n```js\nif (!token) {\n  throw new Error(`Expected a token to be set but got ${typeof token}`)\n}\n```\n\n```js\nimport { invariant } from 'outvariant'\n\ninvariant(token, 'Expected a token to be set but got %s', typeof token)\n```\n\nUsing `invariant` reduces the visual nesting of the code and leads to cleaner error messages thanks to formatted positionals (i.e. the `%s` (string) positional above).\n\n## Usage\n\n### Install\n\n```sh\nnpm install outvariant\n```\n\n\u003e You may want to install this library as a dev dependency (`-D`) based on your usage.\n\n### Write an assertion\n\n```js\nimport { invariant } from 'outvariant'\n\ninvariant(user, 'Failed to load: expected user, but got %o', user)\n```\n\n## Positionals\n\nThe following positional tokens are supported:\n\n| Token     | Expected value type                                     |\n| --------- | ------------------------------------------------------- |\n| `%s`      | String                                                  |\n| `%d`/`%i` | Number                                                  |\n| `%j`      | JSON (non-stringified)                                  |\n| `%o`      | Arbitrary object or object-like (i.e. a class instance) |\n\nWhenever present in the error message, a positional token will look up the value to insert in its place from the arguments given to `invariant`.\n\n```js\ninvariant(\n  false,\n  'Expected the \"%s\" property but got %j',\n  // Note that positionals are sensitive to order:\n  // - \"firstName\" replaces \"%s\" because it's first.\n  // - {\"id\":1} replaces \"%j\" because it's second.\n  'firstName',\n  {\n    id: 1,\n  },\n)\n```\n\n## Polymorphic errors\n\nIt is possible to throw a custom `Error` instance using `invariant.as`:\n\n```js\nimport { invariant } from 'outvariant'\n\nclass NetworkError extends Error {\n  constructor(message) {\n    super(message)\n  }\n}\n\ninvariant.as(NetworkError, res.fulfilled, 'Failed to handle response')\n```\n\nNote that providing a custom error constructor as the argument to `invariant.as` requires the custom constructor's signature to be compatible with the `Error` class constructor.\n\nIf your error constructor has a different signature, you can pass a function as the first argument to `invariant.as` that creates a new custom error instance.\n\n```js\nimport { invariant } from 'outvariant'\n\nclass NetworkError extends Error {\n  constructor(statusCode, message) {\n    super(message)\n    this.statusCode = statusCode\n  }\n}\n\ninvariant.as(\n  (message) =\u003e new NetworkError(500, message),\n  res.fulfilled,\n  'Failed to handle response',\n)\n```\n\nAbstract the error into helper functions for flexibility:\n\n```js\nfunction toNetworkError(statusCode) {\n  return (message) =\u003e new NetworkError(statusCode, message)\n}\n\ninvariant.as(toNetworkError(404), res?.user?.id, 'User Not Found')\ninvariant.as(toNetworkError(500), res.fulfilled, 'Internal Server Error')\n```\n\n## Contributing\n\nPlease [open an issue](https://github.com/open-draft/outvariant/issues) or [submit a pull request](https://github.com/open-draft/outvariant/pulls) if you wish to contribute. Thank you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-draft%2Foutvariant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-draft%2Foutvariant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-draft%2Foutvariant/lists"}