Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
{
"env": {
"node": true
"node": true,
"es6": true,
"jest/globals": true
},
"extends": [
"airbnb-base"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"plugins": ["jest"],
"parserOptions": {
"ecmaVersion": 8
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"linebreak-style": 0,
"prefer-destructuring": 0,
"no-param-reassign": ["error", { "props": false }],
"import/extensions": 0,
"import/prefer-default-export": 0,
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error",
"indent": ["error", 2]
}
}
12 changes: 12 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets":{
"node":"current"
}
}
]
]
}
99 changes: 99 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import chalk from "chalk";
import { mdLinks } from "./index.js";

//const chalk = new chalk({level: 2});

const ruta = process.argv[2];
const processArr = process.argv;

if (!ruta) {
console.log('Please enter', chalk.bgBlue('--help'), 'to see options');
}
if (process.argv.includes('--help')) {
console.log(chalk.bgYellow('OPTIONS'));
console.log(chalk.bgBlue('<path> '), 'All links .md');
console.log(chalk.bgBlue('<path> --validate '), 'Links with status and msg');
console.log(chalk.bgBlue('<path> --stats '), 'Stats: Total and Unique links');
console.log(chalk.bgBlue('<path> --stats --validate'), 'Stats: Total, Unique and Broken links');
}
if (processArr[3] === '--v' || processArr[3] === '--validate') {
// console.log(true);
mdLinks(ruta, { validate: true })
.then((data) => {
// console.log(data);
data.forEach(element => {
console.log('');
console.log(chalk.bgBlue('Text: ', element.text));
console.log(chalk.cyan('Href: ', element.href));
console.log('File: ', element.file);
console.log(chalk.cyan('Status:'), (element.status));
console.log(chalk.cyanBright('Msg: ', element.msg));
});
})
.catch((error) => {
console.log(error)
// console.log(chalk.bgRed('TRY WITH:'));
// console.log(chalk.bgBlue('<path> '), 'All links .md');
// console.log(chalk.bgBlue('<path> --validate '), 'Links with status and msg');
// console.log(chalk.bgBlue('<path> --stats '), 'Stats: Total and Unique links');
// console.log(chalk.bgBlue('<path> --stats --validate'), 'Stats: Total, Unique and Broken links');
});
}

if (processArr[3] === '--s' || processArr[3] === '--stats') {
// console.log(true);
mdLinks(ruta, { stats: true })
.then((data) => {
// console.log(data);
console.log(chalk.inverse('Total : '), data.total);
console.log(chalk.inverse('Unique: '), data.unique);
})
.catch((error) => {
console.log(error)
// console.log(error, chalk.bgRed('TRY WITH:2'));
// console.log(chalk.bgBlue('<path> '), 'All links .md');
// console.log(chalk.bgBlue('<path> --validate '), 'Links with status and msg');
// console.log(chalk.bgBlue('<path> --stats '), 'Stats: Total and Unique links');
// console.log(chalk.bgBlue('<path> --stats --validate'), 'Stats: Total, Unique and Broken links');
});
}

if (processArr[3] === '--stats' && processArr[4] === '--validate') {
// console.log(true);
mdLinks(ruta, { combo: true })
.then((data) => {
// console.log(data);
console.log(chalk.inverse('Broken: '), data.broken);
})
.catch((error) => {
console.log(error)
// console.log(chalk.bgRed('TRY WITH:'));
// console.log(chalk.bgBlue('<path> '), 'All links .md');
// console.log(chalk.bgBlue('<path> --validate '), 'Links with status and msg');
// console.log(chalk.bgBlue('<path> --stats '), 'Stats: Total and Unique links');
// console.log(chalk.bgBlue('<path> --stats --validate'), 'Stats: Total, Unique and Broken links');
});
}

if (processArr.length === 3) {
// console.log('no validate');
mdLinks(ruta, { validate: false })
.then((data) => {
// console.log(data);
data.forEach(element => {
console.log('');
console.log(chalk.bgGray('Text: ', element.text));
console.log(chalk.cyan('Href: ', element.href));
console.log('File: ', element.file);
});
})
.catch((error) => {
console.log(error)
console.log(chalk.bgRed('TRY WITH:'));
console.log(chalk.bgBlue('<path>.md <options>'));
// console.log(chalk.bgBlue('<path> '), 'All links .md');
// console.log(chalk.bgBlue('<path> --validate '), 'Links with status and msg');
// console.log(chalk.bgBlue('<path> --stats '), 'Stats: Total and Unique links');
// console.log(chalk.bgBlue('<path> --stats --validate'), 'Stats: Total, Unique and Broken links');
});
}
18 changes: 18 additions & 0 deletions ejemplo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- [ ] **GitHub: Colaboración en Github (branches | forks | pull requests | code review | tags)**

- [ ] **GitHub: Organización en Github (projects | issues | labels | milestones | releases)**

### HTTP

- [ ] **Consulta o petición (request) y respuesta (response).**

<details><summary>Links</summary><p>

* [Generalidades del protocolo HTTP - MDN](https://developer.mozilla.org/es/docs/Web/HTTP/Overview)
* [Mensajes HTTP - MDN](https://developer.mozilla.org/es/docs/Web/HTTP/Messages)
* [Mensajes HTTP - MDN](https://developer.mozilla.org/es/docs/Web/HTTP/Messages)
</p></details>


* [Link roto](https://www.youtube.com/01RHn23Bn_0)
* [Módulos, librerías, paquetes, frameworks... ¿cuál es la diferencia?](http://community.laboratoria.la/t/modulos-librerias-paquetes-frameworks-cual-es-la-diferencia/175)
1 change: 1 addition & 0 deletions ejemplo2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Generalidades del protocolo HTTP - MDN](https://developer.mozilla.org/es/docs/Web/HTTP/Overview)
81 changes: 79 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
module.exports = () => {
// ...
// import fs, { link } from 'node:fs';
// import { isAbsolute, resolve as resolvePath, } from 'node:path';
import { existPath, convertAbsolute, existFile, extFile, readFileMd, getLinks, validateLinks, linkTotal, linkCombo } from './mdlinks.js';
// isAbsolute(jhfdsakjfj)
// import path from 'node:path';
// path.isAbsolute(fdskjhfdkjh)

export const mdLinks = (ruta, options) => {
return new Promise((resolve, reject) => {

// si la ruta existe
if (existPath(ruta)) {

// convertir en absoluta
convertAbsolute(ruta);

// if(convertAbsolute(ruta)===false){
// toAbsolute(ruta);
// }else{
// ruta
// }

// verificar si existe el archivo
existFile(ruta);

// si es archivo ext .md
if (extFile(ruta) == '.md') {

// leer el archivo
readFileMd(ruta)

// luego obtener los links
.then(buff => {
return getLinks(buff)
})

// luego si la opcion es --validate false resuelve con getLinks=arrayBasic
.then((arrayBasic) => {
if (options.validate === false) {
resolve(arrayBasic)
}
return validateLinks(arrayBasic)
})

// luego si la opcion es --validate true resuelve con validateLinks=resultado
.then((resultado) => {
// console.log({resultado});
if (options.validate === true) {
resolve(resultado)
return validateLinks(resultado)
}
if (options.stats === true) {
resolve(resultado)
// return linkTotal(resultado)
return linkTotal(resultado)
//console.log(linkTotal(resultado));
}
if (options.combo === true) {
resolve(resultado)
// return linkCombo(resultado)
return linkCombo(resultado)
}


})

}
} else {
// si no existe la ruta msj error
reject('*-- <PATH> Invalid ❎--*')
}
});

};


/*import { mdLinks } from "./mdLinks.js";

mdLinks()
*/
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default{
transform: {
'^.+\\.(m?js|ts)$': 'babel-jest', // transpile mjs, mts, js, ts files
},
};
Loading