link-checker-cli
Version:
CLI tool to check for broken links in a website or project
63 lines (62 loc) • 1.8 kB
JavaScript
import { TaskView } from 'hanji';
class Spinner {
constructor(frames) {
this.frames = frames;
this.offset = 0;
this.tick = () => {
this.iterator();
};
this.value = () => {
return this.frames[this.offset];
};
this.iterator = () => {
this.offset += 1;
this.offset %= frames.length - 1;
};
}
}
export class GetUrlsView extends TaskView {
constructor() {
super();
this.spinner = new Spinner('⣷⣯⣟⡿⢿⣻⣽⣾'.split(''));
this.counter = 0;
this.setCounter = (count) => {
this.counter = count;
};
this.timeout = setInterval(() => {
this.spinner.tick();
this.requestLayout();
}, 128);
this.on('detach', () => clearInterval(this.timeout));
}
render(status) {
if (status === 'pending') {
const spin = this.spinner.value();
return `${spin} Searching for urls. Found: ${this.counter} \n`;
}
return "";
}
}
export class CheckLinkView extends TaskView {
constructor(linksCount) {
super();
this.linksCount = linksCount;
this.spinner = new Spinner('⣷⣯⣟⡿⢿⣻⣽⣾'.split(''));
this.counter = 0;
this.increment = () => {
this.counter++;
};
this.timeout = setInterval(() => {
this.spinner.tick();
this.requestLayout();
}, 128);
this.on('detach', () => clearInterval(this.timeout));
}
render(status) {
if (status === 'pending') {
const spin = this.spinner.value();
return `${spin} Checked ${this.counter}/${this.linksCount} \n`;
}
return "";
}
}