{"id":16498226,"url":"https://github.com/brillout/libassert","last_synced_at":"2025-06-18T17:37:17.435Z","repository":{"id":57185079,"uuid":"75291989","full_name":"brillout/libassert","owner":"brillout","description":"Tiny zero-dependency tool for library authors to create assertion functions with clean strack traces.","archived":false,"fork":false,"pushed_at":"2022-05-20T19:20:29.000Z","size":83,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-31T18:00:36.607Z","etag":null,"topics":["assert","assertion","assertion-library"],"latest_commit_sha":null,"homepage":"","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/brillout.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-01T12:48:32.000Z","updated_at":"2021-10-16T12:46:41.000Z","dependencies_parsed_at":"2022-09-01T19:10:57.229Z","dependency_job_id":null,"html_url":"https://github.com/brillout/libassert","commit_stats":null,"previous_names":["brillout/assertion-soft","brillout/reassert"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brillout/libassert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brillout%2Flibassert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brillout%2Flibassert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brillout%2Flibassert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brillout%2Flibassert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brillout","download_url":"https://codeload.github.com/brillout/libassert/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brillout%2Flibassert/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260600115,"owners_count":23034644,"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":["assert","assertion","assertion-library"],"created_at":"2024-10-11T14:47:44.002Z","updated_at":"2025-06-18T17:37:12.418Z","avatar_url":"https://github.com/brillout.png","language":"TypeScript","readme":"# `@brillout/libassert`\n\nTiny zero-dependency tool for library authors to create assertion functions with clean strack traces.\n\n- Complete stack traces. (`Error.stackTraceLimit = Infinity;` _only_ for assertion errors.)\n- Cleaned stack traces. (Fist stack line points to the assertion breaking code, useless stack lines are stripped away.)\n- Error messages are guaranteed to not contain new lines.\n\n```ts\nimport { newError } from \"@brillout/libassert\";\n\nexport { assert };\n\nfunction assert(condition: unknown): asserts condition {\n  if (condition) {\n    return;\n  }\n\n  const err = newError(\n    `[${libName}][Internal Error] Something unexpected happened, please open a GitHub issue.`;\n  );\n\n  throw err;\n}\n```\n\nCalling `newError(errorMessage)` is the same than `new Error(errorMessage)` except that:\n\n- The stack trace is complete and cleaned as described above.\n- `errorMessage` is forbidden to contain new lines.\n\nYou can create all kinds of assertion functions, such as `assertUsage` or `assertWarning`:\n\n```ts\nimport { newError } from \"@brillout/libassert\";\n\nexport { assert, assertUsage, assertWarning };\n\nconst libName = \"My Awesome Library\";\n\n// Assertions that are expected to always be true (also known as \"invariants\")\nfunction assert(condition: unknown): asserts condition {\n  if (condition) {\n    return;\n  }\n\n  const err = newError(\n    `[${libName}][Internal Error] Something unexpected happened, please open a GitHub issue.`;\n  );\n\n  throw err;\n}\n\n// Wrong usage of your library\nfunction assertUsage(\n  condition: unknown,\n  errorMessage: string\n): asserts condition {\n  if (condition) {\n    return;\n  }\n\n  const err = newError(prefix: `[${libName}][Wrong Usage] ${errorMessage}`);\n\n  throw err;\n}\n\n// Something unexpected happened but it is non-critical and doesn't\n// warrant interrupting code execution.\nfunction assertWarning(condition: unknown, errorMessage: string): void {\n  if (condition) {\n    return;\n  }\n\n  const err = newError(`[${libName}][Warning] ${errorMessage}`);\n\n  console.warn(err);\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrillout%2Flibassert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrillout%2Flibassert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrillout%2Flibassert/lists"}