0.1.2 • Published 2 years ago

part-regex v0.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Create a RegExp by defining some parts with strings and other parts with RegExp.

import partRegex from 'part-regex' // npm install part-regex

// Only match strings `/product/[0-9]+/edit`
const productEditPageUrl = partRegex`/product/${/[0-9]+/}/edit`
console.log(productEditPageUrl.test('/product/42/edit')) // Prints `true`

// Also supports a mix of String and RegEx variables.
// == Note how the first part is a RegEx and the second part is a string.
const userPageUrl = (isSettingsPage) => partRegex`/user/${/[a-zA-Z]+/}${isSettingsPage ? '/settings' : ''}`
console.log(userPageUrl(true).test('/user/brillout/settings')) // Prints `true`
console.log(userPageUrl(false).test('/user/turing')) // Prints `true`
0.1.2

2 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.0-alpha.0

3 years ago