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

wil-utils

v1.0.5

Published

常用工具集合

Downloads

1

Readme

wil-utils

常用工具集合

Demo示例
前往Gitee

  1. query: 获取url参数值
  2. throttle: 截流函数
  3. debounce:延迟/弹簧函数
  4. cookie 操作
  5. webview webview 环境检测
  6. hash 查询/添加 location.hash
  7. scrollToDistance 缓动滚动到某段距离
  8. emoji2Unicode emoji表情字符转Unicode

安装

npm install wil-utils --save

API

query 模块

import { query } from 'wil-utils';
// http://192.168.31.74:8080/test.html?a=122
console.log('query a的值为:', query.get('a'));  // 122
console.log('query a=100:', query.add(location.href, 'a', 100)); // 返回http://192.168.31.74:8080/test.html?a=100

query.get(key)

返回location.href的query值

| 属性 | 类型 | 默认值 | 是否必填 | 说明 | | ------- | ------ | ------ | -------- | ---- | | key | String | 无 | 是 | |

query.add(url, key, value)

给指定的url字符串增加query值并返回

| 属性 | 类型 | 默认值 | 是否必填 | 说明 | | ------- | -------------- | ------ | -------- | ---- | | url | String | 无 | 是 | | | key | String | 无 | 是 | | | value | String|Number | 无 | 是 | |

throttle 模块

截流函数

import { throttle } from 'wil-utils';
throttle(function () {
  console.log('touch move');
}, 150);

Option

| 参数 | 类型 | 是否必填 | 描述 | | :---------- | :-------| :------- | ------------------------------------------------------------ | | fn | Function | 是 | 传入需要截流的函数 | | interval | Number | 是 | 间隔执行时间,单位是毫秒 | | immediately | Boolean | 否 | 是否需要立即执行一次 |

debounce 模块

防抖函数

import { debounce } from 'wil-utils';
debounce(function () {
  console.log('handle click');
}, 150);

Option

| param | 类型 | 描述 | | :---- | :------- | ------------------------- | | fn | Function | 实际要执行 debounce的函数 | | delay | Number | 延迟时间,单位是毫秒 |

cookie 模块

import { cookie } from 'wil-utils';
cookie.set('tel', '18600000001');
cookie.get('tel');

cookie.get(key)

| param | 类型 | 描述 | | :---- | :----- | ------------------------- | | Key | String | 获取的cookie键值 |

cookie.set(key, value, domain, second, path)

| param | 类型 | 描述 | 默认值 | | :------ | :----- | ------------------ | ---- | | Key | String | 设置的cookie key | 必填 | | value | String | 设置的cookie value | 必填 | | domain | String | 设置的cookie domain | 无 | | second | Number | 设置的cookie 的过期时间(秒) | 无 | | path | String | 设置的cookie path | 无 |

webview 模块

检测当前浏览器环境

import { webview } from 'wil-utils';
console.log(webview.isApple);

| 属性 | 说明 | | | ---------- | ------------------------ | ---- | | isWeibo | 是否是微博客户端内 | | | isQQ | 是否是QQ客户端内 | | | isDingtalk | 是否是钉钉客户端内 | | | isWeixin | 是否是微信客户端内 | | | isAndroid | 是否是安卓设备 | | | isApple | 是否是苹果设备 | | | isIphone | 是否是IPhone设备 | | | iphoneXSet | 是否是全面屏的iPhone设备 | | | isTablet | 是否是平板设备 | | | isIpad | 是否是iPad设备 | | | isAndroidTable | 是否是安卓平板设备 | |

hash 模块

import { hash } from 'wil-utils';
console.log(hash.get('tel'));

hash.get(key)

返回location.hash中某个key的值

| 属性 | 类型 | 默认值 | 是否必填 | 说明 | | ------- | ------ | ------ | -------- | ---- | | key | String | 无 | 是 | 要查询的字段名 |

hash.add(key, value)

location.hash添加某个格式为key=value的值

| 属性 | 类型 | 默认值 | 是否必填 | 说明 | | ------- | -------------- | ------ | -------- | ---- | | key | String | 无 | 是 | 字段名 | | value | String|Number | 无 | 是 | 字段值 |

scrollToDistance

scrollToDistance(container, distance, duration, cb);

| 参数 | 类型 | 默认值 | 是否必填 | 说明 | | --------- | -------- | ------ | -------- | -------------- | | container | dom | 无 | 是 | 滚动容器 | | distance | Number | 无 | 是 | 相对当前所处位置的滚动距离,负值表示向下滚动,正值表示向上滚动 | | duration | Number | 无 | 是 | 滚动时长,毫秒 | | cb | Function | 无 | 是 | 滚动结束回调 |

emoji2Unicode

emoji2Unicode(str);

| 参数 | 类型 | 默认值 | 是否必填 | 说明 | | --------- | -------- | ------ | -------- | -------------- | | str | string | 无 | 是 | 带emoji(😊)表情的字符串 |