{"id":23014820,"url":"https://github.com/iamalexandros/astro-assert","last_synced_at":"2026-02-01T16:33:27.051Z","repository":{"id":265990725,"uuid":"897053171","full_name":"IamAlexandros/astro-assert","owner":"IamAlexandros","description":"Proper Assertions for Astro Endpoints","archived":false,"fork":false,"pushed_at":"2024-12-02T16:44:21.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-16T06:26:45.664Z","etag":null,"topics":["api","assert","assertion","assertions","astro","astrojs","endpoint","endpoints","withastro"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/astro-assert","language":"JavaScript","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/IamAlexandros.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":"2024-12-01T23:41:42.000Z","updated_at":"2024-12-02T16:44:24.000Z","dependencies_parsed_at":"2024-12-02T00:41:12.810Z","dependency_job_id":null,"html_url":"https://github.com/IamAlexandros/astro-assert","commit_stats":null,"previous_names":["iamalexandros/astro-assert"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IamAlexandros%2Fastro-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IamAlexandros%2Fastro-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IamAlexandros%2Fastro-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IamAlexandros%2Fastro-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IamAlexandros","download_url":"https://codeload.github.com/IamAlexandros/astro-assert/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250366688,"owners_count":21418768,"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":["api","assert","assertion","assertions","astro","astrojs","endpoint","endpoints","withastro"],"created_at":"2024-12-15T11:09:54.392Z","updated_at":"2026-02-01T16:33:27.004Z","avatar_url":"https://github.com/IamAlexandros.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `astro-assert` - Proper Assertions for [Astro](https://github.com/withastro/astro) Endpoints\n\n`astro-assert` provides an easy and effective way to assert conditions within your Astro API routes, ensuring that your endpoints handle errors gracefully and return the correct HTTP responses. This package streamlines error handling and validation, allowing you to focus on building your Astro project with confidence.\n\n## Installation (Choose your package manager)\n```bash\nnpm install astro-assert\n```\n```bash\nbun install astro-assert\n```\n```bash\npnpm install astro-assert\n```\n```bash\nyarn add astro-assert\n```\n\n## Usage\n\n### Example: Basic API Route\n\n#### Without `astro-assert`:\n```typescript\nexport const GET: APIRoute = ({ params, request }) =\u003e {\n  return new Response(JSON.stringify({\n      message: \"This was a GET!\"\n    })\n  )\n}\n```\n#### With `astro-assert`:\n```typescript\nimport { AssertAPIRoute, astroApiAssert } from 'astro-assert';\n\nexport const GET: APIRoute = async ({ request, params }) =\u003e AssertAPIRoute(async () =\u003e {\n    let aCoolParam = params.a_cool_param;\n\n    // Default Response(\"Something went wrong\", 400)\n    astroApiAssert(aCoolParam);\n\n    // Or provide a custom error message and status code\n    astroApiAssert(aCoolParam, \"aCoolParam not found\", 404);\n\n    return new Response(JSON.stringify({\n        message: \"This was a GET!\"\n    });\n});\n```\n\n## API\n\n### `AssertAPIRoute(callback: Function)`\n\nWrap your API route logic within this function to ensure that assertions are checked before proceeding. If any assertion fails, an appropriate response is automatically returned.\n\n### `astroApiAssert(value: any, message: string = \"Something went wrong\", statusCode: number = 400)`\n\nAsserts that the given value is truthy. If not, it throws a response with the provided message and status code.\n\n#### Parameters:\n- `value` (`any`): The value to assert.\n- `message` (`string`): The error message to return if the assertion fails (default: \"Something went wrong\").\n- `statusCode` (`number`): The HTTP status code to return if the assertion fails (default: 400).\n\n## Why Use `astro-assert`?\n\n- **Simplified Error Handling**: Easily manage assertions and error responses in your Astro API routes.\n- **Customizable Responses**: Control the error message and status code, making it adaptable to various use cases.\n- **Streamlined Code**: Keep your API logic clean and focused by reducing boilerplate error handling code.\n\n## Contributing\n\nFeel free to open issues and pull requests to help improve the package. Contributions are always welcome!\n\n## License\n\nMIT License. See the [LICENSE](LICENSE) file for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamalexandros%2Fastro-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamalexandros%2Fastro-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamalexandros%2Fastro-assert/lists"}