0.1.0 • Published 7 months ago

@stash-it/prefix-suffix-plugin v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

@stash-it/prefix-suffix-plugin

logo-stash-it-color-dark 2x

@stash-it/prefix-suffix-plugin is a plugin for @stash-it/stash-it that allows you to add a prefix and/or suffix to the key before persisting the value.

When to use it?

Let's say you're using a storage that doesn't support namespaces, but you want to separate the keys for different parts of your application. You can use this plugin to add a prefix and/or suffix to the key. Now your team can save an item for key user1 and so can the other team(s).

Installation

npm

npm install @stash-it/prefix-suffix-plugin

deno

deno add @stash-it/prefix-suffix-plugin

yarn

yarn dlx jsr add @stash-it/prefix-suffix-plugin

pnpm

pnpm dlx jsr add @stash-it/prefix-suffix-plugin

bun

bunx jsr add @stash-it/prefix-suffix-plugin

Usage

// Import stash-it main class.
import { StashIt } from "@stash-it/stash-it";

// Import the plugin.
import { createPrefixSuffixPlugin } from "@stash-it/prefix-suffix-plugin";

// For it to work you will also need an adapter.
// You can use any of the @stash-it adapters or create your own.
import { MemoryAdapter } from "@stash-it/memory-adapter";

// Create an instance of the adapter.
const adapter = new MemoryAdapter();

// Create an instance of stash-it.
const stash = new StashIt(adapter);

// Create an instance of the plugin.
const plugin = createPrefixSuffixPlugin({
  prefix: "prefix-",
  suffix: "-suffix",
});

// Register the plugin to the stash-it instance.
stash.registerPlugins([plugin]);

// Use it.
await stash.set("key", "value");
const item = await stash.get("key");

console.log(item.key); // 'key', same key! but the data is persisted with prefix and suffix
0.1.0

7 months ago

0.0.6

8 months ago

0.0.1

11 months ago

0.0.0-beta.3

11 months ago

0.0.0-beta.2

12 months ago

0.0.0-beta.1

12 months ago