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

jsx-ast-utils

Package Overview
Dependencies
Maintainers
3
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsx-ast-utils

AST utility module for statically analyzing JSX

  • 3.3.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19M
increased by2.53%
Maintainers
3
Weekly downloads
 
Created

What is jsx-ast-utils?

The jsx-ast-utils package provides utilities for working with the Abstract Syntax Tree (AST) of JSX elements. It is commonly used in the development of linting rules and tools that analyze or transform JSX code.

What are jsx-ast-utils's main functionalities?

Element and attribute extraction

This feature allows you to extract properties and their literal values from a JSX element. It is useful when analyzing components for specific attribute values.

const { getProp, getLiteralPropValue } = require('jsx-ast-utils');
const JSXElement = ...; // some JSX element AST node
const prop = getProp(JSXElement, 'href');
const value = getLiteralPropValue(prop);

Event handler detection

This feature helps in detecting event handlers on JSX elements. It can be used to ensure that interactive elements have appropriate event handlers for accessibility.

const { getProp, elementType } = require('jsx-ast-utils');
const JSXElement = ...; // some JSX element AST node
const type = elementType(JSXElement);
const onClickProp = getProp(JSXElement, 'onClick');
const isButtonWithOnClick = type === 'button' && onClickProp !== undefined;

Checking for children

These utilities allow you to check if a JSX element has any children or if every child meets a specific condition. This can be used to enforce content structure within components.

const { hasAnyChildren, hasEveryChild } = require('jsx-ast-utils');
const JSXElement = ...; // some JSX element AST node
const hasChildren = hasAnyChildren(JSXElement);
const hasSpecificChildren = hasEveryChild(JSXElement, child => child.type === 'JSXText');

Other packages similar to jsx-ast-utils

Keywords

FAQs

Package last updated on 29 Jul 2023

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