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 9, 2024 via pnpm

to-regex-range 5.0.1

Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.
Package summary
Share
0
issues
1
license
2
MIT
Package created
7 Aug 2015
Version published
7 Apr 2019
Maintainers
2
Total deps
2
Direct deps
1
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
2 Packages, Including:
is-number@7.0.0
to-regex-range@5.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

1
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-number7.0.03.64 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.