@nimpl/path-parser
Helper for next.js-styled pathname parsing (f.e. /(site)/docs/[key]
) to get dynamic params.
Installation
npm
yarn
npm i @nimpl/path-parser
yarn add @nimpl/path-parser
Usage
import { parse } from "@nimpl/path-parser";
// ...
const params = parse("/docs/path-parser", "/(site)/docs/[key]"); // { key: 'path-parser' }
const { segments } = parse("/docs/path-parser", "/(site)/[[...segments]]"); // { segments: ['docs', 'path-parser'] }
Arguments
pathname
- clean page pathname;
rule
- the expected rule (same as the path to the page directory).
If pathname does not match the expected rule - the parser will return
null
.Development
Read about working on the package and making changes on the contribution page
Additional
Please consider giving a star if you like it, it shows that the package is useful and helps me continue work on this and other packages.
Create issues with wishes, ideas, difficulties, etc. All of them will definitely be considered and thought over.