gg-tools-kit 1.0.1 → 1.0.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 +420 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
# 🛠️ GGToolsKit
|
|
2
|
+
|
|
3
|
+
A comprehensive Node.js toolkit providing utilities, security protections, and project initialization tools for Express applications.
|
|
4
|
+
|
|
5
|
+
## 📦 Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install gg-tools-kit
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🚀 Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import GGToolsKit from "gg-tools-kit";
|
|
15
|
+
|
|
16
|
+
// Initialize protections
|
|
17
|
+
const protections = new GGToolsKit.Protections();
|
|
18
|
+
app.use(protections.getAllMiddlewares());
|
|
19
|
+
|
|
20
|
+
// Use utilities
|
|
21
|
+
const fileSize = GGToolsKit.Utils.getFileSize("myfile.txt");
|
|
22
|
+
const today = GGToolsKit.Utils.today();
|
|
23
|
+
|
|
24
|
+
// Initialize a new backend project
|
|
25
|
+
GGToolsKit.Init.createFullProject(true); // TypeScript project
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 📚 Features
|
|
31
|
+
|
|
32
|
+
### 🔒 **Security Protections**
|
|
33
|
+
|
|
34
|
+
Complete security middleware suite for Express applications:
|
|
35
|
+
|
|
36
|
+
- **Compression**: Response compression with configurable options
|
|
37
|
+
- **Helmet**: Security headers protection
|
|
38
|
+
- **XSS Protection**: Cross-site scripting prevention
|
|
39
|
+
- **Logger**: Request logging with Morgan
|
|
40
|
+
|
|
41
|
+
### 🧰 **Utilities**
|
|
42
|
+
|
|
43
|
+
Comprehensive utility functions for common tasks:
|
|
44
|
+
|
|
45
|
+
- **File Operations**: Size calculation, type detection, extension extraction
|
|
46
|
+
- **Date & Time**: Formatted date and time functions
|
|
47
|
+
- **Audio/Video**: Duration calculation for media files
|
|
48
|
+
- **Array Operations**: Shuffle, dedupe, flatten, min/max, average
|
|
49
|
+
- **Request Data**: IP extraction, method, API path, user agent
|
|
50
|
+
|
|
51
|
+
### 🏗️ **Project Initialization**
|
|
52
|
+
|
|
53
|
+
Automated project setup with best practices:
|
|
54
|
+
|
|
55
|
+
- TypeScript or JavaScript project structure
|
|
56
|
+
- Automatic package installation
|
|
57
|
+
- Pre-configured security middleware
|
|
58
|
+
- Ready-to-use Express server
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 📖 API Documentation
|
|
63
|
+
|
|
64
|
+
### 🔒 Protections
|
|
65
|
+
|
|
66
|
+
#### Initialize Protections
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import GGToolsKit from "gg-tools-kit";
|
|
70
|
+
|
|
71
|
+
const protections = new GGToolsKit.Protections();
|
|
72
|
+
|
|
73
|
+
// Apply all middlewares at once
|
|
74
|
+
protections.getAllMiddlewares().forEach((middleware) => app.use(middleware));
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Configure Protections
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
protections.configure({
|
|
81
|
+
compression: {
|
|
82
|
+
threshold: 2048,
|
|
83
|
+
level: 6,
|
|
84
|
+
},
|
|
85
|
+
logger: {
|
|
86
|
+
format: "dev",
|
|
87
|
+
filePath: "./logs/access.log",
|
|
88
|
+
},
|
|
89
|
+
helmet: {
|
|
90
|
+
contentSecurityPolicy: {
|
|
91
|
+
directives: {
|
|
92
|
+
"default-src": ["'self'"],
|
|
93
|
+
"img-src": ["'self'", "data:", "https:"],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
xss: {
|
|
98
|
+
// XSS filter options
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### 🧰 Utils
|
|
106
|
+
|
|
107
|
+
#### File Operations
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
// Get file size
|
|
111
|
+
const size = GGToolsKit.Utils.getFileSize("myfile.txt", "MB");
|
|
112
|
+
// Returns: "2.45 MB"
|
|
113
|
+
|
|
114
|
+
// Get file extension
|
|
115
|
+
const ext = GGToolsKit.Utils.getFileExtension("photo.jpg");
|
|
116
|
+
// Returns: "jpg"
|
|
117
|
+
|
|
118
|
+
// Check file type
|
|
119
|
+
const isImage = GGToolsKit.Utils.isImageFile("photo.jpg");
|
|
120
|
+
const isVideo = GGToolsKit.Utils.isVideoFile("video.mp4");
|
|
121
|
+
const isAudio = GGToolsKit.Utils.isAudioFile("song.mp3");
|
|
122
|
+
const isDoc = GGToolsKit.Utils.isDocumentFile("doc.pdf");
|
|
123
|
+
const isArchive = GGToolsKit.Utils.isArchiveFile("file.zip");
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Supported file types:**
|
|
127
|
+
|
|
128
|
+
- **Images**: jpg, jpeg, png, gif, bmp, webp, tiff, svg
|
|
129
|
+
- **Videos**: mp4, avi, mov, wmv, flv, mkv, webm
|
|
130
|
+
- **Audio**: mp3, wav, flac, aac, ogg, m4a
|
|
131
|
+
- **Documents**: pdf, doc, docx, xls, xlsx, ppt, pptx, txt, rtf
|
|
132
|
+
- **Archives**: zip, rar, 7z, tar, gz, bz2
|
|
133
|
+
|
|
134
|
+
#### Date & Time
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// Get current date
|
|
138
|
+
const today = GGToolsKit.Utils.today();
|
|
139
|
+
// Returns: "2025/12/13"
|
|
140
|
+
|
|
141
|
+
const todayDashed = GGToolsKit.Utils.today("-");
|
|
142
|
+
// Returns: "2025-12-13"
|
|
143
|
+
|
|
144
|
+
// Get current time
|
|
145
|
+
const time = GGToolsKit.Utils.nowTime();
|
|
146
|
+
// Returns: "PM 09:30:45"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### Audio & Video Duration
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// Get audio duration
|
|
153
|
+
const audioDuration = await GGToolsKit.Utils.getAudioDuration("song.mp3");
|
|
154
|
+
// Returns: "03:45" or "01:23:45"
|
|
155
|
+
|
|
156
|
+
// Get video duration
|
|
157
|
+
const videoDuration = await GGToolsKit.Utils.getVideoDuration("video.mp4");
|
|
158
|
+
// Returns: "10:30" or "01:15:30"
|
|
159
|
+
|
|
160
|
+
// Install required libraries
|
|
161
|
+
GGToolsKit.Init.installAudioLibrary();
|
|
162
|
+
GGToolsKit.Init.installVideoLibrary();
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Request Data
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
app.post("/api/data", (req, res) => {
|
|
169
|
+
// Get client IP
|
|
170
|
+
const ip = GGToolsKit.Utils.getRequestIp(req);
|
|
171
|
+
|
|
172
|
+
// Get request method
|
|
173
|
+
const method = GGToolsKit.Utils.getRequestMethod(req);
|
|
174
|
+
|
|
175
|
+
// Get API endpoint
|
|
176
|
+
const api = GGToolsKit.Utils.getRequestApi(req);
|
|
177
|
+
|
|
178
|
+
// Get user agent
|
|
179
|
+
const userAgent = GGToolsKit.Utils.getRequestUserAgent(req);
|
|
180
|
+
|
|
181
|
+
// Get all info at once
|
|
182
|
+
const info = GGToolsKit.Utils.getReqInfos(req);
|
|
183
|
+
// Returns: { ip, method, api, userAgent }
|
|
184
|
+
|
|
185
|
+
res.json(info);
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
#### Array Operations
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
// Shuffle array
|
|
193
|
+
const shuffled = GGToolsKit.Utils.shuffleArray([1, 2, 3, 4, 5]);
|
|
194
|
+
|
|
195
|
+
// Remove duplicates
|
|
196
|
+
const unique = GGToolsKit.Utils.removeDuplicatesFromArray([1, 1, 2, 3, 3]);
|
|
197
|
+
// Returns: [1, 2, 3]
|
|
198
|
+
|
|
199
|
+
// Get random element
|
|
200
|
+
const random = GGToolsKit.Utils.getRandomElement([1, 2, 3, 4, 5]);
|
|
201
|
+
|
|
202
|
+
// Flatten nested array
|
|
203
|
+
const flat = GGToolsKit.Utils.flattenArray([[1, 2], [3, 4], [5]]);
|
|
204
|
+
// Returns: [1, 2, 3, 4, 5]
|
|
205
|
+
|
|
206
|
+
// Math operations
|
|
207
|
+
const max = GGToolsKit.Utils.maxFromArray([1, 5, 3, 9, 2]);
|
|
208
|
+
const min = GGToolsKit.Utils.minFromArray([1, 5, 3, 9, 2]);
|
|
209
|
+
const sum = GGToolsKit.Utils.sumArray([1, 2, 3, 4, 5]);
|
|
210
|
+
const avg = GGToolsKit.Utils.averageArray([1, 2, 3, 4, 5]);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
### 🏗️ Project Initialization
|
|
216
|
+
|
|
217
|
+
#### Create Full Project
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
// Create TypeScript project
|
|
221
|
+
GGToolsKit.Init.createFullProject(true, "/path/to/project");
|
|
222
|
+
|
|
223
|
+
// Create JavaScript project
|
|
224
|
+
GGToolsKit.Init.createFullProject(false, "/path/to/project");
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
This will:
|
|
228
|
+
|
|
229
|
+
- Create project structure (src, controllers, models, routes, middlewares, utils)
|
|
230
|
+
- Install all necessary packages
|
|
231
|
+
- Configure TypeScript (if selected)
|
|
232
|
+
- Setup package.json scripts
|
|
233
|
+
- Create a ready-to-run Express server
|
|
234
|
+
|
|
235
|
+
#### Manual Setup
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
// Only create folder structure
|
|
239
|
+
GGToolsKit.Init.initBackendProject(true, "/path/to/project");
|
|
240
|
+
|
|
241
|
+
// Only install packages
|
|
242
|
+
GGToolsKit.Init.installPackages(true, "/path/to/project");
|
|
243
|
+
|
|
244
|
+
// Install media libraries
|
|
245
|
+
GGToolsKit.Init.installAudioLibrary();
|
|
246
|
+
GGToolsKit.Init.installVideoLibrary();
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Project Structure
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
📁 project/
|
|
253
|
+
├── 📁 src/
|
|
254
|
+
│ ├── 📄 server.ts (or server.js)
|
|
255
|
+
│ ├── 📁 controllers/
|
|
256
|
+
│ ├── 📁 models/
|
|
257
|
+
│ ├── 📁 routes/
|
|
258
|
+
│ ├── 📁 middlewares/
|
|
259
|
+
│ └── 📁 utils/
|
|
260
|
+
├── 📄 package.json
|
|
261
|
+
└── 📄 tsconfig.json (TypeScript only)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
#### Installed Packages
|
|
265
|
+
|
|
266
|
+
**Core packages:**
|
|
267
|
+
|
|
268
|
+
- express
|
|
269
|
+
- compression@1.7.4
|
|
270
|
+
- helmet
|
|
271
|
+
- morgan
|
|
272
|
+
- xss
|
|
273
|
+
- dotenv
|
|
274
|
+
- cors
|
|
275
|
+
|
|
276
|
+
**TypeScript packages (if selected):**
|
|
277
|
+
|
|
278
|
+
- @types/express
|
|
279
|
+
- @types/compression
|
|
280
|
+
- @types/morgan
|
|
281
|
+
- @types/cors
|
|
282
|
+
- @types/node
|
|
283
|
+
- typescript
|
|
284
|
+
- ts-node
|
|
285
|
+
- ts-node-dev
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## 🎯 Complete Example
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
import express from "express";
|
|
293
|
+
import GGToolsKit from "gg-tools-kit";
|
|
294
|
+
|
|
295
|
+
const app = express();
|
|
296
|
+
app.use(express.json());
|
|
297
|
+
|
|
298
|
+
// Initialize and apply all protections
|
|
299
|
+
const protections = new GGToolsKit.Protections();
|
|
300
|
+
protections.getAllMiddlewares().forEach((middleware) => app.use(middleware));
|
|
301
|
+
|
|
302
|
+
// Example route using utilities
|
|
303
|
+
app.post("/upload", (req, res) => {
|
|
304
|
+
const filePath = req.body.filePath;
|
|
305
|
+
|
|
306
|
+
// Get file information
|
|
307
|
+
const fileSize = GGToolsKit.Utils.getFileSize(filePath, "MB");
|
|
308
|
+
const fileExt = GGToolsKit.Utils.getFileExtension(filePath);
|
|
309
|
+
const isImage = GGToolsKit.Utils.isImageFile(filePath);
|
|
310
|
+
|
|
311
|
+
// Get request information
|
|
312
|
+
const requestInfo = GGToolsKit.Utils.getReqInfos(req);
|
|
313
|
+
|
|
314
|
+
// Get current date and time
|
|
315
|
+
const uploadDate = GGToolsKit.Utils.today();
|
|
316
|
+
const uploadTime = GGToolsKit.Utils.nowTime();
|
|
317
|
+
|
|
318
|
+
res.json({
|
|
319
|
+
file: { size: fileSize, extension: fileExt, isImage },
|
|
320
|
+
request: requestInfo,
|
|
321
|
+
timestamp: { date: uploadDate, time: uploadTime },
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
app.listen(3000, () => {
|
|
326
|
+
console.log("Server running on port 3000");
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## 🔧 Configuration Examples
|
|
333
|
+
|
|
334
|
+
### Custom Logger
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
const protections = new GGToolsKit.Protections();
|
|
338
|
+
|
|
339
|
+
protections.configure({
|
|
340
|
+
logger: {
|
|
341
|
+
format: "combined",
|
|
342
|
+
filePath: "./logs/access.log",
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### Custom Compression
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
protections.configure({
|
|
351
|
+
compression: {
|
|
352
|
+
threshold: 2048, // 2KB minimum
|
|
353
|
+
level: 9, // Maximum compression
|
|
354
|
+
memLevel: 9,
|
|
355
|
+
chunkSize: 32768,
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Custom Helmet Settings
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
protections.configure({
|
|
364
|
+
helmet: {
|
|
365
|
+
contentSecurityPolicy: {
|
|
366
|
+
directives: {
|
|
367
|
+
"default-src": ["'self'"],
|
|
368
|
+
"script-src": ["'self'", "'unsafe-inline'"],
|
|
369
|
+
"style-src": ["'self'", "'unsafe-inline'"],
|
|
370
|
+
"img-src": ["'self'", "data:", "https:"],
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
---
|
|
378
|
+
|
|
379
|
+
## 📝 TypeScript Support
|
|
380
|
+
|
|
381
|
+
Full TypeScript support with type definitions included:
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
import GGToolsKit from "gg-tools-kit";
|
|
385
|
+
import { Request, Response } from "express";
|
|
386
|
+
|
|
387
|
+
app.get("/info", (req: Request, res: Response) => {
|
|
388
|
+
const info = GGToolsKit.Utils.getReqInfos(req);
|
|
389
|
+
res.json(info);
|
|
390
|
+
});
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
---
|
|
394
|
+
|
|
395
|
+
## 🤝 Contributing
|
|
396
|
+
|
|
397
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
398
|
+
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
## 📄 License
|
|
402
|
+
|
|
403
|
+
ISC © MohenedGG
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## 🔗 Links
|
|
408
|
+
|
|
409
|
+
- **GitHub**: [MohenedGG/GGToolsKit](https://github.com/MohenedGG/GGToolsKit)
|
|
410
|
+
- **npm**: [gg-tools-kit](https://www.npmjs.com/package/gg-tools-kit)
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
## 📧 Support
|
|
415
|
+
|
|
416
|
+
For issues and questions, please open an issue on GitHub.
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
**Made with ❤️ by MohenedGG**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gg-tools-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A Node.js toolkit for utilities and protections",
|
|
5
5
|
"main": "dist/GGToolsKit.js",
|
|
6
6
|
"types": "dist/GGToolsKit.d.ts",
|
|
@@ -13,14 +13,15 @@
|
|
|
13
13
|
"author": "MohenedGG",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"type": "commonjs",
|
|
16
|
-
"files": [
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
17
19
|
"dependencies": {
|
|
18
20
|
"compression": "^1.7.4",
|
|
19
21
|
"cookie-parser": "^1.4.7",
|
|
20
22
|
"cors": "^2.8.5",
|
|
21
23
|
"dotenv": "^17.2.3",
|
|
22
24
|
"express": "^5.2.1",
|
|
23
|
-
"express-compression": "^1.0.2",
|
|
24
25
|
"get-video-duration": "^5.0.0",
|
|
25
26
|
"helmet": "^8.1.0",
|
|
26
27
|
"hpp": "^0.2.3",
|