File tree Expand file tree Collapse file tree 2 files changed +10
-40
lines changed Expand file tree Collapse file tree 2 files changed +10
-40
lines changed Original file line number Diff line number Diff line change 1
- const assert = require ( 'assert' ) ;
2
-
3
1
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
+ }
9
5
10
6
const target = targetNumber . replace ( / \D / g, '' ) ;
11
-
12
7
const regexp = / \d + / ;
13
8
const matches = target . match ( regexp ) ;
14
9
const pattern = matches [ 0 ] ;
15
-
16
10
return `${ pattern } @c.us` ;
17
11
}
18
12
Original file line number Diff line number Diff line change @@ -2,37 +2,13 @@ function sleep(seconds) {
2
2
return new Promise ( ( resolve ) => setTimeout ( resolve , seconds * 1000 ) ) ;
3
3
}
4
4
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 ;
36
12
}
37
13
38
14
module . exports = {
You can’t perform that action at this time.
0 commit comments