🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

better-localstorage

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package version was removed
This package version has been unpublished, mostly likely due to security reasons

better-localstorage

NPM package for interactions with localstorage with JSON-like data.

2.0.0
unpublished
Source
npm
Version published
Weekly downloads
56
-56.25%
Maintainers
1
Weekly downloads
 
Created
Source

better-localstorage - v1.1.1

Table of content

Installation

This module is published through the NPM registry. You can easly install it with the following command:

npm i better-localstorage

Usage

This module allow to interact with client's localstorage and store JSON-parsed data, so each entry can contains JSON-like data.

get(key[, options])

Get an element from the local storage.

Returns

  • Object - Entry's content if it exists and its content as been parsed.
  • undefined - If the entry doesn't exists.

Parameters

NameTypeFacultativeDescription
keystringEntry's name
optionsGetOptions:white_check_mark:Getter's options

Throw

  • RangeError - If key is not provided.
  • TypeError - If the entry's value cannot be parsed as JSON.

Examples

// { test: { something: true } }
get("test"); // { something: true }
// { test: { something: true } }
get("something"); // undefined
// { test: 1 }
get("test"); // 1

set(key, value)

Set an element to the local storage.

Returns

  • undefined.

Parameters

NameFacultativeFacultativeDescription
keystringEntry's name
valueObjectContent to set in the localstorage

Throw

  • RangeError - If key or value is not provided.
  • TypeError if the value cannot be strigified as JSON.

Examples

// { test: { something: true } }
set("test", true);
// { test: true }
// { test: { something: true } }
set("something", { hi: "everyone" });
// { test: { something: true }, hi: "everyone" }

exists(key)

Check if an entry exists in the local storage.

Returns

  • boolean - true if the entry exists, false otherwise.

Parameters

NameTypeFacultativeDescription
keystringEntry's name

Throw

  • RangeError - If key is not provided.

Examples

// { test: "hi" }
exists("test"); // true
// { test: "hi" }
exists("something"); // false

destroy(key)

Remove an entry from the local storage.

Returns

  • boolean - true if the entry has been removed by the function's call, false otherwise.

Parameters

NameTypeFacultativeDescription
keystringEntry's name

Throw

  • RangeError - If key is not provided.

Examples

// { test: "hi", something: "everyone" }
destroy("test"); // true
// { something: "everyone" }
// { test: "hi" }
destroy("something"); // false
// { test: "hi" }

clear()

Clear all entries from the local storage.

Returns

  • boolean - true if the entries have been removed by the function's call, false otherwise.

Examples

// { test: "hi", something: "everyone" }
clear(); // true
// {  }
// {  }
clear(); // false
// {  }

GetOptions

get() options.

Content

NameTypeFacultativeDescription
destroyboolean:white_check_mark:If true, will destroy the entry after calling this function (even if an error occured)
destroyOnErrorboolean:white_check_mark:If true, will destroy the entry only if an error occured

Contributing

Feel free to open an issue if you want to report bugs or discuss about suggestions!

License

MIT

Made with ❤ by Ratibus11.

Keywords

localstorage

FAQs

Package last updated on 11 Aug 2022

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