Gathering detailed insights and metrics for @mrcthms/jsx-ast-utils
Gathering detailed insights and metrics for @mrcthms/jsx-ast-utils
Gathering detailed insights and metrics for @mrcthms/jsx-ast-utils
Gathering detailed insights and metrics for @mrcthms/jsx-ast-utils
AST utility module for statically analyzing JSX
npm install @mrcthms/jsx-ast-utils
Typescript
Module System
Min. Node Version
Node Version
NPM Version
73.3
Supply Chain
98.7
Quality
74.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
1,047
Last Day
1
Last Week
7
Last Month
21
Last Year
169
MIT License
158 Commits
128 Branches
1 Contributors
Updated on May 19, 2020
Minified
Minified + Gzipped
Latest Version
2.2.7
Package Id
@mrcthms/jsx-ast-utils@2.2.7
Unpacked Size
193.62 kB
Size
25.69 kB
File Count
91
NPM Version
6.13.4
Node Version
12.16.1
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
16.7%
7
Compared to previous week
Last Month
-36.4%
21
Compared to previous month
Last Year
3.7%
169
Compared to previous year
2
21
AST utility module for statically analyzing JSX.
1$ npm i jsx-ast-utils --save
This 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, however I thought it could be useful to be extracted and maintained separately so you could write new interesting rules to statically analyze JSX.
1import { hasProp } from 'jsx-ast-utils'; 2// OR: var hasProp = require('jsx-ast-utils').hasProp; 3// OR: const hasProp = require('jsx-ast-utils/hasProp'); 4// OR: import hasProp from 'jsx-ast-utils/hasProp'; 5 6module.exports = context => ({ 7 JSXOpeningElement: node => { 8 const onChange = hasProp(node.attributes, 'onChange'); 9 10 if (onChange) { 11 context.report({ 12 node, 13 message: `No onChange!` 14 }); 15 } 16 } 17});
1hasProp(props, prop, options);
Returns boolean indicating whether an prop exists as an attribute on a JSX element node.
Object - The attributes on the visited node. (Usually node.attributes
).
String - A string representation of the prop you want to check for existence.
Object - An object representing options for existence checking
ignoreCase
- automatically set to true
.spreadStrict
- automatically set to true
. This means if spread operator exists in
props, it will assume the prop you are looking for is not in the spread.
Example: <div {...props} />
looking for specific prop here will return false if spreadStrict
is true
.1hasAnyProp(props, prop, options);
Returns a boolean indicating if any of props in prop
argument exist on the node.
Object - The attributes on the visited node. (Usually node.attributes
).
Array
Object - An object representing options for existence checking
ignoreCase
- automatically set to true
.spreadStrict
- automatically set to true
. This means if spread operator exists in
props, it will assume the prop you are looking for is not in the spread.
Example: <div {...props} />
looking for specific prop here will return false if spreadStrict
is true
.1hasEveryProp(props, prop, options);
Returns a boolean indicating if all of props in prop
argument exist on the node.
Object - The attributes on the visited node. (Usually node.attributes
).
Array
Object - An object representing options for existence checking
ignoreCase
- automatically set to true
.spreadStrict
- automatically set to true
. This means if spread operator exists in
props, it will assume the prop you are looking for is not in the spread.
Example: <div {...props} />
looking for specific prop here will return false if spreadStrict
is true
.1getProp(props, prop, options);
Returns the JSXAttribute itself or undefined, indicating the prop is not present on the JSXOpeningElement.
Object - The attributes on the visited node. (Usually node.attributes
).
String - A string representation of the prop you want to check for existence.
Object - An object representing options for existence checking
ignoreCase
- automatically set to true
.1elementType(node)
Returns the tagName associated with a JSXElement.
Object - The visited JSXElement node object.
1getPropValue(prop);
Returns the value of a given attribute. Different types of attributes have their associated values in different properties on the object.
This function should return the most closely associated value with the intention of the JSX.
Object - The JSXAttribute collected by AST parser.
1getLiteralPropValue(prop);
Returns the value of a given attribute. Different types of attributes have their associated values in different properties on the object.
This 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.)
Object - The JSXAttribute collected by AST parser.
1propName(prop);
Returns the name associated with a JSXAttribute. For example, given <div foo="bar" />
and the JSXAttribute for foo
, this will return the string "foo"
.
Object - The JSXAttribute collected by AST parser.
1console.log(eventHandlers); 2/* 3[ 4 'onCopy', 5 'onCut', 6 'onPaste', 7 'onCompositionEnd', 8 'onCompositionStart', 9 'onCompositionUpdate', 10 'onKeyDown', 11 'onKeyPress', 12 'onKeyUp', 13 'onFocus', 14 'onBlur', 15 'onChange', 16 'onInput', 17 'onSubmit', 18 'onClick', 19 'onContextMenu', 20 'onDblClick', 21 'onDoubleClick', 22 'onDrag', 23 'onDragEnd', 24 'onDragEnter', 25 'onDragExit', 26 'onDragLeave', 27 'onDragOver', 28 'onDragStart', 29 'onDrop', 30 'onMouseDown', 31 'onMouseEnter', 32 'onMouseLeave', 33 'onMouseMove', 34 'onMouseOut', 35 'onMouseOver', 36 'onMouseUp', 37 'onSelect', 38 'onTouchCancel', 39 'onTouchEnd', 40 'onTouchMove', 41 'onTouchStart', 42 'onScroll', 43 'onWheel', 44 'onAbort', 45 'onCanPlay', 46 'onCanPlayThrough', 47 'onDurationChange', 48 'onEmptied', 49 'onEncrypted', 50 'onEnded', 51 'onError', 52 'onLoadedData', 53 'onLoadedMetadata', 54 'onLoadStart', 55 'onPause', 56 'onPlay', 57 'onPlaying', 58 'onProgress', 59 'onRateChange', 60 'onSeeked', 61 'onSeeking', 62 'onStalled', 63 'onSuspend', 64 'onTimeUpdate', 65 'onVolumeChange', 66 'onWaiting', 67 'onLoad', 68 'onError', 69 'onAnimationStart', 70 'onAnimationEnd', 71 'onAnimationIteration', 72 'onTransitionEnd', 73] 74*/
Contains a flat list of common event handler props used in JSX to attach behaviors to DOM events.
The same list as eventHandlers
, grouped into types.
1console.log(eventHandlersByType); 2/* 3{ 4 clipboard: [ 'onCopy', 'onCut', 'onPaste' ], 5 composition: [ 'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate' ], 6 keyboard: [ 'onKeyDown', 'onKeyPress', 'onKeyUp' ], 7 focus: [ 'onFocus', 'onBlur' ], 8 form: [ 'onChange', 'onInput', 'onSubmit' ], 9 mouse: [ 'onClick', 'onContextMenu', 'onDblClick', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp' ], 10 selection: [ 'onSelect' ], 11 touch: [ 'onTouchCancel', 'onTouchEnd', 'onTouchMove', 'onTouchStart' ], 12 ui: [ 'onScroll' ], 13 wheel: [ 'onWheel' ], 14 media: [ 'onAbort', 'onCanPlay', 'onCanPlayThrough', 'onDurationChange', 'onEmptied', 'onEncrypted', 'onEnded', 'onError', 'onLoadedData', 'onLoadedMetadata', 'onLoadStart', 'onPause', 'onPlay', 'onPlaying', 'onProgress', 'onRateChange', 'onSeeked', 'onSeeking', 'onStalled', 'onSuspend', 'onTimeUpdate', 'onVolumeChange', 'onWaiting' ], 15 image: [ 'onLoad', 'onError' ], 16 animation: [ 'onAnimationStart', 'onAnimationEnd', 'onAnimationIteration' ], 17 transition: [ 'onTransitionEnd' ], 18} 19*/
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More