# js-util-fun

> 一些常用的js工具函数

Latest version **0.0.7** (published 2025-01-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install js-util-fun
pnpm add js-util-fun
yarn add js-util-fun
bun add js-util-fun
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2025-01-22 |
| First published | 2023-04-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | zz |
| Maintainers | wutong88 |
| Keywords | tool, js, function, util |

## Links

- npm: https://www.npmjs.com/package/js-util-fun
- npm.io page: https://npm.io/package/js-util-fun

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.0.7 (latest) — 2025-01-22
- 0.0.6 — 2023-04-25
- 0.0.5 — 2023-04-25
- 0.0.4 — 2023-04-11
- 0.0.3 — 2023-04-11
- 0.0.2 — 2023-04-11
- 0.0.1 — 2023-04-11

## README

# js-util-fun

## 常用的一些js工具函数，目前包含
* 识别http链接

## 使用
#### 1. 组件引入
* 先进行下载 `npm install --save js-util-fun`
* 组件调用
```js
import getQueryString from "js-util-fun"
const value = getQueryString('id')
// 例如地址栏https://www.baidu.com?id=22则获取到value为22
```

## 对应方法和参数说明
### 1. `getQueryString`：获取链接中key为name的属性值

|参数|说明|类型|默认值|返回值|
| --- |----|---|---| --- |
|name|对应key值|string|null|name对应的属性值|

### 2. `eventBus`：事件总线
* `eventBus.$emit(key, params)`: 发送事件

|参数|说明|类型|默认值|
| --- |----|---|---|
|key|发布事件名称|string|null|
|params|发布事件携带的参数，非必传|不限|null|

* `eventBus.$on(key, hanlder)`: 接收事件

|参数|说明|类型|默认值|
| --- |----|---|---|
|key|订阅事件名称|string|null|
|hanlder|监听订阅事件之后的操作，可以接收发布者传的参数|函数|null|

* `eventBus.$off(key, hanlder)`: 销毁事件

|参数|说明|类型|默认值|
| --- |----|---|---|
|key|移除事件名称|string|null|
|hanlder|销毁事件事件之后的操作，非必传|function|null|

### 3. `asyncLoadScript(url, callback)`：异步加载对应的js

|参数|说明|类型|默认值|
| --- |----|---|---|
|url|需要异步加载的js地址|string|null|
|callback|需要异步加载之后的回调函数|function|()=>{}|

### 4. `regSearchResult(str, key, type, color)`：搜索高亮显示某一词语

|参数|说明|类型|默认值|返回值|
| --- |----|---|---| --- |
|str|需要搜索的文本|string|null|
|key|搜索的关键字|string|null|
|type|input-模拟输入框内容折行使用/text-纯文字|string|text|
|color|高亮颜色|string|#588CE9| 带有高亮关键字的html文本

### 5. `removeDuplicate (arr1, arr2, key)`：去掉arr2中与arr1 中重复的对象

|参数|说明|类型|默认值|返回值|
| --- |----|---|---|--- |
|arr1|数组1|Array|[]|
|arr2|数组2|Array|[]|
|key|去重的属性|string|id|去重后的数组

### 6. `eleFormat(ele, httpEnd)`：字转换成p标签文本，带有http的转换为a链接

|参数|说明|类型|默认值|返回值|
| --- |----|---|---| --- |
|ele|原始文本|string||
|httpEnd|地址链接后缀|Array|['com', 'cn', 'cc', 'top', 'net', 'shop', 'wiki', 'icu', 'ltd', 'vip', 'club', 'art', 'online','fun']| 带有p标签或者带有p中含有a的html

### 7. `replaceAllStr(str, symStr1, symStr2 = '')`：用一个符号替换字符串中的另一个符号

|参数|说明|类型|默认值|返回值|
| --- |----|---|---| --- |
|str|文本|string|[]|
|symStr1|需要替换的符号|string|null|
|symStr2|替换后的符号|string|' '|替换后的文本

### 8. `userAgentVersion(key)`：从userAgent获取包含某一字符串对应的版本号

|参数|说明|类型|默认值|返回值|
| --- |----|---|---| --- |
|key|需要获取版本号的属性|string|youzone|对应的版本号|

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