# @baiwusanyu/utils-com

> ## Function

Latest version **1.1.2** (published 2024-12-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @baiwusanyu/utils-com
pnpm add @baiwusanyu/utils-com
yarn add @baiwusanyu/utils-com
bun add @baiwusanyu/utils-com
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2024-12-12 |
| First published | 2023-05-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 20 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | baiwusanyu-c |
| Maintainers | baiwusanyu |
| Keywords | typescript, javascript, utils, vue, vue3, vite, react |

## Links

- npm: https://www.npmjs.com/package/@baiwusanyu/utils-com
- Repository: https://github.com/baiwusanyu-c/bwsy-utils
- Homepage: https://github.com/baiwusanyu-c
- Issues: https://github.com/baiwusanyu-c/bwsy-utils/issues
- npm.io page: https://npm.io/package/@baiwusanyu/utils-com

## Dependencies (1)

- [hash-sum](https://npm.io/package/hash-sum.md) ^2.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2024-12-12
- 1.1.1 — 2024-12-12
- 1.1.0 — 2024-12-12
- 1.0.18 — 2023-12-28
- 1.0.17 — 2023-12-28
- 1.0.16 — 2023-09-02
- 1.0.15 — 2023-08-15
- 1.0.14 — 2023-07-08
- 1.0.13 — 2023-05-25
- 1.0.12 — 2023-05-10
- 1.0.11 — 2023-05-08
- 1.0.10 — 2023-05-08
- 1.0.9 — 2023-05-07

## README

# @baiwusanyu/utils-com

## Function

### downloadFile

根据下载链接下载文件

| 参数     | 参数类型                            | 默认值     | 说明       |
|--------|---------------------------------|---------|----------|
| url    | `string`                        | `-`     | 下载链接     |

### createHash

基于 `hash-sum` 生成一个随机哈希

| 参数  | 参数类型              | 默认值                                 | 说明             |
|-----|-------------------|-------------------------------------|----------------|
| id  | `string \ number` | `(new Date()).getTime().toString()` | 生成`hash` 的 `id` |
| prefix | `string`          | `''`                             | 自定义前缀          |
| suffix | `string`          | `''`                             | 自定义后缀          |

| 返回值 | 返回类型     | 说明      |
|-----|----------|---------|
| res | `string` | 生成的哈希结果 |

### debounce

防抖函数返回一个新的函数，这个新函数会在 wait 时间内被连续调用时，  
会取消上一次调用并重新开始等待 wait 时间。

| 参数     | 参数类型                                  | 默认值  | 说明                                 |
|--------|---------------------------------------|------|------------------------------------|
| func   | `T extends (...args: any[]) => any`   | `-`  | 需要进行防抖的函数                          |
| wait   | `number`                              | `''` | 等待时间（毫秒），即在该时间内没有新的调用时才会真正地执行 `func` |

| 返回值        | 返回类型                                | 说明        |
|------------|-------------------------------------|-----------|
| debounceFn | `(...args: Parameters<T>) => void`  | 防抖函数   |

### throttle

节流函数返回一个新的函数，这个新函数会在 wait 时间内被连续调用时，  
只会执行第一次调用，并在 wait 时间后才能再次执行。

| 参数     | 参数类型                                  | 默认值  | 说明                                 |
|--------|---------------------------------------|------|------------------------------------|
| func   | `T extends (...args: any[]) => any`   | `-`  | 需要进行节流的函数                          |
| wait   | `number`                              | `''` | 等待时间（毫秒），即在该时间内只能执行一次 `func`|

| 返回值        | 返回类型                                | 说明        |
|------------|-------------------------------------|-----------|
| throttleFn | `(...args: Parameters<T>) => void`  | 节流函数   |

### copyText

将字符串复制到粘贴板

| 参数     | 参数类型                 | 默认值     | 说明   |
|--------|----------------------|---------|------|
| content    | `string`             | `-`     | 复制内容 |
| resolve    | `() => void`         | `-`     | 调用成功回调 |
| err    | `(err: any) => void` | `-`     | 调用错误回调 |

### sessionCache

基于 sessionStorage 的缓存函数

#### sessionCache.set

存储缓存

| 参数    | 参数类型                 | 默认值     | 说明  |
|-------|----------------------|---------|-----|
| key   | `string`             | `-`     | key |
| value | `string`             | `-`     | 值   |

#### sessionCache.get

获取缓存

| 参数     | 参数类型                 | 默认值     | 说明   |
|--------|----------------------|---------|------|
| key   | `string`             | `-`     | key |

| 返回值 | 返回类型     | 说明   |
|-----|----------|------|
| res | `string` | 缓存数据 |

#### sessionCache.setJSON

以对象格式存储缓存

| 参数     | 参数类型     | 默认值     | 说明   |
|-------|----------|---------|-----|
| key   | `string` | `-`     | key |
| value | `any`    | `-`     | 值   |

#### sessionCache.getJSON

以对象格式获取缓存

| 参数     | 参数类型                 | 默认值     | 说明   |
|--------|----------------------|---------|------|
| key   | `string`             | `-`     | key |

| 返回值 | 返回类型  | 说明   |
|-----|-------|------|
| res | `any` | 缓存数据 |

#### sessionCache.remove

移除缓存

| 参数     | 参数类型                 | 默认值     | 说明   |
|--------|----------------------|---------|------|
| key   | `string`             | `-`     | key |

### localCache

基于 localStorage 的缓存函数, 函数与 sessionCache 相同

---
_Source: https://npm.io/package/@baiwusanyu/utils-com · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
