Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

put it all together up to getting extensions #12

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b30c802
primer commit
ArelyGutierrez Oct 13, 2022
8802188
borrador esqueleto función
ArelyGutierrez Oct 19, 2022
9344068
resolve if a path exists and resolve a relative path if it is not
ArelyGutierrez Oct 21, 2022
29e193a
Get an extension and check if it is a file or directory
ArelyGutierrez Oct 24, 2022
95cb108
Extension of a file and Find out if it is a file or directory
ArelyGutierrez Oct 24, 2022
5f4b8cd
ext and file or directory
ArelyGutierrez Oct 24, 2022
4c90d2e
intento 3
ArelyGutierrez Oct 24, 2022
1ad348a
Merge pull request #8 from ArelyGutierrez/draft
ArelyGutierrez Oct 24, 2022
9189e34
put it all together up to extensions
ArelyGutierrez Oct 27, 2022
a74bca1
Merge pull request #15 from ArelyGutierrez/draft
ArelyGutierrez Oct 27, 2022
a98a31a
get links with regEx
ArelyGutierrez Oct 27, 2022
4485ac9
Merge pull request #16 from ArelyGutierrez/draft
ArelyGutierrez Oct 27, 2022
3c7286f
shows href, text and path of each md file
ArelyGutierrez Oct 31, 2022
0131c21
Merge pull request #17 from ArelyGutierrez/draft
ArelyGutierrez Oct 31, 2022
7e119dd
first step validation
ArelyGutierrez Nov 4, 2022
9005f1c
validation function
ArelyGutierrez Nov 4, 2022
bb246a7
Merge pull request #18 from ArelyGutierrez/validation
ArelyGutierrez Nov 4, 2022
d587da4
using Promise.all
ArelyGutierrez Nov 5, 2022
f711a86
solve stadistics
ArelyGutierrez Nov 9, 2022
dd0b922
Merge pull request #19 from ArelyGutierrez/validation
ArelyGutierrez Nov 9, 2022
c492bea
show stadistics as a promise
ArelyGutierrez Nov 9, 2022
5b53ae4
modulation
ArelyGutierrez Nov 10, 2022
7d3f0c8
Merge pull request #21 from ArelyGutierrez/validation
ArelyGutierrez Nov 10, 2022
bf133a8
cli, this fixes with a file .md
ArelyGutierrez Nov 16, 2022
fd145ce
Merge pull request #23 from ArelyGutierrez/validation
ArelyGutierrez Nov 16, 2022
6ff1cf3
test of the most of the files and fuctions
ArelyGutierrez Nov 16, 2022
5afe615
Merge pull request #24 from ArelyGutierrez/validation
ArelyGutierrez Nov 16, 2022
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
24 changes: 24 additions & 0 deletions answerFileOrDirectory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

const fs = require('fs'); // this module enables interacting with the file system in a way modeled on standard POSIX functions.


function answerFileOrDirectory(pathE){

let stats = fs.statSync(pathE); // Use statSync() method to store the returned tru or false
if(stats.isFile()){
//console.log(pathE + '---> IS A FILE ');
console.log('3. is it directory? ' + stats.isDirectory()); // false
return (pathE) // false
} else if(fs.statSync(pathE)){
//console.log(pathE +'---> IS A DIRECTORY' );
console.log('3. is it directory? ' + stats.isDirectory()); // true
return (pathE + ' este es un directorio, intentalo con un archivo') // true
}

}

module.exports = { answerFileOrDirectory }

//File test run
//console.log(answerFileOrDirectory(pathE));

73 changes: 73 additions & 0 deletions borrador.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const fs = require('fs'); // this module enables interacting with the file system in a way modeled on standard POSIX functions.
const path = require('path');
const axios = require('axios');
const { validate } = require('./validate')

const pathdeprueba = './holis.md';

function getMdLinks(TestPath, option) {
return new Promise((resolve, reject) => {
// 01_a Verify if a file exists in node.js
if (fs.existsSync(TestPath)) { //01_a a file exists in node.js
console.log('El archivo EXISTE');
// si la ruta no es absoluta conviertela en absoluta ..... etc... -> resolvepath
if (!path.isAbsolute(TestPath)) { // if it's not absolute
path.resolve(TestPath); // become in absolute
console.log(path.resolve(TestPath));
}
//////// BE SURE YOU'RE WORKING WITH A FILE
let stats = fs.statSync(TestPath); // Use statSync() method to store the returned
if (stats.isFile()) {
console.log(TestPath + '---> IS A FILE ');
// BE SURE YOU'RE WORKING WITH MD FILES
if (path.extname(TestPath) === '.md') {
console.log(path.extname(TestPath));
// read the file
const textFile = fs.readFileSync(TestPath, 'utf-8');
// extraer links y guardarlos en un array de objetos ///(\[.*\])\((https?)(:\/\/[^\s\)]+)\)/
const regex = /(\[.*\])(\(https?(:\/\/[^\s\)]+)\))/g
const allLinks = textFile.match((regex));
// console.log(allLinks);
const newArray = [];
allLinks.forEach(element => {
const separate = element.split('](');
const text = separate[0].replace('[', '');
const url = separate[1].replace(')', '');

newArray.push({
href: url, // URL encontrada.
text: text, // Texto que aparecía dentro del link (<a>).
file: path.resolve(TestPath) // Ruta del archivo donde se encontró el link.
})
})
// console.log(newArray); // => [{ href, text, file}]

if (option.validate === true) {
// console.log(validate(newArray));
validate(newArray).then(resolve);

// resolvedPromise.then((resultado) => console.log(resultado))
// console.log(resolvedPromise);
} else {
resolve(newArray);
}



} else {
// console.log(path.extname(TestPath));
console.log('Tu archivo es ' + path.extname(TestPath) + ' intenta con alguno que sea .md ');
}

} else if (fs.statSync(TestPath)) {
console.log(TestPath + '---> IS A DIRECTORY');

}

} else { // 01_a a file doesn't exist in node.js
console.log('El archivo NO EXISTE')
}
})


}
41 changes: 41 additions & 0 deletions checkingExistentPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const fs = require('fs');
// const pathE = 'C:/Users/ylera/Desktop/Laboratoria/learnyounodeexercises';

// verify if a file exists in node.js //done
function checkingExistentPath(pathE) {

if(fs.existsSync(pathE)){
//console.log((pathE)); //true
return (pathE);
}else if(!fs.existsSync(pathE)){
//console.log(fs.existsSync(pathE)); //false
return ('El archivo NO existe');
}

}

module.exports = { checkingExistentPath }

//File test run
// checkingExistentPath(pathE);






/////////////////////////////////////////////
// // verify if a file exists in node.js //done
// function checkingExistentPath(pathE){
// fs.existsSync(pathE)
// if(fs.existsSync(pathE)){
// console.log('El archivo EXISTE');
// }else{
// console.log('El archivo NO EXISTE')
// }

// }
// module.exports = { checkingExistentPath }
// //File test run
// checkingExistentPath(pathE);

17 changes: 17 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const { getMdLinks } = require('./index.js')

const[,, ...args] = process.argv

const validateValue = args.includes('--validate');
const statsValue = args.includes('--stats');

getMdLinks(args[0], {validate:validateValue, stats: statsValue }).then(res=>console.log(res))



//module.exports={ CLI }

// md-links C:/Users/ylera/Desktop/Labo2/CDMX013-md-links/holis.md
// md-links C:\\Users\\ylera\\Desktop\\Labo2\\CDMX013-md-links\\holis.md --validate
10 changes: 10 additions & 0 deletions equis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
![md-links](https://user-images.githubusercontent.com/110297/42118443-b7a5f1f0-7bc8-11e8-96ad-9cc5593715a6.jpg)

## 2. Resumen del proyecto

En este proyecto crearás una herramienta de línea de comando (CLI) así como tu
propia librería (o biblioteca - library) en JavaScript.

[How to Write a JavaScript Promise - 404 freecodecamp](https://www.freecodecamp.org/news/how-to-write-a-javascript-promise-4ed8d44292b8/)',

['Recursión o Recursividad - 503 Laboratoria Developers](https://medium.com/laboratoria-developers/recursi%C3%B3n-o-recursividad-ec8f1a359727),
23 changes: 23 additions & 0 deletions gettingFileExtention.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require('fs'); // this module enables interacting with the file system in a way modeled on standard POSIX functions.
var path = require('path');

const pathE = './holis.md'; //this is a constat of a test path (ruta prueba)
//const pathE = './thumb.png';
// const pathE = '.C:/Users/ylera/Desktop/Laboratoria/learnyounodeexercises/my-first-io.js';


// getting an extension of a path
function gettingFileExtention(testPath){

if(path.extname(testPath)==='.md'){

return(testPath)
}else{
return ('Tu archivo es ' + path.extname(testPath) + ' intenta con alguno que sea .md ')
}

}

module.exports = { gettingFileExtention }
//File test run
//console.log(gettingFileExtention(pathE));
34 changes: 34 additions & 0 deletions gettingLinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require('fs'); // this module enables interacting with the file system in a way modeled on standard POSIX functions.
const path = require('path');

const pathE = './holis.md';

function gettingLinks(TestMDFile){

const textFile = fs.readFileSync(pathE, 'utf-8');
const regex = /(\[.*\])(\(https?(:\/\/[^\s\)]+)\))/g // / (\[.*\]) (\(https? (:\/\/[^\s\)]+) \))/g
const allLinks = textFile.match((regex));
const newArray = [];

allLinks.forEach( element => {
const separate = element.split('](');
const text = separate[0].replace('[','');
const url = separate[1].replace(')','');

newArray.push({
href: url, // URL encontrada.
text: text, // Texto que aparecía dentro del link (<a>).
file: path.resolve(pathE) // Ruta del archivo donde se encontró el link.
} )
})

return newArray;

}

module.exports = { gettingLinks }
// File test run
console.log(gettingLinks(pathE));



46 changes: 46 additions & 0 deletions holis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Markdown Links

## Índice

* [1. Preámbulo](#1-preámbulo)
* [2. Resumen del proyecto](#2-resumen-del-proyecto)
* [3. Objetivos de aprendizaje](#3-objetivos-de-aprendizaje)
* [4. Consideraciones generales](#4-consideraciones-generales)
* [5. Criterios de aceptación mínimos del proyecto](#5-criterios-de-aceptación-mínimos-del-proyecto)
* [6. Entregables](#6-entregables)
* [7. Hacker edition](#7-hacker-edition)
* [8. Pistas, tips y lecturas complementarias](#8-pistas-tips-y-lecturas-complementarias)
* [9. Checklist](#9-checklist)
* [10. Achicando el problema](#10-achicando-el-problema)

***

## 1. Preámbulo

[Markdown](https://es.wikipedia.org/wiki/Markdown) es un lenguaje de marcado
ligero muy popular entre developers. Es usado en muchísimas plataformas que
manejan texto plano (GitHub, foros, blogs, ...) y es muy común
encontrar varios archivos en ese formato en cualquier tipo de repositorio
(empezando por el tradicional `README.md`).

Estos archivos `Markdown` normalmente contienen _links_ (vínculos/ligas) que
muchas veces están rotos o ya no son válidos y eso perjudica mucho el valor de
la información que se quiere compartir.

Dentro de una comunidad de código abierto, nos han propuesto crear una
herramienta usando [Node.js](https://nodejs.org/), que lea y analice archivos
en formato `Markdown`, para verificar los links que contengan y reportar
algunas estadísticas.

![md-links](https://user-images.githubusercontent.com/110297/42118443-b7a5f1f0-7bc8-11e8-96ad-9cc5593715a6.jpg)

## 2. Resumen del proyecto

En este proyecto crearás una herramienta de línea de comando (CLI) así como tu
propia librería (o biblioteca - library) en JavaScript.

[How to Write a JavaScript Promise - 404 freecodecamp](https://www.youtube.com/fulanitodetal/20202)',

[Recursión o Recursividad - 503 Laboratoria Developers](https://medium.com/laboratoria-developers/recursi%C3%B3n-o-recursividad-ec8f1a359727),


Loading