Socket
Socket
Sign inDemoInstall

@types/hast

Package Overview
Dependencies
1
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/hast

TypeScript definitions for hast


Version published
Weekly downloads
8.1M
decreased by-5.03%
Maintainers
1
Install size
15.6 kB
Created
Weekly downloads
 

Package description

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

Readme

Source

Installation

npm install --save @types/hast

Summary

This package contains type definitions for hast (https://github.com/syntax-tree/hast).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/hast.

Additional Details

  • Last updated: Tue, 30 Jan 2024 21:35:45 GMT
  • Dependencies: @types/unist

Credits

These definitions were written by lukeggchapman, Junyoung Choi, Christian Murphy, and Remco Haszing.

FAQs

Last updated on 30 Jan 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc