@aricma/browser-storage-actions
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

browser storage actions

this is a typescript project

lint compile test coverage

A functional approach to creating common actions for all your browser storage options. Using the browser storage options is always a pain. Let's make this as easy and secure as we can.

We currently support:

  • LocalStorage

We will support:

  • Cookies
  • Session Storage
  • ... what do you need?

setup

yarn add @aricma/browser-storage-actions

or

npm install @aricma/browser-storage-actions

usage

import { createLocalStorageActions } from '@aricma/browser-storage-actions';

const localStorageActions = createLocalStorageActions({
    nameSpace: "YOU_NAME_SPACE",
    localStorage: window.localStorage,
})

interface SomeFeatureState {
    value: string,
    counter: numbre,
    selection: string,
}

const item: SomeFeatureState = localStorageActions.addItem<SomeFeatureState>({
    name: 'my-feature-state',
    value: {
        value: 'hello world!',
        counter: 3,
        selection: 'some value from selection',
    },
}).value;

domain models

export interface BrowserStorageActions {
    hasItem: (name: string) => boolean,
    addItem: <Value>(item: BrowserStorageItem<Value>) => BrowserStorageItem<Value>,
    getItemByName: <Value>(name: string) => BrowserStorageItem<Value>,
    getAllItemsForNameSpace: () => Array<BrowserStorageItem<any>>,
    updateItem: <Value>(item: BrowserStorageItem<Value>) => BrowserStorageItem<Value>,
    removeItemByName: (name: string) => void,
    removeAllItemsForNameSpace: () => void,
}

export interface BrowserStorageItem<Value = string> {
    name: string,
    value: Value,
}

createLocalStorageActions

interface createLocalStorageActions {
    (depenedncies: LocalStorageActionsDependencies): BrowserStorageActions
}

interface LocalStorageActionsDependencies {
    nameSpace: string,
    localStorage: BrowserLocalStorage
}

Feedback

Package Sidebar

Install

npm i @aricma/browser-storage-actions

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

20.6 kB

Total Files

12

Last publish

Collaborators

  • aricma