Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nimpl/path-parser

vordgi309MIT1.0.1TypeScript support: included

Helper for next.js-styled pathname parsing (f.e. /(site)/docs/[key]) to get dynamic params

next, next.js, server components, react.js, get-pathname, get-params, pathname, params, parse, implementation, rsc

readme

@nimpl/path-parser

Helper for next.js-styled pathname parsing (f.e. /(site)/docs/[key]) to get dynamic params

Visit https://nimpl.dev/docs/path-parser to view the full documentation.

Installation

Using npm:

npm i @nimpl/path-parser

Using yarn:

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'] }

Additional

Please consider giving a star if you like it, it will help promote the implementation in the eyes of the Next.js team. This also motivates the author to continue working on this and other solutions ❤️

Create issues with wishes, ideas, difficulties, etc. All of them will definitely be considered and thought over.