Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

regexbuddy

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regexbuddy

Implement regex expressions in JavaScript

  • 0.8.35
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-55%
Maintainers
1
Weekly downloads
 
Created
Source

RegexBuddy

regexbuddy allows you to implement common regex functionality in your code, using a simplified syntax. Currently, regexbuddy has functions for regex-based password validation, as well as array duplicate functions. The array functions - along with other features - are being added, and a new version is released weekly.

Installation

Install in your project locally:

npm install regexbuddy

Implement into your project

Step 1: Import into your project

NOTE: Since regexbuddy has function names that are considered generic (i.e. password(input).validate()), it's recommended to import it like this:

import * as regexBuddy from "regexbuddy";

Step 2: That way, you can use it in your code like this

regexBuddy.password(input).validate();

COMMENT: While having generic-sounding function names is a (rightfully) contested topic, doing so makes the syntax feel more natural. And implementing it like the example above makes it easier to find where regexbuddy is used in your code, because the functions are prefixed with regexBuddy.

Available Functions and Methods

Password Validation

NOTE: The password validation method simply returns true or false.

For password validation, you can simply use:

regexBuddy.password(input).validate();

This takes the input value you pass in as an argument, and validates against the default password requirements.

Default requirements are that a password must contain (with the option name and data type for overwriting defaults):

  1. At least one uppercase letter (name: requireUpperCase, type: boolean)
  2. At least one lowercase letter (name: requireLowerCase, type: boolean)
  3. At least one number (name: requireNumber, type: boolean)
  4. At least one special character (name: requireSpecialCharacter, type: boolean)
  5. A minimum of 5 characters (name: minLength, type: number)

The default requirements can be overwritten by passing in your requirements in the validate function like this:

regexBuddy.password(input).validate({ minlength: 8, requireSpecialCharacter: false });

NOTE: Options that are ignored will still have their default values used. So in the example above, a password must have at least 8 characters and does not need to have a number. But it must also still include an uppercase letter, lowercase letter, and a special character.

An example of how to use this in your code would be:

const validPassword = regexBuddy.password(input).validate({ minlength: 8, requireSpecialCharacter: false });

This would let you reference the validPassword variable in a simple way, like this conditional statement:

// If a password is valid
if (validPassword) {
  // Run this code
  ...
}

Or implement in your corresponding template file, like this:

<button type="submit" disabled={!validPassword}>Submit</button>

Keywords

FAQs

Package last updated on 23 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc