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

wpdb-js

v1.0.2

Published

retrieve posts/categories/tags data from wordpress database

Downloads

1

Readme

About

This package is for retrieving posts/categories/tags directly from wordpress database.

Written in TypeScript and type declarations are provided.

Usage

Installation

$ npm i wpdb-js mysql2

Initialization

knex.js is used internally. knex-style config should be passed at initialization.

const db = require('wpdb-js')({
  client: "mysql2",
  connection: {
    host: "...",
    user: "...",
    password: "...",
    database: "...",
  },
});

Methods

listCategories

db.listCategories()
  .then(categories => {
    // categories is like
    // [
    //   {
    //     id: 1,
    //     slug: 'category1',
    //     name: 'Category 1',
    //     parent: null,
    //   },
    //   {
    //     id: 2,
    //     slug: 'category2',
    //     name: 'Category 2',
    //     parent: {
    //       id: 1,
    //       slug: 'category1',
    //       name: 'Category 1',
    //     },
    //   },
    // ]
  });

listTags

db.listTags()
  .then(tags => {
    // tags is like
    // [
    //   { id: 10, slug: 'tag1', name: 'Tag 1' },
    //   { id: 20, slug: 'tag2', name: 'Tag 2' },
    // ]
  });

listPosts

db.listPosts()
  .then(posts => {
    // posts is like
    // [
    //   {
    //     id: 100,
    //     excerpt: 'excerpt1',
    //     modified: new Date(1),
    //     published: new Date(6),
    //     title: 'title1',
    //     status: 'publish',
    //     author: {
    //       id: 1,
    //       displayName: '',
    //     },
    //     thumbnail: {
    //       width: 100,
    //       height: 100,
    //       file: '',
    //     },
    //   },
    // ]
  });
// sort posts (ascending order)
db.listPosts({ sortBy: 'id' })
db.listPosts({ sortBy: 'published' })
db.listPosts({ sortBy: 'modified' })
// sort posts (descending order)
db.listPosts({ sortBy: 'id', order: 'desc' })
// filter by status
db.listPosts({ status: 'publish' })
db.listPosts({ status: 'draft' })
// filter by category id
db.listPosts({ categoryId: 1 })
// filter by tag id
db.listPosts({ tagId: 10 })
// set limit/offset
db.listPosts({ limit: 100 })
db.listPosts({ limit: 100, offset: 100 })

findCategory

db.findCategory({ id: 1 })
  .then(category => {
    // `category` is like
    // {
    //   id: 1,
    //   slug: 'category1',
    //   name: 'Category 1',
    //   parent: null,
    //   children: [
    //     { id: 3, slug: 'category3', name: 'Category 3' },
    //     { id: 4, slug: 'category4', name: 'Category 4' },
    //   ],
    // }
  });

findTag

db.findTag({ id: 10 })
  .then(tag => {
    // `tag` is like
    // {
    //   id: 10,
    //   slug: 'tag1',
    //   name: 'Tag 1',
    // }
  });

findPost

db.findPost({ id: 100 })
  .then(post => {
    // `post` is like
    // {
    //   id: 100,
    //   excerpt: 'excerpt1',
    //   modified: new Date(1),
    //   published: new Date(6),
    //   title: 'title1',
    //   content: 'content1',
    //   author: {
    //     id: 1,
    //     displayName: '',
    //   },
    //   tags: [
    //     {
    //       id: 10,
    //       slug: 'tag1',
    //       name: 'Tag 1',
    //     },
    //     {
    //       id: 20,
    //       slug: 'tag2',
    //       name: 'Tag 2',
    //     },
    //   ],
    //   categories: [
    //     {
    //       id: 1,
    //       slug: 'category1',
    //       parent: null,
    //     },
    //   ],
    //   thumbnail: {
    //     file: '',
    //     width: 100,
    //     height: 100,
    //   },
    // }
  });