@putout/operator-jsx
🐊Putout operator adds methods that simplifies JSX transformations
Last updated 7 months ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/operator-jsx 
SYNC missed versions from official npm registry.

@putout/operator-regexp NPM version

????Putout operator operator adds methods that simplifies JSX transformations.

Install

npm i putout @putout/operator-regexp

API

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

Current Tags

  • 3.0.0                                ...           latest (3 months ago)

15 Versions

  • 3.0.0                                ...           3 months ago
  • 2.0.0                                ...           4 months ago
  • 1.8.2                                ...           7 months ago
  • 1.8.1                                ...           7 months ago
  • 1.8.0                                ...           7 months ago
  • 1.7.0                                ...           7 months ago
  • 1.6.0                                ...           7 months ago
  • 1.5.0                                ...           7 months ago
  • 1.4.0                                ...           7 months ago
  • 1.3.0                                ...           7 months ago
  • 1.2.0                                ...           7 months ago
  • 1.1.0                                ...           7 months ago
  • 1.0.2                                ...           7 months ago
  • 1.0.1                                ...           7 months ago
  • 1.0.0                                ...           7 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (2)
Dev Dependencies (10)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |