princejs 1.7.1 β 1.7.2
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 +36 -126
- 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
|
|
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,33 +71,19 @@ 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
|
-
---
|
|
143
|
-
|
|
144
|
-
## π¦ Installation
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
npm install princejs
|
|
148
|
-
# or
|
|
149
|
-
bun add princejs
|
|
150
|
-
# or
|
|
151
|
-
yarn add princejs
|
|
152
|
-
```
|
|
153
|
-
|
|
154
87
|
---
|
|
155
88
|
|
|
156
89
|
## π― Full Example
|
|
@@ -163,47 +96,29 @@ import { cache, ai, upload } from "princejs/helpers";
|
|
|
163
96
|
import { cron } from "princejs/scheduler";
|
|
164
97
|
import { z } from "zod";
|
|
165
98
|
|
|
166
|
-
const app = prince(true);
|
|
99
|
+
const app = prince(true);
|
|
167
100
|
|
|
168
|
-
// Middleware
|
|
169
101
|
app.use(cors());
|
|
170
102
|
app.use(logger());
|
|
171
103
|
app.use(rateLimit({ max: 100, window: 60 }));
|
|
172
104
|
|
|
173
|
-
// Validation
|
|
174
105
|
app.use(validate(z.object({ name: z.string() })));
|
|
175
106
|
|
|
176
|
-
|
|
177
|
-
app.get("/", () => ({
|
|
178
|
-
message: "Welcome to PrinceJS",
|
|
179
|
-
version: "3.3.1"
|
|
180
|
-
}));
|
|
107
|
+
app.get("/", () => ({ message: "Welcome to PrinceJS" }));
|
|
181
108
|
|
|
182
|
-
app.get("/users/:id", (req) => ({
|
|
183
|
-
id: req.params.id,
|
|
184
|
-
name: "John Doe"
|
|
185
|
-
}));
|
|
109
|
+
app.get("/users/:id", (req) => ({ id: req.params.id }));
|
|
186
110
|
|
|
187
|
-
// New: Cache
|
|
188
111
|
app.get("/data", cache(60)(() => ({ time: Date.now() })));
|
|
189
112
|
|
|
190
|
-
// New: AI
|
|
191
113
|
app.post("/ai", async (req) => ({ reply: await ai(req.body.q) }));
|
|
192
114
|
|
|
193
|
-
|
|
194
|
-
app.post("/upload", upload(), (req) => ({
|
|
195
|
-
files: Object.keys(req.files || {}),
|
|
196
|
-
body: req.body
|
|
197
|
-
}));
|
|
115
|
+
app.post("/upload", upload(), (req) => ({ files: Object.keys(req.files || {}) }));
|
|
198
116
|
|
|
199
|
-
// New: Cron
|
|
200
117
|
cron("*/1 * * * *", () => console.log("PrinceJS heartbeat"));
|
|
201
118
|
|
|
202
|
-
// WebSocket
|
|
203
119
|
app.ws("/chat", {
|
|
204
120
|
open: (ws) => ws.send("Welcome!"),
|
|
205
|
-
message: (ws, msg) => ws.send(`Echo: ${msg}`)
|
|
206
|
-
close: () => console.log("Disconnected")
|
|
121
|
+
message: (ws, msg) => ws.send(`Echo: ${msg}`)
|
|
207
122
|
});
|
|
208
123
|
|
|
209
124
|
app.listen(3000);
|
|
@@ -211,6 +126,18 @@ app.listen(3000);
|
|
|
211
126
|
|
|
212
127
|
---
|
|
213
128
|
|
|
129
|
+
## π¦ Installation
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npm install princejs
|
|
133
|
+
# or
|
|
134
|
+
bun add princejs
|
|
135
|
+
# or
|
|
136
|
+
yarn add princejs
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
214
141
|
## π Documentation
|
|
215
142
|
|
|
216
143
|
Visit: **princejs.vercel.app**
|
|
@@ -219,8 +146,6 @@ Visit: **princejs.vercel.app**
|
|
|
219
146
|
|
|
220
147
|
## π€ Contributing
|
|
221
148
|
|
|
222
|
-
Issues and PRs welcome!
|
|
223
|
-
|
|
224
149
|
```bash
|
|
225
150
|
git clone https://github.com/MatthewTheCoder1218/princejs
|
|
226
151
|
cd princejs
|
|
@@ -230,35 +155,20 @@ bun test
|
|
|
230
155
|
|
|
231
156
|
---
|
|
232
157
|
|
|
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
158
|
## β Star This Repo
|
|
249
159
|
|
|
250
160
|
If PrinceJS helped you, star the repo!
|
|
251
161
|
|
|
252
|
-
GitHub: [github.com/MatthewTheCoder1218/princejs](https://github.com/MatthewTheCoder1218/princejs)
|
|
162
|
+
GitHub: [https://github.com/MatthewTheCoder1218/princejs](https://github.com/MatthewTheCoder1218/princejs)
|
|
253
163
|
|
|
254
164
|
---
|
|
255
165
|
|
|
256
166
|
## π Links
|
|
257
167
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
168
|
+
* npm: [https://www.npmjs.com/package/princejs](https://www.npmjs.com/package/princejs)
|
|
169
|
+
* GitHub: [https://github.com/MatthewTheCoder1218/princejs](https://github.com/MatthewTheCoder1218/princejs)
|
|
170
|
+
* Twitter: [https://twitter.com/Lil_Prince_1218](https://twitter.com/Lil_Prince_1218)
|
|
261
171
|
|
|
262
172
|
---
|
|
263
173
|
|
|
264
|
-
**PrinceJS: Small in size. Giant in
|
|
174
|
+
**PrinceJS: Small in size. Giant in capability. π**
|