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

markupDiff

v0.0.2

Published

Finds differences in modular markup

Downloads

1

Readme

MarkupDiffjs

MarkupDiffjs is a NodeJs tool for detecting differences in markup. It is built around a workflow style wherein markup is organized into discreet modules. One team creates markup in a codebase (normally a frontend rapid prototyping environment), and another team re-implements that markup in a separate codebase (normally a deep stack like a content management system). Detecting markup changes in this scenario can be difficult, and this tool helps to assist with that.

Assumptions

Your markup is stored in HTML files.

Your markup is modular, you are willing to delimit your modules with some kind of inline comment, and you can give your modules unique names.

<!--module:MyModule -->
<div>
   ...
<div>
<!--/module -->

You want to check markup structure, not content. Elements and attributes like class name matter, everything else is noise. The following pieces of markup are therefore functionally identical even though image paths and alt/title differ.

File1.html :
<!--module:MyModule -->
<div class="MyModule">
   <img class="MyModule-image" src="someImage.jpg" alt="">
<div>
<!--/module -->

File2.html :
<!--module:MyModule -->
<div class="MyModule">
   <img class="MyModule-image" src="someOther.jpg" title="Some Other Image" />
<div>
<!--/module -->

The following are not identical because image class name differs.

File3.html :
<!--module:MyModule -->
<div class="MyModule">
   <img class="MyModule-image" src="someImage.jpg" />
<div>
<!--/module -->

File4.html :
<!--module:MyModule -->
<div class="MyModule">
   <img class="MyModule-otherimage" src="someImage.jpg" />
<div>
<!--/module -->

and the following cannot be compared because module names differ even though markup is identical.

File5.html :
<!--module:MyModule -->
<div class="MyModule">
   <img class="MyModule-image" src="someImage.jpg" alt="">
<div>
<!--/module -->

File6.html :
<!--module:MyOtherModule -->
<div class="MyModule">
   <img class="MyModule-image" src="someImage.jpg" alt="">
<div>
<!--/module -->

Use

Compare modules found in two local files.

var markupDiff = require('markupDiff');
markupDiff.compare(
    { glob: './some/file1.html' },
    { glob: './some/file2.html' }
);

Compare modules from a remote HTML document, and all the files nested in a local folder.

markupDiff.compare(
    { host: 'www.someDomain.com', port : 8080, path : '/doc.html'},
    { glob: './some/path/**/*.html' },
    { glob: './some/other/path/**/*.html' }
);

Any combination of remote or local sources can be used.

Options

Options is not required. It can be used to override the following default settings.

markupDiff.compare(
    ...
    {
        encoding : 'utf8',
        consoleOut : true,
        consoleOutFirstErrorOnly : true
        attributes : ['class', 'data-*'],
        processInnerText : true,
        startModuleRegex : /<!--module:(\S*) -->/,
        endModuleRegex : /<!--\/module -->/,
        startIgnoreRegex : /<!--module!ignore-->/,
        endIgnoreRegex : /<!--\/module!ignore-->/
    }
);

encoding

Default: 'utf8'

Encoding used for loading file content.

consoleOut

Default: true

If true, errors will be written to the console by MarkupDiff.js.

attributes

Default: [] (all attributes).

The element attributes you want to include in your check.

['class', 'data-*']

Will compare the contents of class and any attribute starting with 'data-'. Values must be regex-ready strings.

startModuleRegex

Default: //

Regex used to identify the start of your modules. Must return module name.

endModuleRegex

Default: //

Regex used to identify the end of your modules.