ls
Easy localStorage
Usage
npm install @losting/ls
ES Module
import * as ls from '@losting/ls';
set('name', 'admin');
set('data', {
name: '张三',
password: '12345678',
});
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('__EXAMPLE_');
set
import { set } from '@losting/ls';
set('key', 'value');
set('key', 'value', {
expires: 0,
encrypt: false,
});
get
import { get } from '@losting/ls';
const value = get('key');
const value = get('token', ({value, expires}) => {
if (expires - Date.now() <= 1000 * 60 * 5) {
}
return value;
});
remove
import { remove } from '@losting/ls';
remove('key');
clear
import { clear } from '@losting/ls';
clear();