Giter Site home page Giter Site logo

alik0211 / tiny-storage Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 13 KB

Tiny wrapper around localStorage and sessionStorage

Home Page: https://www.npmjs.com/package/tiny-storage

License: MIT License

JavaScript 100.00%
storage localstorage sessionstorage tiny-library

tiny-storage's Introduction

tiny-storage

NPM Travis Coverage Status

Tiny wrapper around localStorage and sessionStorage with reliable data storage.

Description

The tinyLocalStorage is the wrapper over the localStorage.

The tinySessionStorage is the wrapper over the sessionStorage.

Quick start

Module

Installation

npm install tiny-storage

Usage

import { tinyLocalStorage, tinySessionStorage } from 'tiny-storage';
// Or as CommonJS
// const { tinyLocalStorage, tinySessionStorage } = require('tiny-storage');

tinyLocalStorage.set('user', {
  name: 'Ali',
  surname: 'Gasymov'
});

tinySessionStorage.set('user', {
  name: 'Ali',
  surname: 'Gasymov'
});

Browser

Installation

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/tiny-storage.min.js"></script>

Usage

<script>
  tinyLocalStorage.set('user', {
    name: 'Ali',
    surname: 'Gasymov'
  });

  tinySessionStorage.set('user', {
    name: 'Ali',
    surname: 'Gasymov'
  });
</script>

Methods

key(index)

When passed a number n, returns the name of the nth key in the storage. The order of keys is user-agent defined, so you should not rely on it.

tinyLocalStorage.key(0);

tinySessionStorage.key(0);

get(keyName)

When passed a key name, will return that key's value or null if the key does not exist.

tinyLocalStorage.get('user');

tinySessionStorage.get('user');

set(keyName, keyValue)

When passed a key name and value, will add that key to the storage, or update that key's value if it already exists.

tinyLocalStorage.set('user', {
  name: 'Ali',
  surname: 'Gasymov'
});

tinySessionStorage.set('user', {
  name: 'Ali',
  surname: 'Gasymov'
});

remove(keyName)

When passed a key name, will remove that key from the storage if it exists. If there is no item associated with the given key, this method will do nothing.

tinyLocalStorage.remove('user');

tinySessionStorage.remove('user');

clear()

When invoked, clears all stored keys.

tinyLocalStorage.clear();

tinySessionStorage.clear();

Properties

length

Returns an integer representing the number of data items stored in the storage.

tiny-storage's People

Contributors

alik0211 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  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.