{"id":36985628,"url":"https://github.com/tlonny/astroparse","last_synced_at":"2026-01-13T23:02:54.512Z","repository":{"id":329185466,"uuid":"1113905618","full_name":"tlonny/astroparse","owner":"tlonny","description":"A minimal, zero dependency, fully-typed parser combinator library","archived":false,"fork":false,"pushed_at":"2025-12-18T15:08:32.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-21T08:56:35.824Z","etag":null,"topics":["functional","parser","parser-combinators","typescript"],"latest_commit_sha":null,"homepage":"https://tlonny.github.io/astroparse/","language":"TypeScript","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/tlonny.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-10T16:18:21.000Z","updated_at":"2025-12-18T15:07:38.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tlonny/astroparse","commit_stats":null,"previous_names":["tlonny/astroparse"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/tlonny/astroparse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlonny%2Fastroparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlonny%2Fastroparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlonny%2Fastroparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlonny%2Fastroparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tlonny","download_url":"https://codeload.github.com/tlonny/astroparse/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tlonny%2Fastroparse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28399674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["functional","parser","parser-combinators","typescript"],"created_at":"2026-01-13T23:02:52.034Z","updated_at":"2026-01-13T23:02:54.505Z","avatar_url":"https://github.com/tlonny.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AstroParse\n\n![ci](https://github.com/tlonny/astroparse/actions/workflows/check.yml/badge.svg)\n\nA minimal, zero dependency, fully-typed parser combinator library.\n\n## Installation\n\n```bash\nnpm install astroparse\n```\n\n## Quick Look\n\n```typescript\nimport {\n    parserAtomMapValue,\n    parserAtomSequence,\n    parserAtomCharacter,\n    parserAtomTry,\n    parserAtomPredicate,\n    parserText,\n    parserWhitespace,\n    parserAtomMany\n} from \"astroparse\"\n\nconst parserName = parserAtomMapValue(\n    parserAtomMany(\n        parserAtomTry(\n            parserAtomPredicate(\n                parserAtomCharacter,\n                c =\u003e /[a-zA-Z]/.test(c)\n                    ? { success: true }\n                    : { success: false, error: null }\n            )\n        )\n    ),\n    (chars) =\u003e chars.join(\"\").toUpperCase()\n)\n\n\nconst parserShout = parserAtomMapValue(\n    parserAtomSequence([\n        parserText({ word: \"hello\" }),\n        parserWhitespace,\n        parserName\n    ]),\n    ([,, name]) =\u003e `Hello, ${name}!`\n)\n\nconst result = parserShout({ data: \"hello \\tsteven\", cursor: 0 })\n\nif (result.success) {\n    console.log(result.value) // Hello, STEVEN!\n} else {\n    console.error(result.error)\n}\n```\n\n## Parser Definition\n\nA parser is simply a function that takes a `ParseInput` and returns a `ParseResult\u003cTValue, TError\u003e`.\n\nA `ParseInput` is simply an object containing some string to be parsed, and a cursor describing how much of the string has been consumed.\n\n```typescript\nexport type ParseInput = {\n    data: string\n    cursor: number\n}\n```\n\nA `ParseResult\u003cTValue, TError\u003e` is a discriminated union type describing either a successful or failed parse on a given input:\n\n```typescript\nexport type ParseResult\u003cTValue, TError\u003e =\n    | ParseResultValue\u003cTValue\u003e\n    | ParseResultError\u003cTError\u003e\n```\n\nA successful parse will yield a `ParseResultValue\u003cTValue\u003e` object, containing a boolean success discriminator, the value parsed from the input (of type `TValue`) and a new `ParseInput` reflecting any potential changes to input consumption:\n\n```typescript\nexport type ParseResultValue\u003cTValue\u003e = {\n    success: true\n    value: TValue,\n    input: ParseInput\n}\n```\n\nA failed parse will yield a `ParseResultError\u003cTError\u003e` object, containing a boolean success discriminator, the error returned by the parser (of type `TError`) and a new `ParseInput` reflecting any potential changes to input consumption:\n\n```typescript\nexport type ParseResultError\u003cTError\u003e = {\n    success: false\n    error: TError,\n    input: ParseInput\n}\n```\n\nThus it is possible to create your own custom parsers by directly implementing functions that conform to the above spec. However, it is recommended that you instead construct custom parsers by composing the suite of atomic parsers provided by AstroParse where possible (it is a parser _combinator_ library after all!)\n\n## Atomic Parsers\n\nAstroParse provides a minimal (but arguably \"complete\") set of generic, atomic parsers:\n\n - `parserAtomCharacter`: consumes and returns the next input character. Errors if at the end of the input.\n - `parserAtomEnd`: complements `parserAtomCharacter` - returns a null if at the end of the input. Errors otherwise.\n - `parserAtomValue`: always \"parses\" a specified value without consuming any input.\n - `parserAtomError`: always returns a specified error without consuming any input.\n - `parserAtomPredicate`: wraps an existing parser, checking the result against a predicate function and erroring if the predicate fails.\n - `parserAtomTry`: wraps an existing parser, backtracking any consumed input if the inner parser errors.\n - `parserAtomPeek`: wraps an existing parser, backtracking any consumed input if the inner parser succeeds.\n - `parserAtomMany`: wraps an existing parser, applying it repeatedly to produce an array of parsed values until an error is observed. The error will propagate if the erroring parser has consumed input.\n - `parserAtomEither`: wraps an array of parsers, attempting to parse each in order until a first value is successfully parsed. Any errors produced by sub-parsers will only propagate if input has been consumed.\n - `parserAtomSequence`: wraps an array of parsers, attempting to parse each in sequence until all have successfully parsed. Any errors produced by sub-parsers are propagated straight away.\n - `parserAtomMapValue`: wraps a parser with a mapping function that transforms any parsed value whilst ignoring errors.\n - `parserAtomMapError`: wraps a parser with a mapping function that transforms any errors whilst ignoring parsed values.\n\n## Non-Atomic Parsers\n\nAstroParse also provides a small set of non-atomic \"utility/common\" parsers. You're encouraged to inspect the source for these parsers as it is a useful resource when it comes to composing your own parsers:\n\n- `parserText`: parses a specified text string exactly as-is. Will not consume input on failure.\n- `parserAlpha`: parses a single alphabetical character (A-Z or a-z). Will not consume input on failure.\n- `parserDigit`: parses a single numeric digit (0-9). Will not consume input on failure.\n- `parserNewline`: parses a newline sequence, supporting both `\\n` and `\\r\\n`. Will not consume input on failure.\n- `parserWhitespace`: parses a (potentially empty) region of whitespace. Will never return an error.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlonny%2Fastroparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftlonny%2Fastroparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftlonny%2Fastroparse/lists"}