0.2.1 • Published 6 years ago

superreg v0.2.1

Weekly downloads
5
License
MIT
Repository
-
Last release
6 years ago

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' }
0.2.1

6 years ago

0.1.0

6 years ago

0.0.0

6 years ago