{"id":13998491,"url":"https://github.com/ryohey/tspc","last_synced_at":"2025-09-01T10:09:18.721Z","repository":{"id":57381793,"uuid":"199483069","full_name":"ryohey/tspc","owner":"ryohey","description":"A Strongly-typed parser combinator written in TypeScript.","archived":false,"fork":false,"pushed_at":"2022-08-22T02:49:51.000Z","size":132,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-28T05:42:22.659Z","etag":null,"topics":["parser","parser-combinators","typescript"],"latest_commit_sha":null,"homepage":"","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/ryohey.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}},"created_at":"2019-07-29T15:50:32.000Z","updated_at":"2025-03-15T16:09:11.000Z","dependencies_parsed_at":"2022-09-13T11:30:59.371Z","dependency_job_id":null,"html_url":"https://github.com/ryohey/tspc","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ryohey/tspc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryohey%2Ftspc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryohey%2Ftspc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryohey%2Ftspc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryohey%2Ftspc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryohey","download_url":"https://codeload.github.com/ryohey/tspc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryohey%2Ftspc/sbom","scorecard":{"id":793056,"data":{"date":"2025-08-11","repo":{"name":"github.com/ryohey/tspc","commit":"b134a095e1974ecc653d3604eecc1a702204fc99"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"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":"Code-Review","score":0,"reason":"Found 0/19 approved changesets -- score normalized to 0","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":"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":"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":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/ryohey/tspc/node.js.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/ryohey/tspc/node.js.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/ryohey/tspc/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/ryohey/tspc/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/ryohey/tspc/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/ryohey/tspc/npm-publish.yml/main?enable=pin","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   3 out of   3 npmCommand 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":"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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/node.js.yml:1","Warn: no topLevel permission defined: .github/workflows/npm-publish.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":"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":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"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":"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 6 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":2,"reason":"8 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw"],"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-23T08:07:19.375Z","repository_id":57381793,"created_at":"2025-08-23T08:07:19.375Z","updated_at":"2025-08-23T08:07:19.375Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273105960,"owners_count":25046950,"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-09-01T02:00:09.058Z","response_time":120,"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":["parser","parser-combinators","typescript"],"created_at":"2024-08-09T19:01:43.167Z","updated_at":"2025-09-01T10:09:18.699Z","avatar_url":"https://github.com/ryohey.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# tspc\n\nA Strongly-typed parser combinator written in TypeScript, heavily inspired by [fnparse.js](https://github.com/anatoo/fnparse.js).\n\n## Installation\n\n```sh\nnpm install tspc\n```\n\n## Example\n\n```ts\nconst part = map(many(num), (arr) =\u003e parseInt(arr.join(\"\")))\nconst ipString = seq(part, token(\".\"), part, token(\".\"), part, token(\".\"), part)\nconst ipParser = map(ipString, ([a, _, b, __, c, ___, d]) =\u003e [a, b, c, d])\nipParser(\"192.168.0.1\", 0).value // [192, 168, 0, 1]\n```\n\n## What is tspc\n\nIt is a simple and very flexible parser combinator, capable of converting parsed results not only to strings, but also to complex arrays and objects.\n\n```ts\n// Parse hex color or color name\n// returns color value in number\nconst parser = or(\n  map(seq(token(\"#\"), map(regexp(/[0-9a-f]/), str =\u003e parseInt(str, 16)), arr =\u003e arr[1]),\n  map(token(\"red\"), () =\u003e 0xff0000)\n)\nparser(\"#c0ffee\", 0).value // 0xc0ffee\nparser(\"red\", 0).value // 0xff0000\nparser(\"hello\", 0).success // false\nconsole.log(parser(\"hello\", 0).error) // prints parsing error\n```\n\n## Strongly Typed\n\nCareful design ensures that type information is kept complete, so even complex parsers can automatically determine the type of the result.\n\n```ts\nconst attr = (name: string) =\u003e\n  map(\n    seq(token(name), token('=\"'), regexp(/[a-zA-Z0-9]/), token('\"')), // Parser\u003cstring, [string, '=\"', string, '\"']\u003e\n    (result) =\u003e ({ [name]: result[2] })\n  ) // Parser\u003cstring, {[key: string]: string}\u003e\nconst aTagParser = map(\n  seq(token(\"\u003ca\"), many(or(attr(\"href\"), attr(\"target\"))), token(\"\u003e\")), // Parser\u003cstring, [\"\u003ca\", {[key: string]: string}[], \"\u003e\"]\u003e\n  (result) =\u003e ({\n    tagName: name,\n    attributes: result[1],\n  })\n) // Parser\u003cstring, { tagName: string, attributes: {[key: string]: string}[] }\u003e\n```\n\n## Generic\n\nParser input is not limited to strings. Any type that can represent the parse position numerically, such as an array of numbers, can be used.\n\n```ts\nconst\n```\n\n## Core API\n\n### Parser\n\nThe type for parser functions. Parser takes a input and the reading position.\n\n```ts\ntype Parser\u003cT, S\u003e = (target: T, position: number) =\u003e Result\u003cS\u003e\n\ntype Result\u003cT\u003e =\n  | {\n      success: true\n      position: number\n      value: T\n    }\n  | {\n      success: false\n      position: number\n      error: string\n    }\n```\n\n### `or`\n\nParser that succeeds if any of the given parsers succeeds.\n\n```ts\nconst bit = or(token(\"0\"), token(\"1\"))\n```\n\n### `many`\n\nParser that iterates until the given parser fails and returns as an array.\n\n```ts\nconst binary = many(bit) // Parser\u003cstring, string[]\u003e\n```\n\n### `seq`\n\nReturns Parser from the sequence of Parsers.\n\n```ts\nconst parser = seq(token(\"0b\"), binary)\n```\n\n### `map`\n\nConvert the result of the given parser.\n\n```ts\nconst parser = map(binary, (str) =\u003e parseInt(str, 2)) // Parser\u003cstring, number\u003e\n```\n\n### `opt`\n\nParser that returns a given parser as a success even if it fails. The value will be nullable.\n\n```ts\nconst parser = seq(token(\"http\"), opt(\"s\"), token(\"://\")) // Parser\u003cstring, [string, string | null, string]\u003e\n```\n\n### `vec`\n\nRepeats the given parser a specified number of times. Unlike `many`, if parsing fails before the specified number of times, it fails.\n\n```ts\nconst byte = vec(bit, 8)\n```\n\n### `seqMap`\n\nParser that generates and applies a parser from the results of a given parser.\n\n```ts\n// Parser that reads the remaining byte sequence for the number read in the first byte\nconst parser = seqMap(byte, (size) =\u003e vec(byte, size))\n```\n\n### `transform`\n\nParser that passes the result of the first parser as input to the second parser.\n\n```ts\nconst parser = transform(byteToStringParser, jsonParser)\n```\n\n### `lazy`\n\nParser that returns the parser generated by the given closure. Typically used to create a recursive parser.\n\n### `fail`\n\nParser that always fails.\n\n### `pass`\n\nParser that always succeeds.\n\n### `terminate`\n\nParser that always succeeds. Unlike `pass`, it does not advance the position.\n\n## String API\n\n### `token`\n\nParser that succeeds if it matches the given string.\n\n```ts\nconst parser = token(\"hello\")\nparser(\"hello, world!\", 0).value // \"hello\"\n```\n\n### `regexp`\n\nParser that succeeds if it matches the given regular expression.\n\n```ts\nconst parser = regexp(/[a-zA-Z]+/)\nparser(\"hello, world!\", 0).value // \"hello\"\n```\n\n### `num`\n\nParser matching a single numeric character.\n\n```ts\nnum(\"31415\") // \"3\"\n```\n\n### `uint`\n\nParser to match positive decimal integers. Results are number.\n\n```ts\nuint(\"926535\").value // 926535\n```\n\n### `int`\n\nParser to match decimal integers. Results are number.\n\n```ts\nint(\"-12345\").value // -12345\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryohey%2Ftspc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryohey%2Ftspc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryohey%2Ftspc/lists"}