{"id":13528268,"url":"https://github.com/swiing/Bit-TypedArray","last_synced_at":"2025-04-01T11:31:17.263Z","repository":{"id":36953062,"uuid":"359143940","full_name":"swiing/Bit-TypedArray","owner":"swiing","description":"A BitArray object exhibiting the interface of standard ecmascript TypedArray's","archived":false,"fork":false,"pushed_at":"2025-03-01T19:42:48.000Z","size":110,"stargazers_count":16,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-01T20:33:25.175Z","etag":null,"topics":["bitarray","javascript","nodejs","typedarray"],"latest_commit_sha":null,"homepage":"","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/swiing.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}},"created_at":"2021-04-18T13:00:16.000Z","updated_at":"2025-03-01T19:42:45.000Z","dependencies_parsed_at":"2023-01-17T08:01:09.068Z","dependency_job_id":"3bee4a24-5827-4ecd-8488-fae6e655cd6c","html_url":"https://github.com/swiing/Bit-TypedArray","commit_stats":{"total_commits":81,"total_committers":3,"mean_commits":27.0,"dds":"0.32098765432098764","last_synced_commit":"3fe12201263febe920e20ca8c5fc7153a5b5d8ce"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiing%2FBit-TypedArray","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiing%2FBit-TypedArray/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiing%2FBit-TypedArray/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiing%2FBit-TypedArray/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swiing","download_url":"https://codeload.github.com/swiing/Bit-TypedArray/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246631857,"owners_count":20808771,"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","javascript","nodejs","typedarray"],"created_at":"2024-08-01T06:02:22.588Z","updated_at":"2025-04-01T11:31:16.927Z","avatar_url":"https://github.com/swiing.png","language":"TypeScript","readme":" \u003cp align=\"center\"\u003e\n\n  \u003cimg src=\"https://img.shields.io/badge/TypeScript-007ACC?style=flat\u0026logo=typescript\u0026logoColor=white\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/JavaScript-F7DF1E?style=flat\u0026logo=javascript\u0026logoColor=black\" /\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Node.js-43853D?style=flat\u0026logo=node.js\u0026logoColor=white\" /\u003e\n  \n \u003c/p\u003e\n\n# @bitarray/typedarray\n\n[![GitHub package.json dynamic](https://img.shields.io/github/package-json/keywords/swiing/bit-typedarray)](https://github.com/swiing/Bit-TypedArray#bitarraytypedarray)\n\nA bit array object exhibiting the interface of standard ecmascript [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)'s.\n\n\u003e :bulb: If you are looking for easily applying bitwise operations, check out [@bitarray/es6](https://github.com/swiing/BitArray), which builds on top of the present library. Here, we purposely stick to methods and properties described by the ecmascript specification (there are no bitwise operations on arrays specified by ecmascript).\n\n## Rationale\n\nThe ecmascript specification has introduced `TypedArray`s for `Int8`, `Uint8`, `Uint8Clamped`, `Int16`, `Uint16`, `Int32`, `Uint32`, `Float32`, `Float64`, `BigInt64` and `BigUint64` types.\n\nThis library adds support for the `Bit` type. It provides a very memory-efficient means\nto store sequences of bits, while exposing the familiar, standard interface of typed arrays.\n\n## Compatibility\n\n[![compatibility](https://img.shields.io/badge/compatibility-%3E%3D%20ES6-orange?style=flat)](https://github.com/swiing/Bit-TypedArray#compatibility)\n\nThe library uses a [Proxy](https://caniuse.com/?search=Proxy) object, which is an ES6 (aka ES2015) feature. It can **NOT** be polyfilled (to the extent it is used by the library).\n\n_Note: standard `TypedArray` is also a feature of ecmascript ES6._\n\n## Installation\n\n[![npm version](https://badge.fury.io/js/@bitarray%2Ftypedarray.svg)](https://www.npmjs.com/package/@bitarray/typedarray)\n\n```sh\nnpm install @bitarray/typedarray\n```\n\nor\n\n```sh\nyarn add @bitarray/typedarray\n```\n\n## Usage\n\nUsage is same as for any standard typed array. You may check the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) for details.\n\n### Instantiating\n\n```js\nimport BitArray from \"@bitarray/typedarray\"\n\nconst length = 32; // or whatever length value\nconst bits = new BitArray(length);\n\n// Bit arrays can be created from iterables.\n// The following are all equivalent\n\nnew BitArray(\"11001010\");\nnew BitArray([1, 1, 0, 0, 1, 0, 1, 0]);\nnew BitArray([true, true, false, false, true, false, true, false]);\n\nBitArray.from(\"11001010\");\nBitArray.from([1, 1, 0, 0, 1, 0, 1, 0]);\nBitArray.from([true, true, false, false, true, false, true, false]);\n\nBitArray.of(...\"11001010\");\nBitArray.of(1, 1, 0, 0, 1, 0, 1, 0);\nBitArray.of(true, true, false, false, true, false, true, false);\n```\n\n### Reading/writing values\n\n```js\nbits[1]; // 0 by default\nbits[1] = 1; \nbits[1]; // 1\nbits.at(1); // 1\n\n// can also take boolean values\n// (will be coerced to bit)\nbits[1] = false;\nbits.at(1); // 0\n```\n\n### Iterating\n\n```js\nfor (let i=0; i\u003cbits.length; i++) \n  // do something with bits[i]\n\nbits.forEach((val, i, arr) =\u003e { /* do something */ });\n\nfor (let i in bits)\n  // do something with bits[i]\n\nfor (let bit of bits) \n  // do something with bit\n```\n\n### Indexes \u0026 values\n\n```js\n// indexes - following two are the same\nObject.keys(bits); // [0, 1, 2, ...]\nObject.getOwnPropertyNames(bits);\n\n// values\nObject.values(bits); // [0, 1, 0, 0, 0, ...]\n\n// entries\nObject.entries(bits); // [[\"0\", 0], [\"1\", 1], [\"2\", 0], [\"3\", 0], ...]\n```\n\n### Instance properties\n\n```js\n// properties\nbits.buffer;\nbits.byteLength;\nbits.byteOffset;\nbits.length;\n\n```\n\n### static properties\n\n```js\nBitArray.BYTES_PER_ELEMENT; // 0.125 == 1/8, read-only\nBitArray.name;              // \"BitArray\", read-only\nBitArray.prototype;         // Object {...}\n```\n\n## Implementation notes\n\nFor the most part, mapping the behaviour of standard _methods_ and _properties_ to the case of bit arrays is obvious. There are a few caveats though.\n\n_Note: not all features of the specification are implemented yet **[[WIP](https://github.com/swiing/Bit-TypedArray/issues/3); PRs welcome!]**._\n\n### Setting values\n\nIn standard typed arrays, except for the Uint8clamped type, values exceeding the limits go round. For instance, setting value 257 to a Uint8 results in the value of 1 (== 257 % 0xFF). Also, non-numerical values become 0.\n\nWith BitArray, values are first coerced to number. If the result is truthy, the bit will be set to 1; 0 otherwise.\n\n```js\nlet arr = new BitArray(2);\n\n// one would normally set values like this\narr[0] = 0;\narr[1] = 1;\n\n// or using booleans:\narr[0] = false;\narr[1] = true;\n\n// this will also work\narr[0] = -.000001; // arr[0] === 1, because Boolean(-.000001) === true\narr[1] = \"a\";      // arr[1] === 0, because Number(\"a\") === NaN, which is falsy\n```\n\n### `.toString()` method\n\nThe standard method returns a comma-separated list of numbers. In the case of bit sequences, interleaving commas is unnecessarily heavy, for no benefit. Instead, we list 0|1 bits in sequence, grouping them by eight for better clarity (human-reading), and separating groups by a space rather than a comma, to match common practice of text representation of bit sequences.\n\n```js\nnew BitArray(20).toString(); // \"00000000 00000000 0000\"\n```\n\n## License\n\n[![license](https://img.shields.io/github/license/swiing/Bit-TypedArray)](https://github.com/swiing/Bit-TypedArray/blob/main/LICENSE)\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiing%2FBit-TypedArray","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiing%2FBit-TypedArray","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiing%2FBit-TypedArray/lists"}