Skip to content

francoisrv/paramizer

Repository files navigation

paramizer

Helper with url params such as /posts/:postId

Install

npm install paramizer

Matches

Check if a pathname matches a paramized pathname

import { matchesPattern } from 'paramizer'

if (matchesPattern(location.href, '/posts/:postId')) {
  // ...
}

Get parameters

Get parameters values

import { getParameters } from 'paramizer'

const pathname = '/posts/123/comments/456'
const pattern = '/posts/:postId/comments/:commentId'

const params = getParameters(pathname, pattern)
console.log(params)
{
  postId: '123',
  commentId: '456'
}

Apply parameters

Apply values to parameters

import { applyParameters } from 'paramizer'

const pattern = '/posts/:postId/comments/:commentId'

const pathname = applyParameters(pattern, { postId: '1', commentId: '2' })
console.log(pathname)
// '/posts/1/comments/2'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published