{"id":21654639,"url":"https://github.com/localvoid/routekit","last_synced_at":"2025-04-11T21:13:50.466Z","repository":{"id":65474302,"uuid":"83103131","full_name":"localvoid/routekit","owner":"localvoid","description":":twisted_rightwards_arrows: RouteKit is a set of tools for generating efficient routers.","archived":false,"fork":false,"pushed_at":"2018-11-14T07:44:25.000Z","size":147,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T21:13:44.836Z","etag":null,"topics":["javascript","perfmatters","routekit","router","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/localvoid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-25T03:27:42.000Z","updated_at":"2019-03-09T20:19:58.000Z","dependencies_parsed_at":"2023-01-25T12:45:54.653Z","dependency_job_id":null,"html_url":"https://github.com/localvoid/routekit","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Froutekit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Froutekit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Froutekit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/localvoid%2Froutekit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/localvoid","download_url":"https://codeload.github.com/localvoid/routekit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480427,"owners_count":21110937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","perfmatters","routekit","router","typescript"],"created_at":"2024-11-25T08:28:35.009Z","updated_at":"2025-04-11T21:13:50.436Z","avatar_url":"https://github.com/localvoid.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [RouteKit](https://github.com/localvoid/routekit) \u0026middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/localvoid/routekit/blob/master/LICENSE) [![codecov](https://codecov.io/gh/localvoid/routekit/branch/master/graph/badge.svg)](https://codecov.io/gh/localvoid/routekit) [![CircleCI Status](https://circleci.com/gh/localvoid/routekit.svg?style=shield\u0026circle-token=:circle-token)](https://circleci.com/gh/localvoid/routekit) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/localvoid/routekit)\n\nRouteKit is a set of tools for generating lightweight and efficient routers.\n\n|packages         |NPM version                                                                                                          |\n|-----------------|---------------------------------------------------------------------------------------------------------------------|\n|routekit         |[![npm version](https://img.shields.io/npm/v/routekit.svg)](https://www.npmjs.com/package/routekit)                  |\n|routekit-resolver|[![npm version](https://img.shields.io/npm/v/routekit-resolver.svg)](https://www.npmjs.com/package/routekit-resolver)|\n\n## Installation\n\n```sh\n$ npm install -D routekit\n```\n\n## Usage Example\n\nCreate a routes file: `routes.build.js`\n\n```ts\n#!/usr/bin/env node\n\nimport { r, emitter } from \"routekit\";\n\nconst enum Location { Home, UserView, UserEdit }\n\nprocess.stdout.write(emitter()(\n  r(\"/\", Location.Home),\n  r(\"/user/:id\", Location.UserView),\n  r(\"/user/:id/edit\", Location.UserEdit),\n));\n```\n\nRun `routes.build.js` file\n\n```sh\n$ node routes.build.js \u003e routes.js\n```\n\nAnd it will generate `routes.js` file with a compact flattened trie.\n\n```js\nconst ROUTES = {\n  f: [35, 38, 33, 7],\n  p: [\"user/\", \"/edit\"],\n  s: [0, 1, 2],\n};\n```\n\n## Emmiter\n\nEmitter generates flattened tries that can be used by `routekit-resolver` for matching urls.\n\n```ts\nexport function emitter\u003cT\u003e(name = \"ROUTES\"): (...routes: Route\u003cT\u003e[]) =\u003e string;\nexport function injector\u003cT\u003e(src: string): (...routes: Route\u003cT\u003e[]) =\u003e string;\n```\n\n`inject` function injects code blocks into existing code using [incode](https://github.com/localvoid/incode) package.\nThis function is using `routekit` prefix to detect injectable regions.\n\n## Resolver\n\n### Installation\n\nNPM package `routekit-resolver` provides a commonjs, es2015 modules and TypeScript typings.\n\n```sh\nnpm install routekit-resolver\n```\n\n### Usage Example\n\n```js\nimport { resolve } from \"routekit-resolver\";\n\n// routekit:emit(\"routes\")\nconst ROUTES = {\n  f: [35, 38, 33, 7],\n  p: [\"user/\", \"/edit\"],\n  s: [0, 1, 2],\n};\n// routekit:end\n\nconst match = (path) =\u003e resolve(ROUTES, path);\n\nmatch(\"/user/123\");\n// {\n//   state: 1,\n//   vars: [\"123\"],\n// }\n```\n\n### API\n\n```ts\nexport interface ResolveResult\u003cT\u003e {\n  readonly state: T;\n  readonly vars: string[];\n}\n\nexport function resolve\u003cT\u003e(map: RouteMap\u003cT\u003e, path: string): ResolveResult\u003cT\u003e | null;\n```\n\n`resolve()` function has 2 parameters:\n\n- `map` is a flattened trie generated by routekit.\n- `path` is a path that should be resolved.\n\nWhen resolve function returns `null` value it means that no match was found.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalvoid%2Froutekit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flocalvoid%2Froutekit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flocalvoid%2Froutekit/lists"}