@iammadab/string-matcher

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i @iammadab/string-matcher

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

3.98 kB

Total Files

3

Last publish

Collaborators

  • iammadab