Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Apr 13, 2024 via pnpm

to-regex-range 1.0.1

Returns a regex-compatible range from two numbers, min and max. Validated against more than 1.1 million generated unit tests that run in less than 400ms! Useful for creating regular expressions to validate numbers, ranges, years, etc.
Package summary
Share
0
issues
1
license
5
MIT
Package created
7 Aug 2015
Version published
19 Oct 2016
Maintainers
2
Total deps
5
Direct deps
2
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
5 Packages, Including:
is-buffer@1.1.6
is-number@3.0.0
kind-of@3.2.2
repeat-string@1.6.1
to-regex-range@1.0.1
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

2
All Dependencies CSV
β“˜ This is a list of to-regex-range 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
is-number3.0.02.78 kBMIT
prod
repeat-string1.6.13.26 kBMIT
prod

Visualizations

Frequently Asked Questions

What does to-regex-range do?

The npm package "to-regex-range" provides a JavaScript utility for creating a regex-compatible source string for matching numerical ranges. It requires two numbers as arguments and is capable of handling a large variety of number ranges, making it a flexible and robust solution for match number ranges in applications. This package has been validated against more than 2.78 million test assertions, providing users with a high level of assurance about the quality and accuracy of its output.

How do you use to-regex-range?

To utilise the "to-regex-range" npm package, first, it needs to be installed into your JavaScript project. This can be performed by running the command npm install --save to-regex-range in your terminal. Once installed, you can import this library into your JavaScript file using const toRegexRange = require('to-regex-range');.

This function requires two numbers (or strings that can be converted into numbers) as parameters representing the min and max of the range. The output is a string that can be used to create a new RegExp instance.

const toRegexRange = require('to-regex-range');
const source = toRegexRange('15', '95');
//=> 1[5-9]|[2-8][0-9]|9[0-5]

const regex = new RegExp(`^${source}$`);
console.log(regex.test('14')); //=> false
console.log(regex.test('50')); //=> true
console.log(regex.test('94')); //=> true
console.log(regex.test('96')); //=> false

In this given example, the toRegexRange function creates a regex-compatible string to match any number within the range 15 to 95. This is then used to create a new RegExp, which can be tested against different values.

Where are the to-regex-range docs?

The official documentation for the "to-regex-range" npm package is included within the README on the project's GitHub repository. It provides detail on installation, usage, options, examples and also includes a section on how the order of arguments can be flipped to create a valid range. Furthermore, this README is updated with each new version of the package, ensuring users have accurate information that matches the current state of the package.