Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@types/hast
Advanced tools
TypeScript definitions for hast
The @types/hast package provides TypeScript type definitions for HAST (Hypertext Abstract Syntax Tree) format, which is a virtual DOM format for HTML and XML. This allows developers to work with HAST trees in TypeScript projects with type safety, enabling better development experience, auto-completion, and error checking.
Creating a HAST node
This code sample demonstrates how to create a simple HAST node representing a paragraph element containing the text 'Hello, world!'. The node is typed, ensuring that only valid properties and child nodes are used.
{"type": "element", "tagName": "p", "properties": {}, "children": [{"type": "text", "value": "Hello, world!"}]}
Type-checking a HAST tree
This code sample shows how to type-check a HAST tree to safely access properties. It specifically checks if a node is an anchor ('a') element and logs its 'href' property if available.
import {Element} from 'hast';
function processNode(node: Element): void {
if (node.tagName === 'a' && node.properties) {
console.log(node.properties.href);
}
}
Rehype is a processor powered by plugins to work with HTML. It uses HAST under the hood, allowing manipulation of HTML documents. Compared to @types/hast, rehype offers higher-level operations like parsing, serializing, and transforming HTML content, whereas @types/hast focuses on providing type definitions.
Unified is an interface for processing text using syntax trees, including HAST for HTML. It's more general-purpose than @types/hast, offering a framework to parse, transform, and serialize text through a unified ecosystem of plugins, whereas @types/hast specifically provides TypeScript types for HAST nodes.
Remark is part of the unified ecosystem, focusing on Markdown processing using MDAST (Markdown Abstract Syntax Tree). While it serves a different syntax (Markdown vs. HTML/XML in HAST), it offers a similar concept of providing a structured tree format for content. Remark and @types/hast both enable developers to work with content trees, but they target different types of content.
npm install --save @types/hast
This package contains type definitions for hast (https://github.com/syntax-tree/hast).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/hast.
These definitions were written by lukeggchapman, Junyoung Choi, Christian Murphy, and Remco Haszing.
FAQs
TypeScript definitions for hast
The npm package @types/hast receives a total of 11,096,056 weekly downloads. As such, @types/hast popularity was classified as popular.
We found that @types/hast demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.