New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dreamworld/web-util

Package Overview
Dependencies
Maintainers
4
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dreamworld/web-util - npm Package Compare versions

Comparing version 1.3.1-trim-html-is-not-woking-with-nested-html.1 to 1.3.1-trim-html-is-not-woking-with-nested-html.2

94

htmlTrim.js

@@ -14,23 +14,30 @@ import textToHtml from './textToHtml';

let children = Array.from(html.children || []);
let bRemoveChild = true;
var children = Array.from(html.children || []);
var bRemoveChild = true;
children.forEach(el => {
if (bRemoveChild && el.textContent.trim() === "") {
html.removeChild(el)
} else {
bRemoveChild = false;
if(bRemoveChild) {
if(el.textContent.trim() === "") {
html.removeChild(el);
} else {
bRemoveChild = false;
trimStartTextNode(el);
}
}
});
//find first text nodes element and text content trim from start.
let trimStart = false;
let childNodes = Array.from(el.childNodes || []);
childNodes.forEach(el => {
if(!trimStart && el.nodeType == Node.TEXT_NODE && el.textContent && el.textContent.trim()) {
el.textContent = el.textContent.trimStart();
return html;
}
const trimStartTextNode = (el) => {
var trimStart = false;
var childNodes = Array.from(el.childNodes || []);
childNodes.forEach(child => {
if(!trimStart) {
if(!child.textContent || !child.textContent.trim() === "") {
el.removeChild(child);
} else {
if(child.nodeType == Node.TEXT_NODE) {
child.textContent = child.textContent.trimStart();
trimStart = true;
}
});
//If text node is not found
if(!trimStart) {
el = htmlTrimStart(el);
}

@@ -40,3 +47,5 @@ }

return html;
if(!trimStart && childNodes && childNodes[0]) {
trimStartTextNode(childNodes[0]);
}
}

@@ -55,24 +64,32 @@

let children = Array.from(html.children || []).reverse();
let bRemoveChild = true;
var children = Array.from(html.children || []).reverse();
var bRemoveChild = true;
bRemoveChild = true;
children.forEach(el => {
if (bRemoveChild && el.textContent.trim() === "") {
html.removeChild(el);
} else {
bRemoveChild = false;
if(bRemoveChild) {
if (el.textContent.trim() === "") {
html.removeChild(el);
} else {
bRemoveChild = false;
trimEndTextNode(el);
}
}
});
//find first text nodes element and text content trim from start.
let trimEnd = false;
let childNodes = Array.from(el.childNodes || []).reverse();
childNodes.forEach(el => {
if(!trimEnd && el.nodeType == Node.TEXT_NODE && el.textContent && el.textContent.trim()) {
el.textContent = el.textContent.trimEnd();
return html;
}
const trimEndTextNode = (el) => {
//find first text nodes element and text content trim from start.
var trimEnd = false;
var childNodes = Array.from(el.childNodes || []).reverse();
childNodes.forEach(child => {
if(!trimEnd) {
if(!child.textContent || !child.textContent.trim() === "") {
el.removeChild(child);
} else {
if(child.nodeType == Node.TEXT_NODE) {
child.textContent = child.textContent.trimEnd();
trimEnd = true;
}
});
//If text node is not found
if(!trimEnd) {
el = htmlTrimEnd(el);
}

@@ -82,3 +99,6 @@ }

return html;
//If text node is not found
if(!trimEnd && childNodes && childNodes[0]) {
trimEndTextNode(childNodes[0]);
}
}

@@ -95,3 +115,3 @@

}
//String convert into html.

@@ -98,0 +118,0 @@ if (typeof html === 'string') {

{
"name": "@dreamworld/web-util",
"version": "1.3.1-trim-html-is-not-woking-with-nested-html.1",
"version": "1.3.1-trim-html-is-not-woking-with-nested-html.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -73,3 +73,3 @@ # web-util

<div></div>
<div> hello </div>
<div> hello1 </div>
<div></div>

@@ -79,6 +79,16 @@ <div></div>

<div></div>
<div> hello2 </div>
<div></div>
<div></div>
<div></div>
<div></div>
```
- **Output:**
```
<div>hello</div>
<div>hello1 </div>
<div></div>
<div></div>
<div></div>
<div></div>
<div> hello2</div>
```

@@ -98,5 +108,6 @@

<div></div>
<div> hello </div>
<div> hello1 </div>
<div></div>
<div></div>
<div> hello2 </div>
<div></div>

@@ -112,3 +123,8 @@ <div></div>

```
<div><div>hello</div></div>
<div>
<div>hello1 </div>
<div></div>
<div></div>
<div> hello2</div>
</div>
```
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