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-normalizer

v1.8.5

Published

A JavaScript ES6 library for common fields normalizers

Downloads

16

Readme

@qubit-ltd/common-normalizer

npm package License English Document CircleCI Coverage Status

@qubit-ltd/common-normalizer 是一个JavaScript ES6库,提供了一系列用于规范化Web应用程序中常见字段的工具函数。它可以帮助标准化各种数据类型(如布尔值、日期、数字等)的格式,使数据处理更加一致和可靠。

安装

使用npm安装:

npm install @qubit-ltd/common-normalizer

或者使用yarn安装:

yarn add @qubit-ltd/common-normalizer

使用方法

此库提供了多种用于规范化不同类型数据的函数:

import {
  normalizeBool,         // 规范化布尔值
  normalizeInteger,      // 规范化整数
  normalizeDate,         // 规范化日期
  normalizeDateTime,     // 规范化日期时间
  normalizeTime,         // 规范化时间
  normalizeTimestamp,    // 规范化时间戳
  Normalizer,            // 包含所有函数的规范化器对象
} from '@qubit-ltd/common-normalizer';

// 规范化布尔值
const boolResult = normalizeBool('true');  // 返回 true
const boolResult2 = normalizeBool('false'); // 返回 false
// 无效输入将抛出错误
// normalizeBool('是') 将抛出 RangeError

// 规范化整数
const intResult = normalizeInteger('123'); // 返回 123
const intResult2 = normalizeInteger(''); // 返回 null

// 规范化日期
const dateResult = normalizeDate('2023-5-15'); // 返回 '2023-05-15'
const dateResult2 = normalizeDate('2023/5/15'); // 返回 '2023-05-15'

// 规范化日期时间
const dateTimeResult = normalizeDateTime('2023-5-15 14:30:25'); // 返回 '2023-05-15 14:30:25'

// 规范化时间
const timeResult = normalizeTime('14:30:25'); // 返回 '14:30:25'

// 规范化时间戳
const timestampResult = normalizeTimestamp('2023-5-15 14:30:25'); // 返回 Unix 时间戳

使用 Normalizer 对象

该库还提供了一个方便的 Normalizer 对象,包含所有规范化函数:

import { Normalizer } from '@qubit-ltd/common-normalizer';

// 规范化各种数据类型
const boolValue = Normalizer.bool('true');           // 返回 true
const intValue = Normalizer.int('123');              // 返回 123
const dateValue = Normalizer.date('2023-5-15');      // 返回 '2023-05-15'
const datetimeValue = Normalizer.datetime('2023-5-15 14:30:25'); // 返回 '2023-05-15 14:30:25'
const timeValue = Normalizer.time('14:30:25');       // 返回 '14:30:25'
const trimmedValue = Normalizer.trim('  你好  ');   // 返回 '你好'

// Normalizer 还包括其他工具函数
const trimUpperValue = Normalizer.trimUppercase('  test  '); // 返回 'TEST'
const numberValue = Normalizer.number('123.45');     // 返回 123.45
const moneyValue = Normalizer.money('1234.56');     // 格式化为货币

更多详细的使用示例,请参考API文档。

API文档

完整的API文档可以在项目文档页面中找到。

可用的规范化器

该库提供以下规范化函数:

  • normalizeBool: 将值规范化为布尔值(true/false)
  • normalizeInteger: 将值规范化为整数
  • normalizeDate: 将日期字符串规范化为格式 'YYYY-MM-DD'
  • normalizeDateTime: 将日期时间字符串规范化为格式 'YYYY-MM-DD HH:mm:ss'
  • normalizeTime: 将时间字符串规范化为格式 'HH:mm:ss'
  • normalizeTimestamp: 将日期时间字符串规范化为Unix时间戳

Normalizer 对象还包括以下额外的工具函数:

  • number: 将字符串转换为浮点数
  • money: 格式化货币值
  • trim: 去除字符串两端的空白
  • trimUppercase: 去除空白并转换为大写
  • mobile, phone, personName, email 和其他常见字段类型

贡献

如果您发现任何问题或有改进建议,请随时在GitHub仓库上提交issue或pull request。

许可证

@qubit-ltd/common-normalizer在Apache 2.0许可证下分发。 更多详情请参阅LICENSE文件。