{"_id":"2d-bit-array","_rev":"2-c99dd2995bd12b309d2e6d277ded0ff0","name":"2d-bit-array","dist-tags":{"latest":"0.0.3"},"versions":{"0.0.1":{"name":"2d-bit-array","description":"Efficient 2D Bit Array with Serialization","version":"0.0.1","type":"module","keywords":["2d","flags","bits","bit-array","bit-map","bit-mask","bit-flags","bit-string","bit-vector","image"],"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"module":"dist/index.js","types":"dist/index.d.ts","homepage":"https://captaincodeman.github.io/2d-bit-array/","repository":{"type":"git","url":"git+https://github.com/captaincodeman/2d-bit-array.git"},"author":{"name":"Simon Green","email":"simon@captaincodeman.com","url":"https://www.captaincodeman.com/"},"license":"MIT","devDependencies":{"@sveltejs/adapter-static":"^2.0.3","@sveltejs/kit":"^1.20.4","@vitest/ui":"^0.34.3","svelte":"^4.0.5","svelte-check":"^3.4.3","tslib":"^2.4.1","tsup":"^7.2.0","typescript":"^5.0.0","vite":"^4.4.2","vitest":"^0.34.0"},"scripts":{"dev":"vite dev","build":"vite build","preview":"vite preview","package":"tsup","check":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json","check:watch":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch","test":"vitest","test:ui":"vitest --ui"},"bugs":{"url":"https://github.com/captaincodeman/2d-bit-array/issues"},"_id":"2d-bit-array@0.0.1","_integrity":"sha512-j0iCrrpsc3lwBVh/Vj1mGC3aMkfUXnoJwl4XOKvKSWN8HsZi7Xb4qWtlBWMEmOkAc2iS+/0OJFuQQK1IzgUmdQ==","_resolved":"/private/var/folders/w1/tr45pbks617dj6jdj17g6df40000gn/T/230d42f847c32be3063492d866454d10/2d-bit-array-0.0.1.tgz","_from":"file:2d-bit-array-0.0.1.tgz","_nodeVersion":"18.10.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-j0iCrrpsc3lwBVh/Vj1mGC3aMkfUXnoJwl4XOKvKSWN8HsZi7Xb4qWtlBWMEmOkAc2iS+/0OJFuQQK1IzgUmdQ==","shasum":"ecc89a3be17a87a8b92bef66400db1b65f21a42f","tarball":"https://registry.npmjs.org/2d-bit-array/-/2d-bit-array-0.0.1.tgz","fileCount":2,"unpackedSize":5450,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD4yC/Akes/TsXjnfr+d24unj0XKAfABb+IKXQPd4MrQQIgbiOQCiVRH6qByOhHVIYjDcd/AvY+8xCGv3T3TRH7zVc="}]},"_npmUser":{"name":"captaincodeman","email":"simon@captaincodeman.com"},"directories":{},"maintainers":[{"name":"captaincodeman","email":"simon@captaincodeman.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/2d-bit-array_0.0.1_1693502368939_0.1927320046486809"},"_hasShrinkwrap":false},"0.0.2":{"name":"2d-bit-array","description":"Efficient 2D Bit Array with Serialization","version":"0.0.2","type":"module","keywords":["2d","flags","bits","bit-array","bit-map","bit-mask","bit-flags","bit-string","bit-vector","image"],"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"module":"dist/index.js","types":"dist/index.d.ts","homepage":"https://captaincodeman.github.io/2d-bit-array/","repository":{"type":"git","url":"git+https://github.com/captaincodeman/2d-bit-array.git"},"author":{"name":"Simon Green","email":"simon@captaincodeman.com","url":"https://www.captaincodeman.com/"},"license":"MIT","devDependencies":{"@sveltejs/adapter-static":"^2.0.3","@sveltejs/kit":"^1.20.4","@vitest/ui":"^0.34.3","publint":"^0.2.2","svelte":"^4.0.5","svelte-check":"^3.4.3","tslib":"^2.4.1","tsup":"^7.2.0","typescript":"^5.0.0","vite":"^4.4.2","vitest":"^0.34.0"},"scripts":{"dev":"vite dev","build":"vite build","preview":"vite preview","package":"tsup && publint","check":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json","check:watch":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch","test":"vitest","test:ui":"vitest --ui"},"bugs":{"url":"https://github.com/captaincodeman/2d-bit-array/issues"},"_id":"2d-bit-array@0.0.2","_integrity":"sha512-89gUKyKzGcpDvyWfXR4H1D5zEfb4hl7PED4MxLCsKtMT4UDi/dz7xwK7q7Cgd2NvM5gxSPoxPdFXV80evrcgxA==","_resolved":"/private/var/folders/w1/tr45pbks617dj6jdj17g6df40000gn/T/1107881ac5f9d3fb3a53dedd5d2ecbcb/2d-bit-array-0.0.2.tgz","_from":"file:2d-bit-array-0.0.2.tgz","_nodeVersion":"18.10.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-89gUKyKzGcpDvyWfXR4H1D5zEfb4hl7PED4MxLCsKtMT4UDi/dz7xwK7q7Cgd2NvM5gxSPoxPdFXV80evrcgxA==","shasum":"11f8b32dc120abb427aeddc6d854a8a13ab5c0ca","tarball":"https://registry.npmjs.org/2d-bit-array/-/2d-bit-array-0.0.2.tgz","fileCount":4,"unpackedSize":11324,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHdk8p7ufw7z+ZTyD7IxJW4YPPRRqvmzsCshGguNxqipAiAN6LxetkJpjcrKX8TshlMDn02cYzr9Vy7JMy2aYG2skQ=="}]},"_npmUser":{"name":"captaincodeman","email":"simon@captaincodeman.com"},"directories":{},"maintainers":[{"name":"captaincodeman","email":"simon@captaincodeman.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/2d-bit-array_0.0.2_1694026229495_0.46204546979121397"},"_hasShrinkwrap":false},"0.0.3":{"name":"2d-bit-array","description":"Efficient 2D Bit Array with Serialization","version":"0.0.3","type":"module","keywords":["2d","flags","bits","bit-array","bit-map","bit-mask","bit-flags","bit-string","bit-vector","image"],"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"module":"dist/index.js","types":"dist/index.d.ts","homepage":"https://captaincodeman.github.io/2d-bit-array/","repository":{"type":"git","url":"git+https://github.com/captaincodeman/2d-bit-array.git"},"author":{"name":"Simon Green","email":"simon@captaincodeman.com","url":"https://www.captaincodeman.com/"},"license":"MIT","devDependencies":{"@sveltejs/adapter-static":"^3.0.1","@sveltejs/kit":"^2.4.1","@sveltejs/vite-plugin-svelte":"^3.0.1","@vitest/ui":"^1.2.1","publint":"^0.2.7","svelte":"^4.2.9","svelte-check":"^3.6.3","tslib":"^2.6.2","tsup":"^8.0.1","typescript":"^5.3.3","vite":"^5.0.12","vitest":"^1.2.1","webdriverio":"^8.28.8"},"dependencies":{"fflate":"^0.8.1"},"scripts":{"dev":"vite dev","build":"vite build","preview":"vite preview","package":"tsup && publint","check":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json","check:watch":"svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch","test":"vitest","test:ui":"vitest --ui"},"bugs":{"url":"https://github.com/captaincodeman/2d-bit-array/issues"},"_id":"2d-bit-array@0.0.3","_integrity":"sha512-Z1bwO5eQQZ2obnYsJPJUcfxv6uTugQHx8spVsVI3o8OzmmopjTf6qBRkepWZ5rmc71orSSgjDHZKe4HfZkrv0w==","_resolved":"/private/var/folders/w1/tr45pbks617dj6jdj17g6df40000gn/T/eda50439dd44ed8b4cf3594cd9a5fbb4/2d-bit-array-0.0.3.tgz","_from":"file:2d-bit-array-0.0.3.tgz","_nodeVersion":"20.6.1","_npmVersion":"9.8.1","dist":{"integrity":"sha512-Z1bwO5eQQZ2obnYsJPJUcfxv6uTugQHx8spVsVI3o8OzmmopjTf6qBRkepWZ5rmc71orSSgjDHZKe4HfZkrv0w==","shasum":"277b0acebb9e913c7e2d7daf67137ac649eb3e37","tarball":"https://registry.npmjs.org/2d-bit-array/-/2d-bit-array-0.0.3.tgz","fileCount":4,"unpackedSize":11438,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDuwpkDxc0ke581gBNzzQoQoNv0bI6Q2GUeaD128yY7YwIgdIRAV8NosdzcUY9+6+Y+jC0erE1v+qLh6lu+1GuZR3M="}]},"_npmUser":{"name":"captaincodeman","email":"simon@captaincodeman.com"},"directories":{},"maintainers":[{"name":"captaincodeman","email":"simon@captaincodeman.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/2d-bit-array_0.0.3_1705891877984_0.08911656565421788"},"_hasShrinkwrap":false}},"time":{"created":"2023-08-31T17:19:28.938Z","0.0.1":"2023-08-31T17:19:29.098Z","modified":"2024-01-22T02:51:18.306Z","0.0.2":"2023-09-06T18:50:29.663Z","0.0.3":"2024-01-22T02:51:18.150Z"},"maintainers":[{"name":"captaincodeman","email":"simon@captaincodeman.com"}],"description":"Efficient 2D Bit Array with Serialization","homepage":"https://captaincodeman.github.io/2d-bit-array/","keywords":["2d","flags","bits","bit-array","bit-map","bit-mask","bit-flags","bit-string","bit-vector","image"],"repository":{"type":"git","url":"git+https://github.com/captaincodeman/2d-bit-array.git"},"author":{"name":"Simon Green","email":"simon@captaincodeman.com","url":"https://www.captaincodeman.com/"},"bugs":{"url":"https://github.com/captaincodeman/2d-bit-array/issues"},"license":"MIT","readme":"# 2d-bit-array\n\nA package for afficiently managing a 2D bit-array (also known as a bit-mask, bit-map, bit-string, or bit-vector). It can be used for any 2D array of flags but is especially suitable for working with images where the flags could be mapped to pixel transparencies.\n\n## Installation\n\nInstall using your package manager of choice:\n\n    pnpm i 2d-bit-array\n\n## Usage\n\n### BitArray\n\nCreate an instance of the `BitArray` class with the desired width and height:\n\n```ts\nimport { BitArray } from '2d-bit-array'\n\nconst bv = new BitArray(320, 240)\n```\n\nThe flag for each `x`, and `y` coordinate is stored as a single bit inside a `Uint8Array` which will always be the minimum size necssary to store all the possible flags. Use `get(x, y)` to check the flag value, `set(x, y)` to set it to true, `clear(x, y)` to set it to false, and `toggle(x, y)` to invert the current value.\n\nThe `BitArray` instance has an `empty` and `length` property to indicate if _any_ flags are set, and how many are set. The set flags can be iterated:\n\n```ts\nfor (const [x, y] of bv) {\n  // do something with x & y\n}\n```\n\nThe `.trim()` method returns the smallest instance that bounds the set flags, with the `x` and `y` offsets of the `BitArray` itself set. So given a bit vector:\n\n```ts\nimport { BitArray } from '2d-bit-array'\n\nconst bv = new BitArray(8, 8)\nbv.set(2, 4)\nbv.set(5, 6)\n\nconst trimmed = bv.trim()\n\n// trimmed will be width = 4, height = 3, offset x = 2 and y =4\n// the same flags can still be checked:\n\nexpect(trimmed.get(2, 4)).true\nexpect(trimmed.get(5, 6)).true\n\n// iterating the flags will still return the same [2, 4] and [5, 6] coordinates\n```\n\nThe reason this is desirable is for serialization, when the minimal amount of data can be stored or transmitted. When `.toJSON()` is used, the a trimmed version is returned automatically and the `Uint8Array` data encoded to a `bas64` string. Use `BitArray.fromJSON(value)` to decode a JSON serialized version.\n\nThe flags from one `BitArray` can be added to another. So the previous trimmed values could be added to another instance to get back to the original state:\n\n```ts\nconst bv2 = new BitArray(8, 8)\nbv2.add(trimmed)\n\n// bv2 now matches the original bv instance\n```\n\nUse `.reset()` to clear all the flags in an instance.\n\n### ChangeSet\n\nSometimes you need to track not just what has been set, but also what has been cleared. i.e. to store the difference between one set of flags and another. For this you can use the `ChangeSet` class. It's effectively just two `BitArray` instances, one to store added flags and one to store removed flags. Reversing an operation is slightly different - if you set a flag on a `ChangeSet` (which would set the added `BitArray` coordinate to true) and then clear it, it would simply _delete_ the flag from the added `BitArray`. Likewise, clearing a flag would set the removed `BitArray` coordinate, and then setting it would clear the flag.\n\nOnly if the next result is to set or clear a flag will a flag be set in the added or removed `BitArray` layers.\n\nThe same `empty` and `length` properties indicate if any, and how many, flags are set.\n\nChecking a flag using `get(x, y)` returns either the `Added`, `Removed`, or `Unchanged` state of the coordinate.\n\nIterating the flags returns an object containing the `x` and `y` properties plus the `changed` property (`Added` or `Removed`).\n\nThe `ChangeSet` can be applied to a `BitArray` to update it using the `.applyTo(bv: BitArray)` method, with any `Added` or `Removed` coordinated being applied as appropriate to set or clear the existing flags.\n\nAny use of `.toJSON` will return a compact representation with empty layers marked as null for maximum space saving. Use `ChangeSet.fromJSON` to decode a JSON serialized version.\n\n### Image\n\nThe `applyToImage` method allows a `BitArray` to be applied to an `ImageData` instance. The transparency for a pixel will be set based on whether the matching flag coordinate is true (opaque) or false (transparent).","readmeFilename":"README.md"}