frontend-hamroun 1.2.62 → 1.2.64
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 +244 -49
- package/package.json +1 -1
package/README.md
CHANGED
@@ -4,10 +4,6 @@
|
|
4
4
|
<img src="https://drive.google.com/uc?export=view&id=15VsMSNDhWAfV_R6ZWJltOJd-RMs9UH_y" alt="Frontend Hamroun Logo" width="300">
|
5
5
|
</p>
|
6
6
|
|
7
|
-
<p align="center">
|
8
|
-
<code style="font-size: 24px; color: #4A90E2; background-color: transparent">{ Frontend Hamroun }</code>
|
9
|
-
</p>
|
10
|
-
|
11
7
|
A lightweight full-stack JavaScript framework with Virtual DOM and hooks implementation
|
12
8
|
|
13
9
|
[](https://www.npmjs.com/package/frontend-hamroun)
|
@@ -15,15 +11,32 @@ A lightweight full-stack JavaScript framework with Virtual DOM and hooks impleme
|
|
15
11
|
[](https://www.npmjs.com/package/frontend-hamroun)
|
16
12
|
[](LICENSE)
|
17
13
|
|
18
|
-
##
|
14
|
+
## 📋 Table of Contents
|
15
|
+
|
16
|
+
- [Installation](#installation)
|
17
|
+
- [Quick Start](#quick-start)
|
18
|
+
- [Basic Usage](#basic-usage)
|
19
|
+
- [Features](#features)
|
20
|
+
- [Client-side Features](#client-side-features)
|
21
|
+
- [Server-Side Features](#server-side-features)
|
22
|
+
- [Server-Side Rendering](#server-side-rendering)
|
23
|
+
- [Performance Features](#performance-features)
|
24
|
+
- [CLI Tools](#cli-tools)
|
25
|
+
- [TypeScript Support](#typescript-support)
|
26
|
+
- [Browser Compatibility](#browser-compatibility)
|
27
|
+
- [Documentation](#documentation)
|
28
|
+
- [License](#license)
|
29
|
+
|
30
|
+
## 🚀 Installation
|
19
31
|
|
20
32
|
```bash
|
21
33
|
npm install frontend-hamroun
|
22
34
|
```
|
23
35
|
|
24
|
-
## Quick Start
|
36
|
+
## 🏁 Quick Start
|
25
37
|
|
26
|
-
|
38
|
+
<details>
|
39
|
+
<summary><b>Create a new project using CLI (Click to expand)</b></summary>
|
27
40
|
|
28
41
|
```bash
|
29
42
|
# Using the create-frontend-app command
|
@@ -40,8 +53,21 @@ cd my-app
|
|
40
53
|
npm install
|
41
54
|
npm run dev
|
42
55
|
```
|
56
|
+
</details>
|
57
|
+
|
58
|
+
<details>
|
59
|
+
<summary><b>Add to an existing project (Click to expand)</b></summary>
|
43
60
|
|
44
|
-
|
61
|
+
```bash
|
62
|
+
# Install the package
|
63
|
+
npm install frontend-hamroun
|
64
|
+
|
65
|
+
# Import components in your code
|
66
|
+
import { render, useState } from 'frontend-hamroun';
|
67
|
+
```
|
68
|
+
</details>
|
69
|
+
|
70
|
+
## 💻 Basic Usage
|
45
71
|
|
46
72
|
```jsx
|
47
73
|
import { render, useState } from 'frontend-hamroun';
|
@@ -59,23 +85,30 @@ function App() {
|
|
59
85
|
render(<App />, document.getElementById('root'));
|
60
86
|
```
|
61
87
|
|
62
|
-
## Features
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
88
|
+
## ✨ Features
|
89
|
+
|
90
|
+
<table>
|
91
|
+
<tr>
|
92
|
+
<td><b>🔍 Lightweight Core</b><br>Under 5KB gzipped</td>
|
93
|
+
<td><b>🌐 Full-Stack</b><br>Client and server in one</td>
|
94
|
+
<td><b>⚡ Virtual DOM</b><br>Efficient rendering</td>
|
95
|
+
</tr>
|
96
|
+
<tr>
|
97
|
+
<td><b>🪝 Hooks API</b><br>Complete hook system</td>
|
98
|
+
<td><b>📊 Context API</b><br>Simple state management</td>
|
99
|
+
<td><b>🖥️ SSR</b><br>Server-side rendering</td>
|
100
|
+
</tr>
|
101
|
+
<tr>
|
102
|
+
<td><b>🗄️ Database</b><br>Multiple DB support</td>
|
103
|
+
<td><b>🔐 Authentication</b><br>Built-in JWT</td>
|
104
|
+
<td><b>🧩 TypeScript</b><br>Full type definitions</td>
|
105
|
+
</tr>
|
106
|
+
</table>
|
107
|
+
|
108
|
+
## 🧩 Client-side Features
|
109
|
+
|
110
|
+
<details open>
|
111
|
+
<summary><b>Component Development</b></summary>
|
79
112
|
|
80
113
|
```jsx
|
81
114
|
import { useState, useEffect } from 'frontend-hamroun';
|
@@ -97,16 +130,66 @@ function Counter() {
|
|
97
130
|
);
|
98
131
|
}
|
99
132
|
```
|
133
|
+
</details>
|
134
|
+
|
135
|
+
<details>
|
136
|
+
<summary><b>Hooks API</b></summary>
|
137
|
+
|
138
|
+
### useState
|
139
|
+
```jsx
|
140
|
+
const [count, setCount] = useState(0);
|
141
|
+
setCount(count + 1); // Direct update
|
142
|
+
setCount(prev => prev + 1); // Functional update
|
143
|
+
```
|
144
|
+
|
145
|
+
### useEffect
|
146
|
+
```jsx
|
147
|
+
useEffect(() => {
|
148
|
+
// Effect logic
|
149
|
+
const subscription = api.subscribe();
|
150
|
+
|
151
|
+
return () => {
|
152
|
+
// Cleanup logic
|
153
|
+
subscription.unsubscribe();
|
154
|
+
};
|
155
|
+
}, [dependency]); // Dependency array
|
156
|
+
```
|
100
157
|
|
101
|
-
###
|
158
|
+
### useMemo
|
159
|
+
```jsx
|
160
|
+
const expensiveValue = useMemo(() => {
|
161
|
+
return computeExpensiveValue(a, b);
|
162
|
+
}, [a, b]); // Recomputes only when a or b changes
|
163
|
+
```
|
102
164
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
165
|
+
### useRef
|
166
|
+
```jsx
|
167
|
+
const inputRef = useRef(null);
|
168
|
+
// Access the DOM element directly
|
169
|
+
useEffect(() => {
|
170
|
+
inputRef.current.focus();
|
171
|
+
}, []);
|
172
|
+
return <input ref={inputRef} />;
|
173
|
+
```
|
108
174
|
|
109
|
-
###
|
175
|
+
### useErrorBoundary
|
176
|
+
```jsx
|
177
|
+
const [error, resetError] = useErrorBoundary();
|
178
|
+
|
179
|
+
if (error) {
|
180
|
+
return (
|
181
|
+
<div className="error-boundary">
|
182
|
+
<h2>Something went wrong</h2>
|
183
|
+
<p>{error.message}</p>
|
184
|
+
<button onClick={resetError}>Try again</button>
|
185
|
+
</div>
|
186
|
+
);
|
187
|
+
}
|
188
|
+
```
|
189
|
+
</details>
|
190
|
+
|
191
|
+
<details>
|
192
|
+
<summary><b>Context API</b></summary>
|
110
193
|
|
111
194
|
```jsx
|
112
195
|
// Create context
|
@@ -123,7 +206,7 @@ function App() {
|
|
123
206
|
<button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>
|
124
207
|
Toggle theme
|
125
208
|
</button>
|
126
|
-
</
|
209
|
+
</ThemeContext.Provider>
|
127
210
|
);
|
128
211
|
}
|
129
212
|
|
@@ -133,10 +216,12 @@ function Header() {
|
|
133
216
|
return <header className={theme}><h1>My App</h1></header>;
|
134
217
|
}
|
135
218
|
```
|
219
|
+
</details>
|
136
220
|
|
137
|
-
## Server-Side Features
|
221
|
+
## 🖥️ Server-Side Features
|
138
222
|
|
139
|
-
|
223
|
+
<details>
|
224
|
+
<summary><b>Express Server Integration</b></summary>
|
140
225
|
|
141
226
|
```js
|
142
227
|
import { server } from 'frontend-hamroun/server';
|
@@ -159,8 +244,10 @@ const app = await server.createServer({
|
|
159
244
|
await app.start();
|
160
245
|
console.log('Server running at http://localhost:3000');
|
161
246
|
```
|
247
|
+
</details>
|
162
248
|
|
163
|
-
|
249
|
+
<details>
|
250
|
+
<summary><b>API Routes</b></summary>
|
164
251
|
|
165
252
|
```js
|
166
253
|
// api/users.js - Automatically mapped to /api/users
|
@@ -180,8 +267,87 @@ export async function post(req, res) {
|
|
180
267
|
res.status(201).json(result);
|
181
268
|
}
|
182
269
|
```
|
270
|
+
</details>
|
271
|
+
|
272
|
+
<details>
|
273
|
+
<summary><b>Database Support (MongoDB, MySQL, PostgreSQL)</b></summary>
|
274
|
+
|
275
|
+
#### MongoDB Example
|
276
|
+
|
277
|
+
```js
|
278
|
+
export async function get(req, res) {
|
279
|
+
const { id } = req.params;
|
280
|
+
const user = await req.db.collection('users').findOne({
|
281
|
+
_id: new ObjectId(id)
|
282
|
+
});
|
283
|
+
|
284
|
+
if (!user) {
|
285
|
+
return res.status(404).json({ error: 'User not found' });
|
286
|
+
}
|
287
|
+
|
288
|
+
res.json(user);
|
289
|
+
}
|
290
|
+
```
|
291
|
+
|
292
|
+
#### MySQL Example
|
293
|
+
|
294
|
+
```js
|
295
|
+
export async function get(req, res) {
|
296
|
+
const [users] = await req.db.execute(
|
297
|
+
'SELECT * FROM users WHERE active = ?',
|
298
|
+
[true]
|
299
|
+
);
|
300
|
+
res.json(users);
|
301
|
+
}
|
302
|
+
```
|
303
|
+
|
304
|
+
#### PostgreSQL Example
|
305
|
+
|
306
|
+
```js
|
307
|
+
export async function get(req, res) {
|
308
|
+
const result = await req.db.query(
|
309
|
+
'SELECT * FROM users WHERE role = $1',
|
310
|
+
['admin']
|
311
|
+
);
|
312
|
+
res.json(result.rows);
|
313
|
+
}
|
314
|
+
```
|
315
|
+
</details>
|
316
|
+
|
317
|
+
<details>
|
318
|
+
<summary><b>Authentication</b></summary>
|
319
|
+
|
320
|
+
```js
|
321
|
+
// api/auth/login.js
|
322
|
+
export async function post(req, res) {
|
323
|
+
const { username, password } = req.body;
|
324
|
+
const user = await req.db.collection('users').findOne({ username });
|
325
|
+
|
326
|
+
if (!user || !await req.auth.comparePasswords(password, user.password)) {
|
327
|
+
return res.status(401).json({ error: 'Invalid credentials' });
|
328
|
+
}
|
329
|
+
|
330
|
+
const token = req.auth.generateToken(user);
|
331
|
+
res.json({
|
332
|
+
token,
|
333
|
+
user: { id: user._id, username: user.username }
|
334
|
+
});
|
335
|
+
}
|
336
|
+
|
337
|
+
// Protected route
|
338
|
+
// api/profile.js
|
339
|
+
export async function get(req, res) {
|
340
|
+
// req.auth.requireAuth middleware automatically added
|
341
|
+
// req.user contains the authenticated user
|
342
|
+
res.json(req.user);
|
343
|
+
}
|
344
|
+
```
|
345
|
+
</details>
|
183
346
|
|
184
|
-
## Server-Side Rendering
|
347
|
+
## 🔄 Server-Side Rendering
|
348
|
+
|
349
|
+
<details>
|
350
|
+
<summary><b>SSR Implementation</b></summary>
|
185
351
|
|
186
352
|
```jsx
|
187
353
|
// Server-side
|
@@ -212,10 +378,13 @@ import App from './App';
|
|
212
378
|
|
213
379
|
hydrate(<App url={window.location.pathname} />, document.getElementById('root'));
|
214
380
|
```
|
381
|
+
</details>
|
382
|
+
|
383
|
+
## ⚡ Performance Features
|
215
384
|
|
216
|
-
|
385
|
+
<details>
|
386
|
+
<summary><b>Batch Updates</b></summary>
|
217
387
|
|
218
|
-
### Batch Updates
|
219
388
|
Group multiple state updates together to prevent unnecessary re-renders:
|
220
389
|
|
221
390
|
```jsx
|
@@ -230,10 +399,12 @@ function handleSubmit() {
|
|
230
399
|
});
|
231
400
|
}
|
232
401
|
```
|
402
|
+
</details>
|
233
403
|
|
234
|
-
## CLI Tools
|
404
|
+
## 🛠️ CLI Tools
|
235
405
|
|
236
|
-
|
406
|
+
<details>
|
407
|
+
<summary><b>Project Creation and Component Generation</b></summary>
|
237
408
|
|
238
409
|
```bash
|
239
410
|
# Create a new project
|
@@ -248,16 +419,31 @@ npx frontend-hamroun add:page Home
|
|
248
419
|
# Generate an API route
|
249
420
|
npx frontend-hamroun add:api users --methods=get,post,put,delete
|
250
421
|
```
|
422
|
+
</details>
|
251
423
|
|
252
|
-
|
253
|
-
|
254
|
-
Choose from multiple project templates:
|
424
|
+
<details>
|
425
|
+
<summary><b>Project Templates</b></summary>
|
255
426
|
|
256
427
|
1. **Basic App**: Client-side SPA with essential features
|
428
|
+
- Quick setup
|
429
|
+
- No build step in development
|
430
|
+
- Perfect for learning the framework
|
431
|
+
|
257
432
|
2. **SSR Template**: Server-side rendering with hydration
|
433
|
+
- SEO-friendly
|
434
|
+
- Fast initial load
|
435
|
+
- Express server included
|
436
|
+
|
258
437
|
3. **Fullstack App**: Complete solution with API, authentication, and database
|
438
|
+
- API routes included
|
439
|
+
- Database integration
|
440
|
+
- Authentication ready
|
441
|
+
</details>
|
259
442
|
|
260
|
-
## TypeScript Support
|
443
|
+
## 📝 TypeScript Support
|
444
|
+
|
445
|
+
<details>
|
446
|
+
<summary><b>Type-Safe Components</b></summary>
|
261
447
|
|
262
448
|
```tsx
|
263
449
|
import { useState } from 'frontend-hamroun';
|
@@ -282,15 +468,24 @@ function UserProfile({ id, name, email }: UserProps) {
|
|
282
468
|
);
|
283
469
|
}
|
284
470
|
```
|
471
|
+
</details>
|
285
472
|
|
286
|
-
## Browser Compatibility
|
473
|
+
## 🌐 Browser Compatibility
|
287
474
|
|
288
|
-
Frontend Hamroun works in all modern browsers
|
475
|
+
Frontend Hamroun works in all modern browsers:
|
476
|
+
- Chrome, Firefox, Safari, Edge (latest 2 versions)
|
477
|
+
- IE11 with appropriate transpilation and polyfills
|
289
478
|
|
290
|
-
## Documentation
|
479
|
+
## 📚 Documentation
|
291
480
|
|
292
481
|
For complete documentation, visit our [GitHub repository](https://github.com/hamroun/frontend-hamroun).
|
293
482
|
|
294
|
-
## License
|
483
|
+
## 📄 License
|
295
484
|
|
296
485
|
MIT © Hamroun
|
486
|
+
|
487
|
+
---
|
488
|
+
|
489
|
+
<p align="center">
|
490
|
+
<a href="#-installation">⬆️ Back to top</a>
|
491
|
+
</p>
|