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

@qubit-ltd/common-filter

v1.11.1

Published

A JavaScript ES7 library of common filters

Readme

@qubit-ltd/common-filter

npm包 许可证 English Document CircleCI 测试覆盖率

@qubit-ltd/common-filter 是一个JavaScript ES6库,提供各种常用的过滤和格式化功能,用于处理日期、时间、时长、货币值等多种数据类型。

目录

安装

# 使用 npm
npm install @qubit-ltd/common-filter

# 使用 yarn
yarn add @qubit-ltd/common-filter

功能特点

  • 支持多种模式的日期和时间格式化
  • 支持不同时区间的转换
  • 支持多种样式的时长格式化(包括中文格式)
  • 货币值格式化
  • 是/否,有/无等布尔值过滤
  • 敏感数据隐私保护遮罩
  • 数组到字符串的转换
  • 百分比格式化
  • 以及更多...

使用方法

import { formatDate, formatMoney, formatChineseDuration } from '@qubit-ltd/common-filter';

// 格式化日期
const date = new Date();
console.log(formatDate(date)); // 例如: "2023-05-25"

// 格式化货币
console.log(formatMoney(1234.56)); // 例如: "1,234.56"

// 以中文格式化时长
console.log(formatChineseDuration(3661)); // 例如: "1小时1分1秒"

API概览

本库提供以下主要类别的过滤器:

日期和时间格式化

  • formatDate: 格式化日期
  • formatDatetime: 格式化带时间的日期
  • formatDatetimeWithPattern: 使用自定义模式格式化日期
  • formatChineseDate: 以中文风格格式化日期
  • formatChineseDatetime: 以中文风格格式化带时间的日期
  • formatChineseLocalDatetime: 以中文本地格式格式化带时间的日期

时区处理

  • formatAtTimezone: 在特定时区格式化日期
  • formatToTimezone: 转换并格式化日期到特定时区

时长格式化

  • formatDuration: 格式化以秒为单位的时长
  • formatChineseDuration: 以中文风格格式化时长
  • formatDurationBetween: 格式化两个日期之间的时长
  • formatChineseDurationBetween: 以中文风格格式化两个日期之间的时长

值格式化

  • formatMoney: 格式化货币值
  • formatPercent: 格式化百分比值
  • formatYesNo: 将布尔值格式化为"是/否"
  • formatYesNoUnknown: 将值格式化为"是/否/未知"
  • formatHasHasnot: 将布尔值格式化为"有/无"

文本处理

  • formatPrivacyMask: 遮罩敏感文本数据
  • formatRemoveMidSpace: 移除文本中间的空格
  • formatArrayToString: 将数组转换为字符串表示

完整的API文档,请参考doc目录中生成的JSDoc文档。

贡献

如果您发现任何问题或有改进建议,欢迎在GitHub仓库提出issue或提交pull request。

许可证

@qubit-ltd/common-filter基于Apache 2.0许可证发布。 详情请参阅LICENSE文件。