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 0.1.3 to 0.1.4

test/selector/append.js

2

package.json
{
"name": "htmldom",
"version": "0.1.3",
"version": "0.1.4",
"description": "Simplified html handle in nodejs",

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

@@ -139,3 +139,8 @@ # htmldom — Simplified html handle in nodejs

```
* html(html)
* parent(selector)
```
$('').parent()
$('').parent('.cls')
```
* html(content)
```js

@@ -145,2 +150,10 @@ $('').html() // get html

```
* append(content)
```js
$('').append('<h3>title');
```
* prepend(content)
```js
$('').prepend('<h3>title');
```
* remove()

@@ -147,0 +160,0 @@ ```js

@@ -214,2 +214,21 @@ var css = require('./css');

/**
* $('').parent();
* $('').parent('.cls')
*/
$.prototype.parent = function(selector) {
var result = [];
selector = css.parser(selector || '');
for (var i = 0; i < this.length; i++) {
var parent = this[i].parent;
if (parent && css.match(parent, selector)) {
result.push(parent);
}
}
return $(result, this.document);
}
/**
* @example

@@ -223,3 +242,3 @@ * $('').eq(0)

}
return $(this[index]);
return $(this[index], this.document);
}

@@ -246,3 +265,3 @@

return $(result);
return $(result, this.document);
};

@@ -304,29 +323,2 @@

* @example
* $('').html() // get
* $('').html('<div></div>') // set
*/
$.prototype.html = function(html) {
var HtmlDom = require('../htmldom');
if (util.isUndefined(html)) {
if (this.length) {
var htmldom = new HtmlDom();
return htmldom.html(this[0].children);
} else {
return null;
}
} else {
this.each(function(index, item) {
var htmldom = new HtmlDom(html);
htmldom.dom.forEach(function(child) {
child.parent = item;
});
item.children = htmldom.dom;
});
}
return this;
};
/**
* @example
* $('').remove()

@@ -469,2 +461,65 @@ */

$.prototype._createdom = function(html, callback) {
var HtmlDom = require('../htmldom');
for (var i = 0; i < this.length; i++) {
var htmldom = new HtmlDom(html).dom;
callback(this[i], htmldom);
}
}
/**
* @example
* $('').html() // get
* $('').html('<div></div>') // set
*/
$.prototype.html = function(content) {
if (util.isUndefined(content)) {
if (this.length) {
var HtmlDom = require('../htmldom');
var htmldom = new HtmlDom();
return htmldom.html(this[0].children);
} else {
return null;
}
} else {
this._createdom(content, function(item, children) {
children.forEach(function(child) {
child.parent = item;
});
item.children = children;
});
}
return this;
};
/**
* $('').append('<ul><li>1');
*/
$.prototype.append = function(content) {
this._createdom(content, function(item, children) {
children.forEach(function(child) {
child.parent = item;
item.children.push(child);
});
});
return this;
};
/**
* $('')
*/
$.prototype.prepend = function(content) {
this._createdom(content, function(item, children) {
length = children.length;
while (length--) {
var child = children[length];
child.parent = item;
item.children.unshift(child);
}
});
};
module.exports = $;

@@ -1,3 +0,1 @@

var fs = require('fs');
var path = require('path');
var HtmlDom = require('../../htmldom');

@@ -4,0 +2,0 @@ var assert = require('assert');

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