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 🙏

© 2025 – Pkg Stats / Ryan Hefner

uliian-ts-commons

v0.0.5

Published

uliian's ts dev tools

Readme

ULiiAn的TS开发工具方法

主要设计三个方面的内容:1、集合处理帮助类。2、ajax调用类。3、ReactHook。

ReactHook相关

提供了三个hook:

useModalDetails 弹窗展示hook

这个hook主要用于弹窗展示,用于Modal窗口的控制。使用方法:

const showDetailsProps = useModalDetails()
const {id, value, open, onCancel, openModal} = showDetailsProps

提供了这几个值以供弹窗使用。id和value根据openModal时进行传入,根据自己的需求使用即可,如果传入id,则在组件中根据id获取展示的值再进行展示,如果传入value则直接展示,根据需要自行处理。使用

//CustomComponent.tsx
const CustomComponent = (props:ShowModalProps<V>)=>{
    {/* 根据你传入的是value还是id自行获取数据填充 */ }
    <Modal open={open} onCancel={onCancel}>
     {/* children */ }
    </Modal>
}


<Button onClick={()=>openModal({id:xxxx})}/>

<CustomComponent {...showDetailsProps}/>

useModalEdit 弹窗展示hook

这个hook主要用于编辑类的弹窗管理用法和useModalDetails类似,主要区别在于多了opType用于明确是编辑操作还是新增操作,以及增加了action参数操作用以执行提交数据后的后续操作(如刷新)。 使用方法:

const showEditProps = useModalEdit<V>()

const CustomComponent = (props:ShowModalEditProps<V>)=>{
    const {id,value, opType, open, onCancel, onSubmit} = props
    {/* 根据你传入的是value还是id自行获取数据填充 */ }
    <Modal open={open} onCancel={onCancel}>
        <Form onFinish={(v)=>{/* TODO */ onSubmit()}}>
            {/* children */ }
        </Form>
    </Modal>
}

<Button onClick={()=>openModal(OpType.Edit,{id:xxxx},()=>{ref.current?.reload?.()})}>编辑(传入ID)</Button>
<Button onClick={()=>openModal(OpType.Edit,{value:obj},()=>{ref.current?.reload?.()})}>编辑(传入Value)</Button>


<Button onClick={()=>openModal(OpType.Create,undefined,()=>{ref.current?.reload?.()})}>新增</Button>



<CustomComponent {...showDetailsProps}/>

为什么要在openModal处传入finishAction而不是在调用hook时就传入?一个很典型的应用场景是AntdPro中,ProTable组件的列定义中,render参数中自带了actionRef参数,而不需要自己去uesRef再定义,并且这样的操作自然也更加灵活。

关于弹窗hook的使用技巧

1、如果出现需要向组件中加入更多参数的场景,我们做一个简单的类型体操就好:

const CustomComponent = (props:ShowModalEditProps<V> & {name?:string,info?:string,pid?:number})=>{
        const {value, opType, open, onCancel, onSubmit,name,info,pid} = props
}

useOffsetPage 偏移量分页处理hook

在处理偏移量分页方案时(瀑布流场景),其实处理起来很讨厌,关键在于

1、需要记录最后一次偏移量 2、获取新的值后要与原列表合并而不像普通分页那样直接丢弃原列表 3、变更查询参数后,要置空现有列表

这几个问题处理起来挺讨厌,比普通分页麻烦的多。通过这个hook,能很好的解决这几个问题,使用起来非常简单:

const {
    offset,
    records,
    hasMore,
    loading,
    getMore,
    reload} = useOffsetPage((offestPageCondition)=>request(offsetPageCondition),queryParams,{})

queryParams为查询的其他查询参数,最终会和offsetPageCondition一起作为查询字符串进行处理,同时,该值产生变化将触发列表、分页条件重置。options中,有ready方法,如果存在该方法,则需要在该方法执行结果为true后才会发起请求,pageSize也可以在options中进行配置。另外在options中,有dependencys属性,该属性用于条件刷新。

网络请求相关

AxiosRequestSpringClient封装了基于Axios的HttpClient实现,该实现为了匹配typescript-generator项目的基础操作。 使用方法:找个地方

import { message } from 'antd';
import { AxiosRequestSpringClient } from 'uliian-ts-commons';
import { history } from 'umi';

export const axiosHttpClient = new AxiosRequestSpringClient(
  API_URL, //这里是后端API的base_url
  () => ['x-token', localStorage.getItem('syl-token')], //这里是设置token所在httpheader 中 key和token value的地方
  undefined,  //这里是请求拦截器
  undefined,  //这里是响应拦截器
  (error) => {  //这里是设置错误处理的地方
    message.error(
      `${error.message}-${error.response?.data?.code ?? '0'}-${error.response?.data?.msg ?? ''}`,
    );
    if (error.response.status === 401) {
      if (history.location.pathname !== '/user/login') {
        history.replace('/user/login');
      }
    }
  },
);

集合帮助方法

CollectionHerlper中封装了多叉树的处理: 包括多叉树的查找、映射、过滤操作