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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@btea/utils

v0.0.24

Published

common tool functions

Downloads

29

Readme

说明

common tool functions

安装使用

npm 安装:

npm i @btea/utils

使用

import { isLeapYear } from '@btea/utils';
console.log(isLeapYear(2020)); // true
console.log(isLeapYear(2021)); // false

使用 jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/@btea/utils/out.cjs.js"></script>
<script type="text/javascript">
    const formatDate = zys.formatDate;
</script>

使用 unpkg CDN:

<script src="https://www.unpkg.com/@btea/utils/out.cjs.js"></script>
<script type="text/javascript">
    const formatDate = zys.formatDate;
</script>

API

isLeapYear(year: numer | string)

判断某一年是否为闰年

getMonthTotal(year: number | string, month: number | string)

获取指定月份的总天数

formatDate(date: Date, format: string)

格式化时间

// 栗子
formatDate(new Date(2022, 1, 1, 10, 10, 10), 'yyyy年MM月dd日 hh时mm分ss秒'); // 2022年01月01日 10时10分10秒

getTimeNum(time: unknown, type: 'day' | 'week')

获取指定时间是当年的第几天(周)

getTimeNum(new Date(2022, 1, 1), 'day'); // 2022年2月第32天
getTimeNum(new Date(2022, 1, 1), 'week'); //  2022年2月第6周

randomColor()

随机生成一个 6 位 16 进制的有效颜色

isEven(n: number)

判断一个数是否为偶数

isOdd(n: number)

判断一个数是否为奇数

randomNum(max: number, min: number, isInteger: boolen)

根据区间生成一个随机数, 根据第三个参数 isInteger 判断是否取整

isString(v: unknown)

判断是否为字符串

isNumber(v: unknown)

判断是否为数字

isArray(v: unknown)

判断是否为数组

isObject(v: unknown)

判断是否为对象

isTruly(v: unknown)

判断是否为真值

getType(v: unknown)

获取参数的数据类型

getType({}) // 'object'
getType([]) // 'array'
...

deepClone(v: unknown)

克隆

padString(s: number | string, len: number, char: string, pos: 'start' | 'end')

将目标数字或字符串用特定字符填充到指定的长度

browser vs module vs main