{"_id":"jsx-ast-utils-x","_rev":"3-172f573853fc64db47ef2feeafe31138","name":"jsx-ast-utils-x","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"jsx-ast-utils-x","version":"0.1.0","keywords":["jsx","ast","lint","eslint","jsx-ast-utils"],"author":{"name":"Ethan Cohen"},"license":"MIT","_id":"jsx-ast-utils-x@0.1.0","maintainers":[{"name":"jounqin","email":"admin@1stg.me"}],"homepage":"https://github.com/eslinter/jsx-ast-utils-x#readme","bugs":{"url":"https://github.com/eslinter/jsx-ast-utils-x/issues"},"dist":{"shasum":"b0933d66a69e0aa1ae23f74fb87b079ec298652f","tarball":"https://registry.npmjs.org/jsx-ast-utils-x/-/jsx-ast-utils-x-0.1.0.tgz","fileCount":40,"integrity":"sha512-eQQBjBnsVtGacsG9uJNB8qOr3yA8rga4wAaGG1qRcBzSIvfhERLrWxMAM1hp5fcS6Abo8M4+bUBTekYR0qTPQw==","signatures":[{"sig":"MEUCIDlzGKXB9g1N9MBxOjAg67+yaByFIhmR62dyzVO36ooeAiEA9H25yrM/ex6ExkwQj4BLVb2EG/zrOCFe/bvQF2+6vWk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/jsx-ast-utils-x@0.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":71379},"main":"lib/index.js","engines":{"node":"^18.18.0 || ^20.9.0 || >=21.1.0"},"gitHead":"e43e103a31138d7e6c0dcdcdca1ad1e85dfc0057","_npmUser":{"name":"jounqin","email":"admin@1stg.me"},"repository":{"url":"git+https://github.com/eslinter/jsx-ast-utils-x.git","type":"git"},"_npmVersion":"10.9.2","description":"AST utility module for statically analyzing JSX","directories":{},"_nodeVersion":"22.15.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/jsx-ast-utils-x_0.1.0_1747787977961_0.13792094699169244","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-05-21T00:39:37.900Z","modified":"2026-09-22T16:15:06.254Z","0.1.0":"2025-05-21T00:39:38.153Z"},"bugs":{"url":"https://github.com/eslinter/jsx-ast-utils-x/issues"},"author":{"name":"Ethan Cohen"},"license":"MIT","homepage":"https://github.com/eslinter/jsx-ast-utils-x#readme","keywords":["jsx","ast","lint","eslint","jsx-ast-utils"],"repository":{"url":"git+https://github.com/eslinter/jsx-ast-utils-x.git","type":"git"},"description":"AST utility module for statically analyzing JSX","maintainers":[{"email":"admin@1stg.me","name":"jounqin"},{"email":"info@michaeldeboey.be","name":"michaeldeboey"},{"email":"contact+eslintcbot@eslint.org","name":"eslint-community-bot"}],"readme":"# jsx-ast-utils-x\n\n[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/eslinter/jsx-ast-utils-x/ci.yml?branch=main)](https://github.com/eslinter/jsx-ast-utils-x/actions/workflows/ci.yml?query=branch%3Amain)\n[![Codecov](https://img.shields.io/codecov/c/github/eslinter/jsx-ast-utils-x.svg)](https://codecov.io/gh/eslinter/jsx-ast-utils-x)\n[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Feslinter%2Fjsx-ast-utils-x%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage)\n[![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/eslinter/jsx-ast-utils-x)](https://coderabbit.ai)\n[![npm](https://img.shields.io/npm/v/jsx-ast-utils-x.svg)](https://www.npmjs.com/package/jsx-ast-utils-x)\n[![GitHub Release](https://img.shields.io/github/release/eslinter/jsx-ast-utils-x)](https://github.com/eslinter/jsx-ast-utils-x/releases)\n\n[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/changesets/changesets)\n\nAST utility module for statically analyzing JSX.\n\n## TOC <!-- omit in toc -->\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [ESLint example](#eslint-example)\n- [API](#api)\n  - [AST Resources](#ast-resources)\n  - [hasProp](#hasprop)\n    - [Props](#props)\n    - [Prop](#prop)\n    - [Options](#options)\n  - [hasAnyProp](#hasanyprop)\n    - [Props](#props-1)\n    - [Prop](#prop-1)\n    - [Options](#options-1)\n  - [hasEveryProp](#haseveryprop)\n    - [Props](#props-2)\n    - [Prop](#prop-2)\n    - [Options](#options-2)\n  - [getProp](#getprop)\n    - [Props](#props-3)\n    - [Prop](#prop-3)\n    - [Options](#options-3)\n  - [elementType](#elementtype)\n    - [Node](#node)\n  - [getPropValue](#getpropvalue)\n    - [Prop](#prop-4)\n  - [getLiteralPropValue](#getliteralpropvalue)\n    - [Prop](#prop-5)\n  - [propName](#propname)\n    - [Prop](#prop-6)\n  - [eventHandlers](#eventhandlers)\n    - [eventHandlersByType](#eventhandlersbytype)\n- [Sponsors and Backers](#sponsors-and-backers)\n  - [Sponsors](#sponsors)\n  - [Backers](#backers)\n- [Changelog](#changelog)\n- [License](#license)\n\n## Installation\n\n```sh\n# npm\nnpm i jsx-ast-utils-x --save\n\n# yarn\nyarn add jsx-ast-utils-x\n\n# pnpm\npnpm add jsx-ast-utils-x\n\n# bun\nbun add jsx-ast-utils-x\n```\n\n## Usage\n\nThis is a utility module to evaluate AST objects for JSX syntax. This can be super useful when writing linting rules for JSX code. It was originally in the code for [eslint-plugin-jsx-a11y](https://github.com/eslinter/eslint-plugin-jsx-a11y), however I thought it could be useful to be extracted and maintained separately so **you** could write new interesting rules to statically analyze JSX.\n\n### ESLint example\n\n```js\nimport { hasProp } from 'jsx-ast-utils-x';\n// OR: var hasProp = require('jsx-ast-utils-x').hasProp;\n// OR: const hasProp = require('jsx-ast-utils-x/hasProp');\n// OR: import hasProp from 'jsx-ast-utils-x/hasProp';\n\nmodule.exports = context => ({\n  JSXOpeningElement: node => {\n    const onChange = hasProp(node.attributes, 'onChange');\n\n    if (onChange) {\n      context.report({\n        node,\n        message: `No onChange!`,\n      });\n    }\n  },\n});\n```\n\n## API\n\n### AST Resources\n\n1. [JSX spec](https://github.com/facebook/jsx/blob/master/AST.md)\n2. [JS spec](https://github.com/estree/estree/blob/master/spec.md)\n\n### hasProp\n\n```js\nhasProp(props, prop, options);\n```\n\nReturns boolean indicating whether an prop exists as an attribute on a JSX element node.\n\n#### Props\n\nObject - The attributes on the visited node. (Usually `node.attributes`).\n\n#### Prop\n\nString - A string representation of the prop you want to check for existence.\n\n#### Options\n\nObject - An object representing options for existence checking\n\n1. `ignoreCase` - automatically set to `true`.\n2. `spreadStrict` - automatically set to `true`. This means if spread operator exists in\n   props, it will assume the prop you are looking for is not in the spread.\n   Example: `<div {...props} />` looking for specific prop here will return false if `spreadStrict` is `true`.\n\n<hr />\n\n### hasAnyProp\n\n```js\nhasAnyProp(props, prop, options);\n```\n\nReturns a boolean indicating if **any** of props in `prop` argument exist on the node.\n\n#### Props\n\nObject - The attributes on the visited node. (Usually `node.attributes`).\n\n#### Prop\n\nArray<String> - An array of strings representing the props you want to check for existence.\n\n#### Options\n\nObject - An object representing options for existence checking\n\n1. `ignoreCase` - automatically set to `true`.\n2. `spreadStrict` - automatically set to `true`. This means if spread operator exists in\n   props, it will assume the prop you are looking for is not in the spread.\n   Example: `<div {...props} />` looking for specific prop here will return false if `spreadStrict` is `true`.\n\n<hr />\n\n### hasEveryProp\n\n```js\nhasEveryProp(props, prop, options);\n```\n\nReturns a boolean indicating if **all** of props in `prop` argument exist on the node.\n\n#### Props\n\nObject - The attributes on the visited node. (Usually `node.attributes`).\n\n#### Prop\n\nArray<String> - An array of strings representing the props you want to check for existence.\n\n#### Options\n\nObject - An object representing options for existence checking\n\n1.  `ignoreCase` - automatically set to `true`.\n2.  `spreadStrict` - automatically set to `true`. This means if spread operator exists in\n    props, it will assume the prop you are looking for is not in the spread.\n    Example: `<div {...props} />` looking for specific prop here will return false if `spreadStrict` is `true`.\n\n<hr />\n\n### getProp\n\n```js\ngetProp(props, prop, options);\n```\n\nReturns the JSXAttribute itself or undefined, indicating the prop is not present on the JSXOpeningElement.\n\n#### Props\n\nObject - The attributes on the visited node. (Usually `node.attributes`).\n\n#### Prop\n\nString - A string representation of the prop you want to check for existence.\n\n#### Options\n\nObject - An object representing options for existence checking\n\n1. `ignoreCase` - automatically set to `true`.\n\n<hr />\n\n### elementType\n\n```js\nelementType(node);\n```\n\nReturns the tagName associated with a JSXElement.\n\n#### Node\n\nObject - The visited JSXElement node object.\n\n<hr />\n\n### getPropValue\n\n```js\ngetPropValue(prop);\n```\n\nReturns the value of a given attribute. Different types of attributes have their associated values in different properties on the object.\n\nThis function should return the most _closely_ associated value with the intention of the JSX.\n\n#### Prop\n\nObject - The JSXAttribute collected by AST parser.\n\n<hr />\n\n### getLiteralPropValue\n\n```js\ngetLiteralPropValue(prop);\n```\n\nReturns the value of a given attribute. Different types of attributes have their associated values in different properties on the object.\n\nThis function should return a value only if we can extract a literal value from its attribute (i.e. values that have generic types in JavaScript - strings, numbers, booleans, etc.)\n\n#### Prop\n\nObject - The JSXAttribute collected by AST parser.\n\n<hr />\n\n### propName\n\n```js\npropName(prop);\n```\n\nReturns the name associated with a JSXAttribute. For example, given `<div foo=\"bar\" />` and the JSXAttribute for `foo`, this will return the string `\"foo\"`.\n\n#### Prop\n\nObject - The JSXAttribute collected by AST parser.\n\n<hr />\n\n### eventHandlers\n\n```js\nconsole.log(eventHandlers);\n/*\n[\n  'onCopy',\n  'onCut',\n  'onPaste',\n  'onCompositionEnd',\n  'onCompositionStart',\n  'onCompositionUpdate',\n  'onKeyDown',\n  'onKeyPress',\n  'onKeyUp',\n  'onFocus',\n  'onBlur',\n  'onChange',\n  'onInput',\n  'onSubmit',\n  'onClick',\n  'onContextMenu',\n  'onDblClick',\n  'onDoubleClick',\n  'onDrag',\n  'onDragEnd',\n  'onDragEnter',\n  'onDragExit',\n  'onDragLeave',\n  'onDragOver',\n  'onDragStart',\n  'onDrop',\n  'onMouseDown',\n  'onMouseEnter',\n  'onMouseLeave',\n  'onMouseMove',\n  'onMouseOut',\n  'onMouseOver',\n  'onMouseUp',\n  'onSelect',\n  'onTouchCancel',\n  'onTouchEnd',\n  'onTouchMove',\n  'onTouchStart',\n  'onScroll',\n  'onWheel',\n  'onAbort',\n  'onCanPlay',\n  'onCanPlayThrough',\n  'onDurationChange',\n  'onEmptied',\n  'onEncrypted',\n  'onEnded',\n  'onError',\n  'onLoadedData',\n  'onLoadedMetadata',\n  'onLoadStart',\n  'onPause',\n  'onPlay',\n  'onPlaying',\n  'onProgress',\n  'onRateChange',\n  'onSeeked',\n  'onSeeking',\n  'onStalled',\n  'onSuspend',\n  'onTimeUpdate',\n  'onVolumeChange',\n  'onWaiting',\n  'onLoad',\n  'onError',\n  'onAnimationStart',\n  'onAnimationEnd',\n  'onAnimationIteration',\n  'onTransitionEnd',\n]\n*/\n```\n\nContains a flat list of common event handler props used in JSX to attach behaviors\nto DOM events.\n\n#### eventHandlersByType\n\nThe same list as `eventHandlers`, grouped into types.\n\n```js\nconsole.log(eventHandlersByType);\n/*\n{\n  clipboard: [ 'onCopy', 'onCut', 'onPaste' ],\n  composition: [ 'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate' ],\n  keyboard: [ 'onKeyDown', 'onKeyPress', 'onKeyUp' ],\n  focus: [ 'onFocus', 'onBlur' ],\n  form: [ 'onChange', 'onInput', 'onSubmit' ],\n  mouse: [ 'onClick', 'onContextMenu', 'onDblClick', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp' ],\n  selection: [ 'onSelect' ],\n  touch: [ 'onTouchCancel', 'onTouchEnd', 'onTouchMove', 'onTouchStart' ],\n  ui: [ 'onScroll' ],\n  wheel: [ 'onWheel' ],\n  media: [ 'onAbort', 'onCanPlay', 'onCanPlayThrough', 'onDurationChange', 'onEmptied', 'onEncrypted', 'onEnded', 'onError', 'onLoadedData', 'onLoadedMetadata', 'onLoadStart', 'onPause', 'onPlay', 'onPlaying', 'onProgress', 'onRateChange', 'onSeeked', 'onSeeking', 'onStalled', 'onSuspend', 'onTimeUpdate', 'onVolumeChange', 'onWaiting' ],\n  image: [ 'onLoad', 'onError' ],\n  animation: [ 'onAnimationStart', 'onAnimationEnd', 'onAnimationIteration' ],\n  transition: [ 'onTransitionEnd' ],\n}\n*/\n```\n\n## Sponsors and Backers\n\n[![Sponsors and Backers](https://raw.githubusercontent.com/1stG/static/master/sponsors.svg)](https://github.com/sponsors/JounQin)\n\n### Sponsors\n\n| 1stG                                                                                                                   | RxTS                                                                                                                   | UnTS                                                                                                                   |\n| ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |\n| [![1stG Open Collective sponsors](https://opencollective.com/1stG/organizations.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective sponsors](https://opencollective.com/rxts/organizations.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective sponsors](https://opencollective.com/unts/organizations.svg)](https://opencollective.com/unts) |\n\n### Backers\n\n| 1stG                                                                                                                | RxTS                                                                                                                | UnTS                                                                                                                |\n| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |\n| [![1stG Open Collective backers](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |\n\n## Changelog\n\nDetailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).\n\n## License\n\n[MIT][] © [JounQin][]@[1stG.me][]\n\n[1stG.me]: https://www.1stG.me\n[JounQin]: https://github.com/JounQin\n[MIT]: http://opensource.org/licenses/MIT\n","readmeFilename":"README.md"}