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

@echo_945/cw-tools

v0.0.6

Published

自己的常用工具库

Downloads

6

Readme

@echo_945/cw-tools

1. 说明

这是一个自己的工具库,用于存放自己常用的工具函数,方便以后使用。 使用 TypeScript 编写,支持按需引入。参数和返回值都有类型提示。

2. 安装

1. 使用 npm 安装

npm install @echo_945/cw-tools

2. 使用 cdn 安装


<script src="https://cdn.jsdelivr.net/npm/@echo_945/cw-tools/dist/index.umd.js"></script>

3. 使用

**1.按需导入

import { debounce } from '@echo_945/cw-tools'
const fn = debounce(() => {
  console.log('debounce')
}, 1000)
fn()

**2.全部导入

import * as tools from '@echo_945/cw-tools'
const fn = tools.debounce(() => {
  console.log('debounce')
}, 1000)
fn()

**3.在浏览器中使用

<script src="https://cdn.jsdelivr.net/npm/@echo_945/cw-tools/dist/index.umd.js"></script>
<script>
  const fn = cw.debounce(() => {
    console.log('debounce')
  }, 1000)
  fn()
</script>

4. 所有工具函数

接口说明

type ObjectStringType =
  'array'
  | 'object'
  | 'function'
  | 'null'
  | 'undefined'
  | 'string'
  | 'number'
  | 'boolean'
  | 'symbol'
  | 'bigint'

interface FilePickerOptions {
  accept?: string;
  multiple?: boolean;
}

函数说明

| 函数名 | 参数 | 返回值 | 备注 | |----------------------|------------------------------------------------|-----------------------------------------------------|------------------------------------| | isNodeEnv | 无参数 | boolean | 判断是否在 Node.js 环境 | | isWindowEnv | 无参数 | boolean | 判断是否在浏览器环境 | | debounce | fn: Function, delay: number | Function | 返回一个防抖函数 | | throttle | fn: Function, delay: number | Function | 返回一个节流函数 | | getObjType | obj: any | ObjectStringType | 获取对象的数据类型 | | deepClone | obj: any | any | 返回一个对象的深拷贝 | | randomN2M | n: number, m: number | number | 生成指定范围的随机数 | | randomN2MInt | n: number, m: number | number | 生成指定范围的随机整数 | | randomStr | len: number | string | 生成指定长度的随机字符串 | | getQueryParams | urlString: string | Record<string, any> | 获取 URL 参数对象 | | getQueryParam | urlString: string, key: string | string | 获取 URL 参数中指定键的值 | | removeHtmlTag | str: string | string | 移除字符串中的 HTML 标签 | | range | start: number, end: number, step: number | Array<number> | 生成指定范围的数组 | | isPhone | phone: string | boolean | 判断是否是手机号码 | | isEmail | email: string | boolean | 判断是否是邮箱地址 | | isIdCard | idCard: string | boolean | 判断是否是身份证号码 | | isIos | userAgent: string | boolean | 判断是否是 iOS 设备 | | isAndroid | userAgent: string | boolean | 判断是否是 Android 设备 | | isWechat | userAgent: string | boolean | 判断是否是微信浏览器 | | isWechatMobile | userAgent: string | boolean | 判断是否是微信移动端浏览器 | | isWechatPC | userAgent: string | boolean | 判断是否是微信PC端浏览器 | | isAlipay | userAgent: string | boolean | 判断是否是支付宝浏览器 | | filePicker | options: FilePickerOptions | Promise<FileList> | 唤起文件选择器 | | imageSelector | 无参数 | Promise<{ file: File, blob: Blob, base64: string }> | 唤起图片选择器 | | imageCompress | file: File, quality: number | Promise<{ blob: Blob, base64: string, file: File }> | 图片压缩函数 | | downloadFile | url: string, fileName: string | void | 下载文件 | | createTempFilePath | blob: Blob \| File | string | 生成临时文件路径 | | isNull | obj: any | boolean | 判断对象是否为 null | | setLocalStorage | key: string, value: any | void | 设置 localStorage | | getLocalStorage | key: string | any | 获取 localStorage | | removeLocalStorage | key: string | void | 删除 localStorage | | clearLocalStorage | 无参数 | void | 清空 localStorage | | setSessionStorage | key: string, value: any | void | 设置 sessionStorage | | getSessionStorage | key: string | any | 获取 sessionStorage | | removeSessionStorage | key: string | void | 删除 sessionStorage | | clearSessionStorage | 无参数 | void | 清空 sessionStorage | | toUrlEncoded | data: Record<string, any> | string | 将对象转换为 x-www-form-urlencoded 格式字符串 | | fromUrlEncoded | str: string | Record<string, any> | 将 x-www-form-urlencoded 格式字符串解析为对象 | | toFormData | data: Record<string, any> | FormData | 将对象转换为 FormData 对象 | | fromFormData | formData: FormData | Record<string, any> | 将 FormData 对象解析为对象 |