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

htmldom

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmldom - npm Package Compare versions

Comparing version 4.0.4 to 4.0.5

test/beautify.js

37

htmldom.umd.js

@@ -1627,2 +1627,8 @@ (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.createHtmlDom = 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){

const RAW_ELEMENTS = [
'textarea',
'script',
'style'
]
function getRawEndTag (name) {

@@ -1647,2 +1653,6 @@ if (name === 'style') {

function isRawElement (name) {
return RAW_ELEMENTS.includes(name)
}
/**

@@ -1668,6 +1678,2 @@ *

if (this.rawTag()) {
continue
}
if (this.openTag()) {

@@ -1721,15 +1727,4 @@ continue

*/
rawTag () {
let match = this.match(RAW_TAG)
if (!match) return false
let attributes = this.match(OPEN_TAG_CLOSE)
if (!attributes) return
let name = match[1]
rawTag (name, attributes) {
let endTag = getRawEndTag(name)
let content = this.match(endTag)

@@ -1747,3 +1742,3 @@

name,
attributes: attributes[0].slice(0, -1),
attributes,
textContent: content

@@ -1753,4 +1748,2 @@ }

this.doms.push(item)
return true
}

@@ -1784,2 +1777,8 @@

} else {
// script, style, textarea
if (isRawElement(name)) {
this.rawTag(name, attributes)
return true
}
type = isVoidElement(name) ? 'voidTag' : 'openTag'

@@ -1786,0 +1785,0 @@ }

// <style, <script
const RAW_TAG = /^<(script|style|textarea)/
const STYLE_RAW = /([\s\S]*?)<\/style\s*>/

@@ -40,2 +39,8 @@ const SCRIPT_RAW = /([\s\S]*?)<\/script\s*>/

const RAW_ELEMENTS = [
'textarea',
'script',
'style'
]
function getRawEndTag (name) {

@@ -60,2 +65,6 @@ if (name === 'style') {

function isRawElement (name) {
return RAW_ELEMENTS.includes(name)
}
/**

@@ -81,6 +90,2 @@ *

if (this.rawTag()) {
continue
}
if (this.openTag()) {

@@ -134,15 +139,4 @@ continue

*/
rawTag () {
let match = this.match(RAW_TAG)
if (!match) return false
let attributes = this.match(OPEN_TAG_CLOSE)
if (!attributes) return
let name = match[1]
rawTag (name, attributes) {
let endTag = getRawEndTag(name)
let content = this.match(endTag)

@@ -160,3 +154,3 @@

name,
attributes: attributes[0].slice(0, -1),
attributes,
textContent: content

@@ -166,4 +160,2 @@ }

this.doms.push(item)
return true
}

@@ -197,2 +189,8 @@

} else {
// script, style, textarea
if (isRawElement(name)) {
this.rawTag(name, attributes)
return true
}
type = isVoidElement(name) ? 'voidTag' : 'openTag'

@@ -199,0 +197,0 @@ }

{
"name": "htmldom",
"version": "4.0.4",
"version": "4.0.5",
"description": "Simplified html handle in nodejs",

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

@@ -172,6 +172,82 @@ # htmldom — Simplified html or xml handle in nodejs

Get a dom tree
```js
/**
* <div id="test" class="title header" style="color:red;width:200px;"></div>
*/
{
type: 'tag',
name: 'div',
attributes: {
class: 'title header',
id: 'test',
style: 'color:red;width:200px;'
},
parent: null,
children: [],
classList: new Set(['title', 'header']),
style: {
color: 'red',
width: '200px'
}
}
```
$.nodes
```js
/**
* raw tag (script, style, textarea)
* <script>alert(1)</script>
*/
{
type: 'tag',
name: 'script',
tagType: 'rawTag',
textContent: 'alert(1)'
}
```
```js
/**
* selfClosingTag
* <image src="" />
*/
{
type: 'tag',
name: 'image',
attributes: { src: '' },
tagType: 'selfClosingTag'
}
```
```js
/**
* voidTag
* <input>
*/
{
type: 'tag',
name: 'input',
tagType: 'voidTag',
}
```
```js
/**
* text tag
*/
{
type: 'text',
data: 'text tag'
}
```
```js
/**
* <!-- comemnt data -->
*/
{
type: 'comment',
data: ' comemnt data '
}
```
### $.root()

@@ -178,0 +254,0 @@ ```js

@@ -135,28 +135,3 @@ let assert = require('assert')

describe('rawTag', function () {
it('script', function () {
let { nodes } = new Parser(`<script type="text/javascript">alert(1)</script>`)
assert.deepEqual(nodes[0].attributes, {
type: 'text/javascript'
})
assert.deepEqual(nodes[0].textContent, 'alert(1)')
})
it('style', function () {
let { nodes } = new Parser(`<style type="text/css">.title{}</style>`)
assert.deepEqual(nodes[0].attributes, {
type: 'text/css'
})
assert.deepEqual(nodes[0].textContent, '.title{}')
})
it('textarea', function () {
let { nodes } = new Parser(`<textarea><div>1</div><a></a>2</textarea>`)
assert.deepEqual(nodes[0].textContent, '<div>1</div><a></a>2')
})
})
describe('classList', function () {

@@ -163,0 +138,0 @@ it('[]', function () {

@@ -22,3 +22,3 @@ let assert = require('assert')

it('Self closing tag', function () {
let { doms } = new Tokenize('<br/><img /><input />')
let { doms } = new Tokenize('<textarea /><br/><img /><input />')

@@ -62,4 +62,2 @@ for (let item of doms) {

})
})
let assert = require('assert')
let createHtmlDom = require('../../htmldom')
let createHtmlDom = require('../htmldom')

@@ -4,0 +4,0 @@

Sorry, the diff of this file is not supported yet

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