Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
level-js is a JavaScript implementation of LevelDB for use in the browser. It provides a simple key-value store API that is compatible with the LevelUP interface, making it easy to use in conjunction with other LevelDB-based libraries.
Basic Key-Value Store
This feature allows you to perform basic key-value operations such as putting, getting, and deleting data in the database.
const level = require('level-js');
const db = level('my-database');
// Put a value
await db.put('key', 'value');
// Get a value
const value = await db.get('key');
console.log(value); // 'value'
// Delete a value
await db.del('key');
Batch Operations
Batch operations allow you to perform multiple put and delete operations in a single atomic action, which can be more efficient than performing each operation individually.
const level = require('level-js');
const db = level('my-database');
// Perform batch operations
await db.batch()
.put('key1', 'value1')
.put('key2', 'value2')
.del('key3')
.write();
Stream API
The Stream API allows you to create readable and writable streams for iterating over the database entries, which is useful for processing large datasets.
const level = require('level-js');
const db = level('my-database');
// Create a read stream
const stream = db.createReadStream();
stream.on('data', ({ key, value }) => {
console.log(key, value);
});
stream.on('end', () => {
console.log('Stream ended');
});
PouchDB is an open-source JavaScript database inspired by Apache CouchDB that is designed to run well within the browser. It provides a similar key-value store functionality but also includes advanced features like synchronization with CouchDB and other PouchDB instances.
LocalForage is a fast and simple storage library for JavaScript. It improves the offline experience of your web app by using asynchronous storage (IndexedDB or WebSQL) with a simple, localStorage-like API. It is more abstracted compared to level-js and is designed to be easier to use.
Dexie.js is a wrapper for IndexedDB that provides a more developer-friendly API. It offers advanced querying capabilities and transaction support, making it a powerful alternative to level-js for complex use cases.
An
abstract-leveldown
compliant store on top of IndexedDB.
Here are the goals of level-js
:
abstract-leveldown
test suiteBuffer
keys and valuesBeing abstract-leveldown
compliant means you can use many of the Level modules on top of this library.
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')
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 })
With npm do:
npm install level-js
Not to be confused with leveljs.
This library is best used with browserify.
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.
Cross-browser Testing Platform and Open Source ♥ Provided by Sauce Labs.
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.
Support us with a monthly donation on Open Collective and help us continue our work.
FAQs
An abstract-leveldown compliant store on top of IndexedDB
The npm package level-js receives a total of 381,925 weekly downloads. As such, level-js popularity was classified as popular.
We found that level-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.