Skip to content

Store

Functions for creating and working with a simple key-value storage.

Method List

Store Creation

FunctionSignatureDescription
createStore<T extends object>(storeObject: T): { get: (key: keyof T) => T[keyof T], set: <K extends keyof T>(key: K, value: T[K]) => void, has: (key: string) => boolean, delete: (key: keyof T) => boolean }Creates a simple key-value storage from an object.

Usage Examples

Store Creation

1. createStore

typescript
import { createStore } from 'snappykit';

// Create store with initial data
const userStore = createStore({
  name: 'Alice',
  age: 30,
  email: 'alice@example.com'
});

// Get a value
console.log(userStore.get('name')); // "Alice"

// Set a value
userStore.set('age', 31);
console.log(userStore.get('age')); // 31

// Check if a key exists
console.log(userStore.has('email')); // true
console.log(userStore.has('address')); // false

// Delete a key
console.log(userStore.delete('email')); // true
console.log(userStore.has('email')); // false

dev@priveted.com | priveted.com