npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xuelin/storage

v0.3.0

Published

封装 localStorage, sessionStorage

Downloads

4

Readme

封装 localStorage, sessionStorage

维护人: xuelin

安装

npm i @xuelin/storage
or
yarn add @xuelin/storage

功能

  1. 命名空间,防止微前端应用之间命名污染
  2. 消除错误边界,防止报错导致应用崩溃

与原生 localStorage, sessionStorage 功能方法上的区别

  1. clear()方法,只清除命名空间内的 key

用法

// utils.js
import storage from '@xuelin/storage'
export const local = new storage({
    name: 'local-',
    type: 'localStorage'
})
export const session = new storage({
    name: 'session-',
    type: 'sessionStorage'
})

// main.js
import {
    local,
    session
} from './utils'
local.setItem('number', 123) // number
local.setItem('string', 'string') // string
local.setItem('object', {
    a: 1,
    b: 2
}) // object
local.setItem('array', [1, 2, 3]) // array
local.setItem('null', null) // null
local.setItem('undefined', undefined) // undefined
local.setItem('boolean', false) // boolean
console.log('number', local.getItem('number')) // 123
console.log('string', local.getItem('string')) // 'string'
console.log('object', local.getItem('object')) // { a: 1, b: 2 }
console.log('array', local.getItem('array')) // [1, 2, 3]
console.log('null', local.getItem('null')) // null
console.log('undefined', local.getItem('undefined')) // undefined
console.log('boolean', local.getItem('boolean')) // false
console.log('key', local.key(0))
console.log('length from local', local.getLength())
local.removeItem('number')
local.clear()
console.log('----------------------------------------------------------------')
session.setItem('number', 123) // number
session.setItem('string', 'string') // string
session.setItem('object', {
    a: 1,
    b: 2
}) // object
session.setItem('array', [1, 2, 3]) // array
session.setItem('null', null) // null
session.setItem('undefined', undefined) // undefined
session.setItem('boolean', false) // boolean
console.log('number', session.getItem('number')) // 123
console.log('string', session.getItem('string')) // 'string'
console.log('object', session.getItem('object')) // { a: 1, b: 2 }
console.log('array', session.getItem('array')) // [1, 2, 3]
console.log('null', session.getItem('null')) // null
console.log('undefined', session.getItem('undefined')) // undefined
console.log('boolean', session.getItem('boolean')) // false
console.log('key', session.key(0))
console.log('length', session.getLength())
session.removeItem('number')
session.clear()