Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
regexbuddy
Advanced tools
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.
Install in your project locally:
npm install regexbuddy
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
.
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):
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.
NOTE: The password validation method returns an object structured like this:
{
valid: boolean,
errors: [ validationErrors ] || null
}
This gives you the option of serving the client an array of the criteria not met when creating a password, or simply using the password validation method in a conditional expression. And the valid
property was added for those who prefer using explicit conditional evaluation over implicit "truthy" methods for something like a password.
An example of how to use this in your code would be:
const passwordCheck = regexBuddy.password(input).validate({ minlength: 8, requireSpecialCharacter: false });
This would let you reference the passwordCheck
variable in a simple way, like these examples:
// If a password is invalid
if (passwordCheck.errors) {
// You can then map the array of errors in passwordCheck.errors to a DOM object, like a toast, modal, etc.
...
}
Or implement as a simple, explicit conditional in your corresponding template file, like this example, where a submit button is disabled when there are any errors with the user's input value:
<button type="submit" disabled={!passwordCheck.valid}>Submit</button>
FAQs
Implement regex functions with ease in JavaScript
The npm package regexbuddy receives a total of 7 weekly downloads. As such, regexbuddy popularity was classified as not popular.
We found that regexbuddy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.