-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight.js
More file actions
361 lines (304 loc) · 7.53 KB
/
light.js
File metadata and controls
361 lines (304 loc) · 7.53 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// Useful constant
export const pi = 3.14159265
export const e = 2.71828183
export const gravityConst = 0.0000000000667430
export const letters = {
uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
lowercase: 'abcdefghijklmnopqrstuvwxyz',
all: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
}
// addon
export function echo(value) {
console.log(value)
}
echo.error = function echo_error(value) { console.error(value) }
echo.warn = function echo_warning(value) {
console.warn('WARN: ' + value)
}
export function Eval(code) {
let safeCode = code.replace(/[^a-zA-Z0-9+\-*/%.()\s^]/g, '')
const sCode = safeCode.replace(/\^/g, '**')
try {
return new Function('return ' + sCode)();
} catch (error) {
echo.error('Error executing code:', error)
return null
}
}
// helpful
export function sleep(t) {
if (typeof t !== "number" || isNaN(t)) {
echo.error("Error in sleep function");
return;
}
return new Promise(resolve => setTimeout(resolve, t));
}
export function clone(original) {
return {...original}
}
export function deepclone(original) {
return JSON.parse(JSON.stringify(original))
}
export function compare(a, b) {
return a === b
}
export function random(min, max) {
let num = Math.floor(Math.random() * (max - min) + min)
return num
}
export function isPalindrome(src) {
src = src.toLowerCase().replace(/[^a-z0-9]/g, "");
return src === src.split("").reverse().join("");
}
export function isEmpty(value) {
return Object.keys(value).length === 0 && value.constructor === Object
}
export function root(a, b) {
if (typeof a !== 'number') {
echo("Error in root(): first argument not a number")
return Null
}
if (typeof b !== 'number') {
echo("Error in root(): second argument not a number")
return Null
}
return (a**(1/b))
}
// Security funcs
export function checkPassLvl(password) {
const symbls = ['#', '$', '&', '@', '!', '?', ';', ',', '.', '_'];
let passLvl = 0;
let passLen = password.length
if (isEmpty(password)) {
return echo("Error: Password is empty");
}
if (/\d/.test(password)) {
passLvl += 1;
}
if (symbls.some(symbol => password.includes(symbol))) {
passLvl += 1;
}
if (/[a-zA-Z]/.test(password)) {
passLvl += 1;
}
if (passLen <= 7) {
return "weak"
}
if (passLvl === 0) {
echo("ERROR: some error in checkPassLvl");
}
if (passLvl === 1) {
return "weak";
}
if (passLvl === 2) {
return "medium";
}
if (passLvl === 3) {
return "good";
}
}
export function equalsType(value, type) {
return typeof value === typeof type
}
export function isSafeStr(str) {
if (isEmpty(str)) {
return "WARNING: value in isSafeStr is empty"
}
if (typeof str !== typeof "string") {
return "WARNING: value in isSafeStr is not string"
}
if (/^[a-zA-Z0-9\s\-_.!]+$/.test(str)) {
return true
}
return false
}
export function isValidNum(number) {
if (/^\+?[1-9]\d{1,14}$/.test(number)) {
return true
}
return false
}
export function isHttps(url) {
if (/^(https):\/\/[^\s/$.?#].[^\s]*$/i.test(url)) {
return true
}
if (isEmpty(url)) {
return null
}
return false
}
export function isValidMail(email) {
if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
return true
}
return false
}
// Some other funcs
export function randomInArray(arr) {
if (!arr) return ""
return arr[Math.floor(Math.random() * arr.length)]
}
export function toBin(num) {
return num.toString(2);
}
export function fromBin(code) {
return parseInt(code, 2)
}
export function toHex(num) {
return num.toString(16)
}
export function fromHex(code) {
return parseInt(code, 16)
}
export class fake {
constructor() {
this.cyrlNames = [
"Іван",
"Данило",
"Яна",
"Сергій",
"Максим",
"Олег",
"Олександр",
"Олексій",
"Євгенія",
"Женя",
"Тимофій",
"Кирило",
"Катерина",
"Феодосій",
"Федор",
"Віталій",
"Василій",
"Мілана",
"Вікторія"
]
this.engNames = [
"Alex",
"Mark",
"Jo",
"John",
"Jordan",
"Leonardo",
"Anna",
"Elizabeth",
"Eliza",
"Fin",
"Donald",
"Andrew",
"Anderson",
"Steve",
"Milan",
"Emily",
"Emilia"
]
}
genCyrlNames() {
return randomInArray(this.cyrlNames)
}
genEngNames() {
return randomInArray(this.engNames)
}
}
export class randEngine {
constructor() {
this.names = [
"Alex",
"Mark",
"Jo",
"John",
"Jordan",
"Leonardo",
"Anna",
"Elizabeth",
"Eliza",
"Fin",
"Donald",
"Andrew",
"Anderson",
"Steve",
"Milan",
"Emily",
"Emilia",
"Ivan",
"Danilo",
"Yana",
"Sergiy",
"Maxim",
"Oleg",
"Alexandr",
"Alexey",
"Evgenia",
"Evgen",
"Jenya",
"Timothy",
"Kiril",
"Katerina",
"Feodosii",
"Fedor",
"Vitaliy",
"Vasylii",
"Milana",
"Viktoria"
]
}
randomBool() {
return Math.random() > 0.5
}
randomName() {
return randomInArray(this.names)
}
randomStr(len = 12) {
let letts = letters.all
let res = ''
for (let i = 0; i < len; i++) {
res += [randomInArray(letts)]
}
return res
}
randomPassword(length = 8) {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_-+=<>?£¥₩€.,;:^–—";
let password = "";
for (let i = 0; i < length; i++) {
password += [randomInArray(chars)]
}
return password;
}
randomEmail() {
let emad = this.randomName()
emad = emad.toLowerCase()
const domains = ["gmail.com", "yahoo.com", "outlook.com", "companyname.net", "fastmail.net", "example.com"]
return emad + "@" + randomInArray(domains)
}
randomBio() {
let name = this.randomName()
const bio = ["I chill guy", "I love cats", "Glory to Ukraine", "why s you here?", "hello", "I am {name}", "I love {name}, he my bestie", "I love {name}, she my bestie", "I love {name}, they my bestie", "Wiwiwi", "I love dogs", "I love foxes", "Legends never dies", "coding...", "mmm... hamburger!"]
let biog = randomInArray(bio)
biog = biog.replace(/{name}/g, name)
return biog
}
randomPronouns() {
let pronouns = ["he/him", "she/her", "they/them", "he/she/him/her", "i dont want say", "any"]
return randomInArray(pronouns)
}
randomBirthday(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()))
}
randomUser() {
let user = {
username: this.randomName(),
password: this.randomPassword(),
email: this.randomEmail(),
bio: this.randomBio(),
pronouns: this.randomPronouns(),
birthday: this.randomBirthday(new Date(1970, 0, 1), new Date()).toString()
}
return user
}
random2DPos() {
return { x: random(0, 100), y: random(0, 100)}
}
random3DPos() {
return { x: random(0, 100), y: random(0, 100), z: random(0, 100)}
}
}