{"name":"browser-level","version":"3.0.0","description":"An abstract-level database for browsers, backed by IndexedDB","author":{"name":"max ogden"},"license":"MIT","main":"index.js","types":"./index.d.ts","scripts":{"test":"standard && hallmark && airtap --coverage test/index.js && nyc report","coverage":"nyc report -r lcovonly"},"dependencies":{"abstract-level":"^3.1.0"},"devDependencies":{"@babel/preset-env":"^7.26.9","@voxpelli/tsconfig":"^15.1.2","airtap":"^5.0.0","airtap-playwright":"^1.0.1","babelify":"^10.0.0","hallmark":"^5.0.1","nyc":"^17.1.0","standard":"^17.0.0","tape":"^5.5.2","typescript":"^5.8.3","uuid":"^11.1.0"},"repository":{"type":"git","url":"git+https://github.com/Level/browser-level.git"},"homepage":"https://github.com/Level/browser-level","keywords":["level","leveldb","indexeddb","abstract-level"],"_id":"browser-level@3.0.0","gitHead":"7ae3bae52ec48f2979b48516f2546863054dad89","bugs":{"url":"https://github.com/Level/browser-level/issues"},"_nodeVersion":"22.7.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-kGXtLh29jMwqKaskz5xeDLtCtN1KBz/DbQSqmvH7QdJiyGRC7RAM8PPg6gvUiNMa+wVnaxS9eSmEtP/f5ajOVw==","shasum":"158287e21f44051cc06bf05abc235b385e66d264","tarball":"http://registry-npm.ywwl.com/browser-level/download/browser-level-3.0.0.tgz","fileCount":11,"unpackedSize":38001,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD1RHTPw6papsVVQPdoPwsJU7k+571wGW1IXgK7GNjtwgIhAPNotEyInMkI1av5GkqYOcP2MkZe6Z3PhPNsLgIHkK5p"}],"size":11205,"noattachment":false,"key":"/browser-level/-/browser-level-3.0.0.tgz"},"_npmUser":{"name":"vweevers","email":"dev@vincentweevers.nl"},"directories":{},"maintainers":[{"name":"vweevers","email":"dev@vincentweevers.nl"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/browser-level_3.0.0_1745164243508_0.4800709787880444"},"_hasShrinkwrap":false,"readme":"# browser-level\n\n**An [`abstract-level`][abstract-level] database for browsers, backed by [IndexedDB][indexeddb].** The successor to [`level-js`](https://github.com/Level/level-js). If you are upgrading, please see [UPGRADING.md](UPGRADING.md).\n\n> :pushpin: Which module should I use? What is `abstract-level`? Head over to the [FAQ](https://github.com/Level/community#faq).\n\n[![level badge][level-badge]][awesome]\n[![npm](https://img.shields.io/npm/v/browser-level.svg)](https://www.npmjs.com/package/browser-level)\n[![Test](https://img.shields.io/github/actions/workflow/status/Level/browser-level/test.yml?branch=main\\&label=test)](https://github.com/Level/browser-level/actions/workflows/test.yml)\n[![Coverage](https://img.shields.io/codecov/c/github/Level/browser-level?label=\\&logo=codecov\\&logoColor=fff)](https://codecov.io/gh/Level/browser-level)\n[![Standard](https://img.shields.io/badge/standard-informational?logo=javascript\\&logoColor=fff)](https://standardjs.com)\n[![Common Changelog](https://common-changelog.org/badge.svg)](https://common-changelog.org)\n[![Donate](https://img.shields.io/badge/donate-orange?logo=open-collective\\&logoColor=fff)](https://opencollective.com/level)\n\n## Usage\n\n```js\nconst { BrowserLevel } = require('browser-level')\n\n// Create a database called 'example'\nconst db = new BrowserLevel('example', { valueEncoding: 'json' })\n\n// Add an entry with key 'a' and value 1\nawait db.put('a', 1)\n\n// Add multiple entries\nawait db.batch([{ type: 'put', key: 'b', value: 2 }])\n\n// Get value of key 'a': 1\nconst value = await db.get('a')\n\n// Iterate entries with keys that are greater than 'a'\nfor await (const [key, value] of db.iterator({ gt: 'a' })) {\n  console.log(value) // 2\n}\n```\n\n## API\n\nThe API of `browser-level` follows that of [`abstract-level`](https://github.com/Level/abstract-level) with just two additional constructor options (see below) and one additional method (see below). As such, the majority of the API is documented in `abstract-level`. The `db.getSync()` method is not supported here and neither are the `createIfMissing` and `errorIfExists` options.\n\nLike other implementations of `abstract-level`, `browser-level` has first-class support of binary keys and values, using either [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) or [Buffer](https://nodejs.org/api/buffer.html). In order to sort string and binary keys the same way as other databases, `browser-level` internally converts data to a Uint8Array before passing them to IndexedDB. If you have no need to work with `Buffer` keys or values, you can choose to omit the [`buffer`](https://github.com/feross/buffer) shim from a JavaScript bundle (through configuration of Webpack, Browserify or other bundlers).\n\nDue to limitations of IndexedDB, `browser-level` does not offer snapshot guarantees. Such a guarantee would mean that an iterator does not see the data of simultaneous writes - it would be reading from a snapshot in time. In contrast, a `browser-level` iterator reads a few entries ahead and then opens a new IndexedDB transaction on the next read. A \"few\" means all entries for `iterator.all()`, `size` amount of entries for `iterator.nextv(size)` and a hardcoded 100 entries for `iterator.next()`. Individual calls to those methods have snapshot guarantees but repeated calls do not.\n\nThe result is that an iterator will include the data of simultaneous writes, if `db.put()`, `db.del()` or `db.batch()` are called in between creating the iterator and consuming the iterator, or in between calls to `iterator.next()` or `iterator.nextv()`. For example:\n\n```js\nconst iterator = db.iterator()\nawait db.put('abc', '123')\n\nfor await (const [key, value] of iterator) {\n  // This might be 'abc'\n  console.log(key)\n}\n```\n\nIf snapshot guarantees are a must for your application then use `iterator.all()` and call it immediately after creating the iterator:\n\n```js\nconst entries = await db.iterator({ limit: 50 }).all()\n\n// Synchronously iterate the result\nfor (const [key, value] of entries) {\n  console.log(key)\n}\n```\n\n### `db = new BrowserLevel(location[, options])`\n\nCreate a new database or open an existing one. The required `location` argument is the string name of the [`IDBDatabase`](https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase) to be opened, as well as the name of the object store within that database. The name of the `IDBDatabase` will be prefixed with `options.prefix`.\n\nBesides `abstract-level` options, the optional `options` argument may contain:\n\n- `prefix` (string, default: `'level-js-'`): Prefix for the `IDBDatabase` name. Can be set to an empty string. The default is compatible with `level-js`.\n- `version` (string or number, default: `1`): The version to open the `IDBDatabase` with.\n\nSee [`IDBFactory#open()`](https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory/open) for more details about database name and version.\n\n### `BrowserLevel.destroy(location[, prefix])`\n\nDelete the IndexedDB database at the given `location`. Returns a promise. If `prefix` is not given, it defaults to the same value as the `BrowserLevel` constructor does. This method is an additional method that is not part of the [`abstract-level`](https://github.com/Level/abstract-level) interface.\n\nBefore calling `destroy()`, close a database if it's using the same `location` and `prefix`:\n\n```js\nconst db = new BrowserLevel('example')\nawait db.close()\nawait BrowserLevel.destroy('example')\n```\n\n## Install\n\nWith [npm](https://npmjs.org) do:\n\n```bash\nnpm install browser-level\n```\n\nThis module is best used with [`browserify`](http://browserify.org) or similar bundlers.\n\n## Contributing\n\n[`Level/browser-level`](https://github.com/Level/browser-level) is an **OPEN Open Source Project**. This means that:\n\n> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.\n\nSee the [Contribution Guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details.\n\n## Donate\n\nSupport us with a monthly donation on [Open Collective](https://opencollective.com/level) and help us continue our work.\n\n## License\n\n[MIT](LICENSE)\n\n[level-badge]: https://leveljs.org/img/badge.svg\n\n[indexeddb]: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API\n\n[awesome]: https://github.com/Level/awesome\n\n[abstract-level]: https://github.com/Level/abstract-level\n","publish_time":1745164243709,"_cnpm_publish_time":1745164243709,"dist-tags":{"latest":"3.0.0"}}