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

ls-map-wrap

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ls-map-wrap

A wrapper around localstorage, so it can be used as a Map

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

ls-map-wrap

Build Status Coverage dependencies dev dependencies License: MIT XO code style

A wrapper around localstorage, so it can be used as a Map

Getting Started

Install it via npm:

npm install ls-map-wrap

And include in your project:

// Using ESM
import lsMapWrap from 'ls-map-wrap';
// Or using CJS
const lsMapWrap = require('ls-map-wrap');

Usage

import lsMapWrap from 'ls-map-wrap';

lsMapWrap.set('key', {ultimateAnswer: 42});
lsMapWrap.get('key'); // {ultimateAnswer: 42}
lsMapWrap.has('key'); // true

// works with values not typically handled by JSON.stringify/parse
lsMapWrap.set('nan', NaN);
Number.isNaN(lsMapWrap.get('nan')); // true

// works with functions too
lsMapWrap.set('simpleFn', () => console.log('hello'));
const fn = lsMapWrap.get('simpleFn');
fn(); // hello is logged to the console

lsMapWrap.delete('key');
lsMapWrap.has('key'); // false

lsMapWrap.clear();
lsMapWrap.has('nan'); // false

API

Implements all of the functions nessecary to drop it in place for an in-memory map

get(key)

Returns the value for the given key

key

Type: string

set(key, value)

Saves the value in localstorage for the given key

key

Type: string

value

Type: any

has(key)

Returns true if the map (localStorage) contains this value, false otherwise

key

Type: string

delete(key)

Removes the value from the map with the given key

key

Type: string

clear()

Removes all values from the map (localStorage)

FAQs

Package last updated on 15 Feb 2018

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