0.0
No release in over 3 years
Xici proxy for nx.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.14
~> 12.3, >= 12.3.3
 Project Readme

path-dual-parser

path-dual-parser logo

Path matcher supporting both colon and brace URI template syntax.

version license download

installation

pnpm add @jswork/path-dual-parser

usage

match

Match a path against a template, supports both :param and {param} syntax:

import { match } from '@jswork/path-dual-parser';

const m1 = match('/users/:id');
const m2 = match('/users/{id}');

m1('/users/123');  // { path: '/users/123', params: { id: '123' } }
m2('/users/123');  // { path: '/users/123', params: { id: '123' } }
m1('/other');      // false

compile

Compile a template into a URL generator:

import { compile } from '@jswork/path-dual-parser';

const c1 = compile('/users/:id');
const c2 = compile('/users/{id}');

c1({ id: '123' });  // '/users/123'
c2({ id: '123' });  // '/users/123'

parse

One-step parse template with data to URL (simpler API):

import { parse } from '@jswork/path-dual-parser';

parse('/users/:id', { id: '123' });      // '/users/123'
parse('/users/{id}', { id: '123' });     // '/users/123'
parse('/users/:userId/posts/{postId}', { userId: '1', postId: '2' });  // '/users/1/posts/2'

params

Extract parameter names from a template:

import { params } from '@jswork/path-dual-parser';

params('/users/:id/posts/{postId}')  // ['id', 'postId']
params('/users')                     // []

isMatch

Check whether a path matches a template (boolean result):

import { isMatch } from '@jswork/path-dual-parser';

isMatch('/users/:id', '/users/123')  // true
isMatch('/users/:id', '/posts/1')    // false

license

Code released under the MIT license.