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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xilonglab/js-utils

v1.0.0

Published

JavaScript 工具函数库,包含数组、日期时间、文件、数字、存储等常用工具

Downloads

8

Readme

@xilonglab/js-utils

JavaScript 工具函数库,包含数组、日期时间、文件、数字、存储等常用工具函数。

安装

npm install @xilonglab/js-utils

依赖

  • lodash: ^4.17.21
  • moment: ^2.29.4

使用方式

ES6 模块导入

// 导入整个包
import jsUtils from '@xilonglab/js-utils';

// 使用各个模块
jsUtils.datetime.getToday();
jsUtils.array.forward(arr, index);
jsUtils.number.toFixed(num, 2);
jsUtils.storage.set('key', data);
jsUtils.file.downloadBlob(blob, 'filename.pdf');

// 或者按需导入特定模块
import { datetime, array, number, storage, file } from '@xilonglab/js-utils';

datetime.getToday();
array.forward(arr, index);
number.toFixed(num, 2);
storage.set('key', data);
file.downloadBlob(blob, 'filename.pdf');

模块说明

array.js - 数组操作工具

提供数组元素移动相关的工具函数:

  • forward(arr, i): 将数组元素向前移动一位
  • backward(arr, i): 将数组元素向后移动一位
  • move(arr, oldIndex, newIndex): 将数组元素从旧索引移动到新索引

datetime.js - 日期时间处理工具

基于 moment.js 的日期时间处理工具:

  • formatDate(date): 格式化日期
  • formatDatetime(date): 格式化日期时间
  • getToday(): 获取今天的日期
  • getNow(): 获取当前时间
  • getNextWeek(): 获取下周的日期
  • getHalfYearLater(): 获取半年后的日期
  • getOneQuarterLater(): 获取一个季度后的日期
  • getTwoQuarterLater(): 获取两个季度后的日期
  • getThreeQuarterLater(): 获取三个季度后的日期
  • getOneMonthLater()getElevenMonthLater(): 获取 N 个月后的日期
  • getMonthLater(n): 获取 N 个月后的日期
  • getWeekLater(n): 获取 N 周后的日期
  • nDaysLater(dateStr, n): 获取指定日期 N 天后的日期

file.js - 文件下载工具

提供文件下载相关的工具函数:

  • downloadBlob(obj, filename): 下载 Blob 对象为文件
  • makeBlobUrl(obj): 创建 Blob URL

number.js - 数字处理工具

提供数字处理相关的工具函数:

  • random(start, end): 生成指定范围内的随机数
  • mean(array): 计算数组的平均值
  • sum(array): 计算数组的和
  • toFixed(num, s): 四舍六入(奇进偶不进)保留指定小数位
  • truncate(num, s): 截取指定小数位
  • paddingZero(num, places): 数字补零

storage.js - localStorage 封装工具

提供简化的 localStorage 操作,自动处理 JSON 序列化/反序列化:

  • set(key, data): 设置存储值(自动处理对象序列化)
  • get(key): 获取存储值(自动处理对象反序列化)

示例

import { datetime, array, number, storage, file } from '@xilonglab/js-utils';

// 日期时间
const today = datetime.getToday();
const nextMonth = datetime.getOneMonthLater();

// 数组操作
const arr = [1, 2, 3, 4, 5];
array.forward(arr, 2); // [1, 3, 2, 4, 5]

// 数字处理
const rounded = number.toFixed(3.14159, 2); // "3.14"
const padded = number.paddingZero(5, 3); // "005"

// 存储
storage.set('user', { name: 'John', age: 30 });
const user = storage.get('user');

// 文件下载
const blob = new Blob(['content'], { type: 'text/plain' });
file.downloadBlob(blob, 'example.txt');

License

ISC