Skip to content

Commit

Permalink
🎉 feat: add commonjs support
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed May 15, 2023
1 parent 40f44f2 commit 4d1dc71
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.1.4 - 15 May 2023
fix:
- add commonjs support

# 0.1.3 - 6 May 2023
feat:
- using charCodeAt
Expand Down
75 changes: 75 additions & 0 deletions benchmarks/libs/itty-router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// import { Router } from 'itty-router'
// import { title, now, print, operations } from '../utils'

// const router = Router()

// title('itty-router')

// const routes = [
// { method: 'GET', url: '/user' },
// { method: 'GET', url: '/user/comments' },
// { method: 'GET', url: '/user/avatar' },
// { method: 'GET', url: '/user/lookup/username/:username' },
// { method: 'GET', url: '/user/lookup/email/:address' },
// { method: 'GET', url: '/event/:id' },
// { method: 'GET', url: '/event/:id/comments' },
// { method: 'POST', url: '/event/:id/comment' },
// { method: 'GET', url: '/map/:location/events' },
// { method: 'GET', url: '/status' },
// { method: 'GET', url: '/very/deeply/nested/route/hello/there' },
// { method: 'GET', url: '/static/*a' }
// ]

// function noop() {}
// var i = 0
// var time = 0

// routes.forEach((route) => {
// // @ts-ignore
// router[route.method](route.url, noop)
// })

// time = now()
// let route = { method: 'GET', url: '/user' }
// for (i = 0; i < operations; i++) {
// router.handle(route)
// }
// print('short static:', time)

// time = now()
// route = { method: 'GET', url: '/user/comments' }
// for (i = 0; i < operations; i++) {
// router.handle(route)
// }
// print('static with same radix:', time)

// time = now()
// route = { method: 'GET', url: '/user/lookup/username/john' }
// for (i = 0; i < operations; i++) {
// router.handle(route)
// }
// print('dynamic route:', time)

// time = now()
// route = { method: 'GET', url: '/event/abcd1234/comments' }
// for (i = 0; i < operations; i++) {
// router.handle(route)
// }
// print('mixed static dynamic:', time)

// time = now()
// route = {
// method: 'GET',
// url: '/very/deeply/nested/route/hello/there'
// }
// for (i = 0; i < operations; i++) {
// router.handle(route)
// }
// print('long static:', time)

// time = now()
// route = { method: 'GET', url: '/static/index.html' }
// for (i = 0; i < operations; i++) {
// router.handle(route)
// }
// print('wildcard:', time)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "memoirist",
"version": "0.1.3",
"version": "0.1.4",
"description": "Elysia's Radix Tree router for fast matching dynamic parameters",
"author": {
"name": "saltyAom",
Expand Down Expand Up @@ -30,7 +30,7 @@
"test": "bun wiptest",
"build": "rimraf dist && pnpm build:esm && pnpm build:cjs",
"build:cjs": "swc src --config-file .cjs.swcrc -d dist/cjs && tsc --project tsconfig.esm.json",
"build:esm": "swc src -d dist && tsc --project tsconfig.esm.json",
"build:esm": "swc src --config-file .esm.swcrc -d dist && tsc --project tsconfig.esm.json",
"benchmark": "bun benchmarks/index.ts",
"benchmark:memoirist": "bun benchmarks/libs/memoirist.ts",
"release": "npm run build && npm run test && npm publish --access public"
Expand Down

0 comments on commit 4d1dc71

Please sign in to comment.