paramizer
TypeScript icon, indicating that this package has built-in type declarations

0.0.0 • Public • Published

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'

Readme

Keywords

Package Sidebar

Install

npm i paramizer

Weekly Downloads

0

Version

0.0.0

License

none

Unpacked Size

7.96 kB

Total Files

25

Last publish

Collaborators

  • franleweb