Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
65 lines (61 loc) · 1.78 KB
/
Copy pathutils.js
File metadata and controls
65 lines (61 loc) · 1.78 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
var crypto = require('crypto');
var algorithm = 'aes-256-ctr';
var iv = crypto.randomBytes(16);
module.exports = {
shuffle(array){
var j, temp, i;
for (i = array.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
},
randomElement(array){
return array[Math.floor(Math.random() * array.length)];
},
randomInt(min,max){
return Math.floor(Math.random() * (max - min + 1)) + min;
},
randomNumber(min,max){
return (Math.random() * (max - min) + min);
}
,randomPrice(min,max){
var number = this.randomNumber(min,max);
return parseFloat(number).toFixed(2);
},
percentage(num, percentage) {
return ((num/100) * percentage).toFixed(2);
},
encrypt(text,password){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
},
decrypt(text,password){
var decipher = crypto.createDecipher(algorithm,password)
var dec = decipher.update(text,'hex','utf8')
dec += decipher.final('utf8');
return dec;
},
base64Encode(text){
return new Buffer(text).toString('base64');
},
base64Decode(text){
return new Buffer(text, 'base64').toString('ascii');
},
parse(str) {
var args = [].slice.call(arguments, 1),
i = 0;
return str.replace(/%s/g, function() {
return args[i++];
});
}
};
Array.prototype.insert = function ( index, item ) {
this.splice( index, 0, item );
};
Date.unix = function(unixTime){
return new Date(unixTime * 1000);
}