1- 'use strict' ;
1+ import { setLiteralValue } from '@putout/operate' ;
2+ import { types } from '@putout/babel' ;
23
3- const { setLiteralValue} = require ( '@putout/operate' ) ;
4- const { types} = require ( '@putout/babel' ) ;
54const {
65 isJSXElement,
76 jsxAttribute,
@@ -11,7 +10,7 @@ const {
1110
1211const getNode = ( a ) => a . node || a ;
1312
14- module . exports . hasTagName = ( path , name ) => {
13+ export const hasTagName = ( path , name ) => {
1514 const node = getNode ( path ) ;
1615
1716 if ( ! isJSXElement ( path ) )
@@ -20,7 +19,7 @@ module.exports.hasTagName = (path, name) => {
2019 return node . openingElement . name . name === name ;
2120} ;
2221
23- module . exports . getAttributePath = ( path , name ) => {
22+ export const getAttributePath = ( path , name ) => {
2423 const attributes = path . get ( 'openingElement.attributes' ) ;
2524
2625 for ( const attr of attributes ) {
@@ -31,8 +30,7 @@ module.exports.getAttributePath = (path, name) => {
3130 return null ;
3231} ;
3332
34- module . exports . getAttributeNode = getAttributeNode ;
35- function getAttributeNode ( path , name ) {
33+ export function getAttributeNode ( path , name ) {
3634 let result = null ;
3735 const node = getNode ( path ) ;
3836 const { attributes} = node . openingElement ;
@@ -47,8 +45,7 @@ function getAttributeNode(path, name) {
4745 return result ;
4846}
4947
50- module . exports . getAttributeValue = getAttributeValue ;
51- function getAttributeValue ( path , attributeName ) {
48+ export function getAttributeValue ( path , attributeName ) {
5249 const attribute = getAttributeNode ( path , attributeName ) ;
5350
5451 if ( ! attribute )
@@ -57,8 +54,7 @@ function getAttributeValue(path, attributeName) {
5754 return attribute . value . value ;
5855}
5956
60- module . exports . addAttributeValue = addAttributeValue ;
61- function addAttributeValue ( path , name , value ) {
57+ export function addAttributeValue ( path , name , value ) {
6258 const attributeNode = getAttributeNode ( path , name ) ;
6359
6460 if ( ! attributeNode )
@@ -70,8 +66,7 @@ function addAttributeValue(path, name, value) {
7066 setLiteralValue ( attributeNode . value , `${ attributeNode . value . value } ${ value } ` ) ;
7167}
7268
73- module . exports . addAttribute = addAttribute ;
74- function addAttribute ( path , name , value ) {
69+ export function addAttribute ( path , name , value ) {
7570 const node = getNode ( path ) ;
7671 let attributeNode = getAttributeNode ( node , name ) ;
7772
@@ -81,8 +76,7 @@ function addAttribute(path, name, value) {
8176 }
8277}
8378
84- module . exports . removeAttributeValue = removeAttributeValue ;
85- function removeAttributeValue ( path , name , attributeValue ) {
79+ export function removeAttributeValue ( path , name , attributeValue ) {
8680 if ( ! path )
8781 return ;
8882
@@ -101,7 +95,7 @@ function removeAttributeValue(path, name, attributeValue) {
10195 setLiteralValue ( classAttribute . value , newValue ) ;
10296}
10397
104- module . exports . setAttributeValue = ( path , name , value ) => {
98+ export const setAttributeValue = ( path , name , value ) => {
10599 const attributeNode = getAttributeNode ( path , name ) ;
106100
107101 if ( ! attributeNode )
@@ -110,30 +104,29 @@ module.exports.setAttributeValue = (path, name, value) => {
110104 setLiteralValue ( attributeNode . value , value ) ;
111105} ;
112106
113- module . exports . addClassName = ( path , name ) => {
107+ export const addClassName = ( path , name ) => {
114108 addAttributeValue ( path , 'className' , name ) ;
115109} ;
116110
117- module . exports . getClassName = getClassName ;
118- function getClassName ( path ) {
111+ export function getClassName ( path ) {
119112 return getAttributeValue ( path , 'className' ) ;
120113}
121114
122- module . exports . removeClassName = ( path , name ) => {
115+ export const removeClassName = ( path , name ) => {
123116 removeAttributeValue ( path , 'className' , name ) ;
124117} ;
125118
126- module . exports . containsClassName = ( path , className ) => {
119+ export const containsClassName = ( path , className ) => {
127120 const classNameValue = getClassName ( path ) ;
128121 return classNameValue . includes ( className ) ;
129122} ;
130123
131- module . exports . hasDataName = ( path , value = '' ) => {
124+ export const hasDataName = ( path , value = '' ) => {
132125 const attribute = getAttributeValue ( path , 'data-name' ) ;
133126 return attribute === value ;
134127} ;
135128
136- module . exports . hasAttributeValue = ( path , name , value = '' ) => {
129+ export const hasAttributeValue = ( path , name , value = '' ) => {
137130 const attribute = getAttributeValue ( path , name ) ;
138131 return attribute === value ;
139132} ;
0 commit comments