npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

news-url

v1.0.1

Published

News url Identification module

Downloads

4

Readme

news-url

News url identification. An abstract module of my newspaperjs repo.

Installation

npm install --save news-url

Validation Process

First, perform a few basic checks like making sure the format of the url is right, (scheme, domain, tld).

Prepare the url by removing query arguments but keeps argument if specified.

Checks the url path length, ensurses it is <= 1. e.g http://cnn.com/career.html, this will return false

Ensures the url isn't some static resource, check the file type.

Checks for bad domains like facebook.com, twitter.com. It returns false if the domain is bad.

Then, search of a YYYY/MM/DD pattern in the url. News sites love to use this pattern, this is a very safe bet. Separators can be [.-/_]. Years can be 2 or 4 digits, must have proper digits 1900-2099. Months and days can be ambiguous 2 digit numbers, one is even optional. It automatically pass once date is detected in the url

Checks the url slug, most news url slug have usualwordsly <= 4. The words could be seperated by a "-" or "_". It also ensures the domainname isn't present in the url slug. Incase that happens, it could mean a url like this http://cnn.com/jobs/cnn-is-hiring-new_interns. It returns false incase.

API

News-url provides just a single public api for validation.

const newsUrl = require('news-url');

newsUrl.isValidNewsUrl(url, verbose=false);

By the default verbose is set to false. Setting it to true console.log validation result in details.

 let urls = [
    'http://www.cnn.com/2013/12/17/politics/senate-budget-deal/index.html?hpt=hp_t1',
    'http://www.huffingtonpost.com/akoshia-yoba/giving-the-gift-of-life-a_b_4421799.html',
    'http://www.cnn.com/interactive_legal.html',
    'http://www.cnn.com/feedback/',
    'http://shine.yahoo.com/ellen-good-news/won-8217-t-believe-colin-farrell-8217-surprise-190700409.html?vp=1',
    'http://facebook.com/profile/112121212/post_id/7327372232',
    'http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/nav-arrow.gif',
    'http://www.hlntv.com/shows/jane-velez-mitchell/?hpt=hp_livenow',
    'http://edition.cnn.com/2013/12/19/world/europe/uk-soldier-killing-profiles/index.html',
    'http://cnn.com/trends',
    'http://flickz/entertainment/music/12/03/2015/dance-for-me-wizkid.mp3'
];

let validNewsUrls = urls.filter((url)=>newsUrl.isValidNewsUrl(url)==true);

console.log(validNewsUrls); 

// ['http://www.cnn.com/2013/12/17/politics/senate-budget-deal/index.html?hpt=hp_t1',
  'http://www.huffingtonpost.com/akoshia-yoba/giving-the-gift-of-life-a_b_4421799.html',
  'http://shine.yahoo.com/ellen-good-news/won-8217-t-believe-colin-farrell-8217-surprise-190700409.html?vp=1',
  'http://edition.cnn.com/2013/12/19/world/europe/uk-soldier-killing-profiles/index.html']

Few use cases

  • News aggregator app
  • Any web scraping work.