{"id":22211972,"url":"https://github.com/danielwaltz/ts-define-constant","last_synced_at":"2026-03-07T14:04:42.397Z","repository":{"id":65803164,"uuid":"598921951","full_name":"danielwaltz/ts-define-constant","owner":"danielwaltz","description":"Type safe utility for defining static constants with automatic type narrowing and additional helper functions","archived":false,"fork":false,"pushed_at":"2025-08-19T14:40:51.000Z","size":1592,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-25T16:46:17.369Z","etag":null,"topics":["constant","narrowing","type-narrowing","typescript","utility"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/ts-define-constant","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/danielwaltz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2023-02-08T04:20:53.000Z","updated_at":"2025-08-19T14:40:55.000Z","dependencies_parsed_at":"2024-11-18T18:41:58.143Z","dependency_job_id":"5a3cfa9e-dc30-47d0-b4a8-c35f6f17ffa5","html_url":"https://github.com/danielwaltz/ts-define-constant","commit_stats":{"total_commits":27,"total_committers":2,"mean_commits":13.5,"dds":0.2222222222222222,"last_synced_commit":"ca118b041765a2d81fcdf14d3f90702c3beb91ab"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/danielwaltz/ts-define-constant","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielwaltz%2Fts-define-constant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielwaltz%2Fts-define-constant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielwaltz%2Fts-define-constant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielwaltz%2Fts-define-constant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielwaltz","download_url":"https://codeload.github.com/danielwaltz/ts-define-constant/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielwaltz%2Fts-define-constant/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30216514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T14:02:48.375Z","status":"ssl_error","status_checked_at":"2026-03-07T14:02:43.192Z","response_time":53,"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":["constant","narrowing","type-narrowing","typescript","utility"],"created_at":"2024-12-02T20:46:11.084Z","updated_at":"2026-03-07T14:04:42.367Z","avatar_url":"https://github.com/danielwaltz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TS Define Constant [![npm](https://img.shields.io/npm/v/ts-define-constant.svg)](https://npmjs.com/package/ts-define-constant)\n\nType safe utility for defining static constants with automatic type narrowing and additional helper functions. Zero dependencies.\n\n## Install\n\n```shell\n# npm\nnpm i ts-define-constant\n\n# yarn\nyarn add ts-define-constant\n\n# pnpm\npnpm i ts-define-constant\n```\n\n## Usage\n\nImport and define your constants using the provided `defineConstant` function.\n\nSupports passing in a plain object or an array of strings as the first argument.\n\n```ts\nimport { defineConstant } from 'ts-define-constant';\n\nconst {\n  /* Plain object containing the constants */\n  object,\n  /* Array of the keys */\n  keys,\n  /* Array of the values */\n  values,\n  /* Function that returns the key of a given value */\n  getKey,\n  /* Function that returns the value of a given key */\n  getValue,\n  /* Function that returns true if the given value is a key of the constants */\n  isKey,\n  /* Function that returns true if the given value is a value of the constants */\n  isValue,\n  /* Function that returns true if the given value is equal to the USER constant */\n  isUser,\n  /* Function that returns true if the given value is equal to the ADMIN constant */\n  isAdmin,\n} = defineConstant({ USER: 'USER', ADMIN: 'ADMIN' });\n```\n\nAn example of what this looks like when multiple constants are defined and exported from a shared `constants.ts` file:\n\n```ts\n// constants.ts\nimport { defineConstant } from 'ts-define-constant';\n\nexport const {\n  object: USER_ROLES,\n  keys: USER_ROLE_KEYS,\n  values: USER_ROLE_VALUES,\n  getKey: getUserRoleKey,\n  getValue: getUserRoleValue,\n  isKey: isUserRoleKey,\n  isValue: isUserRoleValue,\n  isUser,\n  isAdmin,\n} = defineConstant({ USER: 'USER', ADMIN: 'ADMIN' });\n\nexport const {\n  object: SORT_ORDERS,\n  keys: SORT_ORDER_KEYS,\n  values: SORT_ORDER_VALUES,\n  getKey: getSortOrderKey,\n  getValue: getSortOrderValue,\n  isKey: isSortOrderKey,\n  isValue: isSortOrderValue,\n  isAsc,\n  isDesc,\n} = defineConstant({ ASC: 'ASC', DESC: 'DESC' });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielwaltz%2Fts-define-constant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielwaltz%2Fts-define-constant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielwaltz%2Fts-define-constant/lists"}