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

@uiw-admin/utils

v6.1.9

Published

> TODO: description

Downloads

233

Readme

Utils工具

npm version

request

系统的请求基于axios进行了二次封装,参见axios

方法

基于restful规范,提供了2个方法:

  • get 获取服务端数据,参数拼接在url上,以 query string 方式发送给后端
  • post 新增数据,参数以body形式发送给后端

参数

| 参数 | 说明 | 类型 | 默认值 | | :------ | :------- | :------------- | :----- | | url | 请求地址 | string | - | | options | 请求配置,即axios的配置, | Options | - |

Options

| 参数 | 说明 | 类型 | 默认值 | | :------ | :------- | :------------- | :----- | | body | 请求传递给后端的参数 | any | - | | requestType | 数据格式 | 'form' 或 'json' 或 'urlencoded' | - |

调用方式

✨配和swr调用

如果已全局配置过swr,可不用传入request

import React from 'react'
import useSWR from 'swr';
import { request } from "@uiw-admin/utils"

export default const Index = () => {
  const [ name ,setName ] = React.useState('')
  const { mutate } = useSWR(
    ['/api/selectById',{ method: 'POST', body: {id:1} }],
    request,
    {
      revalidateOnMount: false,
      revalidateOnFocus: false,
      onSuccess: (data) => {
        if (data && data.code === 200) {
          setName(data.data)
         }
      },
    }
  )

  React.useEffect(()=>mutate(false),[mutate])

  return <div>{name}</div>
}

在rematch中使用

在servers/index.js中

import { request } from "@uiw-admin/utils"

export const selectById  = (params:{id:string}) => request("/api/selectById",{ method:"POST",body: { ...params } })

在model/index.js中

import { RootModel } from '@kkt/pro'
import { createModel } from '@rematch/core'
import { selectById } from '../servers'

const index = createModel<RootModel>()({
  name: 'index',
  state: {
    name:''
  },
  reducers: {
    updateState: (state: any, payload: any) => ({
      ...state,
      ...payload,
    }),
  },
  effects: (dispatch) => ({
    async selectById(payload: {id:string}) {
      const dph = dispatch
      const data = await selectById(payload)
      if (data.code === 200) {
        dph.index.dispatch({
          type:"updateState",
          payload:{
            name:data.data || ''
          }
        })
      }
    },
  }),
})
export default index

在页面中调用

import React from 'react'
import { useDispatch,useSelector } from 'react-redux'
import { RootState,Dispatch } from '@kkt/pro'

export default const Index = () => {
  const dispatch = useDispatch<Dispatch>()
  const stores = useSelector((state: RootState) => state) || {}
  const { index:{ name } } = stores
  React.useEffect(()=>{
     dispatch({
      type: 'index/selectById',
      payload:{id:1},
    })
  },[])
  return <div>{name}</div>
}

splitUrl

拼接url参数

import { splitUrl } from "@uiw-admin/utils"

const url = splitUrl('https://github.com/uiwjs/uiw-admin', { a: 1, b: 2 });

console.log(url); // https://github.com/uiwjs/uiw-admin?a=1&b=2

参数

| 参数 | 说明 | 类型 | 默认值 | | :------ | :------- | :------------- | :----- | | url | 请求地址 | string | - | | options | 请求配置,即axios的配置, | {[x: string]: any} | - |

❤️贡献者

感谢所有的贡献者,欢迎开发者为开源项目贡献力量。

License

Licensed under the MIT License.