Giter Club home page Giter Club logo

custom_storage's Introduction

CUSTOM STORAGE

Custom simple storage

npm i @foxmon/storage

sessionStorage, localStorage, memoryStorage


How to use


1. Memory storage

// In memory storage
const storage = Storage.asInMemory();

storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B

storage.get("A"); // Data-A
storage.get("B"); // Data-B

2. Session storage

// As sessionStorage
const storage = Storage.asSessionMemory();

storage.set("A", "Data-A"); // A: Data-A

storage.get("A"); // Data-A

3. Local storage

// As sessionStorage
const storage = Storage.asLocalMemory();

storage.set("A", "Data-A"); // A: Data-A

storage.get("A"); // Data-A

4. Common functions

4.1 set

Save key-value

const storage = Storage.asInMemory();

storage.set("A", "Data-A"); // A: Data-A

4.2 get

Get item

const storage = Storage.asInMemory();

storage.set("A", "Data-A"); // A: Data-A
storage.get("A"); // Data-A

4.3 keys

Get all keys in memory

const storage = Storage.asInMemory();

storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B

storage.keys(); // return ["A", "B"]

4.4 values

Get all values in memory

const storage = Storage.asInMemory();

storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B

storage.values(); // return ["Data-A", "Data-B"]

4.5 remove

Remove item

const storage = Storage.asInMemory();

storage.set("A", "Data-A"); // A: Data-A

storage.remove("A");

4.6 removeAll

Remove all item in storage

const storage = Storage.asInMemory();

storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B

storage.removeAll();

4.7 length

Count of items in storage

const storage = Storage.asInMemory();

storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B

storage.length; // 2

custom_storage's People

Contributors

foxmon avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.