forked from Laboratoria/bog001-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·28 lines (23 loc) · 731 Bytes
/
index.js
File metadata and controls
executable file
·28 lines (23 loc) · 731 Bytes
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
const getLinks = require('./lib/getLinks.js');
const validateLinks = require('./lib/validateLinks.js');
/**
* @param {string} path - File ubication.
* @param {object} option - Add validate: true for check links.
* @return {promise} resolve whith the links information
*/
const mdLinks = (path, options = {}) => new Promise((resolve, reject) => {
try {
const links = getLinks(path).length > 0 ? getLinks(path)
: (function () { throw new Error('No found links'); }());
if (options.validate) {
resolve(validateLinks(links));
}
resolve(links);
} catch (e) {
reject(e.message);
}
});
/* mdLinks('./', {validate: true})
.then(console.log)
.catch(console.error) */
module.exports = mdLinks;