{"_id":"@adebsa2401/routes-tree-builder","name":"@adebsa2401/routes-tree-builder","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.1":{"name":"@adebsa2401/routes-tree-builder","version":"1.0.1","description":"Some helper functions to easily set up web projects routes schema","main":"./dist/cjs/index.js","module":"./dist/esm/index.js","types":"./dist/esm/index.d.ts","scripts":{"test":"jest","build":"npm run build:esm && npm run build:cjs","build:esm":"tsc","build:cjs":"tsc --module commonjs --outDir dist/cjs","lint":"eslint \"{**/*,*}.{js,ts,jsx,tsx}\"","prettier":"prettier --write \"{src,tests,example/src}/**/*.{js,ts,jsx,tsx}\"","prepare":"npm run build","prepublishOnly":"npm run prettier && npm run lint"},"repository":{"type":"git","url":"git+https://github.com/adebsa2401/routes-builder.git"},"author":{"name":"Ben Salès","url":"adebsa2401@gmail.com"},"license":"MIT","keywords":["routes","builder","react","reactjs","react-native","nextjs","gatsby","router","routing","schema","typescript","ts"],"devDependencies":{"@types/jest":"^29.5.11","@typescript-eslint/eslint-plugin":"^6.4.0","@typescript-eslint/parser":"^6.7.4","eslint":"^8.0.1","eslint-config-prettier":"^9.0.0","eslint-config-standard-with-typescript":"^43.0.1","eslint-plugin-import":"^2.25.2","eslint-plugin-n":"^15.0.0 || ^16.0.0 ","eslint-plugin-prettier":"^5.0.0","eslint-plugin-promise":"^6.0.0","jest":"^29.7.0","prettier":"^3.0.3","ts-jest":"^29.1.2","typescript":"*"},"_id":"@adebsa2401/routes-tree-builder@1.0.1","gitHead":"a3a096b613631adf615d0f5550c5b41bbcde5fdf","bugs":{"url":"https://github.com/adebsa2401/routes-builder/issues"},"homepage":"https://github.com/adebsa2401/routes-builder#readme","_nodeVersion":"21.7.1","_npmVersion":"10.8.1","dist":{"integrity":"sha512-MTwXWUgH1NxWqbccP8YO1waxuPBCpjZCobJR+/OgwazvDwBMaw20KPvLWDkfjz6ej/hi88oWasSVbz4iimlE4g==","shasum":"8da62d8bd8a988581018bfcca0249ecf09a408b1","tarball":"https://registry.npmjs.org/@adebsa2401/routes-tree-builder/-/routes-tree-builder-1.0.1.tgz","fileCount":10,"unpackedSize":50951,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDnxIhlfJDBxzam/DEG9oMW5zcuW9aUyxGiW6fnYsgLfQIgLLu2CxpCE132m93DQWgTcIPxfYZxMyMxP0u+UIK85xA="}]},"_npmUser":{"name":"adebsa2401","email":"adebsa2401@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/routes-tree-builder_1.0.1_1719315148319_0.08482731802839116"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-25T11:32:28.215Z","1.0.1":"2024-06-25T11:32:28.519Z","modified":"2024-06-25T11:32:28.810Z"},"maintainers":[{"name":"adebsa2401","email":"adebsa2401@gmail.com"}],"description":"Some helper functions to easily set up web projects routes schema","homepage":"https://github.com/adebsa2401/routes-builder#readme","keywords":["routes","builder","react","reactjs","react-native","nextjs","gatsby","router","routing","schema","typescript","ts"],"repository":{"type":"git","url":"git+https://github.com/adebsa2401/routes-builder.git"},"author":{"name":"Ben Salès","url":"adebsa2401@gmail.com"},"bugs":{"url":"https://github.com/adebsa2401/routes-builder/issues"},"license":"MIT","readme":"# Routes builder\n\nA set of utilities to set up routes schema for a web application.\n\n```ts\nimport {createRoutes} from \"@adebsa2401/routes-builder\";\n\nconst routes = createRoutes({\n  index: \"/\",\n  dashboard: {\n    index: \"/\",\n    profile: \"/profile\",\n  },\n});\n\nconsole.log(routes) // { index: \"/\", dashboard: { index: \"/dashboard\", profile: \"/dashboard/profile\" } }\n```\n\n# Installation\n\n```bash\nnpm install @adebsa2401/routes-builder\n# or\nyarn add @adebsa2401/routes-builder\n# or\npnpm add @adebsa2401/routes-builder\n```\n\n# Usage\n\n## `createRoutes`\n\n```ts\nimport {createRoutes} from \"@adebsa2401/routes-builder\";\n```\n\n```ts\nconst routes = createRoutes({\n  index: \"/\",\n  dashboard: {\n    index: \"/\",\n    profile: \"/profile\",\n  },\n});\n\nconsole.log(routes) // { index: \"/\", dashboard: { index: \"/dashboard\", profile: \"/dashboard/profile\" } }\n```\n\nBy default, the `createRoutes` function will use the `\"/\"` as the root path. You can change it by passing a second argument `basePath`.\n\n```ts\nconst routes = createRoutes(\n  {\n    index: \"/\",\n    dashboard: {\n      index: \"/\",\n      profile: \"/profile\",\n    },\n  },\n  \"/app\",\n);\n\nconsole.log(routes) // { index: \"/app\", dashboard: { index: \"/app/dashboard\", profile: \"/app/dashboard/profile\" } }\n```\n\nBy default, a block key is prepended to the path. You can disable it by using a `_basePath: \"\"` or `_basePath: \"/\"` attribute inside the block\n\n```ts\nconst routes = createRoutes({\n  index: \"/\",\n  auth: {\n    _basePath: \"\",\n    login: \"/login\",\n    register: \"/register\",\n  },\n});\n\nconsole.log(routes) // { index: \"/\", auth: { login: \"/login\", register: \"/register\" } }\n```\n\nYou can also set a custom block prefix by using the `_basePath` attribute.\n\n```ts\nconst routes = createRoutes({\n  index: \"/\",\n  auth: {\n    _basePath: \"/authentication\",\n    login: \"/login\",\n    register: \"/register\",\n  },\n});\n\nconsole.log(routes) // { index: \"/\", auth: { login: \"/authentication/login\", register: \"/authentication/register\" } }\n```\n\nYou can also set up dynamic routes by using functions.\n\n```ts\nconst routes = createRoutes({\n  index: \"/\",\n  dashboard: {\n    index: \"/\",\n    profile: \"/profile\",\n    user: (id: string) => `/user/${id}`,\n  },\n});\n\nconsole.log(routes) // { index: \"/\", dashboard: { index: \"/dashboard\", profile: \"/dashboard/profile\", user: (id: string) => `/dashboard/user/${id}` } }\n```\n\nAnd of course functions can also return blocks.\n\n```ts\nconst routes = createRoutes({\n  index: \"/\",\n  dashboard: {\n    index: \"/\",\n    profile: \"/profile\",\n    user: (id: string) => ({\n      _basePath: `/user/${id}`,\n      index: \"/\",\n      update: \"/update\",\n    }),\n  },\n});\n\nconsole.log(routes) // { index: \"/\", dashboard: { index: \"/dashboard\", profile: \"/dashboard/profile\", user: { index: \"/dashboard/user/:id\", update: \"/dashboard/user/:id/update\" } } }\n```\n\n## 👥 Author\n\n👤 **Ben Salès**\n\n- Email: [adebsa2401@gmail.com](mailto:adebsa2401@gmail.com)\n- GitHub: [@adebsa2401](https://github.com/adebsa2401)\n- LinkedIn: [adebsa](https://www.linkedin.com/in/adebsa)\n","readmeFilename":"README.md"}