@@ -5,35 +5,46 @@ const mdRegex = /\.md$/;
55const yamlRegex = / \. y m l $ / ;
66const svgRegex = / \. s v g $ / ;
77const jsxRegex = / \. j s x $ / ;
8+ const tsRegex = / \. t s x ? $ / ;
9+ const jsRegex = / \. j s $ / ;
10+ const reasonRegex = / \. r e $ / ;
11+ const sassRegex = / \. s c s s $ / ;
812
913export function getMode ( title : string = '' ) {
10- const removeIgnoreTitle = title . split ( 'ignore' ) [ 0 ] ;
11-
12- if ( removeIgnoreTitle === 'favicon.ico' ) {
13- return 'favicon' ;
14- }
15-
16- if ( removeIgnoreTitle === 'yarn.lock' ) {
17- return 'yarn' ;
18- }
19-
20- if ( removeIgnoreTitle === '.travis.yml' ) {
21- return 'travis' ;
22- }
14+ const removeIgnoreTitle = title . split ( 'ignore' ) [ 0 ] . toLowerCase ( ) ;
2315
24- if ( removeIgnoreTitle === 'package.json' ) {
25- return 'npm' ;
26- }
16+ // EXCEPTIONS
2717
28- if ( removeIgnoreTitle === 'sandbox.config.json' ) {
29- return 'codesandbox' ;
30- }
18+ if ( removeIgnoreTitle === 'favicon.ico' ) return 'favicon' ;
19+ if ( removeIgnoreTitle === 'yarn.lock' ) return 'yarn' ;
20+ if ( removeIgnoreTitle === '.travis.yml' ) return 'travis' ;
21+ if ( removeIgnoreTitle === 'package.json' ) return 'npm' ;
22+ if ( removeIgnoreTitle === 'sandbox.config.json' ) return 'codesandbox' ;
23+ if ( removeIgnoreTitle === 'readme.md' ) return 'readme' ;
24+ if ( removeIgnoreTitle === 'contributing.md' ) return 'contributing' ;
3125
26+ // TEST BASED
3227 if ( mdRegex . test ( removeIgnoreTitle ) ) return 'markdown' ;
3328 if ( yamlRegex . test ( removeIgnoreTitle ) ) return 'yaml' ;
34- if ( jsxRegex . test ( removeIgnoreTitle ) ) return 'reactjs' ;
29+ if ( jsxRegex . test ( removeIgnoreTitle ) ) return 'react' ;
30+ if ( reasonRegex . test ( removeIgnoreTitle ) ) return 'reason' ;
31+ if ( sassRegex . test ( removeIgnoreTitle ) ) return 'sass' ;
3532 if ( ! removeIgnoreTitle . includes ( '.' ) ) return 'raw' ;
33+ if ( removeIgnoreTitle . startsWith ( '.flow' ) ) return 'flow' ;
34+ if (
35+ removeIgnoreTitle . endsWith ( '.module.ts' ) ||
36+ removeIgnoreTitle . endsWith ( '.component.ts' )
37+ )
38+ return 'angular' ;
3639 if ( removeIgnoreTitle . includes ( 'webpack' ) ) return 'webpack' ;
40+ if ( jsRegex . test ( removeIgnoreTitle ) ) return 'javascript' ;
41+ if (
42+ tsRegex . test ( title ) ||
43+ title === 'tsconfig.json' ||
44+ title === 'tslint.json'
45+ ) {
46+ return 'typescript' ;
47+ }
3748
3849 if ( isImage ( removeIgnoreTitle ) && ! svgRegex . test ( removeIgnoreTitle ) ) {
3950 return 'image' ;
@@ -48,22 +59,6 @@ export function getMode(title: string = '') {
4859 return titleArr [ titleArr . length - 1 ] ;
4960}
5061
51- const tsRegex = / \. t s x ? $ / ;
52- function isTS ( title : string ) {
53- if (
54- tsRegex . test ( title ) ||
55- title === 'tsconfig.json' ||
56- title === 'tslint.json'
57- )
58- return 'typescript' ;
59- return undefined ;
60- }
61-
6262export default function getType ( title : string ) {
63- const isTSType = isTS ( title ) ;
64- if ( isTSType ) {
65- return isTSType ;
66- }
67-
6863 return getMode ( title ) ;
6964}
0 commit comments