This repository was archived by the owner on May 9, 2021. It is now read-only.
File tree 2 files changed +14
-12
lines changed
2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 6
6
*/
7
7
function splitDomainsByTlds ( domains ) {
8
8
let retval = [ domains ] ;
9
- for ( let tldCounts = 1 ; tldCounts < 2 ; ++ tldCounts ) {
9
+ for ( let tldCounts = 1 ; tldCounts < 3 ; ++ tldCounts ) {
10
10
let tlds = domains . map ( ( domain ) =>
11
11
domain . split ( "." ) . reverse ( ) . slice ( 0 , tldCounts ) . reverse ( ) . join ( "." )
12
12
) ;
13
13
14
14
// remove possible duplicates
15
15
tlds = Array . from ( new Set ( tlds ) ) ;
16
+ let tmp = tlds
17
+ . map ( ( tld ) =>
18
+ domains . filter ( ( domain ) => domain . endsWith ( `.${ tld } ` ) || domain === tld )
19
+ )
20
+ . filter ( ( arr ) => arr . length > 0 ) ;
16
21
17
- if ( tlds . length > 1 ) {
18
- retval = tlds . map ( ( tld ) =>
19
- domains . filter ( ( domain ) => domain . endsWith ( `.${ tld } ` ) )
20
- ) ;
22
+ if ( tmp . length > 1 ) {
23
+ retval = tmp ;
21
24
break ;
22
25
}
23
26
}
Original file line number Diff line number Diff line change @@ -18,8 +18,7 @@ if (process.argv.length <= 2) {
18
18
}
19
19
20
20
// create a backup of the input FILE if it does not exist
21
- // path.normalize mess up files with underscore in their names
22
- const filename = process . argv [ 2 ] ;
21
+ const filename = path . normalize ( process . argv [ 2 ] ) ;
23
22
const backupFilename = filename + ".bak" ;
24
23
if ( ! fs . existsSync ( backupFilename ) ) {
25
24
fs . copyFileSync ( filename , backupFilename ) ;
@@ -64,11 +63,11 @@ for (const domains of domainGroups) {
64
63
const command = rawCommandParts . filter ( ( part ) => part != null ) . join ( " " ) ;
65
64
child_process . execSync ( command ) ;
66
65
67
- // remove the original file if neccessary
68
- if ( domainGroups . length > 1 ) {
69
- fs . unlinkSync ( filename ) ;
70
- }
71
-
72
66
// remove temporary file
73
67
fs . unlinkSync ( tmpFilename ) ;
74
68
}
69
+
70
+ // remove the original file if neccessary
71
+ if ( domainGroups . length > 1 ) {
72
+ fs . unlinkSync ( filename ) ;
73
+ }
You can’t perform that action at this time.
0 commit comments