11import * as vscode from 'vscode' ;
2- import { InputBoxOptions } from 'vscode ' ;
2+ import * as path from 'path ' ;
33
44export const editorContext = (
55 callback : ( editor : vscode . TextEditor , selection : vscode . Selection , original : string , text : string ) => any ,
@@ -15,15 +15,38 @@ export const editorContext = (
1515 }
1616} ;
1717
18- export const showInputBox = ( defaultValue : InputBoxOptions [ 'value' ] , placeHolder : InputBoxOptions [ 'placeHolder' ] ) =>
18+ export const showInputBox = (
19+ defaultValue : vscode . InputBoxOptions [ 'value' ] ,
20+ placeHolder : vscode . InputBoxOptions [ 'placeHolder' ] ,
21+ ) =>
1922 vscode . window . showInputBox ( {
2023 value : defaultValue ,
2124 placeHolder,
2225 } ) ;
2326
24- export const camelCase = ( string : string ) =>
25- string
27+ export const camelCase = ( string : string ) => {
28+ return string
2629 . toLowerCase ( )
2730 . trim ( )
2831 . split ( / [ . \- _ \s ] / g)
2932 . reduce ( ( string , word ) => string + word [ 0 ] . toUpperCase ( ) + word . slice ( 1 ) ) ;
33+ } ;
34+
35+ export const getFilePath = ( ) => {
36+ const activeEditor = vscode . window . activeTextEditor ;
37+ const document = activeEditor && activeEditor . document ;
38+
39+ return document && document . fileName ;
40+ } ;
41+
42+ export const getNewFileName = ( fileName : string , type : 'tsx' | 'ts' ) => {
43+ const ext = path . extname ( fileName ) . replace ( / ^ \. / , '' ) ;
44+ const extNameRegex = new RegExp ( `${ ext } $` ) ;
45+ return fileName . replace ( extNameRegex , type ) ;
46+ } ;
47+
48+ export const isJsx = ( content : string ) => {
49+ const reg = / < ( [ A - z ] ) / gm;
50+
51+ return reg . test ( content ) ;
52+ } ;
0 commit comments