Socket
Socket
Sign inDemoInstall

@gpx/path-to-name

Package Overview
Dependencies
3
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @gpx/path-to-name

Converts a path into a name


Version published
Maintainers
1
Created

Readme

Source

path-to-name

Converts a path into a name.

Let's start with an example:

import { pathToName } from "@gpx/path-to-name";

pathToName("/user"); // => 'getUser'
pathToName("/users"); // => 'getUsers'
pathToName("/users/:user_id"); // => 'getUserById'
pathToName("/users/:user_id/products"); // => 'getProductsForUserById'
pathToName("/users/:user_id/products/:product_id"); // => 'getProductByIdForUserById'

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"); // => 'createUser'
pathToName("/users/:id", "get"); // => 'getUserById'
pathToName("/users/:id", "post"); // => 'updateUserById'
pathToName("/users/:id", "patch"); // => 'updateUserById'
pathToName("/users/:id", "delete"); // => 'deleteUserById'

FAQs

Last updated on 02 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc