diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/package.json b/package.json index 590a721..d61e4ae 100644 --- a/package.json +++ b/package.json @@ -13,18 +13,21 @@ "type": "git", "url": "http://github.com/vkiryukhin/pretty-data.git" }, - "main":"./pretty-data", + "main": "./pretty-data", "keywords": [ - "pretty print", - "beautify", - "minify", - "XML", - "JSON", - "CSS", - "SQL" + "pretty print", + "beautify", + "minify", + "XML", + "JSON", + "CSS", + "SQL" ], "license": "MIT", "engine": { "node": ">=0.4.9" + }, + "dependencies": { + "minify-xml": "^2.1.0" } } diff --git a/pretty-data.js b/pretty-data.js index 740a4c2..3cb2858 100644 --- a/pretty-data.js +++ b/pretty-data.js @@ -15,24 +15,26 @@ * pd.css(data ) - pretty print CSS; * pd.sql(data) - pretty print SQL; * -* pd.xmlmin(data [, preserveComments] ) - minify XML; -* pd.jsonmin(data) - minify JSON; -* pd.cssmin(data [, preserveComments] ) - minify CSS; -* pd.sqlmin(data) - minify SQL; +* pd.xmlmin(data [, preserveComments, options] ) - minify XML; +* pd.jsonmin(data) - minify JSON; +* pd.cssmin(data [, preserveComments] ) - minify CSS; +* pd.sqlmin(data) - minify SQL; * * PARAMETERS: * -* @data - String; XML, JSON, CSS or SQL text to beautify; -* @preserveComments - Bool (optional, used in minxml and mincss only); -* Set this flag to true to prevent removing comments from @text; -* @Return - String; +* @data - String; XML, JSON, CSS or SQL text to beautify; +* @preserveComments - Bool (optional, used in xmlmin and cssmin only); +* Set this flag to true to prevent removing comments from @data; +* @options - Object (optional, used in xmlmin only); +* Use this object to set additional flags flags; +* @Return - String; * * USAGE: * * var pd = require('pretty-data').pd; * * var xml_pp = pd.xml(xml_text); -* var xml_min = pd.xmlmin(xml_text [,true]); +* var xml_min = pd.xmlmin(xml_text [, true, { removeWhitespaceBetweenTags: false }]); * var json_pp = pd.json(json_text); * var json_min = pd.jsonmin(json_text); * var css_pp = pd.css(css_text); @@ -285,11 +287,10 @@ pp.prototype.sql = function(text) { // ----------------------- min section ---------------------------------------------------- +const minifyXml = require("minify-xml").minify; pp.prototype.xmlmin = function(text, preserveComments) { - - var str = preserveComments ? text - : text.replace(/\/g,""); - return str.replace(/>\s{0,}<"); + return minifyXml(text, typeof preserveComments === "boolean" ? + { removeComments: !preserveComments } : preserveComments); }; pp.prototype.jsonmin = function(text) {