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

@qubit-ltd/validation-rule

v1.8.2

Published

A JavaScript ES6 library for common validation rules

Readme

@qubit-ltd/validation-rule

npm package License English Document CircleCI Coverage Status

@qubit-ltd/validation-rule 是一个提供常用验证规则的JavaScript ES6库。

目录

安装

使用npm安装:

npm install @qubit-ltd/validation-rule

或使用yarn安装:

yarn add @qubit-ltd/validation-rule

使用方法

导入验证规则

// 导入特定的验证规则
import { EmailRule, PasswordRule, UsernameRule } from '@qubit-ltd/validation-rule';

// 验证电子邮件地址
const isValidEmail = EmailRule.isValid('[email protected]'); // 返回 true

// 验证密码
const isValidPassword = PasswordRule.isValid('Password123'); // 根据密码规则返回 true 或 false

// 验证用户名
const isValidUsername = UsernameRule.isValid('user123'); // 根据用户名规则返回 true 或 false

使用ValidationResult

import { ValidationResult } from '@qubit-ltd/validation-rule';

// 创建验证结果
const validResult = new ValidationResult(true, '验证成功');
const invalidResult = new ValidationResult(false, '验证失败');

// 合并多个验证结果
const results = [
  new ValidationResult(true, '第一项验证成功'),
  new ValidationResult(false, '第二项验证失败'),
  new ValidationResult(false, '第三项验证失败')
];

const mergedResult = ValidationResult.merge(results);
// mergedResult 将包含所有失败的验证结果,形成一个链式结构

API文档

验证规则

库提供了以下常用验证规则:

  • AlphaNumberRule: 验证字符串是否只包含字母和数字
  • BoolRule: 验证值是否为布尔值
  • ChinaIdentityCardRule: 验证中国身份证号码
  • ChinaMobileRule: 验证中国手机号码
  • ChinaOfficerCardRule: 验证中国军官证号码
  • ChinaPassportRule: 验证中国护照号码
  • ChinaPhoneRule: 验证中国电话号码(包括座机)
  • EmailRule: 验证电子邮件地址
  • IntegerRule: 验证整数
  • LocalDateRule: 验证本地日期格式
  • LocalDateTimeRule: 验证本地日期时间格式
  • LocalTimeRule: 验证本地时间格式
  • NumberRule: 验证数字
  • NumericRule: 验证数值型字符串
  • OtherCredentialRule: 验证其他证件号码
  • PasswordRule: 验证密码
  • PersonNameRule: 验证人名
  • TimestampRule: 验证时间戳
  • UppercaseAlphaNumberRule: 验证大写字母和数字组合
  • UrlRule: 验证URL地址
  • UsernameRule: 验证用户名
  • VerifyCodeRule: 验证验证码

ValidationResult

ValidationResult 类用于表示验证的结果,并可以将多个验证结果合并。

属性

  • success: 表示验证是否成功
  • description: 验证结果的描述
  • next: 下一个验证结果,用于链接多个失败的验证结果

方法

  • constructor(success = true, description = ''): 创建一个新的验证结果对象
  • static merge(results): 合并多个验证结果对象

贡献

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

许可证

@qubit-ltd/validation-rule 在Apache 2.0许可证下分发。 详情请参阅LICENSE文件。