1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 17:53:39 +00:00

[SM-288] Rename requests and responses to follow naming convention (#3806)

This commit is contained in:
Oscar Hinton
2022-10-18 19:01:42 +02:00
committed by GitHub
parent c2df5c608e
commit cf2d3f5382
375 changed files with 868 additions and 1054 deletions

View File

@@ -0,0 +1,43 @@
export abstract class BaseResponse {
private response: any;
constructor(response: any) {
this.response = response;
}
protected getResponseProperty(
propertyName: string,
response: any = null,
exactName = false
): any {
if (propertyName == null || propertyName === "") {
throw new Error("propertyName must not be null/empty.");
}
if (response == null && this.response != null) {
response = this.response;
}
if (response == null) {
return null;
}
if (!exactName && response[propertyName] === undefined) {
let otherCasePropertyName: string = null;
if (propertyName.charAt(0) === propertyName.charAt(0).toUpperCase()) {
otherCasePropertyName = propertyName.charAt(0).toLowerCase();
} else {
otherCasePropertyName = propertyName.charAt(0).toUpperCase();
}
if (propertyName.length > 1) {
otherCasePropertyName += propertyName.slice(1);
}
propertyName = otherCasePropertyName;
if (response[propertyName] === undefined) {
propertyName = propertyName.toLowerCase();
}
if (response[propertyName] === undefined) {
propertyName = propertyName.toUpperCase();
}
}
return response[propertyName];
}
}