Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

just-nu

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-nu - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

.editorconfig

84

just-nu.js
#! /usr/bin/env node
const http = require("http");
/* eslint-env node */
/* eslint no-console:0 */
const options = {
host: 'www.aftonbladet.se',
port: 80
};
const http = require('http');
const colour = require('colour');
let justNu = 0;
let justNuCount = 0
, justNuTopics = [];
function getJustNuCount (string) {
return (string.match(/JUST NU:/g) || []).length;
console.log(colour.yellow(' ---------------------'));
console.log(colour.yellow(' A F T O N B L A D E T'));
console.log(colour.yellow(' ---------------------'));
console.log('\n');
/**
* Find number of "JUST NU:" in a string.
*
* @param {String} text - String to search in
* @return {Number} - Occurances found.
*/
function getJustNuCount (text) {
return (text.match(/JUST NU:/g) || []).length;
}
function reportAndClose() {
console.log('Antal "JUST NU" just nu:', justNu);
/**
* Finds multiple "JUST NU" in a string and returns them in an array.
*
* @param {String} text - String to search in
* @return {String[]} - Array of topics found.
*/
function saveTopic (text) {
const justNus = text.split(/JUST NU:/g);
let arr = [];
for (let justNu of justNus) {
if (justNu.indexOf('</span>') !== -1 && justNu.indexOf('</h2>') !== -1) {
let topic = justNu.split('</span>')[1].split('</h2>')[0];
if (topic.indexOf('<') === -1) {
arr.push(topic);
}
}
}
return arr;
}
/**
* Prints to console.
*
* @param {Number} count - Number of "JUST NU :"s to reportAndClose
* @param {String[]} topics - Array of topics as strings to list in console.
*/
function reportAndClose (count, topics) {
console.log(colour.white(' Antal "JUST NU" just nu:'), colour.cyan(count));
console.log('\n');
for (let topic of topics) {
console.log(' ' + colour.red('√') + topic.toUpperCase());
}
process.exit(0);
}
const req = http.request(options, (res) => {
http.request({ host: 'www.aftonbladet.se' }, res => {
res.setEncoding('utf8');
res.on('data', (chunk) => {
justNu += getJustNuCount(chunk);
res.on('data', chunk => {
let count = getJustNuCount(chunk);
if (count > 0) {
justNuCount += count;
justNuTopics = justNuTopics.concat(saveTopic(chunk));
}
});
res.on('end', reportAndClose);
});
req.end();
res.on('end', () => reportAndClose(justNuCount, justNuTopics));
}).end();
{
"name": "just-nu",
"version": "1.0.3",
"version": "2.0.0",
"description": "Antal JUST NU på Aftonbladet",
"main": "index.js",
"scripts": {
"test": "eslint *.js",
"start": "node just-nu"

@@ -23,3 +24,10 @@ },

"url": "https://github.com/enjikaka/just-nu.git"
},
"devDependencies": {
"eslint": "^3.3.0",
"eslint-config-tidal": "^1.0.3"
},
"dependencies": {
"colour": "^0.7.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc