{"id":23699749,"url":"https://github.com/aesy/easy-bits","last_synced_at":"2025-09-03T03:30:43.425Z","repository":{"id":57218308,"uuid":"74205527","full_name":"aesy/easy-bits","owner":"aesy","description":"Enums, BitFlags, BitFields, BitMasks and BitArrays for JavaScript \u0026 TypeScript","archived":false,"fork":false,"pushed_at":"2024-07-02T20:45:23.000Z","size":2128,"stargazers_count":22,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T06:38:17.025Z","etag":null,"topics":["bitarray","bitfields","bitflags","bitmasks","bits","bytes"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/aesy.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}},"created_at":"2016-11-19T11:53:16.000Z","updated_at":"2024-10-09T09:24:03.000Z","dependencies_parsed_at":"2022-08-28T21:41:00.827Z","dependency_job_id":null,"html_url":"https://github.com/aesy/easy-bits","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aesy%2Feasy-bits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aesy%2Feasy-bits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aesy%2Feasy-bits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aesy%2Feasy-bits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aesy","download_url":"https://codeload.github.com/aesy/easy-bits/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231829127,"owners_count":18432747,"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":["bitarray","bitfields","bitflags","bitmasks","bits","bytes"],"created_at":"2024-12-30T08:15:37.826Z","updated_at":"2024-12-30T08:15:38.583Z","avatar_url":"https://github.com/aesy.png","language":"JavaScript","readme":"\u003cimg align=\"left\" width=\"80\" height=\"80\" src=\"./img/icon.svg\"\u003e\n\n# Easy Bits\n\n[![npm][npm-image]][npm-url]\n[![Build Status][github-actions-image]][github-actions-url]\n[![Quality Status][code-climate-image]][code-climate-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n[![Code Style][code-style-image]][code-style-url]\n[![License][license-image]][license-url]\n\n[npm-image]: https://img.shields.io/npm/v/easy-bits?style=flat-square \n[npm-url]: https://www.npmjs.com/package/easy-bits\n\n[github-actions-image]: https://img.shields.io/github/actions/workflow/status/aesy/easy-bits/ci.yml?branch=master\u0026style=flat-square\n[github-actions-url]: https://github.com/aesy/easy-bits/actions\n\n[code-climate-image]: https://img.shields.io/codeclimate/maintainability-percentage/aesy/easy-bits?style=flat-square\n[code-climate-url]: https://codeclimate.com/github/aesy/easy-bits\n\n[coveralls-image]: https://img.shields.io/coveralls/github/aesy/easy-bits?style=flat-square\n[coveralls-url]: https://coveralls.io/github/aesy/easy-bits?branch=master\n\n[code-style-image]: https://img.shields.io/badge/code%20style-%20XO-67d5c5?style=flat-square\n[code-style-url]: https://github.com/sindresorhus/xo \n\n[license-image]: https://img.shields.io/github/license/aesy/easy-bits?style=flat-square\n[license-url]: https://github.com/aesy/easy-bits/blob/master/LICENSE\n\nEnums, BitFlags, BitFields, BitMasks and BitArrays for JavaScript \u0026 TypeScript.\n\n### [API Reference](https://aesy.github.io/easy-bits/)\n\n## Usage\n#### BitFlags + BitField:\n```js\nconst options = new BitFlags('OPTION1', 'OPTION2', 'OPTION3');\nconst configuration = options.createBitField();\n\nconfiguration.on(options.OPTION1 | options.OPTION3); // Set option1 \u0026 option3 bits to true\nconfiguration.on(options.OPTION1, options.OPTION3);  // Same as the above\n\nconfiguration.test(options.OPTION1); // true\nconfiguration.test(options.OPTION2); // false\nconfiguration.test(options.OPTION3); // true\nconfiguration.testAny(options.OPTION1 | options.OPTION2); // true\nconfiguration.testAll(options.OPTION1 | options.OPTION2); // false\n\nconfiguration.count(); // 2\nconfiguration.flipAll();\nconfiguration.count(); // 1\nconfiguration.test(options.OPTION2); // true\n\nconst clone = configuration.clone();\n\n// Serialize\nconst serializedOptions = options.serialize();        // 'OPTION1,OPTION2,OPTION3'\nconst serializedBitfield = configuration.serialize(); // '010'\n// Deserialize\nconst deserializedOptions = BitFlags.deserialize(serializedOptions);\nconst deserializedBitfield = BitField.deserialize(serializedBitfield);\n```\nBitFields and BitArrays are interchangeable, their APIs are identical. \nThe only difference between them is how many flags they support (BitField is limited to 31 flags) and their performance \n(BitField is about 25% faster than BitArray). This is due to how they internally store the data.\n\n#### Enums:\n```js\nconst Day = new Enum('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY');\n\nconsole.log(Day.MONDAY);         // EnumConstant('MONDAY':0)\nconsole.log(Day.MONDAY.name);    // 'MONDAY'\nconsole.log(String(Day.MONDAY)); // 'EnumConstant(MONDAY:0)'\nconsole.log(Day.FRIDAY.ordinal); // 4\nconsole.log(Number(Day.FRIDAY)); // 4\n\n// Enums are immutable\nDay.MY_OWN_DAY = 1337; // TypeError: Cannot add property MY_OWN_DAY, object is not extensible\nDay.MONDAY = 42;       // TypeError: Cannot set property MONDAY of [object Object] which has only a getter\n\n// Enums are iterable\nconsole.log(Object.keys(Day)); // ['MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', ...]\nconsole.log(Day.values());     // [EnumConstant('MONDAY':0), EnumConstant('TUESDAY':1), ...]\nfor (let value of Day) {}\nDay.forEach((value, name) =\u003e {});\n\n// Enums are easy to use\nswitch (value) {\n  case Day.MONDAY:\n    break;\n  case Day.TUESDAY:\n    break;\n}\n\nconsole.log(Day.MONDAY.equals(Day.FRIDAY));     // false\nconsole.log(Day.MONDAY === OtherEnum.CONSTANT); // false\nconsole.log(Day.MONDAY == OtherEnum.CONSTANT);  // false\n```\n\nNote that the examples above uses ECMAScript 2015 features.\n\n#### TypeScript\n```ts\n// Typings for the Enum class is not provided, use TypeScripts' enum instead!\nenum Direction { NORTH, SOUTH, EAST, WEST }\n\n// No typings for BitFlags either. Again, use TypeScripts' enum!\nenum FontStyle {\n  NORMAL      = 0,\n  BOLD        = 1 \u003c\u003c 1,\n  ITALICS     = 1 \u003c\u003c 2,\n  UNDERSCORED = 1 \u003c\u003c 3,\n  UPPERCASE   = 1 \u003c\u003c 4,\n  MY_FAVORITE = BOLD | ITALICS\n}\n\nconst configuration: BitSet\u003cFontStyle\u003e = new BitField\u003cFontStyle\u003e();\nconfiguration.on(FontStyle.BOLD | FontStyle.UPPERCASE);\nconfiguration.off(Direction.NORTH); // ERROR: argument type Direction is not assignable to parameter type FontStyle\n```\n\n## Installation\nFrom NPM: run `npm install easy-bits --save`.\n\nFrom GitHub: download [easy-bits.min.js](https://github.com/aesy/easy-bits/releases).\n\n#### and then import\nES2015 style: `import { Enum } from 'easy-bits';`.\n\nor link in HTML: `\u003cscript src=\"easy-bits.min.js\"\u003e\u003c/script\u003e`.\n\n## Support\n\n| Environment       | Supported Version |\n|-------------------|------------------:|\n| Node              |          8 and up |\n| Chrome            |         26 and up |\n| Firefox           |          4 and up |\n| Edge              |         13 and up |\n| Internet Explorer |         10 and up |\n| Safari            |          7 and up |\n\n## Contribute\nUse the [issue tracker](https://github.com/aesy/easy-bits/issues) to report bugs or make feature requests. Pull requests are welcome, but it may be a good idea to create an issue to discuss any \nchanges beforehand.\n\n## License\nMIT, see [LICENSE](/LICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faesy%2Feasy-bits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faesy%2Feasy-bits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faesy%2Feasy-bits/lists"}