@@ -1198,7 +1198,7 @@ export function createErrorStatus(message, errorCode = 'Exception') {
1198
1198
export function createFieldError ( fieldName , message , errorCode = 'Exception' ) {
1199
1199
return new ResponseStatus ( { errors : [ new ResponseError ( { fieldName, errorCode, message } ) ] } ) ;
1200
1200
}
1201
- export function isFormData ( body ) { return typeof window != "undefined" && body instanceof FormData ; }
1201
+ export function isFormData ( body ) { return body instanceof FormData ; }
1202
1202
function createErrorResponse ( errorCode , message , type = null ) {
1203
1203
const error = apply ( new ErrorResponse ( ) , e => {
1204
1204
if ( type != null )
@@ -1219,9 +1219,34 @@ export function createError(errorCode, message, fieldName) {
1219
1219
} )
1220
1220
} ) ;
1221
1221
}
1222
- export function toCamelCase ( s ) { return ! s ? s : s . charAt ( 0 ) . toLowerCase ( ) + s . substring ( 1 ) ; }
1223
- export function toPascalCase ( s ) { return ! s ? s : s . charAt ( 0 ) . toUpperCase ( ) + s . substring ( 1 ) ; }
1224
- export function toKebabCase ( s ) { return ( s || '' ) . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, '$1-$2' ) . toLowerCase ( ) ; }
1222
+ export function toPascalCase ( s ) {
1223
+ if ( ! s )
1224
+ return '' ;
1225
+ const isAllCaps = s . match ( / ^ [ A - Z 0 - 9 _ ] + $ / ) ;
1226
+ if ( isAllCaps ) {
1227
+ const words = s . split ( '_' ) ;
1228
+ return words . map ( x => x [ 0 ] . toUpperCase ( ) + x . substring ( 1 ) . toLowerCase ( ) ) . join ( '' ) ;
1229
+ }
1230
+ if ( s . includes ( '_' ) ) {
1231
+ return s . split ( '_' ) . filter ( x => x [ 0 ] ) . map ( x => x [ 0 ] . toUpperCase ( ) + x . substring ( 1 ) ) . join ( '' ) ;
1232
+ }
1233
+ return s . charAt ( 0 ) . toUpperCase ( ) + s . substring ( 1 ) ;
1234
+ }
1235
+ export function toCamelCase ( s ) {
1236
+ s = toPascalCase ( s ) ;
1237
+ if ( ! s )
1238
+ return '' ;
1239
+ return s . charAt ( 0 ) . toLowerCase ( ) + s . substring ( 1 ) ;
1240
+ }
1241
+ export function toKebabCase ( s ) {
1242
+ if ( ! s || s . length <= 1 )
1243
+ return s . toLowerCase ( ) ;
1244
+ return s
1245
+ . replace ( / ( [ A - Z 0 - 9 ] ) / g, '-$1' )
1246
+ . toLowerCase ( )
1247
+ . replace ( / ^ - / , '' )
1248
+ . replace ( / - + / g, '-' ) ;
1249
+ }
1225
1250
export function map ( o , f ) { return o == null ? null : f ( o ) ; }
1226
1251
export function camelCaseAny ( o ) {
1227
1252
if ( ! o || ! ( o instanceof Object ) || Array . isArray ( o ) )
0 commit comments