Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@types/keyv
Advanced tools
TypeScript definitions for keyv
Package description
The @types/keyv package provides TypeScript type definitions for Keyv, a simple key-value storage with support for multiple backends. It allows TypeScript users to work with Keyv more effectively by offering type checking and IntelliSense features in their IDEs. Keyv itself is a simple, promisified key-value storage solution that supports various storage backends like Redis, MongoDB, SQLite, and more.
Basic Key-Value Operations
This feature demonstrates basic CRUD operations: setting, getting, deleting, and clearing key-value pairs. It's the core functionality of Keyv, allowing simple data storage and retrieval.
{"import Keyv from 'keyv';
const keyv = new Keyv();
// Set a value
await keyv.set('foo', 'bar');
// Get a value
const value = await keyv.get('foo');
console.log(value); // 'bar'
// Delete a value
await keyv.delete('foo');
// Clear all keys
await keyv.clear();"}
Using Namespaces
This feature shows how to use namespaces to separate different types of data within the same database or storage backend. It's useful for organizing data and preventing key collisions.
{"import Keyv from 'keyv';
const users = new Keyv('sqlite://path/to/database.sqlite', { namespace: 'users' });
const cache = new Keyv('sqlite://path/to/database.sqlite', { namespace: 'cache' });
// Set and get values in the 'users' namespace
await users.set('john', { age: 30 });
const john = await users.get('john');
console.log(john); // { age: 30 }
// The 'cache' namespace remains unaffected
const cacheValue = await cache.get('john');
console.log(cacheValue); // undefined"}
Custom Storage Backend
This feature illustrates how to use a custom storage backend, in this case, Redis, with Keyv. It demonstrates Keyv's flexibility in supporting different storage solutions.
{"import Keyv from 'keyv';
import KeyvRedis from '@keyv/redis';
const keyv = new Keyv({ store: new KeyvRedis('redis://user:pass@localhost:6379') });
// Now Keyv will use Redis as its storage backend
await keyv.set('hello', 'world');
const value = await keyv.get('hello');
console.log(value); // 'world'"}
node-cache is an in-memory key-value store similar to Keyv but lacks built-in support for multiple backends like Redis or MongoDB. It's simpler but not as flexible for different storage requirements.
levelup is a wrapper for LevelDB. It provides a flexible key-value database with a simple interface. Unlike Keyv, levelup is more focused on LevelDB and does not natively support multiple backends without additional plugins.
ioredis is a robust, performance-focused Redis client for Node.js. While it offers advanced Redis-specific functionalities, it doesn't provide the backend-agnostic key-value storage interface that Keyv does.
Readme
npm install --save @types/keyv
This package contains type definitions for keyv (https://github.com/lukechilds/keyv).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/keyv.
These definitions were written by AryloYeung, and BendingBender.
FAQs
Stub TypeScript definitions entry for keyv, which provides its own types definitions
The npm package @types/keyv receives a total of 6,132,865 weekly downloads. As such, @types/keyv popularity was classified as popular.
We found that @types/keyv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.