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

daily-h5-utils

v0.0.32

Published

h5日常utils方法合集

Downloads

5

Readme

daily-h5-utils

用于日常使用的工具库

本工具库提供了以下功能:

快速开始

安装

npm i --save daily-h5-utils

使用

import {
    leadDebounce,
    numberFormat,
    randomRange,
    getBeijingTime,
    sleep,
    animationSleep
} from 'daily-h5-utils';

函数列表

leadDebounce

前置放抖函数

import {
    leadDebounce,
} from 'daily-h5-utils';

const handleClick = () => {
  console.log('我点击了')
}

leadDebounce(() => {
  handleClick();
}, 1000);

参数

| 字段名 | 类型 | 默认值 | 含义 | | -------------- | ---------- | ---------- | -------------- | | leadDebounceCb | () => void | () => void | 防抖执行的回调 | | delay | number | 400 | 防抖时长 |

返回

numberFormat

分别以万 / 亿 格式化数字

import {
    numberFormat,
} from 'daily-h5-utils';

numberFormat(10000000)

参数

| 字段名 | 类型 | 默认值 | 含义 | | ------ | ------ | ------ | ------------ | | number | number | | 格式化前数字 |

返回

| 字段名 | 类型 | 默认值 | 含义 | | ------ | ---------------- | ------ | ------------ | | number | number | string | 0 | 格式化后数字 |

randomRange

在2个区间内随机获取一个整数返回

import {
    randomRange,
} from 'daily-h5-utils';

console.log(randomRange(10, 15)) //12

参数

| 字段名 | 类型 | 默认值 | 含义 | | ------ | ------ | ------ | ------ | | min | number | | 最小值 | | max | number | | 最大值 |

getBeijingTime

通过传入系统时间,可以获取格式化后对应的年月日时分秒

import {
    getBeijingTime,
} from 'daily-h5-utils';

const formatStr = getBeijingTimeInNumber(new Date());
console.log(formatStr);
/*
{
    "year": 2023,
    "month": 5,
    "date": 3,
    "hour": 17,
    "minute": 59,
    "second": 55
}
*/

参数

| 字段名 | 类型 | 默认值 | 含义 | | ------ | ------ | -------------------- | ------ | | time | number | 当前北京时间的时间戳 | 时间戳 |

返回

| 字段名 | 类型 | 默认值 | 含义 | | --------- | ------ | ------ | ---------------------- | | formatStr | object | | 包含年月日时分秒的对象 |

sleep

延时函数

import {
    sleep,
} from 'daily-h5-utils';

sleep(1000).then(() => {
	console.log('延时执行');
});

参数

| 字段名 | 类型 | 默认值 | 含义 | | ------- | ---------- | ---------- | ---------- | | sleepCb | () => void | () => void | 延时的回调 | | delay | number | 1000 | 延时时长 |

返回

animationSleep

基于requestAnimationFrame的延时函数

对比起 setIntervalsetTimeout的优势

  • requestAnimationFrame 会把每一帧中的所有DOM操作集中起来,在一次重绘或回流中就完成,并且重绘或回流的时间间隔紧紧跟随浏览器的刷新频率,一般来说,这个频率为每秒60帧。
  • 在隐藏或不可见的元素中,requestAnimationFrame将不会进行重绘或回流,这当然就意味着更少的的cpu,gpu和内存使用量。
import {
    animationSleep,
} from 'daily-h5-utils';

animationSleep(1000).then(() => {
	console.log('延时执行');
});

参数

| 字段名 | 类型 | 默认值 | 含义 | | ---------------- | ---------- | ---------- | ---------- | | animationSleepCb | () => void | () => void | 延时的回调 | | delay | number | 1000 | 延时时长 |

返回