6.1.0 • Published 3 years ago

level-js v6.1.0

Weekly downloads
164,217
License
MIT
Repository
github
Last release
3 years ago

level-js

An abstract-leveldown compliant store on top of IndexedDB.

level badge npm Test Coverage Standard Common Changelog Donate

Table of Contents

Background

Here are the goals of level-js:

  • Store large amounts of data in modern browsers
  • Pass the full abstract-leveldown test suite
  • Support string and Buffer keys and values
  • Be as fast as possible
  • Sync with multilevel over ASCII or binary transports.

Being abstract-leveldown compliant means you can use many of the Level modules on top of this library.

Example

If you are upgrading: please see UPGRADING.md.

const levelup = require('levelup')
const leveljs = require('level-js')
const db = levelup(leveljs('bigdata'))

db.put('hello', Buffer.from('world'), function (err) {
  if (err) throw err

  db.get('hello', function (err, value) {
    if (err) throw err

    console.log(value.toString()) // 'world'
  })
})

With async/await:

const levelup = require('levelup')
const leveljs = require('level-js')
const db = levelup(leveljs('bigdata'))

await db.put('hello', Buffer.from('world'))
const value = await db.get('hello')

Browser Support

Sauce Test Status

Type Support

Keys and values can be a string or Buffer. Any other type will be irreversibly stringified. The only exceptions are null and undefined. Keys and values of that type are rejected.

In order to sort string and Buffer keys the same way, for compatibility with leveldown and the larger ecosystem, level-js internally converts keys and values to binary before passing them to IndexedDB.

If you desire non-destructive encoding (e.g. to store and retrieve numbers as-is), wrap level-js with encoding-down. Alternatively install level which conveniently bundles levelup, level-js and encoding-down. Such an approach is also recommended if you want to achieve universal (isomorphic) behavior. For example, you could have leveldown in a backend and level-js in the frontend. The level package does exactly that.

When getting or iterating keys and values, regardless of the type with which they were stored, keys and values will return as a Buffer unless the asBuffer, keyAsBuffer or valueAsBuffer options are set, in which case strings are returned. Setting these options is not needed when level-js is wrapped with encoding-down, which determines the optimal return type by the chosen encoding.

db.get('key', { asBuffer: false })
db.iterator({ keyAsBuffer: false, valueAsBuffer: false })

Install

With npm do:

npm install level-js

Not to be confused with leveljs.

This library is best used with browserify.

API

db = leveljs(location[, options])

Returns a new leveljs instance. location is the string name of the IDBDatabase to be opened, as well as the object store within that database. The database name will be prefixed with options.prefix.

options

The optional options argument may contain:

  • prefix (string, default: 'level-js-'): Prefix for IDBDatabase name.
  • version (string | number, default: 1): The version to open the database with.

See IDBFactory#open for more details.

Big Thanks

Cross-browser Testing Platform and Open Source ♥ Provided by Sauce Labs.

Sauce Labs logo

Contributing

Level/level-js is an OPEN Open Source Project. This means that:

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.

See the Contribution Guide for more details.

Donate

Support us with a monthly donation on Open Collective and help us continue our work.

License

MIT

@tyz-wallet/tyz-wallet-core-clientvoip-web-sdk-test@mc3-aether/shared-cache@everything-registry/sub-chunk-2061swarm-browsertailgatevue-levelweb3x-evmweb3x-evm-esws-browserify-fsshare-tokenschema-mapper-driver-leveldbrombu-tesseract.jsvoxel-levellevel-browserifylevel-browserify-es5level-ndnlevel-nodejs-mobilelevel-nodejs-mobile-rnlocalstorage-level-migrationlarge-nftlarge-coregittoken-web-workersjh-search-indexhyperpadivy-bitcoinlevel-fs-browserlitemessagelevel-testlevel-test-synclevel-userleviglslify-apindn-js-contribmulticore-clientmaki-client-levelmaskcachepico-engine-browserneural_compressor_ext_lab_customizedneural_compressor_ext_lab_customized_2srepollock-browserify-fsrodabasespace-mvcturtusterraformer-geostore-leveldbtldrawlignin@adora-wallet/adoracore-client@aztec/sdk@aztec/sdk-incubator@aztec/alpha-sdk@buganto/client3box-shared-cache@abcpros/bitcore-client@dashevo/dapi-db-cachexs-js-datastore-levelvigour-level@ducatus/bitcore-client@ducatus/ducatuscore-client@ignitial/iio-app@fuel-js/client@fuel-js/test@infinitebrahmanuniverse/nolb-lev@ludamad-aztec/sdk@micropede/broker@marklb/crypto-fs@erquhart/browserify-fs@maskdex/maskcache@maskdex/maskkeystore@integromat/tesseract.js@joseph184/browserify-fs@polyaztec/sdk@pashoo2/p2p@o0o2022sg/bitcore-client@sotatek-anhdao/bitcore-client@bpanel/bpaneleonacore-client@tecracoin/bitcore-client-tcr@uhhhh2/web3x@uhhhh2/web3x-esfergies-packager-test@virgilsecurity/e3kit-browserack-uialiyun-voip-web-sdk@zeekay/browserify-fs@y-elm/started@zalastax/nolb-levforge-e3kit-browserflatsheet-editorfrylordfuel-corebitcore-clientbitcore-client-tcrboot-bonebpanelbrashbrowser-module-cachebrowserify-fscausal-net.storagedagdbdapi-db-cache
6.1.0

3 years ago

6.0.0

4 years ago

5.0.2

5 years ago

4.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.0.0

7 years ago

3.0.0-rc1

7 years ago

2.2.4

9 years ago

2.2.3

9 years ago

2.2.2

9 years ago

2.2.1

9 years ago

2.2.0

9 years ago

2.1.6

11 years ago

2.1.5

11 years ago

2.1.4

11 years ago

2.1.3

11 years ago

2.1.2

11 years ago

2.0.0

11 years ago

1.2.0

11 years ago

1.1.2

11 years ago

1.1.1

11 years ago

1.1.0

11 years ago

1.0.8

11 years ago

1.0.7

11 years ago

1.0.6

12 years ago

1.0.5

12 years ago

1.0.4

12 years ago

1.0.3

12 years ago

1.0.2

12 years ago

1.0.1

12 years ago

1.0.0

12 years ago

0.0.0

12 years ago