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

js-fn-utils

v1.0.9

Published

utils for js

Readme

获取格式化的日期

getDate(time)

输出格式形如:yyyy-mm-dd hh:mm:ss

getDate() // 2020-11-23 17:12:15
getDate('2020/01/01') // 2020-01-01 00:00:00

getFormatDate(time)

输出格式形如:yyyy-mm-dd

getFormatDate() // 2020-11-23
getFormatDate('2020/01/01') // 2020-01-01

getFormatTime(time)

输出格式形如: hh:mm:ss

getFormatTime() // 17:12:15
getFormatTime('2020/01/01') // 00:00:00

getDawnTime(time)

参数:默认值为当前时间

描述:获取指定日期的凌晨的时间

getDawnTime('2020/01/01') // Wed Jan 01 2020 00:00:00 GMT+0800 (中国标准时间)

getNightTime(time)

参数:默认值为当前时间

描述:获取指定日期的傍晚的时间

getNightTime('2020/01/01') // Wed Jan 01 2020 23:59:59 GMT+0800 (中国标准时间)

getBeginOfMonth(time)

参数:默认值为当前时间

描述:获取指定日期的月初时间

getBeginOfMonth('2020/11/10 10:00:00') // Sun Nov 01 2020 00:00:00 GMT+0800 (中国标准时间)

getEndOfMonth(time)

参数:默认值为当前时间

描述:获取指定日期的月末时间

getEndOfMonth('2020/11/10 10:00:00') // Mon Nov 30 2020 23:59:59 GMT+0800 (中国标准时间)

千分位分割符

thousandSeparatorFormat(value)

value: 合法的数值

// 案例
thousandSeparatorFormat(12345) // 12,345
thousandSeparatorFormat(12345.12345) // 12,345.12345
thousandSeparatorFormat(0.12345) // 0.12345

检测设备类型

checkDevice()

返回值:android | ios | 未知类型

检测浏览器内核

checkBrowser()

返回值:trident | presto | webkit | gecko

检测是移动设备还是pc端设备

checkIsMobile()

返回值:true | false

获取16进制随机色

getRandomColor()

返回值:16进制颜色名,形如:#00ff00

获取由大写的英文字母构成的数组,[A, B, ...]

getUpperCaseArr(len)

len: 默认值为26

// 例:
getUpperCaseArr() // ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

getUpperCaseArr(2) // ['A', 'B']

获取由小写的英文字母构成的数组,[a, b, ...]

getLowerCaseArr(len)

len: 默认值为26

// 例:
getLowerCaseArr() // ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

getLowerCaseArr(2) // ['a', 'b']

将字符串按照指定长度分割成数组

seperateStr(str, len)

str: 需要分割的字符串

len: 默认值为10

var str = 'this is a test 12345678';
seperateStr(str) // ['this is a ', 'test 12345', '678']
seperateStr(str, 12) // ['this is a te', 'st 12345678']

rgb转16进制

RGBToHex(rgb)

RGBToHex('rgb(0, 16, 255)') // #0010ff

16进制转rgb

HexToRGB(hex)

HexToRGB('#10ffff') // rgb(16, 255, 255)

设置文档标题

setTitle(val)

// 设置<title></title>之间的内容
setTitle('这里设置文档标题')