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

shopback-seo-parser

v1.0.1

Published

A Nodejs code challenge.

Downloads

7

Readme

General

Environment

Windows

NodeJS 10.9.0

Linux Based OS Ubuntu/Debian

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

Linux Based OS CentOS/Redhat

curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
sudo apt-get install -y nodejs


Demo

npm install && npm start


Usage

npm install shopback-seo-parser --save

File path

        const ShopbackSEOParser = require('shopback-seo-parser');
        const parser = new ShopbackSEOParser();

        parser.parse('./template.html')
            .then((result)=>{
                //Get result.
            });

Stream

        const fs = require('fs');
        const ShopbackSEOParser = require('shopback-seo-parser');
        const parser = new ShopbackSEOParser();

        fs.createReadStream('./template.html')
            .pipe(parser)
            .pipe(process.stdout); 
            //result

Async

        const ShopbackSEOParser = require('shopback-seo-parser');
        const parser = new ShopbackSEOParser();
        let result = await parser.parse('./template.html');
        //result

Defaults rules

./rules/pre-defined-rules.js

	const rules = [
    /**
     * 1. Detect if any <img /> tag without alt attribute
    */

    {
        tag: {
            include: 'img',
        },
        attrs: {
            without: {
                alt: undefined
            }
        }
    },

    /**
     * 2. Detect if any <a /> tag without rel attribute
    */

    {
        tag: {
            include: 'a',
        },
        attrs: {
            without: {
                rel: undefined
            }
        }
    }, 
    
    /**
     * 3. In <head> tag
     *    i. Detect if header doesn’t have <title> tag
     *    ii. Detect if header doesn’t have <meta name=“descriptions” ... /> tag
     *    iii. Detect if header doesn’t have <meta name=“keywords” ... /> tag
    */

    {
        scope: 'head',
        tag: {
            include: 'title',
        }
    }, 
    {
        scope: 'head',
        tag: {
            exclude: 'img',
        },
        attrs: {
            with: {
                name: 'description'
            }
        }
    }, {
        scope: 'head',
        tag: {
            exclude: 'img',
        },
        attrs: {
            with: {
                name: 'keywords'
            }
        }
    }, 
    
    /**
     * 4. Detect if there’re more than 15 <strong> tag in HTML (15 is a value should be
configurable by user)
    */
    
    {
        tag: {
            include: 'strong',
        },
        condition: {
            '>': 15
        }
    }, 
    
    /**
     * 5. Detect if a HTML have more than one <H1> tag.
    */
    
    {
        tag: {
            include: 'H1',
        },
        condition: {
            '>': 1
        }
    }
];

Speciffy default rules

  • Specify default rules by number array.
        const ShopbackSEOParser = require('shopback-seo-parser');
        const parser = new ShopbackSEOParser({
            defaultRules:[1,3,5]
        });
        parser('./template.html')
            .then((result)=>{
                //Get result.
            });

Customize rules

  • Rule format : This mean find the tag img without alt attribute more than 10 tags.
    {
        "tag": {
            "include": "img"
        },
        "attrs": {
            "without": {
                "alt": "undefined"
            }
        },
        "condition": {
            ">": 10        
        }
    }
  • Set customize rules.
    const customizeRules = [
        {
            "tag": {
                include: "img"
            },
            attrs: {
                without: {
                    "alt": undefined
                }
            },
            condition: {
                ">": 10        
            }
        }
    ];

    const ShopbackSEOParser = require('shopback-seo-parser');
    const parser = new ShopbackSEOParser({
        rules: customizeRules
    })
    parser.parse('./template.html')
        .then((result)=>{
                //Get result.
        });

Development

git clone https://github.com/ssuio/shopback-SEO-parser
npm install
npm test

current active branch: development


Project Structure

  ├models

  │  ├html-parser.js

  │  ├result-parser.js

  │  ├rules-handler.js

  │  ├shopback-seo-parser.js

  ├rules

  │  ├customize-rules.js

  │  ├pre-defined-rules.js

  ├error

  │  ├sb-seo-errors.js

  │  ├config-errors.js

  │  ├rule-errors.js

  │  ├parse-errors.js

  ├demo

  ├test

  │  ├result-parser.mocha.js

  │  ├shopback-seo-parser.mocha.js

  │  ├templates.js

  ├index.js

  ├package.json

  ├README.md

  ├eslintrc.json

  ├LICENSE


UnitTest

Run specified test

step1 install mocha globally

npm install mocha -g

step2 run specified test

mocha <filepath>.mocha.js

Run all test suite

npm test

Author: Noah

LastUpdated: 8/31/2018 04:56:12 PM