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

init-storage

v0.1.1

Published

为应用中的storage提供丝滑的typescript支持

Downloads

23

Readme

为何而生

你是不是受够了Storage.getItem(key: string): string | null没有类型提示的日子
你是不是需要一个在应用中集成一个清晰可见的存储空间列表

  • {
    • token: number
    • info: { id: string, pwd: string}
    • version: string
  • }

那请你试用下init-storage吧!


特性

  • 📦包大小仅为1kb
  • ✅无任何生产依赖。
  • 💪🏼使用原生 Javascript Api,支持任意框架使用
  • 💯100%测试场景覆盖
  • 🚀SSR支持

快速开始

// npm
npm install init-storage --save
import { setInitStorage } from "init-storage";

const { getLocalStorageItem } = setInitStorage(
  local: {
    local: { token: "1" },
    session: {},
  }, 
  session: {}
)

console.log(getLocalStorageItem('token'))       // null
console.log(getLocalStorageItem('token', true)) // "1"

内部自动通过关键字typeof进行类型推断,当你认为自动推断的类型有误时,使用as关键字可以帮助进行类型拓展

下面是可以调用的方法: | 方法 | 说明 | 类 型 | |--------------------------|--------------------|--------------------------------------------------------------------| | getLocalStorageItem | 获取本地存储空间 | (item: 'aa' | 'bb' | '...', ifNullIsGetInit: boolean) => void | | setLocalStorageItem | 存储本地存储空间(某键) | (item: 'aa' | 'bb' | '...', value: ValueType) => void | | removeLocalStorageItem | 移除本地存储空间(某键) | (item: 'aa' | 'bb' | '...') => void | | clearLocalStorageItem | 清空本地存储空间 | (item: 'aa' | 'bb' | '...') => void | | getSessionStorageItem | 获取会话存储空间 | (item: 'aa' | 'bb' | '...', ifNullIsGetInit: boolean) => void | | setSessionStorageItem | 存储会话存储空间(某键) | (item: 'aa' | 'bb' | '...', value: ValueType) => void | | removeSessionStorageItem | 移除会话存储空间(某键) | (item: 'aa' | 'bb' | '...') => void | | clearSessionStorageIte | 清空会话存储空间 | (item: 'aa' | 'bb' | '...') => void |

同时setInitStorage(INIT, option)还有用可配置项,下面是一些有关配置项:

| 参数 | 说明 | 类 型 | 默认值 | |----------------|-------------------------------------|------------|---------------------------------| | defaultUseInit | 返回的方法中ifNullIsGetInit参数的默认值 | boolean | false (如果存储中没有就返回null) |

示例


许可证

MIT