Skip to content

Commit 79a1b58

Browse files
committed
Update servicestack-client.mjs
1 parent 80c6a29 commit 79a1b58

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

AiServer/wwwroot/lib/mjs/servicestack-client.mjs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ export function createErrorStatus(message, errorCode = 'Exception') {
11981198
export function createFieldError(fieldName, message, errorCode = 'Exception') {
11991199
return new ResponseStatus({ errors: [new ResponseError({ fieldName, errorCode, message })] });
12001200
}
1201-
export function isFormData(body) { return typeof window != "undefined" && body instanceof FormData; }
1201+
export function isFormData(body) { return body instanceof FormData; }
12021202
function createErrorResponse(errorCode, message, type = null) {
12031203
const error = apply(new ErrorResponse(), e => {
12041204
if (type != null)
@@ -1219,9 +1219,34 @@ export function createError(errorCode, message, fieldName) {
12191219
})
12201220
});
12211221
}
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-Z0-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-Z0-9])/g, '-$1')
1246+
.toLowerCase()
1247+
.replace(/^-/, '')
1248+
.replace(/-+/g, '-');
1249+
}
12251250
export function map(o, f) { return o == null ? null : f(o); }
12261251
export function camelCaseAny(o) {
12271252
if (!o || !(o instanceof Object) || Array.isArray(o))

0 commit comments

Comments
 (0)