import * as jsxUtils from 'jsx-ast-utils' ; import strip from 'strip-indent' ; import escapeJS from 'js-string-escape' ; import { valueFromTraverse , codeFromNode } from './ast' ; export const propFromElement = ( prop ) => valueFromTraverse ( p => p . isJSXOpeningElement ( ) , p => jsxUtils . getPropValue ( jsxUtils . getProp ( p . node . attributes , prop ) ) ) ; export const removeTags = ( code ) => { const open = codeFromNode ( p => p . isJSXOpeningElement ( ) ) ; const close = codeFromNode ( p => p . isJSXClosingElement ( ) ) ; return code . replace ( open ( code ) , '' ) . replace ( close ( code ) , '' ) ; } ; export const sanitizeCode = ( code ) => { const trimmed = strip ( code ) . trim ( ) ; const newCode = trimmed . startsWith ( '{' ) && trimmed . endsWith ( '}' ) ? trimmed . substr ( 1 , trimmed . length - 2 ) . trim ( ) : trimmed ; return escapeJS ( strip ( newCode ) ) ; } ; const regex = /^\<\\?(\w+)/ ; export const componentName = ( value ) => { const match = value . match ( regex ) ; return match && match [ 1 ] ; } ;