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

@pakwoon/common-utils

v2.0.3

Published

通用工具包

Downloads

19

Readme

@pakwoon/common-utils

通用工具包

日期

compareTime

比较时间大小

参数

  • time (string | number | Date) - 待比较时间
  • target ? (string | number | Date) - 目标时间(默认当前时间)

返回

(number) - 0: 相等,1: 大于,-1: 小于

getBetweenDate

获取两日期间日期列表

参数

  • dateStr (string) - 指定日期
  • targetDateStr ? (string) - 目标日期(默认当天)

返回

(string[]) - 两日期间日期字符串列表

getDateFormat

获取指定日期格式化后的字符串值

参数

  • params (Params)
    • date ? (Date) - 日期(默认今天)
    • formatIndex ? (number) - 格式化模式(默认:0)
      • 0: YYYY-MM-DD
      • 1: YYYY-MM-DD HH:mm:ss
      • 2: YYYY/MM/DD
      • 3: YYYY/MM/DD HH:mm:ss
      • 4: HH:mm:ss
      • 5: YYYY 年 MM 月 DD 日
      • 6: YYYY 年 MM 月 DD 日 HH 时 mm 分 ss 秒
      • 7: YYYY 年 MM 月 DD 日 HH 时 mm 分 ss 秒
    • fillZero(boolean) 是否补零(默认:是)

返回

(string) - 指定日期格式化后的字符串值

判断

isNull

判断是否为 null

入参

  • val (any) - 任何值

返回

(boolean) - 判断结果

isUndefined

判断是否为 undefined

入参

  • val (any) - 任何值

返回

(boolean) - 判断结果

对象

omitNullVal

去除对象中值为空元素的属性(空字符串,null,undefined)

入参

  • obj (Record<string, any>) - 待处理对象

返回

(Record<string, any>) - 不带空元素属性的对象

字符串

toUppercaseFirstLetter

字符串首字母转大写

入参

  • str (string) - 待转换字符串

返回

(string) - 转换后字符串

url

addQueryString

给指定 url 添加 queryString

入参

  • url (string) - 原 url
  • query (Record<string, any>) - 待组装 queryString 对象

返回

(string) - 组装后的完整 url

getQueryString

获取 queryString 对象或属性

入参

  • url ? (string) - url(默认当前 url)
  • param ? (string) - 参数 key

返回

(undefined | string | SARecord) - queryString 对象或属性 或 不存在

urlSearchParams

获取 queryString 对象或属性(用法与getQueryString一致)

类型

ClearRecord

根据范型传入情况去除对象属性类型为 never 的属性

使用

type RequestOption<Query = never, Data = never> = ClearRecord<{
  query: Query;
  data: Data;
  headers?: Record<string, string>;
}>;

业务

token

encryptedToken

加密 token

入参
  • str ? (string) - 待加密的字符串
  • encryptKey ? (string) - 密钥
返回

(string) - 加密后的 token

decryptedToken

解密 token

入参
  • encrypted ? (string) - 加密后的 token
  • encryptKey ? (string) - 密钥
返回

(string) - 加密前 token

getAccessToken

在 url 上获取 accessToken

返回

(string) - accessToken

setRefreshToken

存储 refreshToken 到 localStorage 中

入参
  • refreshToken ? (string) - refreshToken

getRefreshToken

在 localStorage 中获取 refreshToken

返回
  • refreshToken ? (string) - refreshToken

clearRefreshToken

清除 localStorage 中的 refreshToken

setToken

存储 token 到 localStorage 中

入参
  • token ? (string) - token

getToken

在 localStorage 中获取 token

返回
  • (string) - token

clearToken

清除 localStorage 中的 token

tokenConfig

统一设置 encryptKey,并返回完整 token 操作对象

isLogin

根据 token 判断是否已登录

返回
  • (boolean) 是否已登录

useIntl

umi 多语言 hook

createModel

umi dva 快速创建 model 方法

枚举

ENV

系统运行环境

  • DEV - 开发环境
  • TEST - 测试环境
  • PRE - 预发布环境
  • PROD - 开发环境