New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@jf/storage

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jf/storage

Classes and polyfills implementing Web Storage API

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

jf-storage 0.0.1 stable

npm install jf-storage

Several classes and polyfills implementing Web Storage API.

You can store item in memory, cookies, files, browser storage, etc. Also, you can encrypt/decrypt data in storage using jf.storage.serializer classes, and obfuscate keys using key builders.

Proxy

jf.storage.Proxy it's a proxy to other storages but allow us to do advanced things adding some behaviors through injection dependency.

Example

We want store data requested to servers with following requirements:

  • Store data in files.
  • Data in files must be stored using JSON format.
  • Filename must be first 6 chars in MD5 hash of URLs. If data is read from http://joaquinfernandez.net/api/users/1, filename will be 05fdf4.json
const jfStorageFile           = require('jf-storage-api/src/File');
const jfStorageKeyCrypto      = require('jf-storage-api/src/key/Crypto');
const jfStorageProxy          = require('jf-storage-api/src/Proxy');
const jfStorageSerializerJson = require('jf-storage-api/src/serializer/Json');

function doRequest(url)
{
    return {
        firstname : 'Homer',
        lastname  : 'Simpson'
    };    
}

const storage = new jfStorageProxy(
    {
        key        : new jfStorageKeyCrypto('md5', 6),
        serializer : new jfStorageSerializerJson(),
        storage    : new jfStorageFile('/path/to/cache/directory', '.json')
    }
);

// Read data from server.
const url      = 'http://joaquinfernandez.net/api/users/1';
const response = doRequest(url);
// Store in cache.
storage.setItem(url, response);

//...
//...
//...

// Retrieve data:
const data = storage.getItem(url);
console.log(data); // { firstname : 'Homer', lastname : 'Simpson' }

Response will be stored in /path/to/cache/directory/05fdf4.json.

FAQs

Package last updated on 12 Jul 2019

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