superreg

0.2.1 • Public • Published

SuperReg

Better RegExp support for Javascript

Usage

SuperReg extends from RegExp. It adds a few extra methods.

const reg = new SuperReg(/^[a-z](\d+)/)
const matches = reg.exec('a123')
// matches === [ 'a123', '123' ]

Methods

static escape (str pattern) str

Escapes all special chars in a string to make it usable as a RegExp.

const pat = SuperReg.escape('Hello ${name}')
// pat === Hello \$\{name\}

map (arr pattern) obj

Maps an array of keys onto a regexp

const keys = [
  'one', 'two', 'three'
]
 
const pattern = /(one)|(two)|(three)/
const res = new SuperReg(pattern).map(keys, 'Number three')
// res = { one: '', two: '', 'three: 'three' }

Readme

Keywords

Package Sidebar

Install

npm i superreg

Weekly Downloads

4

Version

0.2.1

License

MIT

Unpacked Size

5.03 kB

Total Files

6

Last publish

Collaborators

  • andifeind