@onurege3467/zerohelper 2.1.2 โ 3.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/database/index.js +14 -0
- package/database/postgresql/index.js +118 -0
- package/database/redis/index.js +102 -0
- package/functions/index.js +287 -0
- package/index.js +2 -7
- package/package.json +15 -8
- package/readme.md +254 -63
- package/database/test.js +0 -50
- package/functions/functions.js +0 -100
package/database/index.js
CHANGED
|
@@ -6,6 +6,8 @@ var JsonDatabase = require("./jsondatabase/index");
|
|
|
6
6
|
var MongoDB = require("./mongodb/index");
|
|
7
7
|
var MySQLDatabase = require("./mysql/index");
|
|
8
8
|
var SQLiteDatabase = require("./sqldb/index");
|
|
9
|
+
var RedisDatabase = require("./redis/index");
|
|
10
|
+
var PostgreSQL = require("./postgresql/index");
|
|
9
11
|
|
|
10
12
|
module.exports = {
|
|
11
13
|
/**
|
|
@@ -31,4 +33,16 @@ module.exports = {
|
|
|
31
33
|
* @type {SQLiteDatabase}
|
|
32
34
|
*/
|
|
33
35
|
SQLiteDatabase,
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Redis-based database.
|
|
39
|
+
* @type {RedisDatabase}
|
|
40
|
+
*/
|
|
41
|
+
RedisDatabase,
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* PostgreSQL-based database.
|
|
45
|
+
* @type {PostgreSQL}
|
|
46
|
+
*/
|
|
47
|
+
PostgreSQL,
|
|
34
48
|
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const { Pool } = require("pg");
|
|
2
|
+
|
|
3
|
+
class PostgreSQL {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
this.pool = new Pool(config);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async set(key, value) {
|
|
9
|
+
const keys = key.split(".");
|
|
10
|
+
const rootKey = keys.shift();
|
|
11
|
+
const currentValue = (await this.get(rootKey)) || {};
|
|
12
|
+
|
|
13
|
+
let target = currentValue;
|
|
14
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
15
|
+
if (!target[keys[i]]) target[keys[i]] = {};
|
|
16
|
+
target = target[keys[i]];
|
|
17
|
+
}
|
|
18
|
+
target[keys[keys.length - 1]] = value;
|
|
19
|
+
|
|
20
|
+
await this.pool.query(
|
|
21
|
+
"INSERT INTO key_value_store (key, value) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET value = $2",
|
|
22
|
+
[rootKey, JSON.stringify(currentValue)]
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async get(key) {
|
|
27
|
+
const keys = key.split(".");
|
|
28
|
+
const rootKey = keys.shift();
|
|
29
|
+
const res = await this.pool.query(
|
|
30
|
+
"SELECT value FROM key_value_store WHERE key = $1",
|
|
31
|
+
[rootKey]
|
|
32
|
+
);
|
|
33
|
+
const rootValue = res.rows[0] ? JSON.parse(res.rows[0].value) : null;
|
|
34
|
+
|
|
35
|
+
if (!rootValue) return null;
|
|
36
|
+
|
|
37
|
+
let target = rootValue;
|
|
38
|
+
for (const k of keys) {
|
|
39
|
+
if (target[k] === undefined) return null;
|
|
40
|
+
target = target[k];
|
|
41
|
+
}
|
|
42
|
+
return target;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async has(key) {
|
|
46
|
+
return (await this.get(key)) !== null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async delete(key) {
|
|
50
|
+
const keys = key.split(".");
|
|
51
|
+
const rootKey = keys.shift();
|
|
52
|
+
const currentValue = (await this.get(rootKey)) || {};
|
|
53
|
+
|
|
54
|
+
let target = currentValue;
|
|
55
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
56
|
+
if (!target[keys[i]]) return; // Key path does not exist
|
|
57
|
+
target = target[keys[i]];
|
|
58
|
+
}
|
|
59
|
+
delete target[keys[keys.length - 1]];
|
|
60
|
+
|
|
61
|
+
await this.pool.query(
|
|
62
|
+
"INSERT INTO key_value_store (key, value) VALUES ($1, $2) ON CONFLICT (key) DO UPDATE SET value = $2",
|
|
63
|
+
[rootKey, JSON.stringify(currentValue)]
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async add(key, amount) {
|
|
68
|
+
const currentValue = (await this.get(key)) || 0;
|
|
69
|
+
if (typeof currentValue !== "number") {
|
|
70
|
+
throw new TypeError("The value is not a number.");
|
|
71
|
+
}
|
|
72
|
+
await this.set(key, currentValue + amount);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async sub(key, amount) {
|
|
76
|
+
const currentValue = (await this.get(key)) || 0;
|
|
77
|
+
if (typeof currentValue !== "number") {
|
|
78
|
+
throw new TypeError("The value is not a number.");
|
|
79
|
+
}
|
|
80
|
+
await this.set(key, currentValue - amount);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async push(key, value) {
|
|
84
|
+
const currentValue = (await this.get(key)) || [];
|
|
85
|
+
if (!Array.isArray(currentValue)) {
|
|
86
|
+
throw new TypeError("The value is not an array.");
|
|
87
|
+
}
|
|
88
|
+
currentValue.push(value);
|
|
89
|
+
await this.set(key, currentValue);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async ping() {
|
|
93
|
+
try {
|
|
94
|
+
await this.pool.query("SELECT 1");
|
|
95
|
+
return true;
|
|
96
|
+
} catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async close() {
|
|
102
|
+
await this.pool.end();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Ensure the table exists
|
|
107
|
+
(async () => {
|
|
108
|
+
const pool = new Pool();
|
|
109
|
+
await pool.query(`
|
|
110
|
+
CREATE TABLE IF NOT EXISTS key_value_store (
|
|
111
|
+
key TEXT PRIMARY KEY,
|
|
112
|
+
value TEXT NOT NULL
|
|
113
|
+
)
|
|
114
|
+
`);
|
|
115
|
+
await pool.end();
|
|
116
|
+
})();
|
|
117
|
+
|
|
118
|
+
module.exports = PostgreSQL;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const { createClient } = require("redis");
|
|
2
|
+
|
|
3
|
+
class RedisDatabase {
|
|
4
|
+
constructor(config = {}) {
|
|
5
|
+
this.client = createClient(config);
|
|
6
|
+
this.client.on("error", (err) => console.error("Redis Client Error", err));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async connect() {
|
|
10
|
+
await this.client.connect();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async set(key, value) {
|
|
14
|
+
const keys = key.split(".");
|
|
15
|
+
const rootKey = keys.shift();
|
|
16
|
+
const currentValue = (await this.get(rootKey)) || {};
|
|
17
|
+
|
|
18
|
+
let target = currentValue;
|
|
19
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
20
|
+
if (!target[keys[i]]) target[keys[i]] = {};
|
|
21
|
+
target = target[keys[i]];
|
|
22
|
+
}
|
|
23
|
+
target[keys[keys.length - 1]] = value;
|
|
24
|
+
|
|
25
|
+
await this.client.set(rootKey, JSON.stringify(currentValue));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async get(key) {
|
|
29
|
+
const keys = key.split(".");
|
|
30
|
+
const rootKey = keys.shift();
|
|
31
|
+
const value = await this.client.get(rootKey);
|
|
32
|
+
const rootValue = value ? JSON.parse(value) : null;
|
|
33
|
+
|
|
34
|
+
if (!rootValue) return null;
|
|
35
|
+
|
|
36
|
+
let target = rootValue;
|
|
37
|
+
for (const k of keys) {
|
|
38
|
+
if (target[k] === undefined) return null;
|
|
39
|
+
target = target[k];
|
|
40
|
+
}
|
|
41
|
+
return target;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async has(key) {
|
|
45
|
+
return (await this.get(key)) !== null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async delete(key) {
|
|
49
|
+
const keys = key.split(".");
|
|
50
|
+
const rootKey = keys.shift();
|
|
51
|
+
const currentValue = (await this.get(rootKey)) || {};
|
|
52
|
+
|
|
53
|
+
let target = currentValue;
|
|
54
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
55
|
+
if (!target[keys[i]]) return; // Key path does not exist
|
|
56
|
+
target = target[keys[i]];
|
|
57
|
+
}
|
|
58
|
+
delete target[keys[keys.length - 1]];
|
|
59
|
+
|
|
60
|
+
await this.client.set(rootKey, JSON.stringify(currentValue));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async add(key, amount) {
|
|
64
|
+
const currentValue = (await this.get(key)) || 0;
|
|
65
|
+
if (typeof currentValue !== "number") {
|
|
66
|
+
throw new TypeError("The value is not a number.");
|
|
67
|
+
}
|
|
68
|
+
await this.set(key, currentValue + amount);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async sub(key, amount) {
|
|
72
|
+
const currentValue = (await this.get(key)) || 0;
|
|
73
|
+
if (typeof currentValue !== "number") {
|
|
74
|
+
throw new TypeError("The value is not a number.");
|
|
75
|
+
}
|
|
76
|
+
await this.set(key, currentValue - amount);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async push(key, value) {
|
|
80
|
+
const currentValue = (await this.get(key)) || [];
|
|
81
|
+
if (!Array.isArray(currentValue)) {
|
|
82
|
+
throw new TypeError("The value is not an array.");
|
|
83
|
+
}
|
|
84
|
+
currentValue.push(value);
|
|
85
|
+
await this.set(key, currentValue);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async ping() {
|
|
89
|
+
try {
|
|
90
|
+
const pong = await this.client.ping();
|
|
91
|
+
return pong === "PONG";
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async close() {
|
|
98
|
+
await this.client.quit();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = RedisDatabase;
|
|
@@ -0,0 +1,287 @@
|
|
|
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 encryptText(text, secret) {
|
|
128
|
+
const cipher = crypto.createCipher("aes-256-cbc", secret);
|
|
129
|
+
let encrypted = cipher.update(text, "utf8", "hex");
|
|
130
|
+
encrypted += cipher.final("hex");
|
|
131
|
+
return encrypted;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function decryptText(encryptedText, secret) {
|
|
135
|
+
const decipher = crypto.createDecipher("aes-256-cbc", secret);
|
|
136
|
+
let decrypted = decipher.update(encryptedText, "hex", "utf8");
|
|
137
|
+
decrypted += decipher.final("utf8");
|
|
138
|
+
return decrypted;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function hashPassword(password) {
|
|
142
|
+
const saltRounds = 10;
|
|
143
|
+
return bcrypt.hashSync(password, saltRounds);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function verifyPassword(password, hash) {
|
|
147
|
+
return bcrypt.compareSync(password, hash);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function generateJWT(payload, secret) {
|
|
151
|
+
return jwt.sign(payload, secret, { expiresIn: "1h" });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function verifyJWT(token, secret) {
|
|
155
|
+
try {
|
|
156
|
+
return jwt.verify(token, secret);
|
|
157
|
+
} catch {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function generateSalt() {
|
|
163
|
+
return crypto.randomBytes(16).toString("hex");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function generateRandomString(length) {
|
|
167
|
+
const characters =
|
|
168
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
169
|
+
return Array.from({ length }, () =>
|
|
170
|
+
characters.charAt(Math.floor(Math.random() * characters.length))
|
|
171
|
+
).join("");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function validateUUID(uuid) {
|
|
175
|
+
const uuidRegex =
|
|
176
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
177
|
+
return uuidRegex.test(uuid);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isPasswordStrong(password) {
|
|
181
|
+
const strongPasswordRegex =
|
|
182
|
+
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
|
|
183
|
+
return strongPasswordRegex.test(password);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Matematiksel ฤฐลlemler
|
|
187
|
+
function mean(arr) {
|
|
188
|
+
if (!arr.length) return 0;
|
|
189
|
+
return arr.reduce((sum, num) => sum + num, 0) / arr.length;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function median(arr) {
|
|
193
|
+
if (!arr.length) return 0;
|
|
194
|
+
const sorted = [...arr].sort((a, b) => a - b);
|
|
195
|
+
const mid = Math.floor(sorted.length / 2);
|
|
196
|
+
return sorted.length % 2 !== 0
|
|
197
|
+
? sorted[mid]
|
|
198
|
+
: (sorted[mid - 1] + sorted[mid]) / 2;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function variance(arr) {
|
|
202
|
+
if (!arr.length) return 0;
|
|
203
|
+
const avg = mean(arr);
|
|
204
|
+
return arr.reduce((sum, num) => sum + Math.pow(num - avg, 2), 0) / arr.length;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function standardDeviation(arr) {
|
|
208
|
+
return Math.sqrt(variance(arr));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function sum(arr) {
|
|
212
|
+
return arr.reduce((total, num) => total + num, 0);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function max(arr) {
|
|
216
|
+
return Math.max(...arr);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function min(arr) {
|
|
220
|
+
return Math.min(...arr);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function range(start, end) {
|
|
224
|
+
if (start > end) return [];
|
|
225
|
+
return Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function isPrime(num) {
|
|
229
|
+
if (num <= 1) return false;
|
|
230
|
+
if (num <= 3) return true;
|
|
231
|
+
if (num % 2 === 0 || num % 3 === 0) return false;
|
|
232
|
+
for (let i = 5; i * i <= num; i += 6) {
|
|
233
|
+
if (num % i === 0 || num % (i + 2) === 0) return false;
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Exportlar
|
|
239
|
+
module.exports = {
|
|
240
|
+
random: {
|
|
241
|
+
makeUniqueId,
|
|
242
|
+
randomArray,
|
|
243
|
+
randomText,
|
|
244
|
+
randomNumber,
|
|
245
|
+
randomEmoji,
|
|
246
|
+
randomHex,
|
|
247
|
+
randomFloat,
|
|
248
|
+
},
|
|
249
|
+
string: {
|
|
250
|
+
titleCase,
|
|
251
|
+
generateRandomString,
|
|
252
|
+
},
|
|
253
|
+
array: {
|
|
254
|
+
shuffleArray,
|
|
255
|
+
flattenArray,
|
|
256
|
+
removeFalsyValues,
|
|
257
|
+
groupBy,
|
|
258
|
+
pluck,
|
|
259
|
+
sortBy,
|
|
260
|
+
},
|
|
261
|
+
object: {
|
|
262
|
+
filterObjectByKey,
|
|
263
|
+
deepMerge,
|
|
264
|
+
},
|
|
265
|
+
crypto: {
|
|
266
|
+
encryptText,
|
|
267
|
+
decryptText,
|
|
268
|
+
hashPassword,
|
|
269
|
+
verifyPassword,
|
|
270
|
+
generateJWT,
|
|
271
|
+
verifyJWT,
|
|
272
|
+
generateSalt,
|
|
273
|
+
validateUUID,
|
|
274
|
+
isPasswordStrong,
|
|
275
|
+
},
|
|
276
|
+
math: {
|
|
277
|
+
mean,
|
|
278
|
+
median,
|
|
279
|
+
variance,
|
|
280
|
+
standardDeviation,
|
|
281
|
+
sum,
|
|
282
|
+
max,
|
|
283
|
+
min,
|
|
284
|
+
range,
|
|
285
|
+
isPrime,
|
|
286
|
+
},
|
|
287
|
+
};
|
package/index.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
var database = require("./database/index");
|
|
2
|
-
var functions = require("./functions/
|
|
2
|
+
var functions = require("./functions/index");
|
|
3
3
|
|
|
4
4
|
module.exports = {
|
|
5
|
-
database
|
|
6
|
-
JsonDatabase: database.JsonDatabase,
|
|
7
|
-
MongoDB: database.MongoDB,
|
|
8
|
-
MySQLDatabase: database.MySQLDatabase,
|
|
9
|
-
SQLiteDatabase: database.SQLiteDatabase,
|
|
10
|
-
},
|
|
5
|
+
database,
|
|
11
6
|
functions,
|
|
12
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onurege3467/zerohelper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node test.js"
|
|
@@ -12,22 +12,29 @@
|
|
|
12
12
|
"uuid",
|
|
13
13
|
"mongodb",
|
|
14
14
|
"mysql",
|
|
15
|
-
"db",
|
|
16
15
|
"jsondatabase",
|
|
17
|
-
"sqlitedatabase",
|
|
18
16
|
"sqlite3",
|
|
19
|
-
"quick.db"
|
|
17
|
+
"quick.db",
|
|
18
|
+
"postgresql",
|
|
19
|
+
"redis",
|
|
20
|
+
"utility",
|
|
21
|
+
"functions",
|
|
22
|
+
"nodejs"
|
|
20
23
|
],
|
|
21
24
|
"author": "Onure9e",
|
|
22
25
|
"license": "ISC",
|
|
26
|
+
"description": "ZeroHelper is a versatile JavaScript library offering helper functions and database utilities for developers. It supports MongoDB, MySQL, SQLite, Redis, and PostgreSQL.",
|
|
23
27
|
"dependencies": {
|
|
24
|
-
"
|
|
28
|
+
"bcrypt": "^5.1.1",
|
|
29
|
+
"crypto": "^1.0.1",
|
|
25
30
|
"fs": "^0.0.1-security",
|
|
31
|
+
"jsonwebtoken": "^9.0.2",
|
|
26
32
|
"lodash": "^4.17.21",
|
|
27
33
|
"mongodb": "^6.12.0",
|
|
28
34
|
"path": "^0.12.7",
|
|
35
|
+
"pg": "^8.14.1",
|
|
29
36
|
"promise-mysql": "^5.2.0",
|
|
37
|
+
"redis": "^4.7.0",
|
|
30
38
|
"sqlite3": "^5.1.7"
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}
|
|
39
|
+
}
|
|
40
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,90 +1,221 @@
|
|
|
1
|
-
# ZeroHelper
|
|
1
|
+
# ZeroHelper ๐
|
|
2
2
|
|
|
3
|
-
ZeroHelper is a package
|
|
3
|
+
ZeroHelper is a versatile JavaScript package providing helper functions and database utilities for developers. It includes essential tools for manipulating data, generating random values, performing cryptographic operations, and interacting with various databases like MySQL, MongoDB, PostgreSQL, SQLite, and Redis.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ๐ Table of Contents
|
|
8
|
+
|
|
9
|
+
1. [๐ฆ Installation](#-installation)
|
|
10
|
+
2. [โจ Helper Functions](#-helper-functions)
|
|
11
|
+
- [๐ฒ Random Functions](#random-functions-)
|
|
12
|
+
- [๐ String Functions](#string-functions-)
|
|
13
|
+
- [๐ Array Functions](#array-functions-)
|
|
14
|
+
- [๐ง Object Functions](#object-functions-)
|
|
15
|
+
- [๐ Crypto Functions](#crypto-functions-)
|
|
16
|
+
- [โ Math Functions](#math-functions-)
|
|
17
|
+
3. [๐พ Database Utilities](#-database-utilities)
|
|
18
|
+
- [๐๏ธ JsonDatabase](#jsondatabase-๏ธ)
|
|
19
|
+
- [๐๏ธ MongoDB](#mongodb-๏ธ)
|
|
20
|
+
- [๐ฌ MySQL](#mysql-)
|
|
21
|
+
- [๐ฑ SQLiteDB](#sqlitedb-)
|
|
22
|
+
- [๐ PostgreSQL](#postgresql-)
|
|
23
|
+
- [โก Redis](#redis-)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## ๐ Installing ZeroHelper
|
|
28
|
+
|
|
29
|
+
To install ZeroHelper, use npm:
|
|
6
30
|
|
|
7
31
|
```bash
|
|
8
32
|
npm i @onurege3467/zerohelper
|
|
9
33
|
```
|
|
10
34
|
|
|
11
|
-
## Using ZeroHelper for helper functions
|
|
35
|
+
## ๐ ๏ธ Using ZeroHelper for helper functions
|
|
36
|
+
|
|
37
|
+
# Random Functions ๐ฒ
|
|
12
38
|
|
|
13
39
|
```js
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
console.log(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
console.log(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
console.log(
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
const helpers = require("@onurege3467/zerohelper/functions");
|
|
41
|
+
|
|
42
|
+
const id = helpers.random.makeUniqueId();
|
|
43
|
+
console.log(id); // Example: "lzx8k9x8k9"
|
|
44
|
+
|
|
45
|
+
const item = helpers.random.randomArray([1, 2, 3, 4, 5]);
|
|
46
|
+
console.log(item); // Example: 3
|
|
47
|
+
|
|
48
|
+
const text = helpers.random.randomText(10);
|
|
49
|
+
console.log(text); // Example: "aBcDeFgHiJ"
|
|
50
|
+
|
|
51
|
+
const number = helpers.random.randomNumber(1, 100);
|
|
52
|
+
console.log(number); // Example: 42
|
|
53
|
+
|
|
54
|
+
const emoji = helpers.random.randomEmoji();
|
|
55
|
+
console.log(emoji); // Example: "๐"
|
|
56
|
+
|
|
57
|
+
const hex = helpers.random.randomHex();
|
|
58
|
+
console.log(hex); // Example: "#A1B2C3"
|
|
59
|
+
|
|
60
|
+
const float = helpers.random.randomFloat(1.5, 5.5);
|
|
61
|
+
console.log(float); // Example: 3.14
|
|
26
62
|
```
|
|
27
63
|
|
|
28
|
-
|
|
64
|
+
# String Functions ๐
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
const title = helpers.string.titleCase("hello world");
|
|
68
|
+
console.log(title); // "Hello World"
|
|
69
|
+
|
|
70
|
+
const randomString = helpers.string.generateRandomString(8);
|
|
71
|
+
console.log(randomString); // Example: "AbCdEfGh"
|
|
72
|
+
```
|
|
29
73
|
|
|
30
|
-
|
|
74
|
+
# Array Functions ๐
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
const shuffled = helpers.array.shuffleArray([1, 2, 3, 4, 5]);
|
|
78
|
+
console.log(shuffled); // Example: [3, 1, 5, 4, 2]
|
|
79
|
+
|
|
80
|
+
const flat = helpers.array.flattenArray([1, [2, [3, 4]], 5]);
|
|
81
|
+
console.log(flat); // [1, 2, 3, 4, 5]
|
|
82
|
+
|
|
83
|
+
const filtered = helpers.array.removeFalsyValues([0, 1, false, 2, "", 3]);
|
|
84
|
+
console.log(filtered); // [1, 2, 3]
|
|
85
|
+
|
|
86
|
+
const grouped = helpers.array.groupBy(
|
|
87
|
+
[
|
|
88
|
+
{ category: "fruit", name: "apple" },
|
|
89
|
+
{ category: "fruit", name: "banana" },
|
|
90
|
+
{ category: "vegetable", name: "carrot" },
|
|
91
|
+
],
|
|
92
|
+
"category"
|
|
93
|
+
);
|
|
94
|
+
console.log(grouped);
|
|
95
|
+
// {
|
|
96
|
+
// fruit: [{ category: "fruit", name: "apple" }, { category: "fruit", name: "banana" }],
|
|
97
|
+
// vegetable: [{ category: "vegetable", name: "carrot" }]
|
|
98
|
+
// }
|
|
99
|
+
|
|
100
|
+
const names = helpers.array.pluck(
|
|
101
|
+
[{ name: "Alice" }, { name: "Bob" }, { name: "Charlie" }],
|
|
102
|
+
"name"
|
|
103
|
+
);
|
|
104
|
+
console.log(names); // ["Alice", "Bob", "Charlie"]
|
|
105
|
+
|
|
106
|
+
const sorted = helpers.array.sortBy(
|
|
107
|
+
[{ age: 30 }, { age: 20 }, { age: 40 }],
|
|
108
|
+
"age"
|
|
109
|
+
);
|
|
110
|
+
console.log(sorted); // [{ age: 20 }, { age: 30 }, { age: 40 }]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
# Object Functions ๐ง
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
const filtered = helpers.object.filterObjectByKey(
|
|
117
|
+
{ name: "Alice", age: 25, city: "New York" },
|
|
118
|
+
["name", "city"]
|
|
119
|
+
);
|
|
120
|
+
console.log(filtered); // { name: "Alice", city: "New York" }
|
|
121
|
+
|
|
122
|
+
const merged = helpers.object.deepMerge(
|
|
123
|
+
{ a: 1, b: { c: 2 } },
|
|
124
|
+
{ b: { d: 3 }, e: 4 }
|
|
125
|
+
);
|
|
126
|
+
console.log(merged); // { a: 1, b: { c: 2, d: 3 }, e: 4 }
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
# Crypto Functions ๐
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
const secret = "mySecretKey";
|
|
133
|
+
const encrypted = helpers.crypto.encryptText("Hello, World!", secret);
|
|
134
|
+
console.log(encrypted); // Encrypted text
|
|
135
|
+
|
|
136
|
+
const decrypted = helpers.crypto.decryptText(encrypted, secret);
|
|
137
|
+
console.log(decrypted); // "Hello, World!"
|
|
138
|
+
|
|
139
|
+
const hash = helpers.crypto.hashPassword("myPassword");
|
|
140
|
+
console.log(hash); // Hashed password
|
|
141
|
+
|
|
142
|
+
const isValid = helpers.crypto.verifyPassword("myPassword", hash);
|
|
143
|
+
console.log(isValid); // true or false
|
|
144
|
+
|
|
145
|
+
const token = helpers.crypto.generateJWT({ userId: 1 }, "mySecret");
|
|
146
|
+
console.log(token); // JWT
|
|
147
|
+
|
|
148
|
+
const payload = helpers.crypto.verifyJWT(token, "mySecret");
|
|
149
|
+
console.log(payload); // { userId: 1, iat: ..., exp: ... }
|
|
150
|
+
```
|
|
31
151
|
|
|
32
|
-
|
|
152
|
+
# Math Functions โ
|
|
33
153
|
|
|
34
154
|
```js
|
|
35
|
-
const
|
|
155
|
+
const avg = helpers.math.mean([1, 2, 3, 4, 5]);
|
|
156
|
+
console.log(avg); // 3
|
|
157
|
+
|
|
158
|
+
const prime = helpers.math.isPrime(7);
|
|
159
|
+
console.log(prime); // true
|
|
36
160
|
```
|
|
37
161
|
|
|
38
|
-
|
|
162
|
+
## ๐พ Using ZeroHelper as Database
|
|
163
|
+
|
|
164
|
+
ZeroHelper provides multiple database utilities for seamless integration with various databases.
|
|
165
|
+
|
|
166
|
+
# JsonDatabase ๐๏ธ
|
|
39
167
|
|
|
40
168
|
```js
|
|
41
|
-
|
|
42
|
-
const
|
|
169
|
+
(async function () {
|
|
170
|
+
const JsonDatabase = require("@onurege3467/zerohelper/database/jsondatabase");
|
|
171
|
+
const db = new JsonDatabase();
|
|
43
172
|
|
|
44
|
-
db.set("foo", "bar");
|
|
45
|
-
db.push("array", "x");
|
|
46
|
-
db.delete("foo");
|
|
173
|
+
await db.set("foo", "bar");
|
|
174
|
+
await db.push("array", "x");
|
|
175
|
+
await db.delete("foo");
|
|
47
176
|
|
|
48
|
-
db.add("number", 1);
|
|
49
|
-
db.sub("number", 1);
|
|
177
|
+
await db.add("number", 1);
|
|
178
|
+
await db.sub("number", 1);
|
|
50
179
|
|
|
51
|
-
db.get("foo");
|
|
52
|
-
db.has("foo");
|
|
180
|
+
await console.log(db.get("foo"));
|
|
181
|
+
await console.log(db.has("foo"));
|
|
182
|
+
})();
|
|
53
183
|
```
|
|
54
184
|
|
|
55
|
-
|
|
185
|
+
# MongoDB ๐๏ธ
|
|
56
186
|
|
|
57
187
|
```js
|
|
58
188
|
(async function () {
|
|
59
189
|
const MongoDB = require("@onurege3467/zerohelper/database/mongodb");
|
|
60
|
-
|
|
190
|
+
const db = await MongoDB.createData(
|
|
61
191
|
"database",
|
|
62
192
|
"collection",
|
|
63
193
|
"data",
|
|
64
194
|
undefined,
|
|
65
195
|
"mongourl"
|
|
66
196
|
);
|
|
67
|
-
db.set("foo", "bar"); // sets foo to bar
|
|
68
|
-
db.push("array", "x"); // pushs x to array
|
|
69
|
-
db.delete("foo"); // deletes foo
|
|
70
197
|
|
|
71
|
-
db.
|
|
72
|
-
db.
|
|
198
|
+
await db.set("foo", "bar");
|
|
199
|
+
await db.push("array", "x");
|
|
200
|
+
await db.delete("foo");
|
|
73
201
|
|
|
74
|
-
db.
|
|
75
|
-
db.
|
|
202
|
+
await db.add("number", 1);
|
|
203
|
+
await db.sub("number", 1);
|
|
76
204
|
|
|
77
|
-
db.
|
|
205
|
+
console.log(await db.get("foo"));
|
|
206
|
+
console.log(await db.has("foo"));
|
|
207
|
+
|
|
208
|
+
console.log(await db.ping());
|
|
78
209
|
})();
|
|
79
210
|
```
|
|
80
211
|
|
|
81
|
-
|
|
212
|
+
# MySQL ๐ฌ
|
|
82
213
|
|
|
83
214
|
```js
|
|
84
215
|
(async function () {
|
|
85
|
-
const
|
|
216
|
+
const MySQL = require("@onurege3467/zerohelper/database/mysql");
|
|
86
217
|
|
|
87
|
-
const db = new
|
|
218
|
+
const db = new MySQL();
|
|
88
219
|
await db.connect({
|
|
89
220
|
host: "localhost",
|
|
90
221
|
port: "3306",
|
|
@@ -94,42 +225,102 @@ db.has("foo"); // returns true or false
|
|
|
94
225
|
charset: "utf8mb4",
|
|
95
226
|
});
|
|
96
227
|
|
|
97
|
-
db.on("connected", async (
|
|
228
|
+
db.on("connected", async () => {
|
|
98
229
|
console.log("Database Connected");
|
|
99
230
|
});
|
|
100
231
|
|
|
101
|
-
db.set("table", "foo", "bar");
|
|
102
|
-
db.push("table", "array", "x");
|
|
103
|
-
db.delete("table", "foo");
|
|
232
|
+
await db.set("table", "foo", "bar");
|
|
233
|
+
await db.push("table", "array", "x");
|
|
234
|
+
await db.delete("table", "foo");
|
|
104
235
|
|
|
105
|
-
db.add("table", "number", 1);
|
|
106
|
-
db.sub("table", "number", 1);
|
|
236
|
+
await db.add("table", "number", 1);
|
|
237
|
+
await db.sub("table", "number", 1);
|
|
107
238
|
|
|
108
|
-
db.get("table", "foo");
|
|
109
|
-
db.has("table", "foo");
|
|
239
|
+
console.log(await db.get("table", "foo"));
|
|
240
|
+
console.log(await db.has("table", "foo"));
|
|
110
241
|
|
|
111
|
-
db.ping();
|
|
242
|
+
console.log(await db.ping());
|
|
112
243
|
})();
|
|
113
244
|
```
|
|
114
245
|
|
|
115
|
-
|
|
246
|
+
# SQLiteDB ๐ฑ
|
|
116
247
|
|
|
117
248
|
```js
|
|
118
249
|
(async function () {
|
|
119
|
-
const
|
|
250
|
+
const SQLiteDB = require("@onurege3467/zerohelper/database/sqldb");
|
|
251
|
+
|
|
252
|
+
const db = new SQLiteDB();
|
|
253
|
+
|
|
254
|
+
await db.set("foo", "bar");
|
|
255
|
+
await db.push("array", "x");
|
|
256
|
+
await db.delete("foo");
|
|
257
|
+
|
|
258
|
+
await db.add("number", 1);
|
|
259
|
+
await db.sub("number", 1);
|
|
260
|
+
|
|
261
|
+
console.log(await db.get("foo"));
|
|
262
|
+
console.log(await db.has("foo"));
|
|
263
|
+
})();
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
# PostgreSQL ๐
|
|
267
|
+
|
|
268
|
+
```js
|
|
269
|
+
(async function () {
|
|
270
|
+
const PostgreSQL = require("@onurege3467/zerohelper/database/postgresql");
|
|
271
|
+
|
|
272
|
+
const db = new PostgreSQL({
|
|
273
|
+
user: "your_username",
|
|
274
|
+
host: "localhost",
|
|
275
|
+
database: "your_database",
|
|
276
|
+
password: "your_password",
|
|
277
|
+
port: 5432,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
await db.set("foo", "bar");
|
|
281
|
+
console.log(await db.get("foo"));
|
|
282
|
+
console.log(await db.has("foo"));
|
|
283
|
+
await db.delete("foo");
|
|
284
|
+
|
|
285
|
+
await db.add("number", 10);
|
|
286
|
+
await db.sub("number", 5);
|
|
287
|
+
|
|
288
|
+
await db.set("array", []);
|
|
289
|
+
await db.push("array", "value");
|
|
290
|
+
console.log(await db.get("array"));
|
|
291
|
+
|
|
292
|
+
console.log(await db.ping());
|
|
293
|
+
|
|
294
|
+
await db.close();
|
|
295
|
+
})();
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
# Redis โก
|
|
299
|
+
|
|
300
|
+
```js
|
|
301
|
+
(async function () {
|
|
302
|
+
const RedisDatabase = require("@onurege3467/zerohelper/database/redis");
|
|
303
|
+
|
|
304
|
+
const db = new RedisDatabase({
|
|
305
|
+
url: "redis://localhost:6379",
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
await db.connect();
|
|
120
309
|
|
|
121
|
-
|
|
310
|
+
await db.set("user.name", "John Doe");
|
|
311
|
+
console.log(await db.get("user.name"));
|
|
312
|
+
console.log(await db.has("user.name"));
|
|
313
|
+
await db.delete("user.name");
|
|
122
314
|
|
|
123
|
-
await db.
|
|
315
|
+
await db.add("stats.score", 10);
|
|
316
|
+
await db.sub("stats.score", 5);
|
|
124
317
|
|
|
125
|
-
db.set("
|
|
126
|
-
db.push("
|
|
127
|
-
db.
|
|
318
|
+
await db.set("items", []);
|
|
319
|
+
await db.push("items", "item1");
|
|
320
|
+
console.log(await db.get("items"));
|
|
128
321
|
|
|
129
|
-
db.
|
|
130
|
-
db.sub("table", "number", 1); // subtracts 1 from number
|
|
322
|
+
console.log(await db.ping());
|
|
131
323
|
|
|
132
|
-
db.
|
|
133
|
-
db.has("table", "foo"); // returns true or false
|
|
324
|
+
await db.close();
|
|
134
325
|
})();
|
|
135
326
|
```
|
package/database/test.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
require("dotenv").config();
|
|
2
|
-
const runMongoDB = async () => {
|
|
3
|
-
const { MongoDB } = require("./index");
|
|
4
|
-
|
|
5
|
-
var db = await MongoDB.createData(
|
|
6
|
-
"database",
|
|
7
|
-
"collection",
|
|
8
|
-
"data",
|
|
9
|
-
undefined,
|
|
10
|
-
"mongourl"
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
db.set("foo", "bar");
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const runMySQL = async () => {
|
|
17
|
-
const { MySQLDatabase } = require("./index");
|
|
18
|
-
const db = new MySQLDatabase();
|
|
19
|
-
await db.connect({
|
|
20
|
-
host: "localhost",
|
|
21
|
-
port: "3306",
|
|
22
|
-
user: "root",
|
|
23
|
-
password: "",
|
|
24
|
-
database: "database",
|
|
25
|
-
charset: "utf8mb4",
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
db.on("connected", async (connection) => {
|
|
29
|
-
console.log("Database Connected");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
db.set("table", "foo", "bar");
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
//runMySQL()
|
|
36
|
-
|
|
37
|
-
const runJsonDatabase = async () => {
|
|
38
|
-
const { JsonDatabase } = require("./index");
|
|
39
|
-
var db = new JsonDatabase();
|
|
40
|
-
db.set("foo", "bar");
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const runSQLite = async () => {
|
|
44
|
-
const { database } = require("../index");
|
|
45
|
-
var db = new database.SQLiteDatabase();
|
|
46
|
-
await db.set("foo.test2", { Date: Date.now(), name: "Onur" });
|
|
47
|
-
console.log(await db.has("foo.test2.a"));
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
runSQLite();
|
package/functions/functions.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
function makeUniqueId() {
|
|
2
|
-
return Date.now().toString(36) + Math.random().toString(36).substr(2);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function randomArray(arr) {
|
|
6
|
-
var random1 = Math.floor(Math.random() * (arr.length - 0 + 0) + 0);
|
|
7
|
-
var random = arr[random1];
|
|
8
|
-
return random;
|
|
9
|
-
}
|
|
10
|
-
function randomText(length) {
|
|
11
|
-
if (!length) length = 8;
|
|
12
|
-
var result = "";
|
|
13
|
-
var characters =
|
|
14
|
-
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
15
|
-
var charactersLength = characters.length;
|
|
16
|
-
for (var i = 0; i < length; i++) {
|
|
17
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
function randomNumber(bas, son) {
|
|
22
|
-
if (!bas) bas = 0;
|
|
23
|
-
if (!son) son = 9999999;
|
|
24
|
-
return Math.floor(Math.random() * (son - bas + 1)) + bas;
|
|
25
|
-
}
|
|
26
|
-
function randomEmoji() {
|
|
27
|
-
var emojiler = ['๐','๐','๐','๐','โบ','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐ณ','๐','๐','๐','๐','๐','๐ฃ','๐ข','๐','๐ญ','๐ช','๐ฅ','๐ฐ','๐
','๐','๐ฉ','๐ซ','๐จ','๐ฑ','๐ ','๐ก','๐ค','๐','๐','๐','๐ท','๐','๐ด','๐ต','๐ฒ','๐','๐ฆ','๐ง','๐','๐ฟ','๐ฎ','๐ฌ','๐','๐','๐ฏ','๐ถ','๐','๐','๐','๐ฒ','๐ณ','๐ฎ','๐ท','๐','๐ถ','๐ฆ','๐ง','๐จ','๐ฉ','๐ด','๐ต','๐ฑ','๐ผ','๐ธ','๐บ','๐ธ','๐ป','๐ฝ','๐ผ','๐','๐ฟ','๐น','๐พ','๐น','๐บ','๐','๐','๐','๐','๐ฝ','๐ฉ','๐ฅ','โจ','๐','๐ซ','๐ฅ','๐ข','๐ฆ','๐ง','๐ค','๐จ','๐','๐','๐','๐
','๐','๐','๐','๐','๐','โ','โ','๐','โ','๐','๐','๐','๐','๐','๐','๐','โ','๐','๐ช','๐ถ','๐','๐','๐ซ','๐ช','๐ฌ','๐ญ','๐','๐','๐ฏ','๐','๐
','๐','๐','๐','๐','๐
','๐ฐ','๐','๐','๐','๐ฉ','๐','๐','๐','๐','๐ก','๐ ','๐ข','๐','๐','๐','๐','๐ฝ','๐','๐','๐','๐ผ','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','โค','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐ค','๐ฅ','๐ฌ','๐ฃ','๐ญ','๐ถ','๐บ','๐ฑ','๐ญ','๐น','๐ฐ','๐ธ','๐ฏ','๐จ','๐ป','๐ท','๐ฝ','๐ฎ','๐','๐ต','๐','๐ด','๐','๐','๐ผ','๐ง','๐ฆ','๐ค','๐ฅ','๐ฃ','๐','๐','๐ข','๐','๐','๐','๐','๐','๐','๐','๐ ','๐','๐ฌ','๐ณ','๐','๐','๐','๐','๐','๐
','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐ฒ','๐ก','๐','๐ซ','๐ช','๐','๐','๐ฉ','๐พ','๐','๐ธ','๐ท','๐','๐น','๐ป','๐บ','๐','๐','๐','๐ฟ','๐พ','๐','๐ต','๐ด','๐ฒ','๐ณ','๐ฐ','๐ฑ','๐ผ','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐ ','โญ','โ','โ
','โ','โก','โ','โ','โ','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐ป','๐
','๐','๐','๐','๐','๐','๐','๐','๐ฎ','๐ฅ','๐ท','๐น','๐ผ','๐ฟ','๐','๐ฝ','๐พ','๐ป','๐ฑ','โ','๐','๐','๐ ','๐ก','๐บ','๐ป','๐','๐','๐','๐','๐','๐','๐ข','๐ฃ','โณ','โ','โฐ','โ','๐','๐','๐','๐','๐','๐','๐ก','๐ฆ','๐','๐
','๐','๐','๐','๐','๐','๐ฟ','๐ฝ','๐ง','๐ฉ','๐จ','๐ช','๐ฌ','๐ฃ','๐ซ','๐ช','๐','๐','๐ฐ','๐ด','๐ต','๐ท','๐ถ','๐ณ','๐ธ','๐ฒ','๐ง','๐ฅ','๐ค','โ','๐ฉ','๐จ','๐ฏ','๐ซ','๐ช','๐ฌ','๐ญ','๐ฎ','๐ฆ','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐
','๐','๐','๐','๐','โ','๐','๐','โ','โ','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐ฌ','๐ญ','๐ฐ','๐จ','๐ฌ','๐ค','๐ง','๐ผ','๐ต','๐ถ','๐น','๐ป','๐บ','๐ท','๐ธ','๐พ','๐ฎ','๐','๐ด','๐','๐ฒ','๐ฏ','๐','๐','โฝ','โพ','๐พ','๐ฑ','๐','๐ณ','โณ','๐ต','๐ด','๐','๐','๐','๐ฟ','๐','๐','๐','๐ฃ','โ','๐ต','๐ถ','๐ผ','๐บ','๐ป','๐ธ','๐น','๐ท','๐ด','๐','๐','๐','๐','๐','๐','๐','๐ค','๐ฑ','๐ฃ','๐ฅ','๐','๐','๐','๐','๐ฒ','๐ข','๐ก','๐ณ','๐','๐ฉ','๐ฎ','๐ฆ','๐จ','๐ง','๐','๐ฐ','๐ช','๐ซ','๐ฌ','๐ญ','๐ฏ','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐ ','๐','๐
','๐ฝ','๐ ','๐ก','๐ซ','๐ข','๐ฃ','๐ฅ','๐ฆ','๐ช','๐ฉ','๐จ','๐','โช','๐ฌ','๐ค','๐','๐','๐ฏ','๐ฐ','โบ','๐ญ','๐ผ','๐พ','๐ป','๐','๐
','๐','๐ฝ','๐','๐ ','๐ก','โฒ','๐ข','๐ข','โต','๐ค','๐ฃ','โ','๐','โ','๐บ','๐','๐','๐','๐','๐','๐','๐','๐
','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐จ','๐','๐','๐','๐','๐','๐ฒ','๐ก','๐','๐ ','๐','๐','๐','๐ซ','๐ฆ','๐ฅ','โ ','๐ง','๐ฐ','โฝ','๐ฎ','๐ฐ','โจ','๐ฟ','๐ช','๐ญ','๐','๐ฉ','โฌ','โฌ','โฌ
','โก','๐ ','๐ก','๐ค','โ','โ','โ','โ','โ','โ','๐','โ','โถ','๐ผ','๐ฝ','โฉ','โช','โน','โช','โฉ','โซ','โฌ','โคต','โคด','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐ถ','๐ฆ','๐','๐ฏ','๐ณ','๐ต','๐ด','๐ฒ','๐','๐น','๐บ','๐ถ','๐','๐ป','๐น','๐บ','๐ผ','๐พ','๐ฐ','๐ฎ','๐
ฟ','โฟ','๐ญ','๐ท','๐ธ','๐','โ','๐','๐','๐
','๐','๐','ใ','ใ','๐','๐','๐','๐ซ','๐','๐ต','๐ฏ','๐ฑ','๐ณ','๐ท','๐ธ','โ','โณ','โ','โ','โ
','โด','๐','๐','๐ณ','๐ด','๐
ฐ','๐
ฑ','๐','๐
พ','๐ ','โฟ','โป','โ','โ','โ','โ','โ','โ','โ','โ','โ','โ','โ','โ','โ','๐ฏ','๐ง','๐น','๐ฒ','๐ฑ','ยฉ','ยฎ','โข','ใฝ','ใฐ','๐','๐','๐','๐','๐','โ','โญ','โ','โ','โ','โ','๐','๐','๐ง','๐','๐','๐','๐','๐','๐','๐','๐','๐','๐ ','๐','๐','๐','๐','๐','๐','๐ก','๐ข','๐ฃ','๐ค','๐ฅ','๐ฆ','โ','โ','โ','โ','โ ','โฅ','โฃ','โฆ','๐ฎ','๐ฏ','โ','โ','๐','๐','โฐ','๐ฑ','๐ฒ','๐ณ','โผ','โป','โพ','โฝ','โช','โซ','๐บ','โฌ','โฌ','โซ','โช','๐ด','๐ต','๐ป','๐ถ','๐ท','๐ธ','๐น'];
|
|
28
|
-
return emojiler[Math.floor(Math.random() * emojiler.length)];
|
|
29
|
-
}
|
|
30
|
-
function randomHex() {
|
|
31
|
-
var letters = "0123456789ABCDEF";
|
|
32
|
-
var color = "#";
|
|
33
|
-
for (var i = 0; i < 6; i++) {
|
|
34
|
-
color += letters[Math.floor(Math.random() * 16)];
|
|
35
|
-
}
|
|
36
|
-
return color;
|
|
37
|
-
}
|
|
38
|
-
var uuidRegex = {
|
|
39
|
-
|
|
40
|
-
'3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
41
|
-
|
|
42
|
-
'4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
43
|
-
|
|
44
|
-
'5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
45
|
-
|
|
46
|
-
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
function uuid() {
|
|
50
|
-
var uuid = "",
|
|
51
|
-
i,
|
|
52
|
-
random;
|
|
53
|
-
|
|
54
|
-
for (i = 0; i < 32; i++) {
|
|
55
|
-
random = (Math.random() * 16) | 0;
|
|
56
|
-
|
|
57
|
-
if (i === 8 || i === 12 || i === 16 || i === 20) uuid += "-";
|
|
58
|
-
|
|
59
|
-
uuid += (i === 12 ? 4 : i === 16 ? (random & 3) | 8 : random).toString(16);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return uuid;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function isUUID(str, version) {
|
|
66
|
-
var pattern = uuidRegex[version || "all"];
|
|
67
|
-
|
|
68
|
-
return (pattern && pattern.test(str)) || false;
|
|
69
|
-
}
|
|
70
|
-
function shuffleArray(array) {
|
|
71
|
-
let currentIndex = array.length;
|
|
72
|
-
while (currentIndex != 0) {
|
|
73
|
-
let randomIndex = Math.floor(Math.random() * currentIndex);
|
|
74
|
-
currentIndex--;
|
|
75
|
-
[array[currentIndex], array[randomIndex]] = [
|
|
76
|
-
array[randomIndex], array[currentIndex]];
|
|
77
|
-
}
|
|
78
|
-
return array;
|
|
79
|
-
}
|
|
80
|
-
function titleCase(sentence) {
|
|
81
|
-
return sentence
|
|
82
|
-
.toLowerCase()
|
|
83
|
-
.split(" ")
|
|
84
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
85
|
-
.join(" ");
|
|
86
|
-
}
|
|
87
|
-
module.exports = {
|
|
88
|
-
makeUniqueId,
|
|
89
|
-
randomArray,
|
|
90
|
-
randomText,
|
|
91
|
-
randomNumber,
|
|
92
|
-
randomEmoji,
|
|
93
|
-
randomHex,
|
|
94
|
-
uid: {
|
|
95
|
-
uuid,
|
|
96
|
-
isUUID,
|
|
97
|
-
},
|
|
98
|
-
shuffleArray,
|
|
99
|
-
titleCase
|
|
100
|
-
};
|