xml-formatter
Advanced tools
Comparing version 3.2.1 to 3.3.0-rc-minify.0
@@ -358,3 +358,9 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.xmlFormatter = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
if (!preserveSpace) { | ||
content = content.trim(); | ||
var trimmedContent = content.trim(); | ||
if (state.options.lineSeparator) { | ||
content = trimmedContent; | ||
} else if (trimmedContent.length === 0) { | ||
content = trimmedContent; | ||
} | ||
} | ||
@@ -482,2 +488,7 @@ | ||
}); | ||
if (!options.lineSeparator) { | ||
return state.content; | ||
} | ||
return state.content.replace(/\r\n/g, '\n').replace(/\n/g, options.lineSeparator); | ||
@@ -493,2 +504,10 @@ } catch (err) { | ||
formatXml.minify = function (xml) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return formatXml(xml, Object.assign(Object.assign({}, options), { | ||
indentation: '', | ||
lineSeparator: '' | ||
})); | ||
}; | ||
if (typeof module !== 'undefined' && (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object') { | ||
@@ -495,0 +514,0 @@ module.exports = formatXml; |
@@ -358,3 +358,9 @@ require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
if (!preserveSpace) { | ||
content = content.trim(); | ||
var trimmedContent = content.trim(); | ||
if (state.options.lineSeparator) { | ||
content = trimmedContent; | ||
} else if (trimmedContent.length === 0) { | ||
content = trimmedContent; | ||
} | ||
} | ||
@@ -482,2 +488,7 @@ | ||
}); | ||
if (!options.lineSeparator) { | ||
return state.content; | ||
} | ||
return state.content.replace(/\r\n/g, '\n').replace(/\n/g, options.lineSeparator); | ||
@@ -493,2 +504,10 @@ } catch (err) { | ||
formatXml.minify = function (xml) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return formatXml(xml, Object.assign(Object.assign({}, options), { | ||
indentation: '', | ||
lineSeparator: '' | ||
})); | ||
}; | ||
if (typeof module !== 'undefined' && (typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object') { | ||
@@ -495,0 +514,0 @@ module.exports = formatXml; |
@@ -35,3 +35,9 @@ "use strict"; | ||
if (!preserveSpace) { | ||
content = content.trim(); | ||
const trimmedContent = content.trim(); | ||
if (state.options.lineSeparator) { | ||
content = trimmedContent; | ||
} | ||
else if (trimmedContent.length === 0) { | ||
content = trimmedContent; | ||
} | ||
} | ||
@@ -138,2 +144,5 @@ if (content.length > 0) { | ||
}); | ||
if (!options.lineSeparator) { | ||
return state.content; | ||
} | ||
return state.content | ||
@@ -150,2 +159,5 @@ .replace(/\r\n/g, '\n') | ||
} | ||
formatXml.minify = (xml, options = {}) => { | ||
return formatXml(xml, Object.assign(Object.assign({}, options), { indentation: '', lineSeparator: '' })); | ||
}; | ||
if (typeof module !== 'undefined' && typeof exports === 'object') { | ||
@@ -152,0 +164,0 @@ module.exports = formatXml; |
@@ -30,3 +30,9 @@ import xmlParser from 'xml-parser-xo'; | ||
if (!preserveSpace) { | ||
content = content.trim(); | ||
const trimmedContent = content.trim(); | ||
if (state.options.lineSeparator) { | ||
content = trimmedContent; | ||
} | ||
else if (trimmedContent.length === 0) { | ||
content = trimmedContent; | ||
} | ||
} | ||
@@ -133,2 +139,5 @@ if (content.length > 0) { | ||
}); | ||
if (!options.lineSeparator) { | ||
return state.content; | ||
} | ||
return state.content | ||
@@ -145,2 +154,5 @@ .replace(/\r\n/g, '\n') | ||
} | ||
formatXml.minify = (xml, options = {}) => { | ||
return formatXml(xml, Object.assign(Object.assign({}, options), { indentation: '', lineSeparator: '' })); | ||
}; | ||
if (typeof module !== 'undefined' && typeof exports === 'object') { | ||
@@ -147,0 +159,0 @@ module.exports = formatXml; |
@@ -35,2 +35,3 @@ import { XmlParserNode } from 'xml-parser-xo'; | ||
}; | ||
export declare type XMLFormatterMinifyOptions = Omit<XMLFormatterOptions, 'lineSeparator' | 'indentation'>; | ||
/** | ||
@@ -40,3 +41,6 @@ * Converts the given XML into human readable format. | ||
declare function formatXml(xml: string, options?: XMLFormatterOptions): string; | ||
declare namespace formatXml { | ||
var minify: (xml: string, options?: XMLFormatterMinifyOptions) => string; | ||
} | ||
export default formatXml; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "xml-formatter", | ||
"version": "3.2.1", | ||
"version": "3.3.0-rc-minify.0", | ||
"repository": "github:chrisbottin/xml-formatter", | ||
@@ -5,0 +5,0 @@ "bugs": { |
@@ -6,4 +6,6 @@ | ||
This module can also be used on the browser using the browserified version with a small footprint (8KB file size). | ||
Reciprocally, the `xml-formatter` package can minify pretty printed XML. | ||
The `xml-formatter` package can also be used on the browser using the browserified version with a small footprint. | ||
[![Build Status](https://github.com/chrisbottin/xml-formatter/actions/workflows/ci.yml/badge.svg)](https://github.com/chrisbottin/xml-formatter/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/xml-formatter.svg)](https://npmjs.org/package/xml-formatter) | ||
@@ -70,2 +72,31 @@ | ||
## Minify mode | ||
### Usage: | ||
```js | ||
import xmlFormat from 'xml-formatter'; | ||
const xml = ` | ||
<root> | ||
<content> | ||
<p> | ||
This is <b>some</b> content. | ||
</p> | ||
</content> | ||
</root>`; | ||
xmlFormat.minify(xml, { | ||
filter: (node) => node.type !== 'Comment', | ||
collapseContent: true | ||
}); | ||
``` | ||
### Output: | ||
```xml | ||
<root><content><p>This is<b>some</b>content.</p></content></root> | ||
``` | ||
## On The Browser | ||
@@ -72,0 +103,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72428
12
1199
147
1