0.0.6 • Published 1 year ago

@echo_945/cw-tools v0.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

@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判断是否在浏览器环境
debouncefn: Function, delay: numberFunction返回一个防抖函数
throttlefn: Function, delay: numberFunction返回一个节流函数
getObjTypeobj: anyObjectStringType获取对象的数据类型
deepCloneobj: anyany返回一个对象的深拷贝
randomN2Mn: number, m: numbernumber生成指定范围的随机数
randomN2MIntn: number, m: numbernumber生成指定范围的随机整数
randomStrlen: numberstring生成指定长度的随机字符串
getQueryParamsurlString: stringRecord<string, any>获取 URL 参数对象
getQueryParamurlString: string, key: stringstring获取 URL 参数中指定键的值
removeHtmlTagstr: stringstring移除字符串中的 HTML 标签
rangestart: number, end: number, step: numberArray\<number>生成指定范围的数组
isPhonephone: stringboolean判断是否是手机号码
isEmailemail: stringboolean判断是否是邮箱地址
isIdCardidCard: stringboolean判断是否是身份证号码
isIosuserAgent: stringboolean判断是否是 iOS 设备
isAndroiduserAgent: stringboolean判断是否是 Android 设备
isWechatuserAgent: stringboolean判断是否是微信浏览器
isWechatMobileuserAgent: stringboolean判断是否是微信移动端浏览器
isWechatPCuserAgent: stringboolean判断是否是微信PC端浏览器
isAlipayuserAgent: stringboolean判断是否是支付宝浏览器
filePickeroptions: FilePickerOptionsPromise\<FileList>唤起文件选择器
imageSelector无参数Promise<{ file: File, blob: Blob, base64: string }>唤起图片选择器
imageCompressfile: File, quality: numberPromise<{ blob: Blob, base64: string, file: File }>图片压缩函数
downloadFileurl: string, fileName: stringvoid下载文件
createTempFilePathblob: Blob \| Filestring生成临时文件路径
isNullobj: anyboolean判断对象是否为 null
setLocalStoragekey: string, value: anyvoid设置 localStorage
getLocalStoragekey: stringany获取 localStorage
removeLocalStoragekey: stringvoid删除 localStorage
clearLocalStorage无参数void清空 localStorage
setSessionStoragekey: string, value: anyvoid设置 sessionStorage
getSessionStoragekey: stringany获取 sessionStorage
removeSessionStoragekey: stringvoid删除 sessionStorage
clearSessionStorage无参数void清空 sessionStorage
toUrlEncodeddata: Record<string, any>string将对象转换为 x-www-form-urlencoded 格式字符串
fromUrlEncodedstr: stringRecord<string, any>将 x-www-form-urlencoded 格式字符串解析为对象
toFormDatadata: Record<string, any>FormData将对象转换为 FormData 对象
fromFormDataformData: FormDataRecord<string, any>将 FormData 对象解析为对象
0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago