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

often-regexp

v1.0.9

Published

****

Downloads

3

Readme

often-regexp


介绍

常用正则匹配,主要是限制input输入时,只能是浮点数(如0.1 / 1.01),整数(如123),通过第二个控制输入的位置。如果是小数,第二个参数则是控制小数点后的位数

Features

  • 1去掉字符中所有空隔:regRemoveAllS
  • 2去掉首字符空隔:regRemoveFS
  • 3去掉首尾字符空隔:regRemoveFES
  • 4输入小数:regBaseNum
  • 5浮点数,可以是0开头小数(p > 0),第二参数控制小数点后位数:regFloat
  • 6整数/浮点数,非0开头小数(p > 1),第二参数控制小数点后位数:regFloatGtZero
  • 7可以是零开头整数,第二参数控制输入整数的位数:regZeroInt
  • 8非零开头整数,第二参数控制输入整数的位数:regInt

Set up

The library is the single JavaScript file often-regexp.js.

Browser:

<script src='path/to/often-regexp.js'></script>

Node.js:

$ npm install often-regexp
$ yarn add often-regexp
const oftenRegExp = require('often-regexp.js');

ES6 module:

import _ from 'often-regexp';

Use

The library exports a single function,

1.去掉字符中所有空隔:

regRemoveAllS

    let str = ' a b c ';
    console.log(regRemoveAllS(str))    // 'abc'

2.去掉首字符空隔:

regRemoveFS

    let str = ' a b c ';
    console.log(regRemoveFS(str))     // 'a b c '

3.去掉首尾字符空隔:

regRemoveFES

    let str = ' a b c ';
    console.log(regRemoveFES(str))    // 'a b c'

4.输入小数,过滤输入的内容保留小数,如:0.12abc,返回(0.12):

regBaseNum

    let str = '0.12abc ';
    console.log(regBaseNum(str))    // '0.12'

5.浮点数,可以是0开头小数(p > 0),第二参数控制小数点后位数,如:0.12a,返回(0.12):

regFloat

    let str = '0.12a ';
    console.log(regFloat(str,2))    // '0.12'

6.整数/浮点数,非0开头小数(p > 1),第二参数控制小数点后位数,如:1.2a,返回(1.2):

regFloatGtZero

    let str = '1.21a ';
    console.log(regFloatGtZero(str,1))    // '1.2'

7.可以是零开头整数,第二参数控制输入整数的位数,如:'a012345',返回(012345):

regZeroInt

    let str = 'a012345 ';
    console.log(regZeroInt(str,3))    // '012'

8.非零开头整数,第二参数控制输入整数的位数,如:'a012345',返回(12345):

regInt

    let str = 'a012345 ';
    console.log(regInt(str,3))    // '12'