@@ -2,9 +2,9 @@ import { checkLink } from "./checkLink";
2
2
import fs from 'fs' ;
3
3
4
4
let PROCESSES : string [ ] [ ] = [ ] ;
5
- let CURRENTPROCESS = 0 ;
6
- let RUNNINGPROCESSES = 0 ;
7
- const MAXPROCESSES = 100 ;
5
+ let CURRENTPROCESS : number = 0 ;
6
+ let RUNNINGPROCESSES : number = 0 ;
7
+ const MAXPROCESSES : number = 100 ;
8
8
9
9
async function runProcess ( callback : any ) {
10
10
if ( MAXPROCESSES <= RUNNINGPROCESSES || PROCESSES . length === CURRENTPROCESS ) return ;
@@ -24,7 +24,7 @@ async function runProcess(callback: any) {
24
24
runProcess ( callback ) ;
25
25
}
26
26
27
- export default async function linkInspector ( arg : string , callback : any , path = '' ) {
27
+ export default async function linkInspector ( arg : string , callback : any , path : string = '' ) {
28
28
try { // If arg is a link
29
29
new URL ( arg ) ;
30
30
PROCESSES . push ( [ arg , path ] ) ;
@@ -33,7 +33,7 @@ export default async function linkInspector(arg: string, callback: any, path='')
33
33
} catch { }
34
34
35
35
try { // If arg is a path
36
- const stats = fs . statSync ( arg ) ;
36
+ const stats : fs . Stats = fs . statSync ( arg ) ;
37
37
38
38
// Skip files over 100mb
39
39
if ( 100 * 1024 * 1024 < stats . size ) return
@@ -48,17 +48,17 @@ export default async function linkInspector(arg: string, callback: any, path='')
48
48
}
49
49
50
50
// Handle file
51
- const content : any = fs . readFileSync ( arg , 'utf8' ) ;
51
+ const content : string = fs . readFileSync ( arg , 'utf8' ) ;
52
52
53
53
// Skip binary files
54
54
if ( ! / ^ [ \x00 - \x7F ] * $ / . test ( content ) ) return ;
55
55
56
56
// Get all the links
57
- const urlRegex = / ( \b ( h t t p s ? | f t p | f i l e ) : \/ \/ [ - A - Z 0 - 9 + & @ # \/ % ? = ~ _ | ! : , . ; ] * [ - A - Z 0 - 9 + & @ # \/ % = ~ _ | ] ) / ig;
57
+ const urlRegex : RegExp = / ( \b ( h t t p s ? | f t p | f i l e ) : \/ \/ [ - A - Z 0 - 9 + & @ # \/ % ? = ~ _ | ! : , . ; ] * [ - A - Z 0 - 9 + & @ # \/ % = ~ _ | ] ) / ig;
58
58
const links : string [ ] = content . match ( urlRegex ) || [ ] ;
59
59
60
- const directoryIndex = arg . indexOf ( path ) ;
61
- const pathAfterDirectory = arg . substring ( directoryIndex ) ;
60
+ const directoryIndex : number = arg . indexOf ( path ) ;
61
+ const pathAfterDirectory : string = arg . substring ( directoryIndex ) ;
62
62
63
63
for ( const link of links ) {
64
64
try { // Runs link inspector on each link
@@ -68,6 +68,6 @@ export default async function linkInspector(arg: string, callback: any, path='')
68
68
} catch { }
69
69
}
70
70
} catch {
71
- console . error ( " Error: Not a valid link or path" )
71
+ console . error ( ` Error: ${ arg } is not a valid link or path` ) ;
72
72
}
73
73
}
0 commit comments