1.0.1 • Published 5 years ago

@iammadab/string-matcher v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

String Matcher

A light-weight url matcher

Example

To create a matcher to match

Format /users/:id/find

Sample Match /users/25/find

Since : was before id its dynamic, so can be anything in the match

const urlMatcher = require("string-matcher")

//First argument is the delimeter used to split the string
//Second argument is the identifier for dynamic links
const urlFormat = urlMatcher("/", ":")

//Define matcher for finding specific users
//Takes the format that would be used to match
const findUserMatcher = urlFormat("/users/:id/find")

//Usage
let data = findUserMatcher.parse("/users/25/find") //{ match: true, id: 25, ...}

//You can access your dynamic parts as such
userId = data.id