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

g-trends

v0.0.9

Published

A simple API client for Google Trends.

Downloads

424

Readme

G Trends

A simple API client for Google Trends.

Quick Start

npm install g-trends

Super simple to use

G Trends client is designed to be the simplest way for developers to access Google Trends data.

const { ExploreTrendRequest } = require('g-trends')

const explorer = new ExploreTrendRequest()

explorer.addKeyword('Dream about snakes')
        .compare('Dream about falling')
        .download().then( csv => {
            console.log('[✔] Done, take a look at your beautiful CSV formatted data!')
            console.log(csv)
        }).catch( error => {
            console.log('[!] Failed fetching csv data due to an error',error)
        })
[✔] Done, take a look at your beautiful CSV formatted data!
[ [ 'Day',
    'Dream about snakes: (Worldwide)',
    'Dream about falling: (Worldwide)' ],
  [ '2017-09-29', '26', '58' ],
  [ '2017-09-30', '68', '88' ],
  [ '2017-10-01', '57', '100' ],
  [ '2017-10-02', '72', '60' ],
  [ '2017-10-03', '65', '70' ],
  [ '2017-10-04', '35', '55' ],
  [ '2017-10-05', '55', '58' ],
  [ '2017-10-06', '34', '80' ],
  [ '2017-10-07', '66', '69' ],
  ...

ExploreTrendRequest

Method Listing

normalize()

the normalize method give you a quick way to overwrite the default normalization function and process the raw Google Trends data before it resolved.

const explorer = new ExploreTrendRequest()
explorer.normalize( raw => raw.split("\n") ).addKeyword('dogs').

searchProvider()

The searchProvider method allow you to choose the search provider you wise to extract data from.


const { ExploreTrendRequest,SearchProviders } = require('g-trends')

const explorer = new ExploreTrendRequest()

// SearchProviders.News, SearchProviders.Web, SearchProviders.YouTube
// SearchProviders.GoogleImages, SearchProviders.GoogleShopping

explorer.searchProvider(SearchProviders.News)
        .addKeyword('Bitcoin')
        .download().then( csv => {
            console.log('[✔] Done, take a look at your beautiful CSV formatted data!')
            console.log(csv)
        }).catch( error => {
            console.log('[!] Failed fetching csv data due to an error',error)
        })

addKeyword()

The addKeyword method appends a given keywords to the trend exploration request.

const explorer = new ExploreTrendRequest()

explorer.searchProvider(SearchProviders.News)
        .addKeyword('Bitcoin')
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

between()

The between method allows you to extract trend data for a given time period.

const explorer = new ExploreTrendRequest()

explorer.searchProvider(SearchProviders.News)
        .addKeyword('Bitcoin')
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .between('2017-01-01','2017-01-10')
        .download().then( csv => {
            console.log(csv)
        })

pastHour()

The pastHour method allows you to extract trend data for a the past hour.

explorer.pastHour()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

pastFourHours()

The pastFourHours method allows you to extract trend data for a the past 4 hours.

explorer.pastFourHours()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

pastDay()

The pastDay method allows you to extract trend data for a the past day.

explorer.pastDay()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past7Days()

The past7Days method allows you to extract trend data for a the past 7 days.

explorer.past7Days()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past30Days()

The past30Days method allows you to extract trend data for a the past 30 days.

explorer.past30Days()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past90Days()

The past90Days method allows you to extract trend data for a the past 90 days.

explorer.past90Days()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past12Months()

The past12Months method allows you to extract trend data for a the past 12 months.

explorer.past12Months()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past5Years()

The past5Years method allows you to extract trend data for a the past 5 years.

explorer.past5Years()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

from2004ToPresent()

The from2004ToPresent method allows you to extract trend data from 2004 to the present.

explorer.from2004ToPresent()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })