@putout/operator-jsx
v3.0.0
Published
🐊Putout operator adds methods that simplifies JSX transformations
Maintainers
Readme
@putout/operator-regexp 
🐊Putout operator operator adds methods that simplifies JSX transformations.
Install
npm i putout @putout/operator-regexpAPI
hasTagName(path: Path | Node): boolean
Check tagName of given Path, for next jsx:
<li>hello</li>;It will work this way:
hasTagName(path, 'li');
// returns
true;getAttributePath(path: Path, name: string): Path | null
Get path of an attribute
const classNamePath = getAttributePath(path, 'className');getAttributeNode(path: Path|Node, name: string): Node | null
Get node of an attribute
const classNameNode = getAttributeNode(node, 'className');getAttributeValue(path: Path | Node, name: string): string
Get value of an attribute
const className = getAttributeValue(node, 'className');addAttributeValue(path: Path | Node, name: string, value: string)
Add value to attribute
addAttributeValue(node, 'className', 'hello');removeAttributeValue(path: Path | Node, name: string)
Remove attribute value:
removeAttributeValue(node, 'className', 'hello');Works this way:
-<section className="hello world"/>
+<section className="world"/>setAttributeValue(path: Path | Node, name: string, value: string)
Set attribute value:
setAttributeValue(node, 'className', 'hello');Works this way:
-<section className="world"/>
+<section className="hello"/>addClassName(path: Path | Node, value: string)
Add className:
addClassName(node, 'hello');Works this way:
-<section className="world"/>
+<section className="hello"/>removeClassName(path: Path | Node, value: string)
Remove className:
removeClassName(node, 'hello');Works this way:
-<section className="hello world"/>
+<section className="world"/>getClassName(path: Path | Node): string
For next jsx:
<section className="world"/>;get className:
getClassName(node);
// returns
'world';containsClassName(path: Path | Node, name: string): boolean
For next jsx:
<section className="hello world"/>;check:
containsClassName(node, 'hello');
// returns
true;hasDataName(path: Path | Node, name: string): boolean
For next jsx:
<section data-name="hello"/>;check:
hasDataName(node, 'hello');
// returns
true;hasAttributeValue(path: Path | Node, name: string, value: string): boolean
For next jsx:
<section data-menu-index="1"/>;check:
hasAttributeValue(node, 'data-menu-index', '1');
// returns
true;addAttribute(path: Path | Node, name: string, value: string)
For next jsx:
<section/>;check:
addAttribute(node, 'data-menu-index', '1');result is:
<section data-menu-index="1"/>;License
MIT
