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

sw-regexp

v1.0.4

Published

RegExp lib.

Downloads

6

Readme

sw-regexp

安装

npm i --save sw-regexp

引入

// 假设导入正则库为以下名字
import swRegExp from 'sw-regexp'

使用

// 假设在 vue 中待验证的值为 value
data() {
  return {
    value: ''
  }
}

Methods

Module of general

general 模块一般是一些通用的正则验证。

开发者无需关心当前的正则属于模块的,只是为了划分正则项目结构。

space()

空格
验证是否存在空格

let r = swRegExp.sapce().test(this.value)

chinese()

全中文
验证当前值是否为全中文

|参数|类型|默认值|说明|
|-|-|:-:|-|
|maxLength|Number|0|字符串最大长度,0 表示无限制|

// 验证当前值是否为全中文,长度不限
let r1 = swRegExp.chinese().test(this.value)
// 验证当前值是否为全中文,长度为 0 - 10
let r2 = swRegExp.chinese(10).test(this.value)

Module of form

form 模块提供的都是 form 表单常用的正则。

account()

账号
只能输入英文和数字

|参数|类型|默认值|说明|
|-|-|:-:|-|
|minLength|Number|0|字符串最小长度|
|maxLength|Number|32|字符串最大长度|

// 验证当前账号是否符合规范,长度为 8 - 16
let r = swRegExp.account(8, 16).test(this.value)

password()

密码
只能输入英文和数字

|参数|类型|默认值|说明|
|-|-|:-:|-|
|minLength|Number|0|字符串最小长度|
|maxLength|Number|16|字符串最大长度|

// 验证当前密码是否符合规范,长度为 8 - 16
let r = swRegExp.password(8, 16).test(this.value)

email()

验证
验证邮箱格式

// 验证当前邮箱格式是否符合规范
let r = swRegExp.email().test(this.value)

IDCard()

身份证 验证 15 位和 18 位身份证(可以带 X )格式

// 验证当前身份证格式是否符合规范
let r = swRegExp.IDCard().test(this.value)

url()

网址
验证网址是否是否合法,必须以"http://"或者"https://"开头

// 验证当前身份证格式是否符合规范
let r = swRegExp.url().test(this.value)

price()

价格
验证价格是否有效

|参数|类型|默认值|说明|
|-|-|:-:|-|
|length|Number|2|小数点后保留位数|

// 验证当前价格是否有效,小数点后默认保留 2 位
let r1 = swRegExp.price().test(this.value)
// 验证当前价格是否有效,小数点后保留 1 位
let r2 = swRegExp.price(1).test(this.value)

phone()

手机号
验证 11 位手机号格式

// 验证当前值是否为 11 位手机号
let r = swRegExp.phone().test(this.value)