Skip to content

Commit 9a569ff

Browse files
committed
[REFACTOR] refactor parse and time
1 parent 5920975 commit 9a569ff

File tree

2 files changed

+10
-40
lines changed

2 files changed

+10
-40
lines changed

alice/scripts/utils/parse.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
const assert = require('assert');
2-
31
function userID(targetNumber) {
4-
assert.strictEqual(
5-
typeof targetNumber,
6-
'string',
7-
'you must pass the number as a string'
8-
);
2+
if (typeof targetNumber !== 'string') {
3+
throw new Error('you must pass the number as a string');
4+
}
95

106
const target = targetNumber.replace(/\D/g, '');
11-
127
const regexp = /\d+/;
138
const matches = target.match(regexp);
149
const pattern = matches[0];
15-
1610
return `${pattern}@c.us`;
1711
}
1812

alice/scripts/utils/time.js

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,13 @@ function sleep(seconds) {
22
return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
33
}
44

5-
function timer(sec, min = 0, hour = 0, day = 0) {
6-
// segundos
7-
if (sec >= 0) {
8-
sec *= 1000;
9-
} else {
10-
throw new Error('seconds must be higher than 0');
11-
}
12-
13-
// minutos
14-
if (min >= 0) {
15-
min = min * 60 * 1000;
16-
} else {
17-
throw new Error('minutes must be higher than 0');
18-
}
19-
20-
// horas
21-
if (hour >= 0) {
22-
hour = hour * 60 * 60 * 1000;
23-
} else {
24-
throw new Error('hours must be higher than 0');
25-
}
26-
27-
// day
28-
if (day >= 0) {
29-
day = day * 24 * 60 * 60 * 100;
30-
} else {
31-
throw new Error('minutes must be higher than 0');
32-
}
33-
34-
const time = sec + min + hour + day;
35-
return time;
5+
function timer(sec = 0, min = 0, hour = 0, day = 0) {
6+
const secsInMS = sec * 1000;
7+
const minsInMS = min * 60 * 1000;
8+
const hoursInMS = hour * 60 * 60 * 1000;
9+
const daysInMS = day * 24 * 60 * 60 * 1000;
10+
const timeInMS = secsInMS + minsInMS + hoursInMS + daysInMS;
11+
return timeInMS;
3612
}
3713

3814
module.exports = {

0 commit comments

Comments
 (0)