Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ClientStorage

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ClientStorage

Bulletproof persistent browser storage, works with disabled Cookies and/or localStorage

  • 2.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
190
decreased by-19.49%
Maintainers
1
Weekly downloads
 
Created
Source

Client Storage

  • Bulletproof Client storage functions, localStorage with fall-back to cookies;
  • Unicode values and keys support;
  • Works in browser with disabled localStorage and cookies;
  • 100% tests coverage.

Install:

npm install --save ClientStorage

Install Meteor:

# Via Atmosphere
meteor add ostrio:cstorage
# Via NPM
meteor npm install --save ClientStorage

Require:

var ClientStorage = require('ClientStorage').ClientStorage;

ES6 Import (Meteor):

import { ClientStorage } from 'meteor/ostrio:cstorage';

Usage:

Get
  • ClientStorage.get('key') - Read a record. If the key doesn't exist a null value will be returned.
Set
  • ClientStorage.set('key', value) - Create/overwrite a value in storage
Remove
  • ClientStorage.remove('key') - Remove a record
Has
  • ClientStorage.has('key') - Check whether a record exists, returns boolean value
Keys
  • ClientStorage.keys() - Returns an array of all storage keys
Empty
  • ClientStorage.empty() - Empty storage (remove all key/value pairs). Use with caution! (May remove cookies which was set not by you)
Use cookies only

To use cookies as a driver for ClientStorage create new instance of clientStorage (camel-case, first letter lower-case)

var clientStorage  = require('ClientStorage').clientStorage;
var csCookies = new clientStorage('cookies');

or in ES6 (Meteor):

import { clientStorage } from 'meteor/ostrio:cstorage';
let csLocalStorage = new clientStorage('cookies');
Use localStorage only

To use localStorage as a driver for ClientStorage create new instance of clientStorage (camel-case, first letter lower-case):

var clientStorage  = require('ClientStorage').clientStorage;
var csLocalStorage = new clientStorage('localStorage');

or in ES6 (Meteor):

import { clientStorage } from 'meteor/ostrio:cstorage';
let csLocalStorage = new clientStorage('localStorage');

Note: All instances shares same cookies and localStorage records!

Example:

ClientStorage.set('locale', 'en'); // true
ClientStorage.set('country', 'usa'); // true
ClientStorage.set('gender', 'male'); // true

ClientStorage.get('gender'); // male

ClientStorage.has('locale'); // true
ClientStorage.has('city'); // false

ClientStorage.keys(); // ['locale', 'country', 'gender']

ClientStorage.remove('locale'); // true
ClientStorage.get('locale'); // undefined

ClientStorage.keys(); // ['country', 'gender']

ClientStorage.empty(); // true
ClientStorage.keys(); // []

ClientStorage.empty(); // false

Keywords

FAQs

Package last updated on 16 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc