Socket
Socket
Sign inDemoInstall

jssoup

Package Overview
Dependencies
74
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.11 to 0.0.12

152

dist/lib/jssoup.js

@@ -81,2 +81,112 @@ 'use strict';

}, {
key: 'insert',
value: function insert(index, newElement) {
var _this = this;
if (newElement == null) {
throw "Cannot insert null element!";
}
if (newElement === this) {
throw "Cannot add one itself!";
}
if (!(this instanceof SoupTag)) {
throw "insert is not support in " + this.constructor.name;
}
if (index < 0) {
throw "index cannot be negative!";
}
if (newElement instanceof JSSoup) {
newElement.contents.forEach(function (element) {
_this.insert(index, element);
++index;
});
return;
}
index = Math.min(index, this.contents.length);
if (typeof newElement == 'string') {
newElement = new SoupString(newElement);
}
if (newElement.parent) {
if (newElement.parent === this) {
var curIndex = this.contents.indexOf(newElement);
if (index == curIndex) return;
if (index > curIndex) {
--index;
}
}
newElement.extract();
}
var count = this.contents.length;
var descendantsOfNewElement = newElement.descendants;
var lastElementOfNewElement = descendantsOfNewElement && descendantsOfNewElement.length > 0 ? descendantsOfNewElement[descendantsOfNewElement.length - 1] : newElement;
// handle previous element of newElement
if (index == 0) {
newElement.previousElement = this;
} else {
var previousChild = this.contents[index - 1];
var previousDescendants = previousChild.descendants;
newElement.previousElement = previousDescendants && previousDescendants.length > 0 ? previousDescendants[previousDescendants.length - 1] : previousChild;
}
if (newElement.previousElement) {
newElement.previousElement.nextElement = newElement;
}
// handle next element of newElement
if (index < count) {
lastElementOfNewElement.nextElement = this.contents[index];
} else {
var parent = this;
var parentNextSibling = null;
while (!parentNextSibling && parent) {
parentNextSibling = parent.nextSibling;
parent = parent.parent;
}
if (parentNextSibling) {
lastElementOfNewElement.nextElement = parentNextSibling;
} else {
lastElementOfNewElement.nextElement = null;
}
}
if (lastElementOfNewElement.nextElement) {
lastElementOfNewElement.nextElement.previousElement = lastElementOfNewElement;
}
newElement.parent = this;
this.contents.splice(index, 0, newElement);
}
}, {
key: 'replaceWith',
value: function replaceWith(newElement) {
if (this.parent == null) {
throw "Cannot replace element without parent!";
}
if (newElement === this) {
return;
}
if (newElement === this.parent) {
throw "Cannot replace element with its parent!";
}
var parent = this.parent;
var index = this.parent.contents.indexOf(this);
this.extract();
try {
parent.insert(index, newElement);
} catch (err) {
throw 'Cannot replace this element!';
}
return this;
}
}, {
key: 'nextSibling',

@@ -112,6 +222,6 @@ get: function get() {

var _this = _possibleConstructorReturn(this, (SoupComment.__proto__ || Object.getPrototypeOf(SoupComment)).call(this, parent, previousElement, nextElement));
var _this2 = _possibleConstructorReturn(this, (SoupComment.__proto__ || Object.getPrototypeOf(SoupComment)).call(this, parent, previousElement, nextElement));
_this._text = text;
return _this;
_this2._text = text;
return _this2;
}

@@ -132,6 +242,6 @@

var _this2 = _possibleConstructorReturn(this, (SoupString.__proto__ || Object.getPrototypeOf(SoupString)).call(this, parent, previousElement, nextElement));
var _this3 = _possibleConstructorReturn(this, (SoupString.__proto__ || Object.getPrototypeOf(SoupString)).call(this, parent, previousElement, nextElement));
_this2._text = text;
return _this2;
_this3._text = text;
return _this3;
}

@@ -156,6 +266,6 @@

var _this3 = _possibleConstructorReturn(this, (SoupDoctypeString.__proto__ || Object.getPrototypeOf(SoupDoctypeString)).call(this, text, parent, previousElement, nextElement));
var _this4 = _possibleConstructorReturn(this, (SoupDoctypeString.__proto__ || Object.getPrototypeOf(SoupDoctypeString)).call(this, text, parent, previousElement, nextElement));
_this3._text = text;
return _this3;
_this4._text = text;
return _this4;
}

@@ -181,10 +291,10 @@

var _this4 = _possibleConstructorReturn(this, (SoupTag.__proto__ || Object.getPrototypeOf(SoupTag)).call(this, parent, previousElement, nextElement));
var _this5 = _possibleConstructorReturn(this, (SoupTag.__proto__ || Object.getPrototypeOf(SoupTag)).call(this, parent, previousElement, nextElement));
_this4.name = name;
_this4.contents = [];
_this4.attrs = attrs || {};
_this4.hidden = false;
_this4.builder = builder;
return _this4;
_this5.name = name;
_this5.contents = [];
_this5.attrs = attrs || {};
_this5.hidden = false;
_this5.builder = builder;
return _this5;
}

@@ -530,3 +640,3 @@

var _this5 = _possibleConstructorReturn(this, (JSSoup.__proto__ || Object.getPrototypeOf(JSSoup)).call(this, ROOT_TAG_NAME, new _builder2.default(), null));
var _this6 = _possibleConstructorReturn(this, (JSSoup.__proto__ || Object.getPrototypeOf(JSSoup)).call(this, ROOT_TAG_NAME, new _builder2.default(), null));

@@ -543,9 +653,9 @@ var handler = new htmlparser.DefaultHandler(function (error, dom) {

if (Array.isArray(handler.dom)) {
_this5._build(handler.dom);
_this6._build(handler.dom);
} else {
_this5._build([handler.dom]);
_this6._build([handler.dom]);
}
_this5.hidden = true;
return _this5;
_this6.hidden = true;
return _this6;
}

@@ -552,0 +662,0 @@

7

package.json
{
"name": "jssoup",
"version": "0.0.11",
"version": "0.0.12",
"description": "JSSoup is a BeautifulSoup style HTML parser library.",

@@ -41,7 +41,10 @@ "main": "./dist/lib/jssoup.js",

"dependencies": {
"braces": "^2.3.1",
"chai": "^4.2.0",
"debug": "^2.6.9",
"growl": "^1.10.5",
"htmlparser": "^1.7.7",
"lodash": "^4.17.15"
"lodash": "^4.17.19",
"minimist": "^1.2.5"
}
}

@@ -118,2 +118,23 @@ JSSoup

```
#### .insert(position, new Element)
```javascript
d.prettify('', '')
// <d>4</d>
div.insert(1, d)
div.contents
// [<a>1</a>, <d>4</d>, <b>2</b>, <c>3</c>]
```
#### .replaceWith(new Element)
```javascript
d.prettify('', '')
// <d>4</d>
b.replaceWith(d)
div.contents
// [<a>1</a>, <d>4</d>, <c>3</c>]
c.string.replaceWith('new')
div.contents
// [<a>1</a>, <d>4</d>, <c>new</c>]
```
### Search

@@ -120,0 +141,0 @@ #### .findAll()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc