Security News
RubyGems.org Adds New Maintainer Role
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.
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 email validation, you can simply use:
regexBuddy.email(input).validate();
This runs a regex function to ensure the input is a valid email address. The return value from the above method is:
{
valid: Boolean
message: `Error message` || null
}
You can also customize validation criteria with permitted
and restricted
values.
For instance, if you wanted to only allow email addresses with a @yourcompanyname
email address, you would do the following:
regexBuddy.email(input).validate({ permitted: "yourcompanyname" });
You can do the same with email domains you explicitly do not want to permit, like this:
regexBuddy.email(input).validate({ restricted: "aol" });
The permitted
and restricted
values let you pass in either a String or Array. So you can also do this:
regexBuddy.email(input).validate({ restricted: ["aol", "hotmail"] });
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>
With regexbuddy, you can convert any string into either pascal, camel, kebab, snake, or sql case. You can do this with the following method:
regexBuddy.convertCase("your String goes Here")
Using the base syntax returns an object that looks like this:
{
original: 'your String goes Here',
camel: 'yourStringGoesHere',
kebab: 'your-string-goes-here',
pascal: 'Your String Goes Here',
snake: 'your_string_goes_here',
sql: 'YOUR_STRING_GOES_HERE'
}
If you need to use different cases for a value throughout your code, you can utilize case conversion like this:
const dName = regexBuddy.convertCase(displayName)
And wherever you use the dName
variable, you can specifiy the case like this:
<h2 className="card-header">{dName.pascal}</h2>
The case converter also accepts a designated case as an option. You can do so like this:
regexBuddy.convertCase("your String goes Here", { case: 'camel' })
The return value of this is simply the string converted into the desired case.
NOTE: This is a much more performant way to utilize the case converter, and is recommended, when you can.
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
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.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.