5.7.114 • Published 2 months ago

@devtea2026/illum-totam-eos-eius v5.7.114

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@devtea2026/illum-totam-eos-eius Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

AST utility module for statically analyzing JSX.

Installation

$ npm i @devtea2026/illum-totam-eos-eius --save

Usage

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.

ESLint example

import { hasProp } from '@devtea2026/illum-totam-eos-eius';
// OR: var hasProp = require('@devtea2026/illum-totam-eos-eius').hasProp;
// OR: const hasProp = require('@devtea2026/illum-totam-eos-eius/hasProp');
// OR: import hasProp from '@devtea2026/illum-totam-eos-eius/hasProp';

module.exports = context => ({
  JSXOpeningElement: node => {
    const onChange = hasProp(node.attributes, 'onChange');

    if (onChange) {
      context.report({
        node,
        message: `No onChange!`
      });
    }
  }
});

API

AST Resources

  1. JSX spec
  2. JS spec

hasProp

hasProp(props, prop, options);

Returns boolean indicating whether an prop exists as an attribute on a JSX element node.

Props

Object - The attributes on the visited node. (Usually node.attributes).

Prop

String - A string representation of the prop you want to check for existence.

Options

Object - An object representing options for existence checking 1. ignoreCase - automatically set to true. 2. 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.

hasAnyProp

hasAnyProp(props, prop, options);

Returns a boolean indicating if any of props in prop argument exist on the node.

Props

Object - The attributes on the visited node. (Usually node.attributes).

Prop

Array - An array of strings representing the props you want to check for existence.

Options

Object - An object representing options for existence checking 1. ignoreCase - automatically set to true. 2. 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.

hasEveryProp

hasEveryProp(props, prop, options);

Returns a boolean indicating if all of props in prop argument exist on the node.

Props

Object - The attributes on the visited node. (Usually node.attributes).

Prop

Array - An array of strings representing the props you want to check for existence.

Options

Object - An object representing options for existence checking 1. ignoreCase - automatically set to true. 2. 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.

getProp

getProp(props, prop, options);

Returns the JSXAttribute itself or undefined, indicating the prop is not present on the JSXOpeningElement.

Props

Object - The attributes on the visited node. (Usually node.attributes).

Prop

String - A string representation of the prop you want to check for existence.

Options

Object - An object representing options for existence checking 1. ignoreCase - automatically set to true.

elementType

elementType(node)

Returns the tagName associated with a JSXElement.

Node

Object - The visited JSXElement node object.

getPropValue

getPropValue(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.

Prop

Object - The JSXAttribute collected by AST parser.

getLiteralPropValue

getLiteralPropValue(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.)

Prop

Object - The JSXAttribute collected by AST parser.

propName

propName(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".

Prop

Object - The JSXAttribute collected by AST parser.

eventHandlers

console.log(eventHandlers);
/*
[
  'onCopy',
  'onCut',
  'onPaste',
  'onCompositionEnd',
  'onCompositionStart',
  'onCompositionUpdate',
  'onKeyDown',
  'onKeyPress',
  'onKeyUp',
  'onFocus',
  'onBlur',
  'onChange',
  'onInput',
  'onSubmit',
  'onClick',
  'onContextMenu',
  'onDblClick',
  'onDoubleClick',
  'onDrag',
  'onDragEnd',
  'onDragEnter',
  'onDragExit',
  'onDragLeave',
  'onDragOver',
  'onDragStart',
  'onDrop',
  'onMouseDown',
  'onMouseEnter',
  'onMouseLeave',
  'onMouseMove',
  'onMouseOut',
  'onMouseOver',
  'onMouseUp',
  'onSelect',
  'onTouchCancel',
  'onTouchEnd',
  'onTouchMove',
  'onTouchStart',
  'onScroll',
  'onWheel',
  'onAbort',
  'onCanPlay',
  'onCanPlayThrough',
  'onDurationChange',
  'onEmptied',
  'onEncrypted',
  'onEnded',
  'onError',
  'onLoadedData',
  'onLoadedMetadata',
  'onLoadStart',
  'onPause',
  'onPlay',
  'onPlaying',
  'onProgress',
  'onRateChange',
  'onSeeked',
  'onSeeking',
  'onStalled',
  'onSuspend',
  'onTimeUpdate',
  'onVolumeChange',
  'onWaiting',
  'onLoad',
  'onError',
  'onAnimationStart',
  'onAnimationEnd',
  'onAnimationIteration',
  'onTransitionEnd',
]
*/

Contains a flat list of common event handler props used in JSX to attach behaviors to DOM events.

eventHandlersByType

The same list as eventHandlers, grouped into types.

console.log(eventHandlersByType);
/*
{
  clipboard: [ 'onCopy', 'onCut', 'onPaste' ],
  composition: [ 'onCompositionEnd', 'onCompositionStart', 'onCompositionUpdate' ],
  keyboard: [ 'onKeyDown', 'onKeyPress', 'onKeyUp' ],
  focus: [ 'onFocus', 'onBlur' ],
  form: [ 'onChange', 'onInput', 'onSubmit' ],
  mouse: [ 'onClick', 'onContextMenu', 'onDblClick', 'onDoubleClick', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp' ],
  selection: [ 'onSelect' ],
  touch: [ 'onTouchCancel', 'onTouchEnd', 'onTouchMove', 'onTouchStart' ],
  ui: [ 'onScroll' ],
  wheel: [ 'onWheel' ],
  media: [ 'onAbort', 'onCanPlay', 'onCanPlayThrough', 'onDurationChange', 'onEmptied', 'onEncrypted', 'onEnded', 'onError', 'onLoadedData', 'onLoadedMetadata', 'onLoadStart', 'onPause', 'onPlay', 'onPlaying', 'onProgress', 'onRateChange', 'onSeeked', 'onSeeking', 'onStalled', 'onSuspend', 'onTimeUpdate', 'onVolumeChange', 'onWaiting' ],
  image: [ 'onLoad', 'onError' ],
  animation: [ 'onAnimationStart', 'onAnimationEnd', 'onAnimationIteration' ],
  transition: [ 'onTransitionEnd' ],
}
*/
importexportcharactersruntimeECMAScript 2022flagMapmomentsameValueZerocorsmovehashreal-timenopestdlib$.extenduuidURLSearchParamsbyteLengthmapreduceoptimizerreactjsdiffwhichequalvalidationfunctionsdateprotocol-buffersmetadatapluginWebSocketsrobustmimehttptrimLeftcopycryptocommand-lineconcatwatchAsyncIteratorargsrouterprotobuf[[Prototype]]patchdatadeepcloneless cssUint32ArraydayjsbundlingutilitytimeECMAScript 2023lazyArrayBufferflatMapefficientReactiveExtensionschineseirqtextpolyfillflattendirectoryshames2018offsetArray.prototype.findLastIndexObservableassertdebuggerECMAScript 2017equalityES2023urlscircularcommandfluxietrimsymlinkexpressfolderemitextratypeofvpcchromeESnext_.extenddefaultwindowslinkdynamodbdeep-copyES7private.envArray.prototype.filtertoStringTagloggerdatastructureinstallrfc4122reduxES2015asciiartmodulesgetterstylingglobalspnpm9issharedarraybufferpackageslrunested cssargumentmatchAlldeep-clonesyntaxclishellingetintrinsicsetImmediatelintworkspace:*computed-typesidentifierstestboundwalkpromisecompile lessdescriptionoptionrestfulvalueassertiongenericssearchfind-uptestingcompilerspawntoobjectprivate datasqssinatrajapanesegdprjsonCSSlinewrapprocessstreamES8censorttyunicodelanguagewalkingrm -rfbrowserlistloggingcharacterspeedjQueryconsumemodulewebinvariantindicatorchaiautoprefixercoerciblereact-hook-formsetPrototypeOfiteratordependenciespackagepromisesoptimistcollectionObservablesfindsuperagentObject.keysString.prototype.matchAllReactiveXendpointArraylivetakeschemacall-bindRegExp#flagsthroatargvpositiveforEachsnsoperating-systemcallboundavasymbolsECMAScript 5typanionregular expressionselbfseventsserializerextenddescriptorstringifierprefixcolorstypedWebSockethasOwnPropertymonorepoprototypeyupRegExp.prototype.flagsawstaskbreakerror-handlingarraybuffersliceajvwatcherphoneiterationweakmap
5.7.114

2 months ago

5.7.113

2 months ago

5.7.112

2 months ago

5.7.111

2 months ago

5.6.111

2 months ago

5.6.110

2 months ago

4.6.110

2 months ago

4.6.109

2 months ago

2.0.37

5 months ago

2.0.35

5 months ago

2.0.36

5 months ago

2.0.33

5 months ago

2.0.34

5 months ago

2.0.32

5 months ago

2.2.53

4 months ago

2.2.54

4 months ago

2.2.51

4 months ago

2.2.52

4 months ago

2.2.50

4 months ago

3.6.79

3 months ago

3.6.78

3 months ago

3.6.77

3 months ago

3.6.76

3 months ago

3.6.75

3 months ago

3.6.74

3 months ago

3.5.74

3 months ago

3.5.73

3 months ago

4.6.100

2 months ago

2.5.69

4 months ago

3.5.72

3 months ago

2.5.65

4 months ago

2.5.66

4 months ago

2.5.67

4 months ago

2.5.68

4 months ago

2.5.62

4 months ago

2.5.63

4 months ago

2.5.64

4 months ago

2.5.70

4 months ago

2.5.71

4 months ago

2.1.38

5 months ago

2.1.39

5 months ago

2.1.37

5 months ago

2.3.57

4 months ago

2.3.56

4 months ago

2.3.55

4 months ago

2.3.54

4 months ago

2.5.72

4 months ago

4.6.80

3 months ago

4.6.81

3 months ago

4.6.84

3 months ago

4.6.85

3 months ago

4.6.82

3 months ago

4.6.83

3 months ago

4.6.88

3 months ago

4.6.89

3 months ago

4.6.86

3 months ago

4.6.87

3 months ago

2.1.43

5 months ago

2.1.41

5 months ago

1.0.22

5 months ago

2.1.42

5 months ago

1.0.21

5 months ago

2.1.40

5 months ago

1.0.26

5 months ago

1.0.25

5 months ago

1.0.24

5 months ago

1.0.23

5 months ago

1.0.29

5 months ago

1.0.28

5 months ago

1.0.27

5 months ago

4.6.107

2 months ago

4.6.108

2 months ago

4.6.105

2 months ago

4.6.106

2 months ago

4.6.103

2 months ago

4.6.104

2 months ago

4.6.101

2 months ago

4.6.102

2 months ago

4.6.79

3 months ago

1.0.32

5 months ago

1.0.31

5 months ago

1.0.30

5 months ago

2.4.58

4 months ago

2.4.57

4 months ago

2.4.59

4 months ago

4.6.91

3 months ago

4.6.92

3 months ago

4.6.90

3 months ago

4.6.95

3 months ago

4.6.96

3 months ago

4.6.93

3 months ago

4.6.94

3 months ago

4.6.99

3 months ago

4.6.97

3 months ago

2.2.48

4 months ago

4.6.98

3 months ago

2.2.49

4 months ago

2.2.46

4 months ago

2.2.47

4 months ago

2.2.44

5 months ago

2.2.45

5 months ago

2.2.43

5 months ago

2.4.61

4 months ago

2.4.60

4 months ago

2.4.62

4 months ago

1.0.20

5 months ago

1.0.19

5 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago