From 491e299411ceb1abd75f225edcffaaf24f24a76a Mon Sep 17 00:00:00 2001 From: DanielJDufour Date: Sun, 21 Aug 2022 05:51:33 -0700 Subject: [PATCH] remove comments --- README.md | 11 +++++++++++ index.js | 4 +++- package.json | 3 ++- remove-comments.js | 6 ++++++ test/test.js | 13 +++++++++++++ test/test.ts | 4 +--- 6 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 remove-comments.js diff --git a/README.md b/README.md index 83e6ce9..c9a8d84 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,17 @@ const tags = findTagByPath(xml, ["Metadata", "MDI"]); // tags is an array of tags ``` +## remove comments +```javascript +const removeComments = require("xml-utils/remove-comments"); +const xml = ` + + +`; +removeComments(xml); +"\n \n"; +``` + ## setup download test files with: diff --git a/index.js b/index.js index c5b2aa7..91eecc0 100644 --- a/index.js +++ b/index.js @@ -3,11 +3,13 @@ const findTagByName = require("./find-tag-by-name"); const findTagsByName = require("./find-tags-by-name"); const findTagByPath = require("./find-tag-by-path"); const findTagsByPath = require("./find-tags-by-path"); +const removeComments = require("./remove-comments"); module.exports = { getAttribute, findTagByName, findTagsByName, findTagByPath, - findTagsByPath + findTagsByPath, + removeComments }; diff --git a/package.json b/package.json index 23791e4..f032357 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "find-tags-by-path.js", "get-attribute.js", "index-of-match.js", - "index-of-match-end.js" + "index-of-match-end.js", + "remove-comments.js" ], "scripts": { "f": "npm run format", diff --git a/remove-comments.js b/remove-comments.js new file mode 100644 index 0000000..8be4802 --- /dev/null +++ b/remove-comments.js @@ -0,0 +1,6 @@ +function removeComments(xml) { + return xml.replace(//g, ""); +} + +module.exports = removeComments; +module.exports.default = removeComments; diff --git a/test/test.js b/test/test.js index 148f9b7..db5614b 100644 --- a/test/test.js +++ b/test/test.js @@ -8,6 +8,7 @@ const findTagsByName = require("../find-tags-by-name.js"); const findTagByPath = require("../find-tag-by-path.js"); const findTagsByPath = require("../find-tags-by-path.js"); const getAttribute = require("../get-attribute.js"); +const removeComments = require("../remove-comments.js"); const iso = readFileSync("test/data/iso.xml", "utf-8"); const mrf = readFileSync("test/data/m_3008501_ne_16_1_20171018.mrf", "utf-8"); @@ -15,6 +16,18 @@ const tiffAux = readFileSync("test/data/rgb_raster.tif.aux.xml", "utf-8"); const nested = ""; +const commented = ` + + +`; + +test("removing comments", ({ eq }) => { + eq(removeComments(commented), "\n\n\n"); + eq(removeComments(""), ""); +}); + test("count substring", ({ eq }) => { eq(countSubstring(nested, " { const urls = findTagsByName(iso, "gmd:URL"); eq(urls[0].inner, "http://geomap.arpa.veneto.it/layers/geonode%3Aatlanteil");