0.1.6 • Published 8 months ago

react-create-url v0.1.6

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

In this small library, you can use typescript object/methods for building route/api urls.

1.First step - create interface with all routings in your web app.

interface IAppRoute {
  auth: {
    account: {
      id: (id?: string) => IUrlItem;
    };
    login: IUrlItem;
  };
}

2.Seccond step - create object and call createUrls() method with similar implementation

const appRoutes = createUrls<IAppRoute>({
  auth: {
    login: EMPTY_URL_ITEM,
    account: {
      id: (id?: string) => EMPTY_URL_ITEM,
    },
  },
});

3. Example of usage.

axios.get(appRoutes.auth.account.id("e87a8340-1a81-4013-a8c8-c5ab8ec205ea")) // instead axios.get("/auth/check/e87a8340-1a81-4013-a8c8-c5ab8ec205ea")
...
describe("create-urls", () => {
  it("test urls", () => {
    expect(appRoutes.auth).toEqual("/auth");
    expect(appRoutes.auth.login).toEqual("/auth/login");
    expect(appRoutes.auth.account.id()).toEqual("/auth/check/:id");
    expect(appRoutes.auth.account.id("e87a8340-1a81-4013-a8c8-c5ab8ec205ea").toEqual("/auth/check/e87a8340-1a81-4013-a8c8-c5ab8ec205ea");
  });
});
0.1.6

8 months ago

0.1.5

8 months ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago