Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
dom-storage
Advanced tools
The dom-storage npm package is a simple implementation of the W3C DOM Storage API, which provides a way to store key-value pairs in a web browser. It is useful for server-side JavaScript environments like Node.js where the browser's localStorage and sessionStorage are not available.
localStorage
This feature allows you to use localStorage in a Node.js environment. You can set, get, remove, and clear items just like you would in a browser.
const { LocalStorage } = require('dom-storage');
const localStorage = new LocalStorage('./localStorage');
// Set an item
localStorage.setItem('key', 'value');
// Get an item
const value = localStorage.getItem('key');
console.log(value); // Outputs: 'value'
// Remove an item
localStorage.removeItem('key');
// Clear all items
localStorage.clear();
sessionStorage
This feature allows you to use sessionStorage in a Node.js environment. You can set, get, remove, and clear items just like you would in a browser.
const { SessionStorage } = require('dom-storage');
const sessionStorage = new SessionStorage();
// Set an item
sessionStorage.setItem('key', 'value');
// Get an item
const value = sessionStorage.getItem('key');
console.log(value); // Outputs: 'value'
// Remove an item
sessionStorage.removeItem('key');
// Clear all items
sessionStorage.clear();
node-localstorage is another package that provides a localStorage API for Node.js. It is similar to dom-storage but focuses solely on localStorage functionality. It also supports persistence by writing data to disk.
localstorage-memory is an in-memory implementation of the localStorage API for Node.js. Unlike dom-storage, it does not persist data to disk, making it suitable for testing and temporary storage.
node-persist is a more general-purpose storage library for Node.js that supports both key-value storage and JSON object storage. It offers more flexibility compared to dom-storage but may be overkill if you only need localStorage or sessionStorage functionality.
An inefficient, but as W3C-compliant as possible using only pure JavaScript, DOMStorage
implementation.
This is meant for the purpose of being able to run unit-tests and such for browser-y modules in node.
var Storage = require('dom-storage')
// in-file, doesn't call `String(val)` on values (default)
, localStorage = new Storage('./db.json', { strict: false })
// in-memory, does call `String(val)` on values (i.e. `{}` becomes `'[object Object]'`
, sessionStorage = new Storage(null, { strict: true })
, myValue = { foo: 'bar', baz: 'quux' }
;
localStorage.setItem('myKey', myValue);
myValue = localStorage.getItem('myKey');
// use JSON to stringify / parse when using strict w3c compliance
sessionStorage.setItem('myKey', JSON.stringify(myValue));
myValue = JSON.parse(localStorage.getItem('myKey'));
0 === localStorage.length;
null === localStorage.getItem('doesn't exist');
undefined === localStorage['doesn't exist'];
localStorage.setItem('myItem');
"undefined" === localStorage.getItem('myItem');
1 === localStorage.length;
localStorage.setItem('myItem', 0);
"0" === localStorage.getItem('myItem');
localStorage.removeItem('myItem', 0);
0 === localStorage.length;
localStorage.clear();
0 === localStorage.length;
Storage
events (not sure how to do)FAQs
W3C DOM Storage (localStorage and sessionStorage) for node.js
The npm package dom-storage receives a total of 0 weekly downloads. As such, dom-storage popularity was classified as not popular.
We found that dom-storage 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.