File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -42,12 +42,29 @@ async function getPageInfo(url) {
42
42
}
43
43
} ) ;
44
44
const funcReg = / v a r \s ( .* ) \s = \s f u n c t i o n /
45
- const index = questionTitle . split ( '.' ) [ 0 ]
45
+ let index = questionTitle . split ( '.' ) [ 0 ]
46
46
const funcMatch = code . match ( funcReg )
47
47
let funcName = ''
48
48
if ( funcMatch && funcMatch . length === 2 ) {
49
49
funcName = funcMatch [ 1 ]
50
50
}
51
+
52
+ // 文件前缀是否数字,不是则用leetcode作为前缀
53
+ const numReg = / ^ [ 0 - 9 ] + ?$ / ;
54
+ if ( ! numReg . test ( index ) ) {
55
+ const leetCodeFileReg = new RegExp ( `^leetcode_[0-9]+?_${ funcName } .js$` ) //;
56
+ const libDir = fs . readdirSync ( 'lib/' )
57
+ let i = 1
58
+ for ( const item of libDir ) {
59
+ if ( item . indexOf ( 'leetcode' ) === 0 ) {
60
+ if ( leetCodeFileReg . test ( item ) ) {
61
+ throw new Error ( "file may exist - " + item ) ;
62
+ }
63
+ i ++
64
+ }
65
+ }
66
+ index = `leetcode_${ i } `
67
+ }
51
68
const fileName = `${ index } _${ funcName } .js`
52
69
53
70
You can’t perform that action at this time.
0 commit comments