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

domutils

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

domutils - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

.npmignore

83

lib/stringify.js
var ElementType = require("domelementtype"),
getOuterHTML = require("dom-serializer"),
isTag = ElementType.isTag;

@@ -10,80 +11,8 @@

function getInnerHTML(elem){
return elem.children ? elem.children.map(getOuterHTML).join("") : "";
function getInnerHTML(elem, opts){
return elem.children ? elem.children.map(function(elem){
return getOuterHTML(elem, opts);
}).join("") : "";
}
//boolean attributes without a value (taken from MatthewMueller/cheerio)
var booleanAttribs = {
__proto__: null,
async: true,
autofocus: true,
autoplay: true,
checked: true,
controls: true,
defer: true,
disabled: true,
hidden: true,
loop: true,
multiple: true,
open: true,
readonly: true,
required: true,
scoped: true,
selected: true
};
var emptyTags = {
__proto__: null,
area: true,
base: true,
basefont: true,
br: true,
col: true,
frame: true,
hr: true,
img: true,
input: true,
isindex: true,
link: true,
meta: true,
param: true,
embed: true
};
function getOuterHTML(elem){
switch(elem.type){
case ElementType.Text:
return elem.data;
case ElementType.Comment:
return "<!--" + elem.data + "-->";
case ElementType.Directive:
return "<" + elem.data + ">";
case ElementType.CDATA:
return "<!CDATA " + getInnerHTML(elem) + "]]>";
}
var ret = "<" + elem.name;
if("attribs" in elem){
for(var attr in elem.attribs){
if(elem.attribs.hasOwnProperty(attr)){
ret += " " + attr;
var value = elem.attribs[attr];
if(value == null){
if( !(attr in booleanAttribs) ){
ret += "=\"\"";
}
} else {
ret += "=\"" + value + "\"";
}
}
}
}
if (elem.name in emptyTags && elem.children.length === 0) {
return ret + " />";
} else {
return ret + ">" + getInnerHTML(elem) + "</" + elem.name + ">";
}
}
function getText(elem){

@@ -94,2 +23,2 @@ if(Array.isArray(elem)) return elem.map(getText).join("");

return "";
}
}

@@ -19,3 +19,3 @@ var getChildren = exports.getChildren = function(elem){

exports.hasAttrib = function(elem, name){
return hasOwnProperty.call(elem.attribs, name);
return !!elem.attribs && hasOwnProperty.call(elem.attribs, name);
};

@@ -22,0 +22,0 @@

{
"name": "domutils",
"version": "1.5.0",
"version": "1.5.1",
"description": "utilities for working with htmlparser2's dom",

@@ -21,2 +21,3 @@ "main": "index.js",

"dependencies": {
"dom-serializer": "0",
"domelementtype": "1"

@@ -23,0 +24,0 @@ },

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