{"id":17013928,"url":"https://github.com/john-paul-r/bitflags-ts","last_synced_at":"2026-05-15T08:05:24.564Z","repository":{"id":169706228,"uuid":"645755782","full_name":"John-Paul-R/bitflags-ts","owner":"John-Paul-R","description":"An enum-like type for representing \u0026 using bit flags","archived":false,"fork":false,"pushed_at":"2023-05-30T03:19:59.000Z","size":2801,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-28T08:26:36.854Z","etag":null,"topics":["bitfield","bitflags","npm-package"],"latest_commit_sha":null,"homepage":"https://bitflags-ts.pages.dev/","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/John-Paul-R.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","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":"2023-05-26T11:11:55.000Z","updated_at":"2023-05-27T19:53:34.000Z","dependencies_parsed_at":"2023-07-08T21:15:44.108Z","dependency_job_id":null,"html_url":"https://github.com/John-Paul-R/bitflags-ts","commit_stats":null,"previous_names":["john-paul-r/bitflags-ts"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/John-Paul-R%2Fbitflags-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/John-Paul-R%2Fbitflags-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/John-Paul-R%2Fbitflags-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/John-Paul-R%2Fbitflags-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/John-Paul-R","download_url":"https://codeload.github.com/John-Paul-R/bitflags-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244968200,"owners_count":20540068,"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","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":["bitfield","bitflags","npm-package"],"created_at":"2024-10-14T06:14:38.622Z","updated_at":"2026-05-15T08:05:24.533Z","avatar_url":"https://github.com/John-Paul-R.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bitflags-ts\n\nAn enum-like type for representing \u0026 using bit flags\n\n![build-status-badge](https://img.shields.io/github/actions/workflow/status/John-Paul-R/bitflags-ts/node.js.yml?label=build%20%26%20test)\n![npm bundle size](https://img.shields.io/bundlephobia/min/bitflags-ts)\n\n## Usage\n\n_Note: I don't particularly recommend using this package!_ Bit flags are great,\nand can be created and used quite simply in TypeScript (demonstrated in\nfantastically concise fashion in [this SO\nanswer](https://stackoverflow.com/a/39359953/8105643)). This package abstracts\naway the bitwise operations, but is not without performance cost. As long as\nyou're fine with seeing `|` and `\u0026`, use native bit flag enums!\n\nAlso note: JS coerces `number`s to 32 bits before performing any bitwise\noperations, so the maximum number of flags that can be represented by a bit\nflag type is 32!\n\n### `bitFlag`\n\n```ts\nconst PermissionsFlag = bitFlag('Read', 'Write', 'Execute');\n\nconst userPermissions = PermissionsFlag.union(PermissionsFlag.Read, PermissionsFlag.Write);\n\nconst canRead = userPermissions.hasFlag(PermissionsFlag.Read); // true\nconst canExecute = userPermissions.hasFlag(PermissionsFlag.Execute); // false\n```\n\n\n### `createBitFlagsEnum`\n\nAn alternative syntax that creates an 'enum' with object-valued (instead of\nNumber-valued, as in `bitFlag`) members. While this has higher one-time\nallocation cost, there are more utilities for working with the values\nthemselves on the enum member instances. \n\n```ts\nconst PermissionsFlag = createBitFlagsEnum(['Read', 'Write', 'Execute'] as const);\n\n{ // offers 'or' syntax on the enum value itself\n  const userPermissions = PermissionsFlag.Read\n    .or(PermissionsFlag.Write)\n    .or(PermissionsFlag.Execute);\n  const canRead = userPermissions.hasFlag(PermissionsFlag.Read); // true\n  const canExecute = userPermissions.hasFlag(PermissionsFlag.Execute); // true\n}\n\n{ // static `union` works in the same fashion as bitFlag\n  const userPermissions = PermissionsFlag.union([PermissionsFlag.Read, PermissionsFlag.Write]);\n  const canRead = userPermissions.hasFlag(PermissionsFlag.Read); // true\n  const canExecute = userPermissions.hasFlag(PermissionsFlag.Execute); // false\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-paul-r%2Fbitflags-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohn-paul-r%2Fbitflags-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-paul-r%2Fbitflags-ts/lists"}