Initial commit from create-turbo

This commit is contained in:
TZGyn
2026-05-09 15:27:01 +08:00
commit 22064d4bc4
482 changed files with 15482 additions and 0 deletions
@@ -0,0 +1,9 @@
export const getParamsFromFilePath = (path: string) => {
const params = path.match(/\[(.*?)\]/gu) || []
return params.map((param) => {
return param.replaceAll(
/\[(.*?)\]/gu,
(_: string, match: string) => `${match}`,
)
})
}
@@ -0,0 +1,30 @@
// https://github.com/wobsoriano/elysia-autoroutes/blob/main/src/utils/transformPathToUrl.ts#L4C31-L4C31
export function transformToUrl(path: string) {
return (
path
// Clean the url extensions
.replace(/\.(ts|tsx|js|jsx|mjs|cjs)$/u, '')
// Fix windows slashes
.replaceAll('\\', '/')
// Handle wild card based routes - users/[...id]/profile.ts -> users/*/profile
.replaceAll(/\[\.\.\..*\]/gu, '*')
// Handle generic square bracket based routes - users/[id]/index.ts -> users/:id
.replaceAll(
/\[(.*?)\]/gu,
(_: string, match: string) => `:${match}`,
)
.replace(/\/?\((.*)\)/, '')
// Handle the case when multiple parameters are present in one file
// users / [id] - [name].ts to users /: id -:name and users / [id] - [name] / [age].ts to users /: id -: name /: age
.replaceAll(']-[', '-:')
.replaceAll(']/', '/')
.replaceAll(/\[|\]/gu, '')
// remove potential route methods in file name
.replace(
/(\.(?<method>connect|delete|get|head|options|patch|post|put|trace))?(\.(?<env>dev|prod|prerender))?$/,
'',
)
// remove index from end of path
.replace(/\/?index$/, '')
)
}