{"id":50449667,"url":"https://github.com/adrgautier/soit","last_synced_at":"2026-05-31T23:32:17.434Z","repository":{"id":42628534,"uuid":"391760577","full_name":"adrgautier/soit","owner":"adrgautier","description":"TypeScript enums replacement which helps type narrowing.","archived":false,"fork":false,"pushed_at":"2025-03-14T08:16:45.000Z","size":159,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-23T18:41:39.324Z","etag":null,"topics":["enum","guard","set","typescript"],"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/adrgautier.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-08-01T23:14:50.000Z","updated_at":"2024-05-13T17:25:03.000Z","dependencies_parsed_at":"2024-05-13T18:41:17.753Z","dependency_job_id":"37701bd5-06cd-488c-936e-438268a6670f","html_url":"https://github.com/adrgautier/soit","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"ce28f11f4f772d1573258507e5857a7de2c6482e"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/adrgautier/soit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrgautier%2Fsoit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrgautier%2Fsoit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrgautier%2Fsoit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrgautier%2Fsoit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adrgautier","download_url":"https://codeload.github.com/adrgautier/soit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrgautier%2Fsoit/sbom","scorecard":{"id":167633,"data":{"date":"2025-08-11","repo":{"name":"github.com/adrgautier/soit","commit":"5ee19f848f225c71265200bbcb0e10b19a3eb762"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"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":"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":0,"reason":"Found 0/21 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":"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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/adrgautier/soit/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/adrgautier/soit/npm-publish.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/adrgautier/soit/npm-publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/adrgautier/soit/tests.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tests.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/adrgautier/soit/tests.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/adrgautier/soit/tests.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/tests.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/adrgautier/soit/tests.yml/main?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   3 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":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1","Warn: no topLevel permission defined: .github/workflows/tests.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":"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":"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":"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":"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":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"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":5,"reason":"5 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-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv"],"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-16T15:21:28.237Z","repository_id":42628534,"created_at":"2025-08-16T15:21:28.237Z","updated_at":"2025-08-16T15:21:28.237Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33753923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"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":["enum","guard","set","typescript"],"created_at":"2026-05-31T23:32:10.007Z","updated_at":"2026-05-31T23:32:17.412Z","avatar_url":"https://github.com/adrgautier.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![Soit](./Soit.svg)\n\n ![typescript](https://img.shields.io/badge/written%20for-typescript-3178c6?style=flat-square) [![codecov](https://img.shields.io/codecov/c/github/adrgautier/soit?style=flat-square\u0026token=IPTGBDRRJE)](https://codecov.io/gh/adrgautier/soit) ![prettier](https://img.shields.io/badge/code%20style-prettier-ff69b4?style=flat-square) [![npm](https://img.shields.io/npm/v/soit?style=flat-square)](https://www.npmjs.com/package/soit)\n\n**Soit** (French for: either) is like an enhanced [Set()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) function which provides **type narrowing** and **template** \u003csup\u003e`beta`\u003c/sup\u003e utils.\n\n## Motivation\n\nOne of the main goal of TypeScript is to deal with **uncertainty**, to ensure that all possibilities have been taken into account during compilation. Sometimes the type itself can be uncertain (e.g. is it a `string` or a  `number`?), but it is also common to know all possible values before runtime.\n\nThe simplest way to declare all possible values is to write a union:\n```ts\ntype HTTPMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\";\n```\n\nAnother approach is to use the enum feature of TypeScript:\n```ts\nenum HTTPMethod {\n    GET = \"GET\",\n    POST = \"POST\",\n    PUT = \"PUT\",\n    DELETE = \"DELETE\"\n}\n```\n\nWhatever approach you use, you won't be able (easily) to [narrow a type down](https://www.typescriptlang.org/docs/handbook/2/narrowing.html) to this set of values or to [get an array from](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from) this set of values.\n\nI created *Soit* to be a simple lib that provide the features aforementioned.\n\n## Declaration\n\nA *Soit* instance can be created by passing an array of *literals* to the `Soit()` function.\n```ts\nimport Soit from \"soit\";\n\nconst isHTTPMethod = Soit([\"GET\", \"POST\", \"PUT\", \"DELETE\"]);\n```\n\nA [literal](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) is a specific string, number or boolean.\n```ts\nconst isOne = Soit([\"1\", \"one\", 1, true]);\n```\n\nYou can infer the corresponding type using the `Infer` generic provided by the lib.\n```ts\nimport { Infer } from \"soit\";\n\ntype HTTPMethod = Infer\u003ctypeof isHTTPMethod\u003e; // infers \"GET\" | \"POST\" | \"PUT\" | \"DELETE\"\n```\n\n## Guard behavior\n\nA *Soit* instance is intended to be used as a type guard:\n```ts\nfunction handleHTTPMethod(method: string) {\n    if(isHTTPMethod(method)) {\n        // method's value is \"GET\", \"POST\", \"PUT\" or \"DELETE\"\n    }\n    throw new Error(\"Unknown HTTP method.\");\n}\n```\n\n## Iterable behavior\n\nBecause the *Soit* instance is **iterable**, you can access the corresponding array:\n```ts\nconst HTTPMethodArray = Array.from(isHTTPMethod);\n```\n\nYou may prefer this syntax:\n```ts\nconst HTTPMethodArray = [...isHTTPMethod];\n```\n\n## Array methods \u003csup\u003e`deprecated`\u003c/sup\u003e\n\nA *Soit* instance gives access to two Array methods : `map` and `forEach`\n\n```ts\nisHTTPMethod.forEach(method =\u003e console.log(method));\n\nconst lowerCaseHTTPMethodArray = isHTTPMethod.map(method =\u003e method.toLowerCase());\n```\n\n\u003e `map` and `forEach` are simple shortcuts, e.g. : \n\u003e ```ts\n\u003e [...isHTTPMethod].forEach(method =\u003e console.log(method));\n\u003e ```\n\u003e\n\u003e The map method for instance can be confusing because it does not return a new *Soit* instance.\n\u003e For this reason, both methods will be removed with the next major release.\n\n## Set methods\n\nSet methods aim to create new *Soit* instances by adding or subtracting values from an existing instance.\n\n\u003e I created these methods before the new [composition methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#set_composition) where added to the **Set** object.\n\u003e This new API will certainly influence the naming of *Soit* methods in the next major release.\n\n### `.subset([])`\n\nYou can create subsets using the `subset` method.\n```ts\nconst isHTTPMutationMethod = isHTTPMethod.subset([\"POST\", \"PUT\", \"DELETE\"]);\n```\n\n\u003e This checks on build time that `\"POST\"`, `\"PUT\"` and `\"DELETE\"` do exist in the `isHTTPMethod` instance.\n\n### `.extend([])`\n\nYou can extend an existing *Soit* instance using the `extend` method.\n```ts\nconst isHTTPMethod = isHTTPMutationMethod.extend([\"GET\"]);\n```\n\n### `.difference([])`\n\nYou can create a new instance without the specified values using the `difference` method.\n\n```ts\nconst isHTTPQueryMethod = isHTTPMethod.difference([\"POST\", \"PUT\", \"DELETE\"]);\n```\n\n\u003e The given array don't need to be a subset and can contain values that don't exist in the initial instance.\n\n## Template \u003csup\u003e`beta`\u003c/sup\u003e\n\nThe template feature allows mimicking the [template literal type](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#handbook-content) mechanism, but with runtime utils.\nLet's take the following template literal type:\n\n```ts\ntype TimeGetter = `get${\"Seconds\" | \"Minutes\" | \"Hours\"}`;\n```\n\nThe `TimeGetter` type will only accept the following values: `\"getSeconds\"`, `\"getMinutes\"` and `\"getHours\"`.\n\nHere is how you would use the template feature from *Soit*:\n\n```ts\nconst isUnit = Soit([\"Seconds\", \"Minutes\", \"Hours\"]);\nconst isTimeGetter = Soit.Template(\"get\", isUnit);\n```\nThe `Template()` function is able to construct the corresponding template using the strings as the \"static\" parts and the *Soit* instances as the \"dynamic\" parts. \n\nYou can get the corresponding type with the usual `Infer` generic.\n\n```ts\ntype TimeGetter = Infer\u003ctypeof isTimeGetter\u003e;\n```\n\n### Guard behavior\n\nLike a *Soit* instance, a *SoitTemplate* is intended to be used as a type guard:\n```ts\nif(isTimeGetter(method)) { ... }\n```\nThe `isTimeGetter` guard will only accept the following values: `\"getSeconds\"`, `\"getMinutes\"` and `\"getHours\"`.\n\n### Capture method 🪄\n\nA *SoitTemplate* instance offers the `capture` method to retrieve the \"dynamic\" parts of the template from a string. \n\n```ts\nconst [unit] = isTimeGetter.capture(\"getSeconds\"); // unit === \"Seconds\"\n```\n\n### Iterable behavior and Array method\n\nA *SoitTemplate* instance is iterable.\n\n```ts\nconst timeGetterMethods = [...isTimeGetter]; // [\"getSeconds\", \"getMinutes\", \"getHours\"]\n```\n\nAs with a regular *Soit* instance, you get the `map` and `forEach` shortcuts. \n\n## Using *Soit* with other tools\n\n### [TS-Pattern](https://github.com/gvergnaud/ts-pattern)\n\nYou can easily integrate *Soit* instances to your patterns using the [P.when](https://github.com/gvergnaud/ts-pattern?tab=readme-ov-file#pwhen-patterns) util :\n\n```ts\nimport { P } from \"ts-pattern\";\n\nconst pattern = P.when(isHTTPMethod);\n```\n\nThe inference will work as expected with TS-Pattern logic :\n\n```ts\ntype Pattern = P.infer\u003ctypeof pattern\u003e; // infers \"GET\" | \"POST\" | \"PUT\" | \"DELETE\"\n```\n\n### [Zod](https://github.com/colinhacks/zod)\n\nYou can integrate *Soit* instances to your Zod schemas using the [custom](https://zod.dev/?id=custom-schemas) util:\n\n```ts\nimport * as z from \"zod\";\nimport { Infer } from \"soit\";\n\ntype HTTPMethod = Infer\u003ctypeof isHTTPMethod\u003e;\n\nconst HTTPMethodSchema = z.custom\u003cHTTPMethod\u003e(isHTTPMethod);\n```\n\nZod is not able to infer the type on its own, therefore you need to pass the corresponding type (inferred beforehand) in the generic.\n\n## Troubleshoot\n\n### `Type 'string' is not assignable to type 'never'.` ts(2345)\n\nYou are maybe trying to create a new *Soit* instance using a named array.\n\n```ts\nconst HTTPMutationMethods = [\"POST\", \"PUT\", \"DELETE\"];\nconst isHTTPMutationMethods = Soit(HTTPMutationMethods); // error ts(2345)\n```\n\n*Soit* throw this error to prevent passing an unknown set of value (i.e. `string[]`). The solution here is to use the `as const` declaration in order to freeze the values and allow a proper type inference.\n\n```ts\nconst HTTPMutationMethods = [\"POST\", \"PUT\", \"DELETE\"] as const;\nconst isHTTPMutationMethods = Soit(HTTPMutationMethods);\n```\n\nThe `Template()` function also requires freezing the values to allow a proper type inference :\n```ts\nconst template = ['get', Soit(['Seconds', 'Minutes', 'Hours'])] as const;\nconst isTimeGetter = Soit.Template(...template);\n```\n\nThis error can also occur if you pass a *Soit* instance directly to a template. You can use `as const` as follows:\n```ts\nconst isTimeGetter = Soit.Template('get', Soit(['Seconds', 'Minutes', 'Hours'] as const));\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrgautier%2Fsoit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrgautier%2Fsoit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrgautier%2Fsoit/lists"}