forked from Laboratoria/BOG003-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (27 loc) · 914 Bytes
/
index.js
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
const path = require("path");
const functions = require('./functions');
const mdLinks = (path_, options) => {
return new Promise((resolve, reject) => {
const pathAbsolute = path.resolve(path_);
if (functions.isDirectory(pathAbsolute)) {
const theLinks = functions.recurRead(pathAbsolute)
.then(array => functions.extractLinks(array))
.then(urls => functions.validateLinks(urls, options.validate))
.then(links => links);
resolve(theLinks);
}
else if (!functions.isDirectory(pathAbsolute) && path.extname(pathAbsolute) === '.md') {
const theLinks2 = functions.extractLinks([pathAbsolute])
.then(urls => functions.validateLinks(urls, options.validate))
.then(links => {
console.log(links);
return links});
resolve(theLinks2);
} else {
reject('Ingrese un directorio o un archivo md');
}
})
};
module.exports = {
mdLinks
};