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

storage-factory

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storage-factory - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

4

CHANGELOG.md
# Changelog
## 0.1.0
* `storageFactory` now accepts a function instead of `Storage`. Learn more: [#10](https://github.com/MichalZalecki/storage-factory/issues/10)
## 0.0.4

@@ -4,0 +8,0 @@

2

lib/index.d.ts

@@ -1,1 +0,1 @@

export declare function storageFactory(storage: Storage): Storage;
export declare function storageFactory(getStorage: () => Storage): Storage;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function storageFactory(storage) {
function storageFactory(getStorage) {
var inMemoryStorage = {};

@@ -8,4 +8,4 @@ function isSupported() {

var testKey = "__some_random_key_you_are_not_going_to_use__";
storage.setItem(testKey, testKey);
storage.removeItem(testKey);
getStorage().setItem(testKey, testKey);
getStorage().removeItem(testKey);
return true;

@@ -19,3 +19,3 @@ }

if (isSupported()) {
storage.clear();
getStorage().clear();
}

@@ -28,3 +28,3 @@ else {

if (isSupported()) {
return storage.getItem(name);
return getStorage().getItem(name);
}

@@ -38,3 +38,3 @@ if (inMemoryStorage.hasOwnProperty(name)) {

if (isSupported()) {
return storage.key(index);
return getStorage().key(index);
}

@@ -47,3 +47,3 @@ else {

if (isSupported()) {
storage.removeItem(name);
getStorage().removeItem(name);
}

@@ -56,3 +56,3 @@ else {

if (isSupported()) {
storage.setItem(name, value);
getStorage().setItem(name, value);
}

@@ -65,3 +65,3 @@ else {

if (isSupported()) {
return storage.length;
return getStorage().length;
}

@@ -68,0 +68,0 @@ else {

{
"name": "storage-factory",
"version": "0.0.4",
"version": "0.1.0",
"main": "lib/index.js",

@@ -10,8 +10,8 @@ "typings": "lib/index.d.ts",

"devDependencies": {
"@types/jest": "^23.3.9",
"codecov": "^3.1.0",
"jest": "^23.6.0",
"prettier": "1.14.3",
"ts-jest": "^23.10.5",
"typescript": "^3.1.6"
"@types/jest": "^24.0.15",
"codecov": "^3.5.0",
"jest": "^24.8.0",
"prettier": "^1.18.2",
"ts-jest": "^24.0.2",
"typescript": "^3.5.3"
},

@@ -18,0 +18,0 @@ "scripts": {

# storage-factory
[![CircleCI](https://circleci.com/gh/MichalZalecki/storage-factory.svg?style=svg)](https://circleci.com/gh/MichalZalecki/storage-factory)
This library is a tiny (1.1KB) wrapper for `localStorage` and `sessionStorage` because using storage directly is a bad idea. [That's why](https://michalzalecki.com/why-using-localStorage-directly-is-a-bad-idea).

@@ -15,4 +17,4 @@

export const local = storageFactory(localStorage);
export const session = storageFactory(sessionStorage);
export const local = storageFactory(() => localStorage);
export const session = storageFactory(() => sessionStorage);
```

@@ -31,4 +33,12 @@

## Example
Run the example using [parcel](https://parceljs.org/)
```bash
npx parcel example/index.html
```
## Contribute
Do you want to contribute? Awesome! Please, create an issue first and tell me about it.
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