JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 70291855
  • Score
    100M100P100Q258101F
  • License MIT

Returns a regex-compatible range from two numbers, min and max, with 855,412 generated unit tests to validate it's accuracy! Useful for creating regular expressions to validate numbers, ranges, years, etc. Returns a string, allowing the returned value to be used in regular expressions generated by other libraries.

Package Exports

  • to-regex-range

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (to-regex-range) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

to-regex-range NPM version NPM downloads Build Status

Returns a regex-compatible range from two numbers, min and max, with 855,412 generated unit tests to validate it's accuracy! Useful for creating regular expressions to validate numbers, ranges, years, etc. Returns a string, allowing the returned value to be used in regular expressions generated by other libraries.

Install

Install with npm:

$ npm install --save to-regex-range

Bower

Install with bower

$ bower install to-regex-range --save

Notes

Inspired by the python lib range-regex, it has never been easier to validate numbers and number ranges with regex!

The unit tests generate 850,000 patterns to provide brute-force validation that the generated regex-ranges are correct.

Usage

var toRegexRange = require('to-regex-range');

var re = new RegExp(toRegexRange('1', '99'));
re.test('50');
//=> true

Examples

toRegexRange('111', '555');
//=> '11[1-9]|1[2-9]\d|[2-4]\d{2}|5[0-4]\d|55[0-5]'
toRegexRange('5', '5');
//=> '5'
toRegexRange('5', '6');
//=> '[5-6]'
toRegexRange('51', '229');
//=> '5[1-9]|[6-9]\d|1\d{2}|2[0-2]\d'

When the min is larger than the max, a regex logical or is returned:

toRegexRange('51', '29');
//=> '51|29'

Currently this does not support steps (increments) or zero-padding.

About

  • expand-range: Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See… more | homepage
  • fill-range: Fill in a range of numbers or letters, optionally passing an increment or multiplier to… more | homepage
  • micromatch: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | homepage
  • repeat-element: Create an array by repeating the given value n times. | homepage
  • repeat-string: Repeat the given string n times. Fastest implementation for repeating a string. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb-generate-readme, v0.1.30, on September 14, 2016.