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

@losting/ls

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@losting/ls

localStorage

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ls

Easy localStorage

Usage

npm install @losting/ls

ES Module

import * as ls from '@losting/ls';

set('name', 'admin');

// json data
set('data', {
  name: '张三',
  password: '12345678',
});

// Set expiration time and enable simple encryption.
set('password', '12345678', {
  expires: 1000 * 60 * 60 * 24 * 7,
  encrypt: true,
});

CDN

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>example page</title>
  <script src="https://unpkg.com/@losting/ls@3.0.0/dist/ls.iife.js"></script>
</head>
<body>
  <div id="app"></div>
  <script>
    window.$ls.set('key', 'value');
    // ...
  </script>
</body>
</html>

setPrefix

import { setPrefix } from '@losting/ls';

// setPrefix(prefix: string)
setPrefix('__EXAMPLE_');

set

import { set } from '@losting/ls';

// set(key: string, value: unknown, option?: { expires?: number, encrypt?: boolean })
set('key', 'value');
// or
set('key', 'value', {
  expires: 0, // 0 or undefined mean never expire. 3000 means expire after 3 seconds
  encrypt: false, // Whether to encrypt
});

get

import { get } from '@losting/ls';

const value = get('key');

// use callback
const value = get('token', ({value, expires}) => {
  if (expires - Date.now() <= 1000 * 60 * 5) {
    // do something
    // return custom value
  }
  return value;
});

remove

import { remove } from '@losting/ls';

// remove(key: string)
remove('key');

clear

import { clear } from '@losting/ls';

clear();

Keywords

FAQs

Package last updated on 29 May 2023

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

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