{"id":19241690,"url":"https://github.com/exuanbo/ts-enum-utilx","last_synced_at":"2026-02-02T03:32:20.070Z","repository":{"id":254101018,"uuid":"844614254","full_name":"exuanbo/ts-enum-utilx","owner":"exuanbo","description":"Strictly typed utilities for working with TypeScript enums.","archived":false,"fork":false,"pushed_at":"2024-08-25T14:09:07.000Z","size":1099,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-13T21:41:23.333Z","etag":null,"topics":["enum","ts-enum-util","tyepscript","util"],"latest_commit_sha":null,"homepage":"http://exuanbo.xyz/ts-enum-utilx/","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/exuanbo.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-08-19T16:07:10.000Z","updated_at":"2024-11-12T12:34:43.000Z","dependencies_parsed_at":"2024-11-09T17:12:23.892Z","dependency_job_id":"7d62d5b4-d605-4910-bb42-ed6cf045a9a9","html_url":"https://github.com/exuanbo/ts-enum-utilx","commit_stats":null,"previous_names":["exuanbo/ts-enum-utilx"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/exuanbo/ts-enum-utilx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exuanbo%2Fts-enum-utilx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exuanbo%2Fts-enum-utilx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exuanbo%2Fts-enum-utilx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exuanbo%2Fts-enum-utilx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exuanbo","download_url":"https://codeload.github.com/exuanbo/ts-enum-utilx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exuanbo%2Fts-enum-utilx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29003228,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T01:32:03.847Z","status":"online","status_checked_at":"2026-02-02T02:00:07.448Z","response_time":58,"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","ts-enum-util","tyepscript","util"],"created_at":"2024-11-09T17:12:17.260Z","updated_at":"2026-02-02T03:32:20.023Z","avatar_url":"https://github.com/exuanbo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-enum-utilx\n\n[![npm](https://img.shields.io/npm/v/ts-enum-utilx.svg)](https://www.npmjs.com/package/ts-enum-utilx)\n[![npm bundle size](https://img.shields.io/bundlephobia/minzip/ts-enum-utilx.svg?label=bundle%20size)](https://bundlephobia.com/package/ts-enum-utilx)\n[![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/exuanbo/ts-enum-utilx/test.yml.svg?branch=main)](https://github.com/exuanbo/ts-enum-utilx/actions)\n[![Codecov (with branch)](https://img.shields.io/codecov/c/gh/exuanbo/ts-enum-utilx/main.svg?token=AlXLkYCvrA)](https://app.codecov.io/gh/exuanbo/ts-enum-utilx/tree/main/src)\n\nStrictly typed utilities for working with TypeScript enums inspired by [`ts-enum-util`](https://github.com/UselessPickles/ts-enum-util).\n\n## Install\n\n```sh\n# npm\nnpm install ts-enum-utilx\n\n# Yarn\nyarn add ts-enum-utilx\n\n# pnpm\npnpm add ts-enum-utilx\n```\n\n## Differences from ts-enum-util\n\n- **Smaller Bundle Size**: `ts-enum-utilx` has a much smaller bundle size and is fully tree-shakable.\n- **Functional Programming Approach**: Supports currying and functional programming paradigms.\n- **Streamlined API**: Provides a set of essential functions without a wrapper class, making it more intuitive and easier to use. Additional functionalities can be easily achieved using modern JavaScript features or simple invariant libraries like [`tiny-invariant`](https://github.com/alexreardon/tiny-invariant).\n\n## Usage\n\n### Basic setup\n\nNamespace import is recommended for better tree-shaking:\n\n```ts\nimport * as E from \"ts-enum-utilx\";\n\nenum Answer {\n  No = 0,\n  Yes = \"YES\",\n}\n```\n\n### size\n\nGet the number of keys in the enum:\n\n```ts\nE.size(Answer);\n// =\u003e 2\n```\n\n### keys\n\nGet an iterable of the enum keys:\n\n```ts\nconst iter = E.keys(Answer);\n//    ^? IterableIterator\u003c\"No\" | \"Yes\"\u003e\n\n[...E.keys(Answer)];\n// =\u003e [\"No\", \"Yes\"]\n```\n\n### values\n\nGet an iterable of the enum values:\n\n```ts\nconst iter = E.values(Answer);\n//    ^? IterableIterator\u003cAnswer\u003e\n\n[...E.values(Answer)];\n// =\u003e [0, \"YES\"]\n```\n\n### entries\n\nGet an iterable of key-value pairs:\n\n```ts\nconst iter = E.entries(Answer);\n//    ^? IterableIterator\u003c[(\"No\" | \"Yes\"), Answer]\u003e\n\n[...E.entries(Answer)];\n// =\u003e [[\"No\", 0], [\"Yes\", \"YES\"]]\n```\n\n### value\n\nGet the value associated with a key:\n\n```ts\nE.value(Answer, \"No\");\n// =\u003e 0\n\nE.value(Answer, \"Unknown\");\n// =\u003e undefined\n\nconst getValue = E.value(Answer);\n//    ^? (key: Nullable\u003cstring\u003e) =\u003e Answer | undefined\n\ngetValue(\"Yes\");\n// =\u003e \"YES\"\n```\n\n### key\n\nGet the key associated with a value:\n\n```ts\nE.key(Answer, 0);\n// =\u003e \"No\"\n\nE.key(Answer, \"Unknown\");\n// =\u003e undefined\n\nconst getKey = E.key(Answer);\n//    ^? (value: Nullable\u003cstring | number\u003e) =\u003e \"No\" | \"Yes\" | undefined\n\ngetKey(\"YES\");\n// =\u003e \"Yes\"\n```\n\nThe `key` function is type-safe and will only accept values that are assignable to the enum values.\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eE.key\u003c/strong\u003e type inference\u003c/summary\u003e\n\n```ts\nenum NumberEnum {\n  One = 1,\n}\n\n// @ts-expect-error: Argument of type '\"A\"' is not assignable to parameter of type 'Nullable\u003cnumber\u003e'\nE.key(NumberEnum, \"A\");\n\nenum StringEnum {\n  A = \"A\",\n}\n\n// @ts-expect-error: Argument of type '1' is not assignable to parameter of type 'Nullable\u003cstring\u003e'\nE.key(StringEnum, 1);\n\nenum HetEnum {\n  A = 1,\n  B = \"B\",\n}\n\n// @ts-expect-error: Argument of type 'true' is not assignable to parameter of type 'Nullable\u003cstring | number\u003e'\nE.key(HetEnum, true);\n```\n\n\u003c/details\u003e\n\n### isKey\n\nCheck if a string is a key in the enum:\n\n```ts\nE.isKey(Answer, \"No\");\n// =\u003e true\n\nconst key: string = \"No\";\n\nif (E.isKey(Answer, key)) {\n  console.log(key);\n  //          ^? \"No\" | \"Yes\"\n}\n\nconst isKey = E.isKey(Answer);\n//    ^? (key: Nullable\u003cstring\u003e) =\u003e key is \"No\" | \"Yes\"\n\nisKey(\"Yes\");\n// =\u003e true\n```\n\n### isValue\n\nCheck if a value is in the enum:\n\n```ts\nE.isValue(Answer, 0);\n// =\u003e true\n\nconst value: string | number = 0;\n\nif (E.isValue(Answer, value)) {\n  console.log(value);\n  //          ^? Answer\n}\n\nconst isValue = E.isValue(Answer);\n//    ^? (value: Nullable\u003cstring | number\u003e) =\u003e value is Answer\n\nisValue(\"YES\");\n// =\u003e true\n```\n\nThe `isValue` function is type-safe and will only accept values that are assignable to the enum values.\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eE.isValue\u003c/strong\u003e type inference\u003c/summary\u003e\n\n```ts\nenum NumberEnum {\n  One = 1,\n}\n\n// @ts-expect-error: Argument of type '\"A\"' is not assignable to parameter of type 'Nullable\u003cnumber\u003e'.\nE.isValue(NumberEnum, \"A\");\n\nenum StringEnum {\n  A = \"A\",\n}\n\n// @ts-expect-error: Argument of type '1' is not assignable to parameter of type 'Nullable\u003cstring\u003e'.\nE.isValue(StringEnum, 1);\n\nenum HetEnum {\n  A = 1,\n  B = \"B\",\n}\n\n// @ts-expect-error: Argument of type 'true' is not assignable to parameter of type 'Nullable\u003cstring | number\u003e'.\nE.isValue(HetEnum, true);\n```\n\n\u003c/details\u003e\n\n### forEach\n\nIterate over the enum:\n\n```ts\nE.forEach(Answer, (value, key, enumObj) =\u003e {\n  console.log(value);\n  //          ^? Answer\n  console.log(key);\n  //          ^? \"No\" | \"Yes\"\n  console.log(enumObj);\n  //          ^? typeof Answer\n});\n\nconst forEachAnswer = E.forEach(Answer);\n//    ^? (iteratee: (value: Answer, key: \"No\" | \"Yes\", enumObj: typeof Answer) =\u003e void) =\u003e void\n\nconst logEntries = E.forEach((value, key) =\u003e console.log([key, value]));\n//    ^? (enumObj: Record\u003cstring, string | number\u003e) =\u003e void\n\nlogEntries(Answer);\n// =\u003e [ \"No\", 0 ]\n// =\u003e [ \"Yes\", \"YES\" ]\n```\n\n## API\n\nSee the [API documentation](https://exuanbo.xyz/ts-enum-utilx/) for more details.\n\n## License\n\n[MIT License](https://github.com/exuanbo/ts-enum-utilx/blob/main/LICENSE) @ 2024-Present [Xuanbo Cheng](https://github.com/exuanbo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexuanbo%2Fts-enum-utilx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexuanbo%2Fts-enum-utilx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexuanbo%2Fts-enum-utilx/lists"}