Skip to main content

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

This package works with Node.js, BrowsersIt is unknown whether this package works with Cloudflare Workers, Deno, Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
JSR Score
70%
Published
a day ago (0.0.7)

@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

Add Package

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

Import symbol

import * as prefix_suffix_plugin from "@stash-it/prefix-suffix-plugin";

---- OR ----

Import directly with a jsr specifier

import * as prefix_suffix_plugin from "jsr:@stash-it/prefix-suffix-plugin";

Add Package

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

Import symbol

import * as prefix_suffix_plugin from "@stash-it/prefix-suffix-plugin";

Add Package

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

Import symbol

import * as prefix_suffix_plugin from "@stash-it/prefix-suffix-plugin";

Add Package

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

Import symbol

import * as prefix_suffix_plugin from "@stash-it/prefix-suffix-plugin";

Add Package

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

Import symbol

import * as prefix_suffix_plugin from "@stash-it/prefix-suffix-plugin";