Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typed-routes-generator

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-routes-generator

Generate typed routes from yaml file

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
300
decreased by-48.54%
Maintainers
1
Weekly downloads
 
Created
Source

typed-routes-generator

Provide route definitions in yaml file and get generated typed routes with parameters in paths. There is no limit how deep routes can be. Also you can define in one yaml file multiple route types that each will be exported as separate const.

Argument (parameter) can be text, numbers but no special characters like _, -, etc.

Usage

yarn typed-routes-generator --source ./example/routes.yaml --output ./example/generated.ts

Example

Source yaml file (./example/routes.yaml)

mainRoutes:
  firstLevel:
    anotherLevel:
      anotherLevel:
        lastLevel:
          homeWithArgument: "/[someargumentkey]"

websiteRoutes:
  home: /
  product:
    archive: "/products"
    detail: "/products/[detail]"
  aboutUs: "/about-us"

Output (./example/generated.ts)

export const mainRoutes = {
  firstLevel: {
    anotherLevel: {
      anotherLevel: {
        lastLevel: {
          homeWithArgument: (params: { someargumentkey: string }) => '/[someargumentkey]'.replace('[someargumentkey]', params.someargumentkey.toLowerCase()),
        },
      },
    },
  },
};

export const websiteRoutes = {
  home: () => '/',
  product: { archive: () => '/products', detail: (params: { detail: string }) => '/products/[detail]'.replace('[detail]', params.detail.toLowerCase()) },
  aboutUs: () => '/about-us',
};

Usage of generated code

websiteRoutes.product.detail({ detail: 'product-id' });
// Output: /products/product-id

Keywords

FAQs

Package last updated on 19 May 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc