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

js-util-fun

v0.0.6

Published

一些常用的js工具函数

Downloads

9

Readme

js-util-fun

常用的一些js工具函数,目前包含

  • 识别http链接

使用

1. 组件引入

  • 先进行下载 npm install --save js-util-fun
  • 组件调用
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|对应的版本号|