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

@types/hast

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/hast

TypeScript definitions for Hast

  • 2.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.2M
decreased by-24%
Maintainers
1
Weekly downloads
 
Created

What is @types/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.

What are @types/hast's main functionalities?

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);
  }
}

Other packages similar to @types/hast

FAQs

Package last updated on 21 Aug 2021

Did you know?

Socket

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.

Install

Related posts

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