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

linshu-utils

v0.0.12

Published

在 node 环境中 stroage dom 相关的方法不能使用

Downloads

1

Readme

个人工具类包

在 node 环境中 stroage dom 相关的方法不能使用

MyStorage 工具

使用方法

import { MyStorage } from "linshu-utils";
// 设置类型 可以是 string number object array 等可以JSON 格式化的数据类型
const token = new MyStorage<string>(
  "token", // 存储在本地缓存的键
  {
    expires: 1 * 60 * 60 * 1000, //过期时间 不设置为永久有效
    once: false, // 只读取一次就失效 默认为false
  },
  "localStorage" // 默认是sessionStorage   
);

实例属性方法

  • remove 删除方法
  • data 当前数据 能直接赋值 当赋值undefined 或 null 时 触发remove 方法 其他触发 set 方法
    console.log(token.data)
    token.data = ''
       
  • set(value) 设置 值
  • subscribe(event: 'set',callback:(data:T)=>any):void 订阅设置事件
  • subscribe(event: 'remove',callback:()=>any):void 订阅移除事件

发布订阅

Topic 类 实例方法

  • subscribe(event: string | symbol, callback: Function) 订阅事件
  • onceSubscribe(event: string | symbol, callback: Function) 订阅事件 只接收一次发布
  • emit(event: string | symbol, ...params: any[]) 推送信息
  • unSubscribe(event: string | symbol, callback: Function) 取消当个订阅事件
  • unSubscribeAll(event: string | symbol) 取消所有订阅事件
import { Topic } from 'linshu-utils'
const topic = new Topic();
const testSub = (...params: any[]) => {
  console.log("sub1 接收到发布信息: ", ...params);
};
const testSub2 = (...params: any[]) => {
  console.log("sub2 接收到发布信息: ", ...params);
};
topic.subscribe("test", testSub);
topic.subscribe("test", testSub2);
topic.onceSubscribe('test',(...params:any[])=>{
  console.log('我只触发一次:',...params)
})

topic.emit("test", "发布test信息");
topic.unSubscribe("test", testSub); // 取消 testSub 订阅
topic.emit("test", "发布test信息2");
topic.unSubscribeAll("test"); //取消所有订阅
topic.emit("test", "发布test信息3");

获取变量类型方法

import { getType } from 'linshu-utils'

getType(1) // number  内部通过 Object.prototype.toString 获取 (转小写) ,获取类的 内部属性 [[Class]] 如果是非内部类 可以通过 设置 get [Symbol.toStringTag] 

dom 方法 (不要在node 环境下调用)

常用正则表达式