@onurege3467/zerohelper 8.0.0 → 9.0.0
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 +292 -612
- package/dist/database/IDatabase.d.ts +77 -0
- package/dist/database/IDatabase.js +10 -0
- package/dist/database/cacheWrapper.d.ts +31 -0
- package/dist/database/cacheWrapper.js +228 -0
- package/dist/database/index.d.ts +11 -0
- package/dist/database/index.js +94 -0
- package/dist/database/json.d.ts +32 -0
- package/dist/database/json.js +210 -0
- package/dist/database/migration.d.ts +21 -0
- package/dist/database/migration.js +97 -0
- package/dist/database/mongodb.d.ts +24 -0
- package/dist/database/mongodb.js +153 -0
- package/dist/database/mysql.d.ts +31 -0
- package/dist/database/mysql.js +385 -0
- package/dist/database/pg.d.ts +30 -0
- package/dist/database/pg.js +300 -0
- package/dist/database/redis.d.ts +23 -0
- package/dist/database/redis.js +157 -0
- package/dist/database/sqlite.d.ts +25 -0
- package/dist/database/sqlite.js +273 -0
- package/dist/database/types.d.ts +76 -0
- package/dist/database/types.js +2 -0
- package/dist/database/zpack.d.ts +59 -0
- package/dist/database/zpack.js +462 -0
- package/dist/functions/index.d.ts +183 -0
- package/dist/functions/index.js +636 -0
- package/dist/functions/temp_isphone.d.ts +1 -0
- package/dist/functions/temp_isphone.js +7 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +45 -0
- package/dist/test.d.ts +1 -0
- package/dist/test.js +55 -0
- package/dist/test_zpack.d.ts +1 -0
- package/dist/test_zpack.js +64 -0
- package/package.json +23 -6
- package/database/IDatabase.js +0 -92
- package/database/cacheWrapper.js +0 -585
- package/database/index.js +0 -72
- package/database/json.js +0 -281
- package/database/migration.js +0 -227
- package/database/mongodb.js +0 -203
- package/database/mysql.js +0 -526
- package/database/pg.js +0 -527
- package/database/redis.js +0 -342
- package/database/sqlite.js +0 -551
- package/functions/index.js +0 -705
- package/index.js +0 -7
package/functions/index.js
DELETED
|
@@ -1,705 +0,0 @@
|
|
|
1
|
-
const crypto = require("crypto");
|
|
2
|
-
const jwt = require("jsonwebtoken");
|
|
3
|
-
const bcrypt = require("bcrypt");
|
|
4
|
-
|
|
5
|
-
// Random İşlemler
|
|
6
|
-
function makeUniqueId() {
|
|
7
|
-
return Date.now().toString(36) + Math.random().toString(36).substr(2);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function randomArray(arr) {
|
|
11
|
-
return arr[Math.floor(Math.random() * arr.length)];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function randomText(length = 8) {
|
|
15
|
-
const characters =
|
|
16
|
-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
17
|
-
return Array.from({ length }, () =>
|
|
18
|
-
characters.charAt(Math.floor(Math.random() * characters.length))
|
|
19
|
-
).join("");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function randomNumber(min = 0, max = 9999999) {
|
|
23
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function randomEmoji() {
|
|
27
|
-
const emojiler = [
|
|
28
|
-
"😄",
|
|
29
|
-
"😃",
|
|
30
|
-
"😀",
|
|
31
|
-
"😊",
|
|
32
|
-
"😉",
|
|
33
|
-
"😍",
|
|
34
|
-
"😘",
|
|
35
|
-
"😚",
|
|
36
|
-
"😜",
|
|
37
|
-
"😝",
|
|
38
|
-
"😛",
|
|
39
|
-
"😁",
|
|
40
|
-
];
|
|
41
|
-
return emojiler[Math.floor(Math.random() * emojiler.length)];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function randomHex() {
|
|
45
|
-
return `#${Array.from({ length: 6 }, () =>
|
|
46
|
-
"0123456789ABCDEF".charAt(Math.floor(Math.random() * 16))
|
|
47
|
-
).join("")}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function randomFloat(min, max) {
|
|
51
|
-
return Math.random() * (max - min) + min;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// String İşlemleri
|
|
55
|
-
function titleCase(sentence) {
|
|
56
|
-
return sentence
|
|
57
|
-
.toLowerCase()
|
|
58
|
-
.split(" ")
|
|
59
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
60
|
-
.join(" ");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Array İşlemleri
|
|
64
|
-
function shuffleArray(array) {
|
|
65
|
-
let currentIndex = array.length;
|
|
66
|
-
while (currentIndex !== 0) {
|
|
67
|
-
const randomIndex = Math.floor(Math.random() * currentIndex);
|
|
68
|
-
currentIndex--;
|
|
69
|
-
[array[currentIndex], array[randomIndex]] = [
|
|
70
|
-
array[randomIndex],
|
|
71
|
-
array[currentIndex],
|
|
72
|
-
];
|
|
73
|
-
}
|
|
74
|
-
return array;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function flattenArray(arr) {
|
|
78
|
-
return arr.reduce(
|
|
79
|
-
(flat, toFlatten) =>
|
|
80
|
-
flat.concat(
|
|
81
|
-
Array.isArray(toFlatten) ? flattenArray(toFlatten) : toFlatten
|
|
82
|
-
),
|
|
83
|
-
[]
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function removeFalsyValues(arr) {
|
|
88
|
-
return arr.filter(Boolean);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function groupBy(arr, key) {
|
|
92
|
-
return arr.reduce((result, item) => {
|
|
93
|
-
const group = item[key];
|
|
94
|
-
if (!result[group]) result[group] = [];
|
|
95
|
-
result[group].push(item);
|
|
96
|
-
return result;
|
|
97
|
-
}, {});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function pluck(arr, key) {
|
|
101
|
-
return arr.map((item) => item[key]);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function sortBy(arr, key) {
|
|
105
|
-
return [...arr].sort((a, b) => (a[key] > b[key] ? 1 : -1));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Object İşlemleri
|
|
109
|
-
function filterObjectByKey(obj, keys) {
|
|
110
|
-
return Object.fromEntries(
|
|
111
|
-
Object.entries(obj).filter(([key]) => keys.includes(key))
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function deepMerge(obj1, obj2) {
|
|
116
|
-
const isObject = (obj) => obj && typeof obj === "object";
|
|
117
|
-
return Object.keys({ ...obj1, ...obj2 }).reduce((result, key) => {
|
|
118
|
-
result[key] =
|
|
119
|
-
isObject(obj1[key]) && isObject(obj2[key])
|
|
120
|
-
? deepMerge(obj1[key], obj2[key])
|
|
121
|
-
: obj2[key] ?? obj1[key];
|
|
122
|
-
return result;
|
|
123
|
-
}, {});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Şifreleme ve Güvenlik
|
|
127
|
-
function getKeyFromSecret(secret) {
|
|
128
|
-
// Use a fixed salt for simplicity in testing. In production, use a unique salt per encryption.
|
|
129
|
-
const salt = Buffer.from('some_fixed_salt_for_testing_only', 'utf8');
|
|
130
|
-
return crypto.pbkdf2Sync(secret, salt, 100000, 32, 'sha512'); // 32 bytes for AES-256
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function encryptText(text, secret) {
|
|
134
|
-
const key = getKeyFromSecret(secret);
|
|
135
|
-
const iv = crypto.randomBytes(16); // Initialization vector
|
|
136
|
-
const cipher = crypto.createCipheriv("aes-256-cbc", key, iv);
|
|
137
|
-
let encrypted = cipher.update(text, "utf8", "hex");
|
|
138
|
-
encrypted += cipher.final("hex");
|
|
139
|
-
return { encryptedText: encrypted, iv: iv.toString('hex') };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function decryptText(encryptedText, secret, ivHex) {
|
|
143
|
-
const key = getKeyFromSecret(secret);
|
|
144
|
-
const iv = Buffer.from(ivHex, 'hex');
|
|
145
|
-
const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
|
|
146
|
-
let decrypted = decipher.update(encryptedText, "hex", "utf8");
|
|
147
|
-
decrypted += decipher.final("utf8");
|
|
148
|
-
return decrypted;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function hashPassword(password) {
|
|
152
|
-
const saltRounds = 10;
|
|
153
|
-
return bcrypt.hashSync(password, saltRounds);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function verifyPassword(password, hash) {
|
|
157
|
-
return bcrypt.compareSync(password, hash);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function generateJWT(payload, secret) {
|
|
161
|
-
return jwt.sign(payload, secret, { expiresIn: "1h" });
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function verifyJWT(token, secret) {
|
|
165
|
-
try {
|
|
166
|
-
return jwt.verify(token, secret);
|
|
167
|
-
} catch {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function generateSalt() {
|
|
173
|
-
return crypto.randomBytes(16).toString("hex");
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function generateRandomString(length) {
|
|
177
|
-
const characters =
|
|
178
|
-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
179
|
-
return Array.from({ length }, () =>
|
|
180
|
-
characters.charAt(Math.floor(Math.random() * characters.length))
|
|
181
|
-
).join("");
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function validateUUID(uuid) {
|
|
185
|
-
const uuidRegex =
|
|
186
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
187
|
-
return uuidRegex.test(uuid);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function isPasswordStrong(password) {
|
|
191
|
-
const strongPasswordRegex =
|
|
192
|
-
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
|
|
193
|
-
return strongPasswordRegex.test(password);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Matematiksel İşlemler
|
|
197
|
-
function mean(arr) {
|
|
198
|
-
if (!arr.length) return 0;
|
|
199
|
-
return arr.reduce((sum, num) => sum + num, 0) / arr.length;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function median(arr) {
|
|
203
|
-
if (!arr.length) return 0;
|
|
204
|
-
const sorted = [...arr].sort((a, b) => a - b);
|
|
205
|
-
const mid = Math.floor(sorted.length / 2);
|
|
206
|
-
return sorted.length % 2 !== 0
|
|
207
|
-
? sorted[mid]
|
|
208
|
-
: (sorted[mid - 1] + sorted[mid]) / 2;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function variance(arr) {
|
|
212
|
-
if (!arr.length) return 0;
|
|
213
|
-
const avg = mean(arr);
|
|
214
|
-
return arr.reduce((sum, num) => sum + Math.pow(num - avg, 2), 0) / arr.length;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function standardDeviation(arr) {
|
|
218
|
-
return Math.sqrt(variance(arr));
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function sum(arr) {
|
|
222
|
-
return arr.reduce((total, num) => total + num, 0);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function max(arr) {
|
|
226
|
-
return Math.max(...arr);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function min(arr) {
|
|
230
|
-
return Math.min(...arr);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function range(start, end) {
|
|
234
|
-
if (start > end) return [];
|
|
235
|
-
return Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function isPrime(num) {
|
|
239
|
-
if (num <= 1) return false;
|
|
240
|
-
if (num <= 3) return true;
|
|
241
|
-
if (num % 2 === 0 || num % 3 === 0) return false;
|
|
242
|
-
for (let i = 5; i * i <= num; i += 6) {
|
|
243
|
-
if (num % i === 0 || num % (i + 2) === 0) return false;
|
|
244
|
-
}
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
// Tarih ve Saat İşlemleri
|
|
248
|
-
function formatDate(date, format = "YYYY-MM-DD") {
|
|
249
|
-
const options = {
|
|
250
|
-
year: "numeric",
|
|
251
|
-
month: "2-digit",
|
|
252
|
-
day: "2-digit",
|
|
253
|
-
hour: "2-digit",
|
|
254
|
-
minute: "2-digit",
|
|
255
|
-
second: "2-digit",
|
|
256
|
-
};
|
|
257
|
-
const formattedDate = new Intl.DateTimeFormat("en-US", options).format(date);
|
|
258
|
-
const [month, day, year, hour, minute, second] = formattedDate.match(/\d+/g);
|
|
259
|
-
|
|
260
|
-
return format
|
|
261
|
-
.replace("YYYY", year)
|
|
262
|
-
.replace("MM", month)
|
|
263
|
-
.replace("DD", day)
|
|
264
|
-
.replace("HH", hour)
|
|
265
|
-
.replace("mm", minute)
|
|
266
|
-
.replace("ss", second);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function dateDifference(date1, date2) {
|
|
270
|
-
const diffTime = Math.abs(date2 - date1);
|
|
271
|
-
return Math.ceil(diffTime / (1000 * 60 * 60 * 24)); // Gün cinsinden fark
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function addDays(date, days) {
|
|
275
|
-
const result = new Date(date);
|
|
276
|
-
result.setDate(result.getDate() + days);
|
|
277
|
-
return result;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function subtractDays(date, days) {
|
|
281
|
-
const result = new Date(date);
|
|
282
|
-
result.setDate(result.getDate() - days);
|
|
283
|
-
return result;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function combination(n, r) {
|
|
287
|
-
return factorial(n) / (factorial(r) * factorial(n - r));
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function permutation(n, r) {
|
|
291
|
-
return factorial(n) / factorial(n - r);
|
|
292
|
-
}
|
|
293
|
-
const https = require("https");
|
|
294
|
-
const http = require("http");
|
|
295
|
-
|
|
296
|
-
function fetchData(url) {
|
|
297
|
-
return new Promise((resolve, reject) => {
|
|
298
|
-
const client = url.startsWith("https") ? https : http;
|
|
299
|
-
|
|
300
|
-
client
|
|
301
|
-
.get(url, (response) => {
|
|
302
|
-
let data = "";
|
|
303
|
-
|
|
304
|
-
// Gelen veriyi parça parça topluyoruz
|
|
305
|
-
response.on("data", (chunk) => {
|
|
306
|
-
data += chunk;
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// Veri tamamen alındığında çözümleme yapıyoruz
|
|
310
|
-
response.on("end", () => {
|
|
311
|
-
try {
|
|
312
|
-
resolve(JSON.parse(data));
|
|
313
|
-
} catch (error) {
|
|
314
|
-
resolve(data); // JSON değilse düz metin döndür
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
})
|
|
318
|
-
.on("error", (error) => {
|
|
319
|
-
reject(error);
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function postData(url, data) {
|
|
325
|
-
return new Promise((resolve, reject) => {
|
|
326
|
-
const client = url.startsWith("https") ? https : http;
|
|
327
|
-
const parsedUrl = new URL(url);
|
|
328
|
-
|
|
329
|
-
const options = {
|
|
330
|
-
hostname: parsedUrl.hostname,
|
|
331
|
-
port: parsedUrl.port || (url.startsWith("https") ? 443 : 80),
|
|
332
|
-
path: parsedUrl.pathname,
|
|
333
|
-
method: "POST",
|
|
334
|
-
headers: {
|
|
335
|
-
"Content-Type": "application/json",
|
|
336
|
-
"Content-Length": Buffer.byteLength(JSON.stringify(data)),
|
|
337
|
-
},
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
const req = client.request(options, (response) => {
|
|
341
|
-
let responseData = "";
|
|
342
|
-
|
|
343
|
-
response.on("data", (chunk) => {
|
|
344
|
-
responseData += chunk;
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
response.on("end", () => {
|
|
348
|
-
try {
|
|
349
|
-
resolve(JSON.parse(responseData));
|
|
350
|
-
} catch (error) {
|
|
351
|
-
resolve(responseData); // JSON değilse düz metin döndür
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
req.on("error", (error) => {
|
|
357
|
-
reject(error);
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
// Gönderilecek veriyi yazıyoruz
|
|
361
|
-
req.write(JSON.stringify(data));
|
|
362
|
-
req.end();
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
function generateSlug(text) {
|
|
367
|
-
return text
|
|
368
|
-
.toLowerCase()
|
|
369
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
370
|
-
.replace(/^-+|-+$/g, "");
|
|
371
|
-
}
|
|
372
|
-
function wordCount(text) {
|
|
373
|
-
return text.trim().split(/\s+/).length;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// Validasyon İşlemleri
|
|
377
|
-
function isEmail(email) {
|
|
378
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
379
|
-
return emailRegex.test(email);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function isPhone(phone) {
|
|
383
|
-
const phoneRegex = /^[\+]?[1-9][\d]{0,15}$/;
|
|
384
|
-
return phoneRegex.test(phone.replace(/[\s\-\(\)]/g, ''));
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function isURL(url) {
|
|
388
|
-
try {
|
|
389
|
-
new URL(url);
|
|
390
|
-
return true;
|
|
391
|
-
} catch {
|
|
392
|
-
return false;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
function sanitizeHTML(html) {
|
|
397
|
-
return html
|
|
398
|
-
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
|
|
399
|
-
.replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi, '')
|
|
400
|
-
.replace(/javascript:/gi, '')
|
|
401
|
-
.replace(/on\w+\s*=/gi, '');
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
function validateCreditCard(cardNumber) {
|
|
405
|
-
// Luhn algoritması
|
|
406
|
-
const cleanNumber = cardNumber.replace(/\D/g, '');
|
|
407
|
-
if (cleanNumber.length < 13 || cleanNumber.length > 19) return false;
|
|
408
|
-
|
|
409
|
-
let sum = 0;
|
|
410
|
-
let isEven = false;
|
|
411
|
-
|
|
412
|
-
for (let i = cleanNumber.length - 1; i >= 0; i--) {
|
|
413
|
-
let digit = parseInt(cleanNumber[i]);
|
|
414
|
-
|
|
415
|
-
if (isEven) {
|
|
416
|
-
digit *= 2;
|
|
417
|
-
if (digit > 9) digit -= 9;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
sum += digit;
|
|
421
|
-
isEven = !isEven;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
return sum % 10 === 0;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function validateSchema(data, schema) {
|
|
428
|
-
const errors = [];
|
|
429
|
-
|
|
430
|
-
for (const [key, rules] of Object.entries(schema)) {
|
|
431
|
-
const value = data[key];
|
|
432
|
-
|
|
433
|
-
if (rules.required && (value === undefined || value === null || value === '')) {
|
|
434
|
-
errors.push(`${key} alanı zorunludur`);
|
|
435
|
-
continue;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
if (value !== undefined && value !== null) {
|
|
439
|
-
if (rules.type && typeof value !== rules.type) {
|
|
440
|
-
errors.push(`${key} alanı ${rules.type} tipinde olmalıdır`);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
if (rules.minLength && value.length < rules.minLength) {
|
|
444
|
-
errors.push(`${key} en az ${rules.minLength} karakter olmalıdır`);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
if (rules.maxLength && value.length > rules.maxLength) {
|
|
448
|
-
errors.push(`${key} en fazla ${rules.maxLength} karakter olmalıdır`);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
if (rules.pattern && !rules.pattern.test(value)) {
|
|
452
|
-
errors.push(`${key} geçerli formatta değil`);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
if (rules.min && value < rules.min) {
|
|
456
|
-
errors.push(`${key} en az ${rules.min} olmalıdır`);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
if (rules.max && value > rules.max) {
|
|
460
|
-
errors.push(`${key} en fazla ${rules.max} olmalıdır`);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return {
|
|
466
|
-
isValid: errors.length === 0,
|
|
467
|
-
errors
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
function sanitizeInput(input, options = {}) {
|
|
472
|
-
if (typeof input !== 'string') return input;
|
|
473
|
-
|
|
474
|
-
let sanitized = input;
|
|
475
|
-
|
|
476
|
-
if (options.trim !== false) {
|
|
477
|
-
sanitized = sanitized.trim();
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
if (options.removeHTML) {
|
|
481
|
-
sanitized = sanitizeHTML(sanitized);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
if (options.escape) {
|
|
485
|
-
sanitized = sanitized
|
|
486
|
-
.replace(/&/g, '&')
|
|
487
|
-
.replace(/</g, '<')
|
|
488
|
-
.replace(/>/g, '>')
|
|
489
|
-
.replace(/"/g, '"')
|
|
490
|
-
.replace(/'/g, ''');
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
return sanitized;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// Logger İşlemleri
|
|
497
|
-
class Logger {
|
|
498
|
-
constructor(options = {}) {
|
|
499
|
-
this.level = options.level || 'info';
|
|
500
|
-
this.enableColors = options.enableColors !== false;
|
|
501
|
-
this.enableTimestamp = options.enableTimestamp !== false;
|
|
502
|
-
this.logFile = options.logFile || null;
|
|
503
|
-
this.levels = {
|
|
504
|
-
error: 0,
|
|
505
|
-
warn: 1,
|
|
506
|
-
info: 2,
|
|
507
|
-
debug: 3
|
|
508
|
-
};
|
|
509
|
-
this.colors = {
|
|
510
|
-
error: '\x1b[31m', // Red
|
|
511
|
-
warn: '\x1b[33m', // Yellow
|
|
512
|
-
info: '\x1b[36m', // Cyan
|
|
513
|
-
debug: '\x1b[35m', // Magenta
|
|
514
|
-
reset: '\x1b[0m'
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
shouldLog(level) {
|
|
519
|
-
return this.levels[level] <= this.levels[this.level];
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
formatMessage(level, message, data) {
|
|
523
|
-
let formatted = '';
|
|
524
|
-
|
|
525
|
-
if (this.enableTimestamp) {
|
|
526
|
-
formatted += `[${new Date().toISOString()}] `;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
if (this.enableColors) {
|
|
530
|
-
formatted += `${this.colors[level]}[${level.toUpperCase()}]${this.colors.reset} `;
|
|
531
|
-
} else {
|
|
532
|
-
formatted += `[${level.toUpperCase()}] `;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
formatted += message;
|
|
536
|
-
|
|
537
|
-
if (data !== undefined) {
|
|
538
|
-
formatted += ' ' + (typeof data === 'object' ? JSON.stringify(data, null, 2) : data);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
return formatted;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
writeToFile(message) {
|
|
545
|
-
if (this.logFile) {
|
|
546
|
-
const fs = require('fs');
|
|
547
|
-
const timestamp = new Date().toISOString();
|
|
548
|
-
const logEntry = `${timestamp} ${message}\n`;
|
|
549
|
-
|
|
550
|
-
try {
|
|
551
|
-
fs.appendFileSync(this.logFile, logEntry);
|
|
552
|
-
} catch (error) {
|
|
553
|
-
console.error('Log dosyasına yazılamadı:', error.message);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
log(level, message, data) {
|
|
559
|
-
if (!this.shouldLog(level)) return;
|
|
560
|
-
|
|
561
|
-
const formatted = this.formatMessage(level, message, data);
|
|
562
|
-
|
|
563
|
-
if (level === 'error') {
|
|
564
|
-
console.error(formatted);
|
|
565
|
-
} else if (level === 'warn') {
|
|
566
|
-
console.warn(formatted);
|
|
567
|
-
} else {
|
|
568
|
-
console.log(formatted);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
this.writeToFile(formatted);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
error(message, data) {
|
|
575
|
-
this.log('error', message, data);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
warn(message, data) {
|
|
579
|
-
this.log('warn', message, data);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
info(message, data) {
|
|
583
|
-
this.log('info', message, data);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
debug(message, data) {
|
|
587
|
-
this.log('debug', message, data);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
setLevel(level) {
|
|
591
|
-
if (this.levels.hasOwnProperty(level)) {
|
|
592
|
-
this.level = level;
|
|
593
|
-
} else {
|
|
594
|
-
throw new Error(`Geçersiz log seviyesi: ${level}`);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
getLevel() {
|
|
599
|
-
return this.level;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
function createLogger(options = {}) {
|
|
604
|
-
return new Logger(options);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// Varsayılan logger instance
|
|
608
|
-
const defaultLogger = new Logger();
|
|
609
|
-
|
|
610
|
-
function logInfo(message, data) {
|
|
611
|
-
defaultLogger.info(message, data);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
function logError(message, data) {
|
|
615
|
-
defaultLogger.error(message, data);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
function logWarn(message, data) {
|
|
619
|
-
defaultLogger.warn(message, data);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
function logDebug(message, data) {
|
|
623
|
-
defaultLogger.debug(message, data);
|
|
624
|
-
}
|
|
625
|
-
// Exportlar
|
|
626
|
-
module.exports = {
|
|
627
|
-
http: {
|
|
628
|
-
fetchData,
|
|
629
|
-
postData,
|
|
630
|
-
},
|
|
631
|
-
date: {
|
|
632
|
-
formatDate,
|
|
633
|
-
dateDifference,
|
|
634
|
-
addDays,
|
|
635
|
-
subtractDays,
|
|
636
|
-
},
|
|
637
|
-
random: {
|
|
638
|
-
makeUniqueId,
|
|
639
|
-
randomArray,
|
|
640
|
-
randomText,
|
|
641
|
-
randomNumber,
|
|
642
|
-
randomEmoji,
|
|
643
|
-
randomHex,
|
|
644
|
-
randomFloat,
|
|
645
|
-
},
|
|
646
|
-
string: {
|
|
647
|
-
titleCase,
|
|
648
|
-
generateRandomString,
|
|
649
|
-
generateSlug,
|
|
650
|
-
wordCount,
|
|
651
|
-
},
|
|
652
|
-
array: {
|
|
653
|
-
shuffleArray,
|
|
654
|
-
flattenArray,
|
|
655
|
-
removeFalsyValues,
|
|
656
|
-
groupBy,
|
|
657
|
-
pluck,
|
|
658
|
-
sortBy,
|
|
659
|
-
},
|
|
660
|
-
object: {
|
|
661
|
-
filterObjectByKey,
|
|
662
|
-
deepMerge,
|
|
663
|
-
},
|
|
664
|
-
crypto: {
|
|
665
|
-
encryptText,
|
|
666
|
-
decryptText,
|
|
667
|
-
hashPassword,
|
|
668
|
-
verifyPassword,
|
|
669
|
-
generateJWT,
|
|
670
|
-
verifyJWT,
|
|
671
|
-
generateSalt,
|
|
672
|
-
validateUUID,
|
|
673
|
-
isPasswordStrong,
|
|
674
|
-
},
|
|
675
|
-
math: {
|
|
676
|
-
mean,
|
|
677
|
-
median,
|
|
678
|
-
variance,
|
|
679
|
-
standardDeviation,
|
|
680
|
-
sum,
|
|
681
|
-
max,
|
|
682
|
-
min,
|
|
683
|
-
range,
|
|
684
|
-
isPrime,
|
|
685
|
-
combination,
|
|
686
|
-
permutation,
|
|
687
|
-
},
|
|
688
|
-
validation: {
|
|
689
|
-
isEmail,
|
|
690
|
-
isPhone,
|
|
691
|
-
isURL,
|
|
692
|
-
sanitizeHTML,
|
|
693
|
-
validateCreditCard,
|
|
694
|
-
validateSchema,
|
|
695
|
-
sanitizeInput,
|
|
696
|
-
},
|
|
697
|
-
logger: {
|
|
698
|
-
createLogger,
|
|
699
|
-
Logger,
|
|
700
|
-
info: logInfo,
|
|
701
|
-
error: logError,
|
|
702
|
-
warn: logWarn,
|
|
703
|
-
debug: logDebug,
|
|
704
|
-
},
|
|
705
|
-
};
|