File tree Expand file tree Collapse file tree
apps/web/src/shared/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- const extensions : Record < string , string > = {
2- rust : "rs" ,
3- typescript : "ts" ,
4- javascript : "js" ,
5- python : "py" ,
1+ const extensionToLanguage : Record < string , string > = {
2+ rs : "rust" ,
3+ ts : "typescript" ,
4+ tsx : "typescript" ,
5+ js : "javascript" ,
6+ jsx : "javascript" ,
7+ py : "python" ,
68 go : "go" ,
79 java : "java" ,
810 cpp : "cpp" ,
9- ruby : "rb" ,
11+ cc : "cpp" ,
12+ cxx : "cpp" ,
13+ hpp : "cpp" ,
14+ h : "c" ,
15+ c : "c" ,
16+ rb : "ruby" ,
1017 swift : "swift" ,
11- kotlin : "kt" ,
18+ kt : "kotlin" ,
19+ txt : "plaintext" ,
20+ md : "plaintext" ,
21+ text : "plaintext" ,
1222} ;
1323
1424export function getFileExtension ( language : string ) : string {
15- return extensions [ language . toLowerCase ( ) ] ?? "txt" ;
25+ const lang = language . toLowerCase ( ) ;
26+ const ext = Object . keys ( extensionToLanguage ) . find ( key => extensionToLanguage [ key ] === lang ) ;
27+ return ext ?? "txt" ;
28+ }
29+
30+ export function getLanguageFromFilename ( filename : string ) : string {
31+ const match = filename . toLowerCase ( ) . match ( / \. ( [ a - z 0 - 9 ] + ) $ / ) ;
32+ if ( ! match ) return "plaintext" ;
33+ return extensionToLanguage [ match [ 1 ] ] ?? "plaintext" ;
1634}
You can’t perform that action at this time.
0 commit comments