domhandler
Advanced tools
Comparing version 2.4.2 to 3.0.0
233
lib/node.js
@@ -0,44 +1,193 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var nodeTypes = new Map([ | ||
["tag" /* Tag */, 1], | ||
["script" /* Script */, 1], | ||
["style" /* Style */, 1], | ||
["directive" /* Directive */, 1], | ||
["text" /* Text */, 3], | ||
["cdata" /* CDATA */, 4], | ||
["comment" /* Comment */, 8] | ||
]); | ||
// This object will be used as the prototype for Nodes when creating a | ||
// DOM-Level-1-compliant structure. | ||
var NodePrototype = module.exports = { | ||
get firstChild() { | ||
var children = this.children; | ||
return children && children[0] || null; | ||
}, | ||
get lastChild() { | ||
var children = this.children; | ||
return children && children[children.length - 1] || null; | ||
}, | ||
get nodeType() { | ||
return nodeTypes[this.type] || nodeTypes.element; | ||
} | ||
}; | ||
var domLvl1 = { | ||
tagName: "name", | ||
childNodes: "children", | ||
parentNode: "parent", | ||
previousSibling: "prev", | ||
nextSibling: "next", | ||
nodeValue: "data" | ||
}; | ||
var nodeTypes = { | ||
element: 1, | ||
text: 3, | ||
cdata: 4, | ||
comment: 8 | ||
}; | ||
Object.keys(domLvl1).forEach(function(key) { | ||
var shorthand = domLvl1[key]; | ||
Object.defineProperty(NodePrototype, key, { | ||
get: function() { | ||
return this[shorthand] || null; | ||
}, | ||
set: function(val) { | ||
this[shorthand] = val; | ||
return val; | ||
} | ||
}); | ||
}); | ||
var Node = /** @class */ (function () { | ||
/** | ||
* | ||
* @param type The type of the node. | ||
*/ | ||
function Node(type) { | ||
this.type = type; | ||
/** Parent of the node */ | ||
this.parent = null; | ||
/** Previous sibling */ | ||
this.prev = null; | ||
/** Next sibling */ | ||
this.next = null; | ||
/** The start index of the node. Requires `withStartIndices` on the handler to be `true. */ | ||
this.startIndex = null; | ||
/** The end index of the node. Requires `withEndIndices` on the handler to be `true. */ | ||
this.endIndex = null; | ||
} | ||
Object.defineProperty(Node.prototype, "nodeType", { | ||
// Read-only aliases | ||
get: function () { | ||
return nodeTypes.get(this.type) || 1; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Node.prototype, "parentNode", { | ||
// Read-write aliases for properties | ||
get: function () { | ||
return this.parent || null; | ||
}, | ||
set: function (parent) { | ||
this.parent = parent; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Node.prototype, "previousSibling", { | ||
get: function () { | ||
return this.prev || null; | ||
}, | ||
set: function (prev) { | ||
this.prev = prev; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Node.prototype, "nextSibling", { | ||
get: function () { | ||
return this.next || null; | ||
}, | ||
set: function (next) { | ||
this.next = next; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return Node; | ||
}()); | ||
exports.Node = Node; | ||
var DataNode = /** @class */ (function (_super) { | ||
__extends(DataNode, _super); | ||
/** | ||
* | ||
* @param type The type of the node | ||
* @param data The content of the data node | ||
*/ | ||
function DataNode(type, data) { | ||
var _this = _super.call(this, type) || this; | ||
_this.data = data; | ||
return _this; | ||
} | ||
Object.defineProperty(DataNode.prototype, "nodeValue", { | ||
get: function () { | ||
return this.data; | ||
}, | ||
set: function (data) { | ||
this.data = data; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return DataNode; | ||
}(Node)); | ||
exports.DataNode = DataNode; | ||
var ProcessingInstruction = /** @class */ (function (_super) { | ||
__extends(ProcessingInstruction, _super); | ||
function ProcessingInstruction(name, data) { | ||
var _this = _super.call(this, "directive" /* Directive */, data) || this; | ||
_this.name = name; | ||
return _this; | ||
} | ||
return ProcessingInstruction; | ||
}(DataNode)); | ||
exports.ProcessingInstruction = ProcessingInstruction; | ||
var NodeWithChildren = /** @class */ (function (_super) { | ||
__extends(NodeWithChildren, _super); | ||
/** | ||
* | ||
* @param type Type of the node. | ||
* @param children Children of the node. Only certain node types can have children. | ||
*/ | ||
function NodeWithChildren(type, children) { | ||
var _this = _super.call(this, type) || this; | ||
_this.children = children; | ||
return _this; | ||
} | ||
Object.defineProperty(NodeWithChildren.prototype, "firstChild", { | ||
// Aliases | ||
get: function () { | ||
return this.children[0] || null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(NodeWithChildren.prototype, "lastChild", { | ||
get: function () { | ||
return this.children[this.children.length - 1] || null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(NodeWithChildren.prototype, "childNodes", { | ||
get: function () { | ||
return this.children; | ||
}, | ||
set: function (children) { | ||
this.children = children; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return NodeWithChildren; | ||
}(Node)); | ||
exports.NodeWithChildren = NodeWithChildren; | ||
var Element = /** @class */ (function (_super) { | ||
__extends(Element, _super); | ||
/** | ||
* | ||
* @param name Name of the tag, eg. `div`, `span` | ||
* @param attribs Object mapping attribute names to attribute values | ||
*/ | ||
function Element(name, attribs) { | ||
var _this = _super.call(this, name === "script" | ||
? "script" /* Script */ | ||
: name === "style" | ||
? "style" /* Style */ | ||
: "tag" /* Tag */, []) || this; | ||
_this.name = name; | ||
_this.attribs = attribs; | ||
_this.attribs = attribs; | ||
return _this; | ||
} | ||
Object.defineProperty(Element.prototype, "tagName", { | ||
// DOM Level 1 aliases | ||
get: function () { | ||
return this.name; | ||
}, | ||
set: function (name) { | ||
this.name = name; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return Element; | ||
}(NodeWithChildren)); | ||
exports.Element = Element; |
{ | ||
"name": "domhandler", | ||
"version": "2.4.2", | ||
"description": "handler for htmlparser2 that turns pages into a dom", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "tests" | ||
}, | ||
"scripts": { | ||
"test": "mocha -R list && jshint index.js test/" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/fb55/DomHandler.git" | ||
}, | ||
"keywords": [ | ||
"dom", | ||
"htmlparser2" | ||
], | ||
"dependencies": { | ||
"domelementtype": "1" | ||
}, | ||
"devDependencies": { | ||
"htmlparser2": "^3.9.0", | ||
"mocha": "^3.0.2", | ||
"jshint": "^2.9.1" | ||
}, | ||
"author": "Felix Boehm <me@feedic.com>", | ||
"license": "BSD-2-Clause", | ||
"jshintConfig": { | ||
"quotmark": "double", | ||
"trailing": true, | ||
"unused": true, | ||
"undef": true, | ||
"node": true, | ||
"proto": true, | ||
"globals": { | ||
"it": true | ||
"name": "domhandler", | ||
"version": "3.0.0", | ||
"description": "Handler for htmlparser2 that turns pages into a dom", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "jest --coverage && npm run lint", | ||
"coverage": "cat coverage/lcov.info | coveralls", | ||
"lint": "eslint src/**/*.ts", | ||
"format": "prettier --write '**/*.{ts,md,json}'", | ||
"build": "tsc", | ||
"prepare": "npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/fb55/DomHandler.git" | ||
}, | ||
"keywords": [ | ||
"dom", | ||
"htmlparser2" | ||
], | ||
"engines": { | ||
"node": ">= 4" | ||
}, | ||
"dependencies": { | ||
"domelementtype": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/htmlparser2": "^3.10.1", | ||
"@types/jest": "^24.0.16", | ||
"@types/node": "^12.6.8", | ||
"@typescript-eslint/eslint-plugin": "^1.13.0", | ||
"@typescript-eslint/parser": "^1.13.0", | ||
"coveralls": "^3.0.5", | ||
"eslint": "^6.1.0", | ||
"eslint-config-prettier": "^6.0.0", | ||
"eslint-config-xo-typescript": "^0.15.0", | ||
"htmlparser2": "^3.9.0", | ||
"jest": "^24.8.0", | ||
"prettier": "^1.18.2", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.5.3" | ||
}, | ||
"author": "Felix Boehm <me@feedic.com>", | ||
"license": "BSD-2-Clause", | ||
"jest": { | ||
"preset": "ts-jest", | ||
"testEnvironment": "node" | ||
}, | ||
"prettier": { | ||
"tabWidth": 4 | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
200138
53
2348
154
0
14
1
+ Addeddomelementtype@2.3.0(transitive)
- Removeddomelementtype@1.3.1(transitive)
Updateddomelementtype@^2.0.1