node-html-parser
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -129,2 +129,4 @@ import Node from './node'; | ||
get rawAttributes(): RawAttributes; | ||
removeAttribute(key: string): void; | ||
hasAttribute(key: string): boolean; | ||
/** | ||
@@ -138,5 +140,5 @@ * Get an attribute | ||
* @param {string} key The attribute name | ||
* @param {string|number} value The value to set, or null / undefined to remove an attribute | ||
* @param {string} value The value to set, or null / undefined to remove an attribute | ||
*/ | ||
setAttribute(key: string, value: string | number): void; | ||
setAttribute(key: string, value: string): void; | ||
/** | ||
@@ -143,0 +145,0 @@ * Replace all the attributes of the HTMLElement by the provided attributes |
@@ -484,2 +484,24 @@ "use strict"; | ||
}); | ||
HTMLElement.prototype.removeAttribute = function (key) { | ||
var attrs = this.rawAttributes; | ||
delete attrs[key]; | ||
// Update this.attribute | ||
if (this._attrs) { | ||
delete this._attrs[key]; | ||
} | ||
// Update rawString | ||
this.rawAttrs = Object.keys(attrs).map(function (name) { | ||
var val = JSON.stringify(attrs[name]); | ||
if (val === undefined || val === 'null') { | ||
return name; | ||
} | ||
else { | ||
return name + '=' + val; | ||
} | ||
}).join(' '); | ||
}; | ||
HTMLElement.prototype.hasAttribute = function (key) { | ||
console.error(this.attributes, key); | ||
return key in this.attributes; | ||
}; | ||
/** | ||
@@ -490,3 +512,3 @@ * Get an attribute | ||
HTMLElement.prototype.getAttribute = function (key) { | ||
return this.attributes[key] || null; | ||
return this.attributes[key]; | ||
}; | ||
@@ -496,23 +518,17 @@ /** | ||
* @param {string} key The attribute name | ||
* @param {string|number} value The value to set, or null / undefined to remove an attribute | ||
* @param {string} value The value to set, or null / undefined to remove an attribute | ||
*/ | ||
HTMLElement.prototype.setAttribute = function (key, value) { | ||
if (arguments.length < 2) { | ||
throw new Error('Failed to execute \'setAttribute\' on \'Element\''); | ||
} | ||
var attrs = this.rawAttributes; | ||
if (value === undefined || value === null) { | ||
delete attrs[key]; | ||
// Update this.attribute | ||
if (this._attrs && this._attrs[key]) { | ||
delete this._attrs[key]; | ||
} | ||
attrs[key] = String(value); | ||
if (this._attrs) { | ||
this._attrs[key] = he_1.decode(attrs[key]); | ||
} | ||
else { | ||
attrs[key] = String(value); | ||
if (this._attrs) { | ||
this._attrs[key] = he_1.decode(attrs[key]); | ||
} | ||
} | ||
// Update rawString | ||
this.rawAttrs = Object.keys(attrs).map(function (name) { | ||
var val = JSON.stringify(attrs[name]); | ||
if (val === undefined || val === null) { | ||
if (val === undefined || val === 'null') { | ||
return name; | ||
@@ -519,0 +535,0 @@ } |
@@ -493,2 +493,24 @@ var __extends = (this && this.__extends) || (function () { | ||
}); | ||
HTMLElement.prototype.removeAttribute = function (key) { | ||
var attrs = this.rawAttributes; | ||
delete attrs[key]; | ||
// Update this.attribute | ||
if (this._attrs) { | ||
delete this._attrs[key]; | ||
} | ||
// Update rawString | ||
this.rawAttrs = Object.keys(attrs).map(function (name) { | ||
var val = JSON.stringify(attrs[name]); | ||
if (val === undefined || val === 'null') { | ||
return name; | ||
} | ||
else { | ||
return name + '=' + val; | ||
} | ||
}).join(' '); | ||
}; | ||
HTMLElement.prototype.hasAttribute = function (key) { | ||
console.error(this.attributes, key); | ||
return key in this.attributes; | ||
}; | ||
/** | ||
@@ -499,3 +521,3 @@ * Get an attribute | ||
HTMLElement.prototype.getAttribute = function (key) { | ||
return this.attributes[key] || null; | ||
return this.attributes[key]; | ||
}; | ||
@@ -505,23 +527,17 @@ /** | ||
* @param {string} key The attribute name | ||
* @param {string|number} value The value to set, or null / undefined to remove an attribute | ||
* @param {string} value The value to set, or null / undefined to remove an attribute | ||
*/ | ||
HTMLElement.prototype.setAttribute = function (key, value) { | ||
if (arguments.length < 2) { | ||
throw new Error('Failed to execute \'setAttribute\' on \'Element\''); | ||
} | ||
var attrs = this.rawAttributes; | ||
if (value === undefined || value === null) { | ||
delete attrs[key]; | ||
// Update this.attribute | ||
if (this._attrs && this._attrs[key]) { | ||
delete this._attrs[key]; | ||
} | ||
attrs[key] = String(value); | ||
if (this._attrs) { | ||
this._attrs[key] = he_1.decode(attrs[key]); | ||
} | ||
else { | ||
attrs[key] = String(value); | ||
if (this._attrs) { | ||
this._attrs[key] = he_1.decode(attrs[key]); | ||
} | ||
} | ||
// Update rawString | ||
this.rawAttrs = Object.keys(attrs).map(function (name) { | ||
var val = JSON.stringify(attrs[name]); | ||
if (val === undefined || val === null) { | ||
if (val === undefined || val === 'null') { | ||
return name; | ||
@@ -528,0 +544,0 @@ } |
{ | ||
"name": "node-html-parser", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157169
2836