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

@parse5/tools

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@parse5/tools - npm Package Compare versions

Comparing version 0.0.2-0 to 0.0.2-1

9

lib/main.d.ts

@@ -0,1 +1,2 @@

import { html, Token } from 'parse5';
import type { Element, ParentNode, CommentNode, ChildNode, TextNode, Template, DocumentFragment, Document, DocumentType, Node } from 'parse5/dist/tree-adapters/default.js';

@@ -103,2 +104,10 @@ /**

/**
* Creates an element node
* @param {string} tagName Name of the tag to create
* @param {NS} namespaceURI Namespace of the element
* @param {Record<string, string>|Attribute[]} attrs Attributes for the element
* @return {Element}
*/
export declare function createElement(tagName: string, namespaceURI?: html.NS, attrs?: Record<string, string> | Token.Attribute[]): Element;
/**
* Sets the text content of the given node

@@ -105,0 +114,0 @@ * @param {Node} node Node to set contents of

28

lib/main.js

@@ -1,2 +0,2 @@

import { defaultTreeAdapter } from 'parse5';
import { defaultTreeAdapter, html } from 'parse5';
/**

@@ -172,2 +172,28 @@ * Determines if a given node is a document or not

/**
* Creates an element node
* @param {string} tagName Name of the tag to create
* @param {NS} namespaceURI Namespace of the element
* @param {Record<string, string>|Attribute[]} attrs Attributes for the element
* @return {Element}
*/
export function createElement(tagName, namespaceURI = html.NS.HTML, attrs = []) {
const normalisedAttrs = [];
if (Array.isArray(attrs)) {
for (const attr of attrs) {
normalisedAttrs.push(attr);
}
}
else {
for (const name in attrs) {
if (Object.prototype.hasOwnProperty.call(attrs, name)) {
normalisedAttrs.push({
name,
value: attrs[name]
});
}
}
}
return defaultTreeAdapter.createElement(tagName, namespaceURI, normalisedAttrs);
}
/**
* Sets the text content of the given node

@@ -174,0 +200,0 @@ * @param {Node} node Node to set contents of

2

package.json
{
"name": "@parse5/tools",
"version": "0.0.2-0",
"version": "0.0.2-1",
"description": "A small set of utilities for dealing with parse5 syntax trees",

@@ -5,0 +5,0 @@ "main": "lib/main.js",

@@ -18,2 +18,13 @@ # @parse5/tools

### Node creation
The default parse5 adapter is usually enough to create the nodes you need.
To make some use cases a little easier, the following do exist, though:
* `createElement(tagName[, namespaceURI[, attrs]])`
* The attributes can be an array (e.g. `[{name: 'foo', value: 'bar'}]`) or
an object (e.g. `{foo: 'bar'}`)
* `createTextNode(value)`
### Node type guards

@@ -20,0 +31,0 @@

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