Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
ClientStorage
Advanced tools
Bulletproof persistent browser storage, works with disabled Cookies and/or localStorage
String
, Array
, Object
, and Boolean
support as values;localStorage
and cookies
;npm install --save ClientStorage
# Via Atmosphere
meteor add ostrio:cstorage
# Via NPM
meteor npm install --save ClientStorage
var ClientStorage = require('ClientStorage').ClientStorage;
var clientStorage = new ClientStorage();
import { ClientStorage } from 'ClientStorage';
const clientStorage = new ClientStorage();
import { ClientStorage } from 'meteor/ostrio:cstorage';
const clientStorage = new ClientStorage();
clientStorage.get('key')
- Read a record. If the key doesn't exist a undefined value will be returned;
key
- {String} - Record's key;clientStorage.set('key', value[, ttl])
- Create/overwrite a value in storage;
key
- {String} - Record's key;value
- {String|[mix]|Boolean|Object} - Record's value (content);ttl
- {Number} — [Optional] Record's TTL in seconds;clientStorage.remove('key')
- Remove a record;
key
- {String} - Record's key;clientStorage.has('key')
- Check whether a record exists, returns a boolean value;
key
- {String} - Record's key;clientStorage.keys()
- Returns an array of all storage keys;clientStorage.empty()
- Empty storage (remove all key/value pairs). Use with caution! (May remove cookies which weren't set by you).By default ClientStorage package handle selecting storage driver in the next order (descending priority):
localStorage
cookies
js
(JS Object driven storage)To alter priority pass "preferred driver" to new ClientStorage(driverName)
constructor.
cookies
only:Pass cookies
as an argument to new instance of ClientStorage
:
const { clientStorage } = require('ClientStorage');
var cookiesStorage = new ClientStorage('cookies');
cookiesStorage.has('locale'); // false
cookiesStorage.set('locale', 'en_US'); // true
localStorage
only:Pass localStorage
as an argument to new instance of ClientStorage
:
const { clientStorage } = require('ClientStorage');
var locStorage = new ClientStorage('localStorage');
locStorage.has('locale'); // false
locStorage.set('locale', 'en_US'); // true
js
only:Pass js
(in-memory js object) as an argument to new instance of ClientStorage
:
const { clientStorage } = require('ClientStorage');
var jsStorage = new ClientStorage('js');
jsStorage.has('locale'); // false
jsStorage.set('locale', 'en_US'); // true
Note: All instances are sharing same cookie and localStorage records!
Persistent ReactiveVar
implementation:
import { ReactiveVar } from 'meteor/reactive-var';
import { ClientStorage } from 'meteor/ostrio:cstorage';
const clientStorage = new ClientStorage();
const persistentReactive = (name, initial = undefined) => {
let reactive;
if (clientStorage.has(name)) {
reactive = new ReactiveVar(clientStorage.get(name));
} else {
clientStorage.set(name, initial);
reactive = new ReactiveVar(initial);
}
reactive.set = function (newValue) {
let oldValue = reactive.curValue;
if ((reactive.equalsFunc || ReactiveVar._isEqual)(oldValue, newValue)) {
return;
}
reactive.curValue = newValue;
clientStorage.set(name, newValue);
reactive.dep.changed();
};
return reactive;
};
const layout = persistentReactive('ui-layout', 'two-columns');
layout.get(); // two-columns
layout.set('single-column');
const clientStorage = new (require('ClientStorage').ClientStorage);
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
# Default
meteor test-packages ./
# With custom port
meteor test-packages ./ --port 8888
# With local MongoDB and custom port
MONGO_URL="mongodb://127.0.0.1:27017/client-storage-tests" meteor test-packages ./ --port 8888
FAQs
Bulletproof persistent browser storage, works with disabled Cookies and/or localStorage
The npm package ClientStorage receives a total of 127 weekly downloads. As such, ClientStorage popularity was classified as not popular.
We found that ClientStorage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.