path-to-name
Converts a path into a name.
Let's start with an example:
import { pathToName } from "@gpx/path-to-name";
pathToName("/user");
pathToName("/users");
pathToName("/users/:user_id");
pathToName("/users/:user_id/products");
pathToName("/users/:user_id/products/:product_id");
That's pretty much it. Pass a path and get back a name for it. The name is camel-cased and follows the RESTful naming conventions.
There's only a second optional argument method
. It matches the HTTP method and can only have values of GET
, POST
, PUT
, PATCH
, and, DELETE
. If the method is not provided, it defaults to GET
.
pathToName("/users", "PUT");
pathToName("/users/:id", "get");
pathToName("/users/:id", "post");
pathToName("/users/:id", "patch");
pathToName("/users/:id", "delete");