{"id":20215028,"url":"https://github.com/maks11060/bits","last_synced_at":"2025-03-03T11:17:36.707Z","repository":{"id":237076486,"uuid":"793766514","full_name":"MAKS11060/bits","owner":"MAKS11060","description":"Utility for working with bits","archived":false,"fork":false,"pushed_at":"2024-12-29T05:41:56.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-13T21:44:44.240Z","etag":null,"topics":["bits","bitset","typescript"],"latest_commit_sha":null,"homepage":"https://jsr.io/@maks11060/bits","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/MAKS11060.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-04-29T20:33:01.000Z","updated_at":"2024-12-29T05:41:59.000Z","dependencies_parsed_at":"2024-12-29T05:22:07.352Z","dependency_job_id":"9454352e-22b1-43d8-b909-512c791a194f","html_url":"https://github.com/MAKS11060/bits","commit_stats":null,"previous_names":["maks11060/bits"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAKS11060%2Fbits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAKS11060%2Fbits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAKS11060%2Fbits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MAKS11060%2Fbits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MAKS11060","download_url":"https://codeload.github.com/MAKS11060/bits/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241652965,"owners_count":19997578,"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":["bits","bitset","typescript"],"created_at":"2024-11-14T06:19:24.485Z","updated_at":"2025-03-03T11:17:36.684Z","avatar_url":"https://github.com/MAKS11060.png","language":"TypeScript","readme":"# Bits manipulation utility\n\n[![JSR][JSR badge]][JSR]\n[![CI](https://github.com/MAKS11060/bits/actions/workflows/ci.yml/badge.svg)](https://github.com/MAKS11060/bits/actions/workflows/ci.yml)\n\n \u003c!-- https://jsr.io/docs/badges --\u003e\n[JSR]: https://jsr.io/@maks11060/bits\n[JSR badge]: https://jsr.io/badges/@maks11060/bits\n\n## Usage\n\n### Install\n```ts\n// deno add jsr:@maks11060/bits\nimport {BitSet} from '@maks11060/bits'\n\n// or\nimport {BitSet} from 'jsr:@maks11060/bits'\n```\n\n#### Create Instance with `flags`\n```ts\nconst bitOptions = BitSet.Instance({\n  option_1: 0,\n  option_2: 1,\n  option_3: 2,\n})\n\nconst flags = bitOptions.now(0) // `BigInt` support when specifying the initial value of '0n'\n\nflags.set('option_1') // use autocomplete for name flags\nflags.set(1) // set bit(n)\nflags.set(flags.options.option_3)\n\nflags.value // 7 / 0b111\n\nflags.has(0) // true\nflags.delete(1) // 5 / 0b101\nflags.toggle('option_3') // 1 / 0b001\n\n// Support iterator\nfor (const [flag, value] of flags.entries()) {\n  console.log(`${flag}: ${value}`)\n}\n// option_1: true\n// option_2: false\n// option_3: false\n\nfor (const [bit, value] of flags.entries(true)) {\n  console.log(`${bit}: ${value}`)\n}\n// 0: true\n\nconsole.log(new Map(flags))               // options =\u003e value\nconsole.log(new Map(flags.entries(true))) // bit     =\u003e value\nconsole.log(Object.fromEntries(flags))    // {option_1: true, option_2: false, option_3: false}\n```\n\n#### Create Instance with `enums`\n```ts\nenum UserAccountFlags {\n  isAdmin = 0,\n  verifyUser = 1,\n  verifyEmail = 2,\n}\n\nconst UserFlags = BitSet.Instance(UserAccountFlags)\nconst userFlags = UserFlags.now()\n\nuserFlags.set('isAdmin')\nuserFlags.set('verifyUser')\n\nconst user = {\n  username: 'Admin',\n  flags: userFlags,\n}\n\nconsole.log(JSON.stringify(user)) // {\"username\":\"Admin\",\"flags\":3}\n```\n\n#### Usage without `flags`\n```ts\nconst bitOptions = BitSet.Instance()\nconst flags = bitOptions.now(0n)\n\nflags.set(0)\nflags.set(1)\nflags.set(30)\nflags.set(100)\n\nflags.has(30)\n\nconsole.log(flags.value) // 1267650600228229401497776947203n\n```\n\n## `API`\n```ts\nconst Flags = BitSet.Instance()\n\nFlags.now()\nFlags.now(0n)\nFlags.fromBin('11111111') // 255\nFlags.fromHex('ff') // 255\nFlags.fromBinBigInt('0b11111111111111111111111111111111') // 2 ^ 32 - 1\nFlags.fromHexBigInt('0xffffffffffffffff') // 2 ^ 64 - 1\n\nconst Flags2 = BitSet.Instance({a: 0, b: 1, c: 2})\nconst flags2 = Flags2.now()\n\nflags2.set(0)\nflags2.set('b')\nflags2.set(flags2.options.c)\n\nflags2.has(0) // true\nflags2.has('b') // true\nflags2.has(flags2.options.c) // true\n\nflags2.toggle('a') // switch bit\n\nflags2.delete('b')\n\nflags2.clear() // value = 0\n\nflags2.toJSON() // for serialization in JSON.Stringify\n\nflags2.write('a', 'b', 'c')\n\nflags2.value // get typed value (number | bigint)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaks11060%2Fbits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaks11060%2Fbits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaks11060%2Fbits/lists"}