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

Core function ready #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
package-lock.json
102 changes: 102 additions & 0 deletions cat-names/cat-names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
[
"Abby",
"Angel",
"Annie",
"Baby",
"Bailey",
"Bandit",
"Bear",
"Bella",
"Bob",
"Boo",
"Boots",
"Bubba",
"Buddy",
"Buster",
"Cali",
"Callie",
"Casper",
"Charlie",
"Chester",
"Chloe",
"Cleo",
"Coco",
"Cookie",
"Cuddles",
"Daisy",
"Dusty",
"Felix",
"Fluffy",
"Garfield",
"George",
"Ginger",
"Gizmo",
"Gracie",
"Harley",
"Jack",
"Jasmine",
"Jasper",
"Kiki",
"Kitty",
"Leo",
"Lilly",
"Lily",
"Loki",
"Lola",
"Lucky",
"Lucy",
"Luna",
"Maggie",
"Max",
"Mia",
"Midnight",
"Milo",
"Mimi",
"Miss kitty",
"Missy",
"Misty",
"Mittens",
"Molly",
"Muffin",
"Nala",
"Oliver",
"Oreo",
"Oscar",
"Patches",
"Peanut",
"Pepper",
"Precious",
"Princess",
"Pumpkin",
"Rascal",
"Rocky",
"Sadie",
"Salem",
"Sam",
"Samantha",
"Sammy",
"Sasha",
"Sassy",
"Scooter",
"Shadow",
"Sheba",
"Simba",
"Simon",
"Smokey",
"Snickers",
"Snowball",
"Snuggles",
"Socks",
"Sophie",
"Spooky",
"Sugar",
"Tiger",
"Tigger",
"Tinkerbell",
"Toby",
"Trouble",
"Whiskers",
"Willow",
"Zoe",
"Zoey"
]
21 changes: 21 additions & 0 deletions cat-names/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node
'use strict';

var meow = require('meow');
var catNames = require('./');

var cli = meow([
'Examples',
' $ cat-names',
' Max',
'',
' $ cat-names --all',
' Abby',
' Angel',
' ...',
'',
'Options',
' --all Get all names instead of a random name'
]);

console.log(cli.flags.all ? catNames.all.join('\n') : catNames.random());
6 changes: 6 additions & 0 deletions cat-names/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';
var uniqueRandomArray = require('unique-random-array');
var catNames = require('./cat-names.json');

exports.all = catNames;
exports.random = uniqueRandomArray(catNames);
39 changes: 39 additions & 0 deletions cat-names/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "cat-names",
"version": "1.0.0",
"description": "Get popular cat names",
"license": "MIT",
"repository": "sindresorhus/cat-names",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]"
},
"bin": "cli.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {},
"files": [
"index.js",
"cli.js",
"cat-names.json"
],
"keywords": [
"cli-app",
"cli",
"bin",
"array",
"random",
"rand",
"animal",
"cats",
"kitten",
"names"
],
"dependencies": {
"chalk": "^4.0.0",
"meow": "^3.6.0",
"unique-random-array": "^1.0.0"
},
"devDependencies": {}
}
15 changes: 15 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node
'use strict';

const meow = require('meow');
var mdLinks = require('./index.js');

var mdLinks = meow([
'Arguments',
' --file Write the path of the file you would like to check',
"Options",
"--validate Tells you the status of the founded link",
"--stats Gives you some basic statistics about the foundes links, as how many broken, working and total links."
]);

// console.log(cli.flags.all ? catNames.all.join('\n') : catNames.random());
92 changes: 92 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'use strict';
//Dependencias
const fs = require('fs');
const path = require("path");
const fetch = require('node-fetch');
const chalk = require('chalk');
const log = console.log;

let uri = "";
let content = "";

function getPath() {
let index = process.argv.indexOf("--file")
if (index < 0) { return log(chalk.bgRed("Por favor ingresa el argumento --file seguido de la ruta del archivo Markdown.")) }
let uri = process.argv[index + 1]
let extension = path.extname(uri)
// log(chalk.black.bgYellowBright("extension:", extension))
if (extension != '.md') {
log(chalk.bgRed("Por favor ingresa la ruta de un archivo Markdown (extensión .md)"));
} else {
return uri
}
}

uri = getPath();

function readFile(uri) {
let content = fs.readFileSync(uri, "utf8")
return content
}

// Falta promesa en readfile,

content = readFile(uri)
//log(chalk.bgCyan("text content: ", content));

function searchLinks(content) {
let regEx = (/https?:\S+\w/g);
let links = content.match(regEx)
return links
}

let links = searchLinks(content)

log(chalk.cyan("Founded links :", links));
let totalLinks = links.length;
log(chalk.black.bgCyan("total links:", totalLinks));

let arrayOfBrokenLinks = [];
let arrayOfCorrectLinks = [];

function verifyLinks(links) {
// let indexVal = process.argv.indexOf("--validate")
// if (indexVal < 0) {
links.forEach(link => {
fetch(link)
.then(res => {
let status = res.status
if (status === 200) {
arrayOfCorrectLinks.push(link)
log(chalk.bgGreen(link, "Status OK: ", status))
}
else {
arrayOfBrokenLinks.push(link)
log(chalk.bgRed(link, "Broken link: ", status))
}
}
)

})
}
// }

verifyLinks(links)

log(chalk.cyan("Total links:", totalLinks));
log(chalk.bgGreen("Working links: ", arrayOfCorrectLinks));
log(chalk.bgRedBright("Broken links: ", arrayOfBrokenLinks));


// log("status: ", verifyLinks(links))


// function statistics(links) {

// let total = links.lenght
// log(chalk.cyan("Total links:", total));
// log(chalk.bgGreen("Working links: ", arrayOfCorrectLinks.lenght));
// log(chalk.bgRedBright("Broken links: ", arrayOfBrokenLinks.lenght));
// }

// statistics(links)
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "markdown-links",
"version": "1.0.0",
"description": "Get links from a markdown file and verify their status.",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "ava"
},
"keywords": [
"cli-app",
"cli",
"links",
"markdown",
"verify",
"stats"
],
"dependencies": {
"chalk": "^4.0.0",
"fs": ".0.1-secu0rity",
"meow": "^7.0.1",
"node-fetch": "^2.6.0",
"path": "^0.12.7",
"yargs": "^15.3.1"
},
"devDependencies": {
"ava": "^3.8.2",
"jest": "^26.0.1"
}
}
13 changes: 13 additions & 0 deletions readmeprueba.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Tópicos: [Node.js](https://nodejs.org/en/),
[módulos (CommonJS)](https://nodejs.org/docs/latest-v0.10.x/api/modules.html),
[file system](https://nodejs.org/api/fs.html),
[path](https://nodejs.org/api/path.html),
[http.get](https://nodejs.org/api/http.html#http_http_get_options_callback),
parsing,
[markdown](https://daringfireball.net/projects/markdown/syntax), CLI,
[npm-scripts](https://docs.npmjs.com/misc/scripts),
[semver](https://semver.org/), ...

[link roto](https://this-is-a-broken-link)
[Fake link](https://this-a-fake-link.com/)
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const test = require('ava');

test('foo', t => {
t.pass();
});

test('bar', async t => {
const bar = Promise.resolve('bar');
t.is(await bar, 'bar');
});