Skip to content

Commit 1b1ea61

Browse files
Merge pull request #56 from justindhillon/Better-Errors
Add Better Error Messages
2 parents 765edea + 92f2126 commit 1b1ea61

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

bin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import linkInspector from "./index";
44
import {dirname, basename} from 'path';
55
import fs from 'fs';
66

7-
const args = process.argv.slice(2);
7+
const args: string[] = process.argv.slice(2);
88

99
if (args.length === 0) {
1010
console.error("no link or path given");
1111
}
1212

13-
async function writeLink(link: string, path: any) {
13+
async function writeLink(link: string, path: string) {
1414
console.log("Broken Link:", link);
1515

1616
if (path) {
@@ -23,7 +23,7 @@ async function writeLink(link: string, path: any) {
2323
}
2424

2525
for (const arg of args) {
26-
let path = '';
26+
let path: string = '';
2727

2828
try {new URL(arg)}
2929
catch {

checkLink.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const axios = require("axios");
22

33
// Return true if link is broken
44
export async function checkLink(link: string): Promise<boolean> {
5-
const params = {
5+
const params: object = {
66
headers: {
77
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
88
"Accept-Encoding": "gzip, deflate, br",

index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { checkLink } from "./checkLink";
22
import fs from 'fs';
33

44
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;
88

99
async function runProcess(callback: any) {
1010
if (MAXPROCESSES <= RUNNINGPROCESSES || PROCESSES.length === CURRENTPROCESS) return;
@@ -24,7 +24,7 @@ async function runProcess(callback: any) {
2424
runProcess(callback);
2525
}
2626

27-
export default async function linkInspector(arg: string, callback: any, path='') {
27+
export default async function linkInspector(arg: string, callback: any, path: string = '') {
2828
try { // If arg is a link
2929
new URL(arg);
3030
PROCESSES.push([arg, path]);
@@ -33,7 +33,7 @@ export default async function linkInspector(arg: string, callback: any, path='')
3333
} catch {}
3434

3535
try { // If arg is a path
36-
const stats = fs.statSync(arg);
36+
const stats: fs.Stats = fs.statSync(arg);
3737

3838
// Skip files over 100mb
3939
if (100*1024*1024 < stats.size) return
@@ -48,17 +48,17 @@ export default async function linkInspector(arg: string, callback: any, path='')
4848
}
4949

5050
// Handle file
51-
const content: any = fs.readFileSync(arg, 'utf8');
51+
const content: string = fs.readFileSync(arg, 'utf8');
5252

5353
// Skip binary files
5454
if (!/^[\x00-\x7F]*$/.test(content)) return;
5555

5656
// Get all the links
57-
const urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
57+
const urlRegex: RegExp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
5858
const links: string[] = content.match(urlRegex) || [];
5959

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);
6262

6363
for (const link of links) {
6464
try { // Runs link inspector on each link
@@ -68,6 +68,6 @@ export default async function linkInspector(arg: string, callback: any, path='')
6868
} catch {}
6969
}
7070
} catch {
71-
console.error("Error: Not a valid link or path")
71+
console.error(`Error: ${arg} is not a valid link or path`);
7272
}
7373
}

package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "link-inspector",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"author": "Justin Dhillon",
55
"license": "AGPL-3.0-or-later",
66

0 commit comments

Comments
 (0)