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

wp2js

v0.1.1

Published

Parse the xml file exported in wordpress to a readable javascript object. The properties of the object can be filtered.

Downloads

12

Readme

wp2js

Parse the XML file exported in wordpress to a readable javascript object. The properties of the object can be filtered.

Installation

Install wp2js is easy, just use npm. Then execute the below command:

npm install wp2js

Usage

It is simple to use it, just like this:

var wp2js = require('wp2js');

wp2js.parse('wordpress.data.xml', function(err, data){
    /**
     * By default, the structure of the `data` object is like the below:
     *  {
     *      generator: 'http://wordpress.org/?v=3.8.4',
     *      title: 'Alex Chao',
     *      link: 'http://www.xiaocaoge.com',
     *      description: 'A frontend',
     *      language: 'zh-CN',
     *      siteUrl: 'http://www.xiaocaoge.com',
     *      blogUrl: 'http://www.xiaocaoge.com',
     *      authors: [Object],
     *      categories: [Object],
     *      tags: [Object],
     *      posts: [Object],
     *      pages: [Object],
     *      attachments: [Object]
     *  }
    */
    // ...
});

Note: The property name is shorten, such as wp:base_site_url >> siteUrl, wp:post_id >> id, content:encoded >> content, etc.

Or you can pass a configurable object as the first argument:

wp2js.parse({
    source: 'wordpress.data.xml',
    encoding: 'utf8', // The utf8 is default
}, function(err, data){
    // ...
});

Or you can filter the properties:

Note: It has a default filter level, see the #opts.

wp2js.parse({
    source: 'wordpress.data.xml',
    // Only the `categories` and `tags` are included in the `data` object
    filterConfig: ['categories', 'tags',]
}, function(err, data){
    // ...
});

Or you can filter out some properties of data.

wp2js.parse({
    source: 'wordpress.data.xml',
    filterConfig: {
        categories: false,
        tags: false
    }
}, function(err, data){
    // ...
});

You can even filter the properties of the object as the element in categories or tags.

wp2js.parse({
    source: 'wordpress.data.xml',
    filterConfig: {
        categories: ['id', 'name'],
        tags: ['id', 'name']
    }
}, function(err, data){
    // ...
});

In the same way, you can filter out some properties of the object as the element in categories.

wp2js.parse({
    source: 'wordpress.data.xml',
    filterConfig: {
        categories: {
            parent: false,
            name: false
        }
    }
}, function(err, data){
    // ...
});

At last, you can output the full data in the XML file.

wp2js.parse({
    source: 'wordpress.data.xml',
    filterConfig: 'full'
}, function(err, data){
    // ...
});

Options

At present, it only provides an asynchronous method - wp2js.parse(opts, callback).

####opts

Type: Object/String

If it is a string, then it will be as an XML file path. If it is an object, then it can include three properties: source, encoding and filterConfig.

The default value of filterConfig:

// By default, only these properties and other string properties
// (such as `title', 'description`, `language`) are included.
filterConfig: { 
    authors: {
        id: true,
        login: true,
        email: true,
        displayName: true
    },
    categories: {
        id: true,
        nicename: true,
        parent: true,
        name: true
    },
    tags: {
        id: true,
        slug: true,
        name: true
    },
    posts: {
        id: true,
        name: true,
        title: true,
        date: true,
        GMTdate: true,
        creator: true,
        content: true,
        excerpt: true,
        commentStatus: true,
        status: true,
        categories: true,
        tags: true,
        comments: true
    },
    pages: {
        id: true,
        name: true,
        title: true,
        date: true,
        GMTdate: true,
        creator: true,
        content: true,
        excerpt: true,
        commentStatus: true,
        status: true,
        categories: true,
        tags: true,
        comments: true
    },
    attachments: {
        id: true,
        name: true,
        title: true,
        date: true,
        GMTdate: true,
        creator: true,
        content: true,
        excerpt: true,
        commentStatus: true,
        status: true,
        attachmentUrl: true,
        categories: true,
        tags: true,
        comments: true
    }
}

####callback

Type: Function

It can accept two arguments - callback(err, blog). The first argument is about the error information and the second argument is an object about the blog data.

Issues

If you come cross a bug or other problems, you can submit an issue in here: https://github.com/Alex1990/wp2js/issues/

Release History

2014-10-26 0.1.1

Fix a type error.

2014-10-26 0.1.0

First version.