Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minify-xml

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minify-xml

Fast XML minifier / compressor / uglifier with a command-line

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.4K
increased by0.09%
Maintainers
1
Weekly downloads
 
Created
Source

minify-xml

minify-xml is a lightweight and fast XML minifier for NodeJS with a command line.

Existing XML minifiers commonly only remove comments and whitespace between tags. This minifier also includes minification of tags, e.g. by collapsing the whitespace between multiple attributes. Additionally the minifier is able to remove any unused namespace declarations. minify-xml is based on regular expressions and thus executes blazingly fast.

Installation

npm install minify-xml -g

Usage

const minifyXML = require("minify-xml").minify;

const xml = `<Tag xmlns:used="used_ns" xmlns:unused="unused_ns">
    <!--
        With the default options all comments will be removed and whitespace
        in tags, like spaces between attributes, will be collapsed / removed
    -->
    <AnotherTag attributeA   =   "..."   attributeB    =   "..."   />

    <!-- By default any unused namespaces will be removed from the tags: -->
    <used:NamespaceTag>
        any valid element content is left unaffected (strangely enough = " ... "
        and even > are valid characters in XML, only &lt; must always be encoded)
    </used:NamespaceTag>
</Tag>`;

console.log(minifyXML(code));

This outputs the minified XML:

<Tag xmlns:used="used_ns"><AnotherTag attributeA="..." attributeB="..."/><used:NamespaceTag>
        any valid element content is left unaffected (strangely enough = " ... "
        and even > are valid characters in XML, only &lt; must always be encoded)
    </used:NamespaceTag></Tag>

Options

You may pass in the following options when calling minify:

require("minify-xml").minify(`<tag/>`, { ... });
  • removeComments (default: true): Remove comments like <!-- ... -->.

  • removeWhitespaceBetweenTags (default: true): Remove whitespace between tags like <anyTag /> <anyOtherTag />.

  • collapseWhitespaceInTags (default: true): Collapse whitespace in tags like <anyTag attributeA = "..." attributeB = "..." />.

  • removeUnusedNamespaces (default: true): Removes any namespaces from tags, which are not used anywhere in the document, like <tag xmlns:unused="any_url" />.

CLI

You can run minify-xml from the command line to minify XML files:

minify-xml sitemap.xml
minify-xml --in-place blog.atom

Author

XML minifier by Kristian Kraljić. Original package and CLI by Mathias Bynens.

Reporting bugs

Please file any issues on Github.

License

This library is dual licensed under the MIT and Apache 2.0 licenses.

Keywords

FAQs

Package last updated on 05 Aug 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc