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