Skip to content

How to safely access the regular expression compiled from a path? #315

@mxxk

Description

@mxxk

@blakeembrey with the removal of the re property in fb4d11d#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80L483-L485, how can the regular expression be safely accessed by the consumers of path-to-regexp?

Motivation

In my case, I'm working around the removal of support for string[] in v7 as mentioned in #310 (comment), so I'm looking for a stable way to get the regular expression.

I see that with fb4d11d, the redos.ts script (which relies on the ability to get the regular expression) performs an as any cast to work around the re property removal from the type signature:

-const { re } = match(path);
+const { re } = match(path) as any;

I could do the same, but it doesn't seem safe to rely on an undocumented property from outside of path-to-regexp.

I'm curious to hear your recommendation @blakeembrey 🙂

Note

P.S. Thank you for maintaining this repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions