forked from Laboratoria/LIM017-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcliFunction.js
More file actions
133 lines (123 loc) Β· 6.77 KB
/
cliFunction.js
File metadata and controls
133 lines (123 loc) Β· 6.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* eslint-disable no-irregular-whitespace */
/* eslint-disable arrow-body-style */
/* eslint-disable import/prefer-default-export */
import chalk from 'chalk';
import figlet from 'figlet';
export const validateFalse = (links) => {
links.then((res) => {
console.log(chalk.blue(`
Links Encontrados
Β«ββββββββββ|-β -|ββββββββββΒ»
`));
res.forEach((link) => {
console.log(chalk.blue.bold(`
- href: ${link.href} \n
- text: ${link.text} \n
- file: ${link.file} \n
_____________________________________________________________
`));
});
})
.catch((error) => {
console.log(chalk.red(`
_______
|.-----.|
||error||
||_.-._||
--)-(--
___[=== o]___
|:::::::::::|\\
jgs Β΄-=========-Β΄()
`));
console.log(chalk.bgRed(error));
});
};
// console.log(validateFalse(mdLinks('prueba.md', false)));
export const validateTrue = (links) => {
links.then((res) => {
console.log(chalk.blue(`
Links Validados
Β«ββββββββββ|-β -|ββββββββββΒ»
`));
res.forEach((link) => {
console.log(chalk.blue.bold(`
- href: ${link.href} \n
- text: ${link.text} \n
- file: ${link.file} \n
- status: ${link.status} \n
- mensaje: ${link.ok} \n
__________________________________________________________________
`));
});
})
.catch((error) => {
console.log(chalk.red.bold(error));
});
};
// console.log(validateTrue(mdLinks('prueba.md', true)));
export const statistics = (links) => {
links.then((res) => {
const extractHref = res.map((elem) => elem.href);
// console.log(extractOnlyHref);
const hrefNoRepeat = new Set(extractHref);// elimino los links repetidos devuelve un objeto
console.log(chalk.cyan.bold(`
Β«ββββββββββ|-β -|ββββββββββΒ»
Links Totales: ${extractHref.length} \n
Links Unicos : ${hrefNoRepeat.size} \n
Β«ββββββββββ|-β -|ββββββββββΒ»
`));
})
.catch((error) => {
console.log(chalk.red.bold(error));
});
};
// console.log(statistics(mdLinks("mdLinks\\prueba", true)));
export const broken = (links) => {
links.then((res) => {
// console.log(res);
const brokenLinks = res.filter((elem) => elem.status >= 400);
console.log(chalk.cyan.bold(`
Β«ββββββββββ|-β -|ββββββββββΒ»
Links Roto: ${brokenLinks.length}
Β«ββββββββββ|-β -|ββββββββββΒ»
`));
})
.catch((error) => {
console.log(chalk.red.bold(error));
});
};
export const tableHelp = () => {
console.log(chalk.blueBright(`
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ${chalk.green('ΔͺNSTRUCCIONES DE USO π')} β
β βββββββββββββββββββββββββββββββββββββββ¦ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β ${chalk.green('mdLink <ruta>')} β Resultado: href, text, file. β
β βββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β ${chalk.green('--validate')} β Resultado: href, text, file, status y mensaje. β
β βββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β ${chalk.green('--stats')} β Resultado: total de links y links unicos. β
β βββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ£
β ${chalk.green('--stats --validate')} β Resultado: total de links, links unicos y links rotos. β
ββββββββββββββββββββββββββββββββββββββββ©ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ${chalk.green('--validate --stats')} β Resultado: total de links, links unicos y links rotos. β
ββββββββββββββββββββββββββββββββββββββββ©ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
`));
};
export const helpBanner = chalk.blueBright(
figlet.textSync(' AYUDA ', {
font: 'Chunky',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 100,
whitespaceBreak: true,
}),
);
export const welcomeBanner = chalk.blueBright(
figlet.textSync('MD - LINKS', {
font: 'Chunky',
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: true,
}),
);