forked from Laboratoria/BOG004-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (50 loc) · 1.49 KB
/
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
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
const {
validatePath,
documentsRoute,
getObjet,
CreateObjectWithvalidateUrl,
objectfitStat,
} = require("./functions.js");
// const userPath = process.argv[2];
// const userValidate = process.argv[3];
// const optionsUser = process.argv;
let response = {
data: [], // array de objetos href, text, etc
errors: "",
};
function mdLinks(path = "", optionsUser = { validate: false, stats: false }) {
// const { validate, stats } = options;
return new Promise((resolve, reject) => {
const validateRoute = validatePath(path);
const resultDocumentsRoute = documentsRoute(validateRoute);
getObjet(resultDocumentsRoute) // intentar dejaar solo la función mdlinks
.then((res) => {
response.data = res;
})
.then(() => {
if (optionsUser.validate) {
// CreateObjectWithvalidateUrl(response.data, optionsUser);
resolve(
CreateObjectWithvalidateUrl(response.data, optionsUser).then(
(data) => data
)
);
} else if (optionsUser.stats) {
resolve(objectfitStat(response.data));
} else {
if (!response.errors) {
// console.log(response.data);
resolve(response.data);
} else {
reject(response.errors);
}
}
});
});
}
// mdLinks(userPath, { validate: optionsUser, stats: optionsUser })
// .then((links) => console.log("links: ", links))
// .catch(console.error);
module.exports = {
mdLinks,
};