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

xtalpi-utils.js

v1.0.0

Published

utils.js

Downloads

6

Readme

utils.js 常用工具方法库

getGMTDateString

  • 获取格林威治时间
  • @returns {Date}

formatTime

  • 格式化时间
  • @param {String} date 日期字符串
  • @param {String} fmt 格式(yyyy-MM-dd hh:mm:ss)
  • @returns {fmt}

downloadFile

  • 下载文件
  • @param {String} url 文件路径
  • @param {String} message。下载失败提示
  • @param {String} name 可选。文件名称

downloadMultipleFile

  • 下载(多个)文件
  • @param {String | Array} url 文件路径
  • @param {String | Array} name 可选。文件名称

downloadFileZip

  • 下载 zip
  • @param {String} name zip的文件名
  • @param {Array} sourcelist 文件列表 [{ name, url }]

splitFileName

  • 切分文件全称,得到文件名和后缀
  • @param {String} filename 文件全称
  • @return {Object} { name, suffix }

getFileName

  • 获取文件名
  • @param {String} filename 文件全称
  • @return {String} name 文件后缀

getFileSuffix

  • 获取文件后缀
  • @param {String} filename 文件全称
  • @return {String} Suffix 文件后缀

readTextFile

  • 导入本地 JSON 文件
  • @param {File} file 文件
  • @param type 默认UTF-8 编码类型
  • @param {Function} callback 回调函数

checkS3FileExpire

  • 判断s3文件是否过期
  • @param {String} url 文件的 s3 路径
  • @return {Boolean} true/false

setCookie

  • 设置 cookie
  • @param {String} key 名称
  • @param {String} value 值
  • @param {sTring} exdays 时间(单位:天)

getCookie

  • 获取 Cookie
  • @param {String} key 名称
  • @return {String} value 值

deleteCookie

  • 删除 cookie(设置为过期)
  • @param {String} key 名称

setLocalStorage

  • 设置 localstorage
  • @param {String} key 名称
  • @param {String} value 值
  • @param {number} exdays 时间(单位:天)

getLocalStorage

  • 获取 LocalStorage
  • @param {String} key 名称
  • @return {String} value 值

removeLocalStorage

  • 删除 key localStorage
  • @param {String} key 需要删除的key名称

clearLocalStorage

  • 清空 key localStorage

isEmptyObj

  • 判断是否是空对象
  • @param {Object} obj 需要判断的值
  • @return {Boolean} true/false

isBool

  • 判断是否是boolean类型
  • @param {Boolean} v 需要判断的值
  • @return {Boolean} true/false

isInt

  • 判断是否是为整型
  • @param {number} v 需要判断的值
  • @return {Boolean} true/false

isNum

  • 判断是否是number类型
  • @param {Number} v 需要判断的值
  • @return {Boolean} true/false

isString

  • 判断是否是string类型
  • @param {String} v 需要判断的值
  • @return {Boolean} true/false

isArray

  • 判断是否是array类型
  • @param {Array} v 需要判断的值
  • @return {Boolean} true/false

isObject

  • 判断是否是object类型
  • @param {Object} v 需要判断的值
  • @return {Boolean} true/false