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

wporg-mini

v0.1.5

Published

A tiny WpOrg API client for requesting all the themes and plugins from the WordPress directory

Downloads

12

Readme

Wporg Mini

This project provides a npm module that can query the WordPress.org API.Currently it supports pulling down plugin and theme information only.

Written in TypeScript, compiled to JavaScript as a node module. See 'Developer' section for how to deploy.

Note that only the GitHub repo, not the npm repository, contains example files and the build script. To build and use the example, read the Developer Docs section below.

Installation

From the npm repository

    npm install wporg-mini

Options

When creating the wpOrg object,you can pass options in its constructor.

options = {
            apiDelay: 2000, //the number of microseconds between api calls
            maxPages: 3, // the maximum number of pages. If you set this to a very high number, 9999 for example, it will stop after retrieving all pages
            maxItemsPerPage: 1 // the maximum items to retrieve from each page. WordPress default appears to be 23
        }

Example

An example is included in the GitHub project, clone and run it:

Clone

    git clone https://github.com/ajdruff/wporg-mini.git
    cd wporg-mini/example

Install

    yarn add wporg-mini 
    

if you built from source using the Developer section below, you'll use:

  yarn add ../dist #run this only if you are installing remotely and are not running `yarn add wporg-mini`

Run the example to list a few themes

    node ./index.js

Output - Upon successful execution, the callback function in the example prints out the first few themes of the first few pages of the WordPress.org Theme directory.

    PageNumber: 1 Item Number: 0 Theme:Pokama Lite
    PageNumber: 2 Item Number: 0 Theme:Store Commerce
    PageNumber: 3 Item Number: 0 Theme:Switch Lite

To get a similar output for plugins, just uncomment the plugins code in example/index.js:

    //Plugins
    const wpPlugins = new wpOrg(options, "plugins");
    wpPlugins.getAllItems(printOutPlugin);

Note that the sequence of results will sometimes be unpredictable due to the asynchronous nature of the API calls. For example, if you run both at the same time, you'll notice that the results are intermixed even though you call the themes api endpoints before starting the plugin api calls.

Usage

#add the module

    const wpOrg = require('wporg-mini')

#set options

    const options = {
        apiDelay: 2000, 
        maxPages: 3,
        maxItemsPerPage: 1
    }

With these options, wporg-mini will wait 2 seconds before requesting another item from the API, and it will get the first 3 pages and will only retrieve one result per page.

#create an instance of the wpOrg module

    const wpThemes = new wpOrg(
        options, //see options section of readme
        "themes"   // 'themes' or 'plugins'
        );

#create a callback to process the result

    function printOutTheme(item, pageNumber, itemNumber) {
        console.log('PageNumber: ' + pageNumber + ' Item Number: ' + itemNumber + ' Theme:' + item["name"])

    }

Call the getAllItems method to retrieve the results and trigger the callback

   wpThemes.getAllItems(printOutTheme);

Developer Docs

This section only applies to you if want to modify the module source code and rebuild it for distribution.

Requirements

To build the package locally you will need:

  • A Bash shell environment
  • TypeScript compiler
  • yarn
  • npm
  • git

Local Install

Clone and build

    git clone https://github.com/ajdruff/wporg-mini.git
    cd wporg-mini
    npm run build

This does the following::

  1. Compiles the TypeScript file src/wporg-mini.tsc into dist/lib/wporg-mini.js
  2. Adds nodejs package.json and supporting files to directory dist
  3. Recreates the example directory and contents

To install into your project:

    cd /path/to/your/node/project
    yarn add /path/to/wporg-min/dist

Try out the example to see how you'd install it locally and use it in a project.

Making Changes

To modify the code, you must edit the files in src and then build the project.

so... the general flow is:

Edit

    vim src/wporg-mini.ts

Build

    npm run build

the resulting module will be built in directory dist. See Example for how you'd install.

Commit

Something like:

git commit -am 'added an awesome feature'
git checkout master
git merge my awesome-feature

Release

    np

this uses the np package and will push to the npm and remote repo

Authors

Andrew Druffner [email protected]

Contributions Welcome

Please submit a pull request!

License

MIT