1
1
import * as t from '@babel/types' ;
2
+ import { toPascalCase } from '@interweb-utils/casing' ;
2
3
import { minimatch } from 'minimatch' ;
3
4
4
5
import { SchemaNamingStrategy } from './context' ;
5
6
6
- export function toPascalCase ( str : string ) {
7
- return str . replace ( / ( ^ | _ | \s | - ) ( \w ) / g, ( _ : any , __ : any , letter : string ) => letter . toUpperCase ( ) ) . replace ( / [ _ \s - ] / g, '' ) ;
8
- }
9
-
10
- export function toCamelCase ( key : string ) {
11
- return key
12
- // First, remove all leading non-alphabet characters
13
- . replace ( / ^ [ ^ a - z A - Z ] + / , '' )
14
- // Convert what follows a separator into upper case
15
- . replace ( / [ - _ \s ] + ( .) ? / g, ( _ , c ) => c ? c . toUpperCase ( ) : '' )
16
- // Ensure the first character of the result is always lowercase
17
- . replace ( / ^ ./ , ( c ) => c . toLowerCase ( ) ) ;
18
- }
19
-
20
- // // Determine if the key is a valid JavaScript identifier
21
- export function isValidIdentifier ( key : string ) {
22
- return / ^ [ $ A - Z _ ] [ 0 - 9 A - Z _ $ ] * $ / i. test ( key ) && ! / ^ [ 0 - 9 ] + $ / . test ( key ) ;
23
- }
24
-
25
-
26
- // Determine if the key is a valid JavaScript-like identifier, allowing internal hyphens
27
- export function isValidIdentifierCamelized ( key : string ) {
28
- return / ^ [ $ A - Z _ ] [ 0 - 9 A - Z _ $ \- ] * $ / i. test ( key ) && ! / ^ [ 0 - 9 ] + $ / . test ( key ) && ! / ^ - / . test ( key ) ;
29
- }
30
-
31
7
export const getTypeNameSafe = ( strategy : SchemaNamingStrategy , str : string ) : string => {
32
8
if ( Object . prototype . hasOwnProperty . call ( strategy . renameMap ?? { } , str ) ) {
33
9
return toPascalCase ( strategy . renameMap [ str ] ) ;
@@ -46,7 +22,6 @@ export const getTypeNameSafe = (strategy: SchemaNamingStrategy, str: string): st
46
22
return toPascalCase ( str ) ;
47
23
} ;
48
24
49
-
50
25
const globPattern = / \* + ( [ ^ + @ ! ? \* \[ \( ] * ) / ;
51
26
52
27
interface ShouldIncludeOptions {
0 commit comments