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

@stroll/verify

v0.0.3

Published

verify

Downloads

1

Readme

validators

验证

安装

npm i -S @stroll/verify

引入

import verify from '@stroll/verify'
// OR
import {
  isUtf8, /** 是否utf8 */
  parmType, /** 判断字段类型 */
  ...
} from '@stroll/verify'

使用

/**
 * 是否utf8
 * @param s string
 * @returns 
 */
isUtf8(s: string): Promise<boolean>

/**
 * 判断字段类型
 * @param val 需要判断的参数
 * @param type 可选需要判断的类型
 * @returns Promise - 类型字符串 或 true/false/error 信息
 */
parmType (
  val: any,
  type?: 'Object' | 'Array' | 'String' | 'Null' | 'Undefined' | 'Number' | 'Function' | 'Date' | 'Boolean' | 'RegExp' | 'Symbol' | 'Set' | 'Map'
): Promise<string | boolean>

/**
 * 判断是否UUID 字符串
 * @param val 需要判断的参数
 * @returns Promise<{status: boolean, msg: string}>
 */
isUUID(val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否全部数字
 * @param val 需要判断的参数
 * @returns Promise<{status: boolean, msg: string}>
 */
isNumeric (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否全部字母和数字
 * @param val 需要判断的参数
 * @returns Promise<{status: boolean, msg: string}>
 */
isAlphanumeric (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否全部字母
 * @param val 需要判断的参数
 * @returns Promise<{status: boolean, msg: string}>
 */
isAlpha (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否全部小写字母
 * @param val 需要判断的参数
 * @returns Promise<{status: boolean, msg: string}>
 */
isAlphaTiny (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否全部大写字母
 * @param val 需要判断的参数
 * @returns Promise<{status: boolean, msg: string}>
 */
isAlphaBig (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是小驼峰
 * - 除首字母外最少一个大写字母
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isSmallHump (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是大驼峰
 * - 首字母大写以外最少再有一个大写字母
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isBigHump (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是严格模式驼峰
 * - 首字母大写以外最少再有一个大写字母并且不能连续大写
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isHump (
  val: string,
): Promise<{status: boolean, msg: string}>

/**
 * 判断是否是时间
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isTime (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是日期
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isDate (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是日期时间
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isDateTime (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是1代或2代身份证
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isIdCard (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是1代身份证
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isIdCard1 (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是2代身份证
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isIdCard2 (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是url
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isUrl (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是V4IP
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isIpV4 (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是V6IP
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isIpV6 (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是url或IP
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isUrlOrIp (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是正整数
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isInt (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是浮点数
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isFloat (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是邮箱
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isEmail (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是手机
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isPhone (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是版本号
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isVersion (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断是否是字母开头, 字母、数字、下划线 组成的账号
 * @param val 字符串
 * @returns Promise<{status: boolean, msg: string}>
 */
isAccount (val: string): Promise<{
  status: boolean,
  msg: string
}>

/**
 * 判断字段长度
 * @param val 需要判断的字符串
 * @param length 最大长度 默认 255
 * @param originate 最小长度 默认 0
 * @returns Promise - 类型字符串 或 true/false/error 信息
 */
export async function stringLength (
  val: string,
  length?: number|{length?: number,originate?: number},
  originate?: number
): Promise<{status: boolean, msg: string}>

/**
 * 判断数字长度
 * @param val 数字串
 * @param length 最大长度 默认 255
 * @param originate 最小长度 默认 0
 * @returns Promise<{status: boolean, msg: string}>
 */
export async function numberLength (
  val: string,
  length?: number|{length?: number,originate?: number},
  originate?: number
): Promise<{status: boolean, msg: string}>

/**
 * 判断是否是时间戳
 * @param val 字符串
 * @param leng 可选 长度参数  默认125
 * @returns Promise<{status: boolean, msg: string}>
 */
isTimestamp(timestamp: string): Promise<{
  status: boolean,
  msg: string
}>
/**
 * 字段验证类型
 * @param validate.is 匹配这个 RegExp
 * @param validate.not 与这个 RegExp 不匹配
 * @param validate.isEmail 检查 email 格式 ([email protected])
 * @param validate.isUrl 检查 url 格式 (http://foo.com)
 * @param validate.isIP 检查 IPv4 (129.89.23.1) 或 IPv6 格式
 * @param validate.isIPv4 检查 IPv4 格式 (129.89.23.1)
 * @param validate.isIPv6 检查 IPv6 格式
 * @param validate.isAlpha 只允许字母
 * @param validate.isAlphanumeric 将仅允许使用字母数字,因此 '_abc' 将失败
 * @param validate.isNumeric 只允许数字
 * @param validate.isInt 检查有效的整数
 * @param validate.isFloat 检查有效的浮点数
 * @param validate.isDecimal 检查任何数字
 * @param validate.isLowercase 检查小写
 * @param validate.isUppercase 检查大写
 * @param validate.notNull 不允许为空
 * @param validate.isNull 只允许为空
 * @param validate.notEmpty 不允许空字符串
 * @param validate.equals 仅允许某个值
 * @param validate.contains 强制特定子字符串
 * @param validate.notIn 检查值不是这些之一
 * @param validate.isIn 检查值是其中之一
 * @param validate.notContains 不允许特定的子字符串
 * @param validate.len 仅允许长度在两个值之间
 * @param validate.isUUID 只允许 uuid
 * @param validate.isDate 只允许日期字符串
 * @param validate.isAfter 仅允许特定日期之后的日期字符串
 * @param validate.isBefore 仅允许特定日期之前的日期字符串
 * @param validate.max 仅允许值 <= 23
 * @param validate.min 仅允许值 >= 23
 * @param validate.isCreditCard 检查有效的信用卡号
 * @param validate.isEven 自定义验证
 * @param validate.isGreaterThanOtherField 未实现
 * @param validate.customValidator 未实现
 */
verifyField.isIP('')
verifyField.isInt('')
...