New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

mhtml2html

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mhtml2html

Converts .mhtml to a single .html page.

Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
878
-28.5%
Maintainers
1
Weekly downloads
 
Created
Source

mhtml2html.js

npm version circleci

mhtml2html converts MHTML files to a single HTML file using javascript.

Usage | API | Development

Usage

mhtml2html is compatible with Node >= v4.3.2.

It has only been tested with MHTML files built and used with the latest versions of Chrome

Node.js

'use strict';

const mhtml2html = require('mhtml2html');

fs.readFile('input.mhtml', 'utf8', function (err, input) {
    if (err) {
        throw err;
    }

    // Returns the html document with embedded resources.
    const htmlDocument = mhtml2html.convert(input);

    // Output the html file.
    fs.writeFile('output.html', htmlDocument.documentElement.innerHTML, err => {
        if(err) {
            return console.log(err);
        }
    });
});

You can also use it from the command line by running:

mhtml2html <path_to_mhtml_file> <output_file_path>

Browser

Include the mhtml2html script under the dist folder:

<script type="text/javascript" src="mhtml2html-${VERSION}-min.js"></script>
<script>
    var reader = new FileReader();

    reader.addEventListener("loadend", function() {
        html = mhtml2html.parse(this.result);

        // Alternatively you could convert the result directly and have
        // it implicitly parsed i.e html = mhtml2html.convert(this.result);

        console.log(mhtml2html.convert(html));
    });

    reader.readAsText(mhtmlBlob);
</script>

API

noConflict

mhtml2html.noConflict();

  • Resets the module that was previously defined for browser conflict resolution.
  • Returns a localized version of mhtml2html.

parse

mhtml2html.parse(mhtml_string, html_only = false);

  • Accepts an MHTML String.
  • If html_only is true, returns the html document without resources. Otherwise it returns an MHTML parsed object:
{
    "index" : "<html-index-url>",
    "assets": {
        "<asset-url>" : {
            "data" : "<resource-string>",
            "id": "<frame-id>",
            "type": "<resource-type",
            "encoding": "<resource-encoding>"
        }
    }
}

convert

mhtml2html.convert(mhtml_string or mhtml_object);

  • Accepts an MHTML String or parsed MHTML Object.
  • Returns an html document element.

Development

To build and test mhtml2html:

  • If node_modules haven't been installed already, run npm install from the root directory.
  • Run ./node_modules/gulp/bin/gulp.js to build the scripts and run tests.

License

Released under the MIT License

FAQs

Package last updated on 17 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts