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

regexlidator

v1.0.0

Published

Validate or get the parts of some patterns using regular expressions

Downloads

1

Readme

Regexlidator

Validate or get the parts of some patterns using regular expressions

I made this package to validate strings using regular expressions, the package contains 4 main objects: is, get, has and search; and every object has this functions:

  • email().
  • number().
  • securePassword().
  • color().
  • slug().

Instalation

npm i regexlidator

Status

This package is published, but I've never used it in a big project and, besides I tested it with some examples, I don't know the limits in the package, soo... It works fine, but if you detect some bug, please let me know so I can fix it.

Is

The is object validates if a given string IS something (checks the whole string), for instance: "#FFF" is a color, but "Fav: #FFF" isn't besides it contains a color in it, "[email protected] " is an email (besides it has white spaces at the end), but "mail.com" (because it doesn't has the @) and "myemail @gmail.com" isn't an email neither, because there is a space in the middle.

The objective of is to validate a small string, if your objective is validate if a bigger text has (contains) something, maybe you're looking for has.

is.color('#FFF') // true
is.color('Fav: #FFF') // false

is.email('[email protected]    ') // true
is.email('mail.com') // false
is.email('myemail @gmail.com') // false

// Other functions
is.number('12')
is.slug('chocolate-cake')
is.securePassword('Passw0rd')

Has

The has object validates if a text has (contains) something, for instance, besides the sentence "The code of my favorite color is #FF69Bf and I hate 0x111" is obviously not a color, it HAS colors in it.

has.email('Email: [email protected]') // true
has.color('My favorite color is: #Fc0') // true
has.number('I love the number ten') // false, "ten", is not a valid number
has.slug('regexlidator') // true
has.securePassword('password') // false 

Get

The get object is helpful when you want to get some components of a string, it first checks if the string IS something, then returns the match and components of the thing.

get.color('#FF00CC      ').red.asNumber // 255. Matches #FF00CC and can return the red, blue or green components
get.email('   [email protected]   ').domain // 'example.com'. Matches [email protected] and can return the predomain (someone) and domain (example.com)
get.number('123.4').value // 124.4. Matches 123.4 and can return the total value, the integer part or the rest.

// get.slug() and get.securePassword() only can return an object with a property "match" (the other functions also returns a match property) that is basically, the input given once trimed. Or throws an error if the parameter isn't a slug or securePassword

Search

The search object search matches across all the text, and returns an object, where the property matches is an array with all the matches found in the text, the property gets is and array of results of execute the get correspondient function (for example, if you use search.color(), then search.color().gets is an array of the results of using get.color(), so you can get, for example, the red value of the second color like this: search.color().gets[1].red.asNumber); and the property first that is the same as the first element of the gets array (For example if you want to get the value of the first number, use search.number().first.value).

const colors = "#FF0000 #CC0 0x87FFcC"
const gotColors = search.color(colors).gets 

const redValues = gotColors.map(gotColor => gotColor.red.asNumber) // [255, 204, 135]
const averageRed = reds.reduce((prev, current) => prev + current, 0) / reds.length // 198