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 🙏

© 2026 – Pkg Stats / Ryan Hefner

guantou-hooks

v0.0.5

Published

guantou-hooks

Downloads

21

Readme

vue3的hooks库

  • 尚不完善,没写任何测试用例

install

npm install guantou-hooks

useBoolean

  • 管理布尔值
count { bool, toggle, setFalse, setTrue} = useBoolean(false);
  • 入参:初始真假性
  • toggle :无参数时切换bool的真假 有参数时,切换bool至参数的真假性
  • setFalse/setTrue:切换至假/真

useLocalStorage

  • 管理useLocalStorage
const { value, setValue } = useLocalStorage("test");
  • 入参: localStorage的key:string

useMouse

  • 实时获取鼠标位置
const  {x,y} = useMouse();
  • x/y: 鼠标此时的坐标

useStep

  • 管理步骤
const { nowStepIndex, nowStep, next, back, jump } = useStep(['step1','step2','step3'],0)
  • 入参1: any[] step列表

  • 入参2: number defaultIndex 初始的第几步

  • nowStepIndex: 目前的步数

  • nowStep: 目前的step值

  • next:Function 下一步

  • back:Function 上一步

  • jump(number): 跳跃至某一步

useUrlState

  • 管理路由的search部分(排他)
const { data, clear, reset } = useUrlState({ page: 1, pageSize: 10 });

useLoading

  • 管理loading状态
const { loading, startSync, start, end } = useLoading(false,300);
  • 入参1: 初始的loading状态
  • 入参2: 调用start时的延迟时间,在延迟之后开始loading
  • loading:bool
  • startSync:不延迟,直接开始loading
  • start:在延迟之后开始loading
  • end:结束loading

useClickAway

  • 响应目标元素之外的点击事件
<div ref="el"></div>
setup(){
  const el = useClickAway(callback:(e: MouseEvent) => any);
  return {
    el
  }
}

useOnline

  • 是否断网
const isOnline = useOnline(
  { onOnLine, onOffline }:{
      onOnLine?: () => any;
      onOffline?: () => any;
  } = {}
);

useSize

  • 监控某个dom元素的大小改变
<div ref="el"></div>
setup(){
  type Size = { width?: number, height?: number };

  const {el,size} = useSize(onResize?: (size: Size) => any);

  return {
    el
  }
}

useTextSelection

  • 监控用户选中的文本内容和位置
<div ref="el"></div>
interface ISelection {
  top: number;
  left: number;
  bottom: number;
  right: number;
  height: number;
  width: number;
  text:string;
}

setup(){
  const {el,selection:ISelection} = useTextSelection(isBody = false);
  return {
    el
  }
}
  • isBodytrue,会监听整个页面的选中

useVirtualList

  • 虚拟滚动
<template>
  <div style="height: 400px; overflow: auto" v-bind="containerBinds">
    <div v-bind="wrapperBinds">
      <div
        v-for="(item, index) in showList"
        :key="index"
        v-bind="item.binds"
      >
        {{ item.value }}
      </div>
    </div>
  </div>
</template>
  setup() {
    let originList = ref([] as number[]);
    const {
      containerEl,
      containerBinds,
      wrapperBinds,
      showList,
      reBuild,
    } = useVirtualList(originList, (i) => 20 + i);

    onMounted(() => {
      originList.value = Array(1000)
        .fill(0)
        .map((_, i) => i);
    });

    return {
      containerEl,
      showList,
      containerBinds,
      wrapperBinds,
      reBuild,
    };
  },
  • useVirtualList<T = any>参数
    • originList: 可以是一个纯数组T[],也可以是一个响应式数组Ref<T[]>,如果数组是响应式的,只会响应浅层修改,如果手动修改了originList中的某个具体项,请手动调用reBuild
    • itemHeight: number | ((index: number, item: T) => number)
      • 列表每一项的高度,因为虚拟滚动的要求,数组每一项的高度必须是可以确定的,不能由内部元素动态决定
    • options:{} 可选, 配置项
      • elName:string,默认"默认containerEl" 绑定ref的key名,考虑到一个页面上可能会有多个虚拟列表,所以需要自定义elName,这里填写的任何值,都需要从在useVirtualList的返回值中接受,并在setup函数中返回,他会体现在containerBinds
      • offset: 上下各额外显示多少个元素,默认5 ,不可小于1;
      • cellOverflow:string 子元素的overflow属性,默认auto