Socket
Book a DemoInstallSign in
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.1.1
latest
Source
npmnpm
Version published
Weekly downloads
8
-27.27%
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

routes

FAQs

Package last updated on 13 Jun 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.