import { PLACEHOLDER , getSettingValue } from '../index' ; export const prefixFormat = ( { isShowLineCount , selectFileName , fileName , lineNumber , selectVariable , prefixLogo , statement } ) => { prefixLogo = joinLineCount ( { prefixLogo , isShowLineCount , lineNumber , fileName , selectFileName } ) ; if ( ! prefixLogo || prefixLogo === '#' ) { return `${ selectVariable }` ; } else if ( prefixLogo . includes ( '#' ) ) { const selectQuotes = getSettingValue ( 'Select Quotes' ) ; if ( selectQuotes === 'double' ) { selectVariable = selectVariable . replace ( /\"/g , "'" ) ; } else { selectVariable = selectVariable . replace ( /\'/g , '"' ) ; } return prefixLogo . replace ( PLACEHOLDER , selectVariable ) ; } else if ( ! prefixLogo . includes ( '#' ) ) { return prefixLogo ; } return statement ; } ; const joinLineCount = ( { prefixLogo , isShowLineCount , lineNumber , fileName , selectFileName } ) => { let template = prefixLogo ; if ( isShowLineCount ) { template = ! prefixLogo || prefixLogo === '#' ? `${ lineNumber }` : `${ prefixLogo }-${ lineNumber }` ; } if ( selectFileName !== '不打印' || ! selectFileName ) { fileName = switchFileName ( selectFileName , fileName ) ; template = template ? `${ template }-「${ fileName }」` : `「${ fileName }」` ; } return template ; } ; const switchFileName = ( selectFileName , fileName ) => { switch ( selectFileName ) { case '打印文件名' : return fileName . replace ( /(.*\/)*([^.]+).*/gi , '$2' ) ; case '打印文件名+文件后缀名' : return fileName . replace ( /(.*\/)*([^.]+)/gi , '$2' ) ; case '打印完整路径' : return fileName ; } } ;