# wj-common-fn

> 常用函数

Latest version **1.1.2** (published 2021-05-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install wj-common-fn
pnpm add wj-common-fn
yarn add wj-common-fn
bun add wj-common-fn
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2021-05-10 |
| First published | 2020-04-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wjjack |
| Maintainers | wjjack |
| Keywords | common, function, typescript, wj |

## Links

- npm: https://www.npmjs.com/package/wj-common-fn
- npm.io page: https://npm.io/package/wj-common-fn

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2021-05-10
- 1.1.1 — 2021-01-05
- 1.0.9 — 2020-11-07
- 1.1.0 — 2020-10-23
- 1.0.8 — 2020-10-12
- 1.0.7 — 2020-10-12
- 1.0.6 — 2020-10-09
- 1.0.5 — 2020-09-30
- 1.0.4 — 2020-09-30
- 1.0.3 — 2020-04-15
- 1.0.2 — 2020-04-15
- 1.0.0 — 2020-04-15

## README

### 常用函数
deepCopy， isEmpty， throttle， debounce， getBase64等等

### 安装
`npm i wj-common-fn -S`

### 使用
```javascript
import { deepCopy, isEmpty, throttle, debounce, getBase64 } from 'wj-common-fn';
let a = [1];
let b = deepCopy(a);
```

### 函数列表

| 函数名称 | 说明 | 返回 |
| ------- | ---- | ---- |
| deepCopy | 深度克隆 deepCopy(o: any) | any |
| isEmpty | 是否为空 isEmpty(val: any) | boolean |
| throttle | 节流 throttle(fn: Function, wait: number) | () => void |
| debounce | 防抖 debounce(fn: Function, wait: number) | () => void |
| getBase64 | 将文件转换成base64 getBase64(file) | Promise<unknown> |
| setCookie | 设置cookie setCookie(name: string,value: string,config: CookieOptions = { type: "天", expires: 1 }) | void |
| getCookie | 获取cookie getCookie(key: string) | string or false |
| delCookie | 删除cookie delCookie(key: string) | void |
| randomNumber | 返回一个在范围内的随机数 randomNumber(n1: number, n2: number) | number |
| changeCase | 字母大小写切换, changeCase(str: string, type: number), type 数字 1:首字母大写、2：首母小写、3：大小写转换、4：全部大写、5：全部小写 | string |
| arraySort | 数组排序，arraySort(arr: number[], desc: ArrayDesc = "asc")，desc 排序方式 'asc'升序，'desc'降序 | number[] |
| arrayObjSort | 对象数组快速排序，arrayObjSort(arr: any[], key: string, desc: ArrayDesc = "asc")，key 排序依据关键字，desc 排序方式 'asc'升序，'desc'降序 | any |
| arrayUnique | 数组去重，arrayUnique(arr: any[]) | any[] |
| arrayIntersection | 数组的交集，arrayIntersection(arr1: any[], arr2: any[]) | any[] |
| arrayMinus | 数组的差集 arr1-arr2，arrayMinus(arr1: any[], arr2: any[]) | any[] |
| arrayUnion | 数组的并集，参数可以使多个，arrayUnion(...args) | any[] |
| isClass | 是否是类，isClass(obj: any, strict: boolean = true) |  boolean |
| getBase64ByUrl | 实现将项目的图片路径转化成base64，getBase64ByUrl(img: string) | Promise<unknown> |
| getBase64Image |将DOM元素img转换为base4的主要方法，getBase64Image(img: HTMLImageElement,width?: number,height?:number) | string |
| convertBase64ToBlob | base64转Blob，convertBase64ToBlob(base64: string) | Blob |
| toFileByUrl | 将图片路径转换成file文件类型，toFileByUrl(url: string, name?: string) | Promise<unknown> |
| isJson | 判断是否是json数据，isJson(obj) | boolean |
| hideElements | 隐藏制定的所有元素，hideElements(...el: HTMLElementTagNameMap[keyof HTMLElementTagNameMap][]) | void |
| hasClassName | 元素是否具有指定的类，hasClassName(el:  HTMLElementTagNameMap[keyof HTMLElementTagNameMap], className: string) | boolean |
| getScrollPosition | 获取当前页面的滚动位置，getScrollPosition(el: any | Window = window) | { x: any, y: any } |
| scrollToTop | 滚动到顶部，scrollToTop() | void |
| elementContains | 父元素是否包含子元素，elementContains(parent:  HTMLElementTagNameMap[keyof HTMLElementTagNameMap], child:  HTMLElementTagNameMap[keyof HTMLElementTagNameMap]) | boolean |
| elementIsVisibleInViewport | 指定元素是否在视口可见，elementIsVisibleInViewport(el: HTMLElementTagNameMap[keyof HTMLElementTagNameMap], partiallyVisible = false) | boolean |
| detectDeviceType | 分辨设备是移动设备还是桌面设备，detectDeviceType() | "Mobile" or "Desktop" |
| getURLParameters | 获取当前 URL参数的对象，getURLParameters(url: string) | {} |
| getDaysDiffBetweenDates| 获取两个日期之间的天数间隔，getDaysDiffBetweenDates(dateInitial: number, dateFinal: number) | number |
| counter | 为指定选择器创建具有指定范围、步长和持续时间的计时器，counter(selector: string, start: number, end: number, step = 1, duration = 2000) | NodeJS.Timeout |
| copyToClipboard | 将一个字符串复制到剪贴板，copyToClipboard(str: string) | void |


### github源代码
<https://github.com/WJjack/wj-common-fn.git>

---
_Source: https://npm.io/package/wj-common-fn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
