-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
39 lines (30 loc) · 1.02 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const sha1 = require('sha1');
const fs = require('fs');
const { v4: uuidv4 } = require('uuid');
function isAnyUndefined(...args) {
return args.some(arg => typeof arg === 'undefined');
}
function isValueExists(arr, key, value) {
return arr.some(item => item[key] === value);
}
function updateJSON(path, json) {
const updatedJsonData = JSON.stringify(json, null, 2);
fs.writeFileSync(path, updatedJsonData);
}
function newUser(name, pass, mail) {
const user = {
username: name,
password: sha1(pass),
mail: mail,
userid: sha1(uuidv4()),
profileUrl: "https://github.com/GroophyLifefor/GroophyLifefor/assets/77299279/b73bfbb8-292c-4144-963f-e25c2543169c",
isPremium: false,
premiumEndDate: null
};
return user;
}
function isValidEmail(email) {
const pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return pattern.test(email);
}
module.exports = { isAnyUndefined, isValueExists, updateJSON, newUser, isValidEmail };