-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.js
34 lines (30 loc) · 934 Bytes
/
index.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
export function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
export function randomIntBetween(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min);
}
export function randomItem(arrayOfItems){
return arrayOfItems[Math.floor(Math.random() * arrayOfItems.length)];
}
export function randomString(length) {
const charset = 'abcdefghijklmnopqrstuvwxyz';
let res = '';
while (length--) res += charset[Math.random() * charset.length | 0];
return res;
}
export function findBetween(content, left, right) {
let start = content.indexOf(left);
if (start === -1) {
return '';
}
start += left.length;
const end = content.indexOf(right, start);
if (end === -1) {
return '';
}
return content.substring(start, end);
}