princejs 1.7.1 β 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +45 -122
- package/dist/create.js +1 -1
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
# PrinceJS
|
|
1
|
+
# π **PrinceJS**
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### β‘ Ultra-clean, modern & minimal Bun web framework. Among the top three in performance.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
6
9
|
|
|
7
10
|
---
|
|
8
11
|
|
|
9
|
-
##
|
|
12
|
+
## π Quick Start
|
|
10
13
|
|
|
11
14
|
```bash
|
|
12
15
|
bun create princejs my-app
|
|
@@ -31,60 +34,6 @@ app.listen(3000);
|
|
|
31
34
|
|
|
32
35
|
---
|
|
33
36
|
|
|
34
|
-
## βοΈ Size War (Gzipped β Real World)
|
|
35
|
-
|
|
36
|
-
| Framework | Gzipped | Minified | vs PrinceJS |
|
|
37
|
-
| ------------ | ---------- | -------- | --------------- |
|
|
38
|
-
| **PrinceJS** | **2.8 kB** | 7.8 kB | β |
|
|
39
|
-
| Hono | 7.3 kB | 18.7 kB | **2.6Γ bigger** |
|
|
40
|
-
| Elysia | 62.5 kB | 245 kB | **22Γ bigger** |
|
|
41
|
-
|
|
42
|
-
PrinceJS fits in a tweet. Elysia needs a ZIP file.
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## β‘ Benchmarks (autocannon -c 100 -d 30)
|
|
47
|
-
|
|
48
|
-
**Windows 11 β’ November 15, 2025 β’ 100 connections β’ 30 seconds**
|
|
49
|
-
**Route:** `GET /users/:id`
|
|
50
|
-
|
|
51
|
-
| Rank | Framework | Req/s | Requests (30s) | Throughput |
|
|
52
|
-
| --------------- | ---------- | ----- | -------------- | ---------- |
|
|
53
|
-
| π₯ **PrinceJS** | **19,200** | 576k | 2.34 MB/s | |
|
|
54
|
-
| π₯ Hono | 16,212 | 486k | 1.98 MB/s | |
|
|
55
|
-
| π₯ Elysia | 15,862 | 476k | 1.94 MB/s | |
|
|
56
|
-
| 4οΈβ£ Express | 9,325 | 280k | 1.84 MB/s | |
|
|
57
|
-
|
|
58
|
-
### Summary
|
|
59
|
-
|
|
60
|
-
* PrinceJS beats **Elysia by 21%** (3,338 more req/s)
|
|
61
|
-
* PrinceJS beats **Hono by 18%** (2,988 more req/s)
|
|
62
|
-
* PrinceJS beats **Express by 106%** (over 2Γ faster)
|
|
63
|
-
|
|
64
|
-
> PrinceJS is the FASTEST framework under 10 kB. Period.
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
## π₯ Why PrinceJS Wins
|
|
69
|
-
|
|
70
|
-
### 1. **Trie-Based Router (Cached)**
|
|
71
|
-
|
|
72
|
-
Most frameworks rebuild routes on every request. PrinceJS builds once and caches.
|
|
73
|
-
|
|
74
|
-
### 2. **Zero Overhead Middleware**
|
|
75
|
-
|
|
76
|
-
Middleware tracking prevents duplicate execution. No wasted cycles.
|
|
77
|
-
|
|
78
|
-
### 3. **Optimized for Bun**
|
|
79
|
-
|
|
80
|
-
Native `Bun.serve()` with WebSocket support. No abstraction layers.
|
|
81
|
-
|
|
82
|
-
### 4. **Smart Body Parsing**
|
|
83
|
-
|
|
84
|
-
Only parses body when needed. GET requests skip parsing entirely.
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
37
|
## π§° Features
|
|
89
38
|
|
|
90
39
|
```ts
|
|
@@ -94,7 +43,7 @@ import { z } from "zod";
|
|
|
94
43
|
|
|
95
44
|
app
|
|
96
45
|
.use(cors())
|
|
97
|
-
.use(logger(
|
|
46
|
+
.use(logger())
|
|
98
47
|
.use(rateLimit({ max: 100, window: 60 }))
|
|
99
48
|
.use(serve({ root: "./public" }))
|
|
100
49
|
.use(validate(z.object({
|
|
@@ -110,9 +59,7 @@ app
|
|
|
110
59
|
* Rate Limiting
|
|
111
60
|
* Static Files
|
|
112
61
|
|
|
113
|
-
### β Validation
|
|
114
|
-
|
|
115
|
-
* Zod schema validation
|
|
62
|
+
### β Validation (Zod)
|
|
116
63
|
|
|
117
64
|
### β WebSocket Support
|
|
118
65
|
|
|
@@ -124,32 +71,31 @@ app
|
|
|
124
71
|
|
|
125
72
|
---
|
|
126
73
|
|
|
127
|
-
## New Tree
|
|
74
|
+
## New TreeβShakable Features
|
|
128
75
|
|
|
129
76
|
```ts
|
|
130
77
|
import { cache, email, upload } from "princejs/helpers";
|
|
131
78
|
import { cron, openapi } from "princejs/scheduler";
|
|
132
79
|
```
|
|
133
80
|
|
|
134
|
-
* `cache(60)(handler)` β In
|
|
135
|
-
* `email(to, subject, html)` β
|
|
136
|
-
* `upload()` β
|
|
137
|
-
* `cron("*/2 * * * *", task)` β Cron
|
|
81
|
+
* `cache(60)(handler)` β Inβmemory cache
|
|
82
|
+
* `email(to, subject, html)` β Email helper
|
|
83
|
+
* `upload()` β Oneβline file upload
|
|
84
|
+
* `cron("*/2 * * * *", task)` β Cron jobs
|
|
138
85
|
* `openapi({ title, version })` β Auto docs
|
|
139
86
|
|
|
140
|
-
**Tree-shakable = only what you import gets bundled**
|
|
141
|
-
|
|
142
87
|
---
|
|
143
88
|
|
|
144
|
-
##
|
|
89
|
+
## Performance With Oha (oha -c 100 -z 30s)
|
|
145
90
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
91
|
+
| Framework | Req/s | Total |
|
|
92
|
+
|-----------|----------------|--------|
|
|
93
|
+
| Elysia | 25,312 req/s | 759k |
|
|
94
|
+
| Hono | 22,124 req/s | 664k |
|
|
95
|
+
| PrinceJS | 21,748 req/s | 653k |
|
|
96
|
+
| Express | 9,325 req/s | 280k |
|
|
97
|
+
|
|
98
|
+
### Among the top three
|
|
153
99
|
|
|
154
100
|
---
|
|
155
101
|
|
|
@@ -163,47 +109,29 @@ import { cache, ai, upload } from "princejs/helpers";
|
|
|
163
109
|
import { cron } from "princejs/scheduler";
|
|
164
110
|
import { z } from "zod";
|
|
165
111
|
|
|
166
|
-
const app = prince(true);
|
|
112
|
+
const app = prince(true);
|
|
167
113
|
|
|
168
|
-
// Middleware
|
|
169
114
|
app.use(cors());
|
|
170
115
|
app.use(logger());
|
|
171
116
|
app.use(rateLimit({ max: 100, window: 60 }));
|
|
172
117
|
|
|
173
|
-
// Validation
|
|
174
118
|
app.use(validate(z.object({ name: z.string() })));
|
|
175
119
|
|
|
176
|
-
|
|
177
|
-
app.get("/", () => ({
|
|
178
|
-
message: "Welcome to PrinceJS",
|
|
179
|
-
version: "3.3.1"
|
|
180
|
-
}));
|
|
120
|
+
app.get("/", () => ({ message: "Welcome to PrinceJS" }));
|
|
181
121
|
|
|
182
|
-
app.get("/users/:id", (req) => ({
|
|
183
|
-
id: req.params.id,
|
|
184
|
-
name: "John Doe"
|
|
185
|
-
}));
|
|
122
|
+
app.get("/users/:id", (req) => ({ id: req.params.id }));
|
|
186
123
|
|
|
187
|
-
// New: Cache
|
|
188
124
|
app.get("/data", cache(60)(() => ({ time: Date.now() })));
|
|
189
125
|
|
|
190
|
-
// New: AI
|
|
191
126
|
app.post("/ai", async (req) => ({ reply: await ai(req.body.q) }));
|
|
192
127
|
|
|
193
|
-
|
|
194
|
-
app.post("/upload", upload(), (req) => ({
|
|
195
|
-
files: Object.keys(req.files || {}),
|
|
196
|
-
body: req.body
|
|
197
|
-
}));
|
|
128
|
+
app.post("/upload", upload(), (req) => ({ files: Object.keys(req.files || {}) }));
|
|
198
129
|
|
|
199
|
-
// New: Cron
|
|
200
130
|
cron("*/1 * * * *", () => console.log("PrinceJS heartbeat"));
|
|
201
131
|
|
|
202
|
-
// WebSocket
|
|
203
132
|
app.ws("/chat", {
|
|
204
133
|
open: (ws) => ws.send("Welcome!"),
|
|
205
|
-
message: (ws, msg) => ws.send(`Echo: ${msg}`)
|
|
206
|
-
close: () => console.log("Disconnected")
|
|
134
|
+
message: (ws, msg) => ws.send(`Echo: ${msg}`)
|
|
207
135
|
});
|
|
208
136
|
|
|
209
137
|
app.listen(3000);
|
|
@@ -211,6 +139,18 @@ app.listen(3000);
|
|
|
211
139
|
|
|
212
140
|
---
|
|
213
141
|
|
|
142
|
+
## π¦ Installation
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
npm install princejs
|
|
146
|
+
# or
|
|
147
|
+
bun add princejs
|
|
148
|
+
# or
|
|
149
|
+
yarn add princejs
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
214
154
|
## π Documentation
|
|
215
155
|
|
|
216
156
|
Visit: **princejs.vercel.app**
|
|
@@ -219,8 +159,6 @@ Visit: **princejs.vercel.app**
|
|
|
219
159
|
|
|
220
160
|
## π€ Contributing
|
|
221
161
|
|
|
222
|
-
Issues and PRs welcome!
|
|
223
|
-
|
|
224
162
|
```bash
|
|
225
163
|
git clone https://github.com/MatthewTheCoder1218/princejs
|
|
226
164
|
cd princejs
|
|
@@ -230,35 +168,20 @@ bun test
|
|
|
230
168
|
|
|
231
169
|
---
|
|
232
170
|
|
|
233
|
-
## π³π¬ Built in Nigeria
|
|
234
|
-
|
|
235
|
-
Made by **@Lil_Prince_1218 β Age 13**
|
|
236
|
-
*"2.8 kB. 19,200 req/s. The fastest framework under 10 kB."*
|
|
237
|
-
|
|
238
|
-
Inspired by the greats (Express, Hono, Elysia) but built to win.
|
|
239
|
-
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
## π License
|
|
243
|
-
|
|
244
|
-
MIT Β© 2025 **Matthew Michael**
|
|
245
|
-
|
|
246
|
-
---
|
|
247
|
-
|
|
248
171
|
## β Star This Repo
|
|
249
172
|
|
|
250
173
|
If PrinceJS helped you, star the repo!
|
|
251
174
|
|
|
252
|
-
GitHub: [github.com/MatthewTheCoder1218/princejs](https://github.com/MatthewTheCoder1218/princejs)
|
|
175
|
+
GitHub: [https://github.com/MatthewTheCoder1218/princejs](https://github.com/MatthewTheCoder1218/princejs)
|
|
253
176
|
|
|
254
177
|
---
|
|
255
178
|
|
|
256
179
|
## π Links
|
|
257
180
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
181
|
+
* npm: [https://www.npmjs.com/package/princejs](https://www.npmjs.com/package/princejs)
|
|
182
|
+
* GitHub: [https://github.com/MatthewTheCoder1218/princejs](https://github.com/MatthewTheCoder1218/princejs)
|
|
183
|
+
* Twitter: [https://twitter.com/Lil_Prince_1218](https://twitter.com/Lil_Prince_1218)
|
|
261
184
|
|
|
262
185
|
---
|
|
263
186
|
|
|
264
|
-
**PrinceJS: Small in size. Giant in
|
|
187
|
+
**PrinceJS: Small in size. Giant in capability. π**
|
package/dist/create.js
CHANGED
|
@@ -7,7 +7,7 @@ import { join } from "path";
|
|
|
7
7
|
var name = Bun.argv[2];
|
|
8
8
|
if (!name) {
|
|
9
9
|
console.error("\u274C Error: Please provide a project name");
|
|
10
|
-
console.log("Usage:
|
|
10
|
+
console.log("Usage: bun create-princejs <project-name>");
|
|
11
11
|
process.exit(1);
|
|
12
12
|
}
|
|
13
13
|
if (existsSync(name)) {
|