New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
increased by26.33%
Maintainers
1
Weekly downloads
 
Created
Source

Persistent Client (Browser) Storage

  • Bulletproof persistent Client storage;
  • Support for Unicode values and keys;
  • 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 a 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 weren't set by you).

Alternate usage:

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';
const 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';
const 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 17 May 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