1.0.2 • Published 2 years ago

@makechtec/router-translator v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

RouterTranslator

Usage

import {RouterTranslator} from "@makechtec/router-translator";

const translator = new RouterTranslator();

const route = translator.extractInfo("/products/{id}/description", "/products/23/description");
console.log(route.variables);

result:

[
    {
        key: "id",
        value: "23"
    }
]

other example:

const route = translator.extractInfo("/category/{category_id}/tag/{tag_id}", "/category/23/tag/45");
console.log(route.variables);

result:

[
    {
        key: "category_id",
        value: "23"
    },
    {
        key: "tag_id",
        value: "45"
    }
]

buildUri

It perform the inverse function:

const uri = translator.buildUri("/products/{id}/description", [ {key: "id", value: "23"} ]);
console.log(uri);

result:

"/products/23/description"