bitwarden-estensione-browser/libs/angular/src/pipes/user-name.pipe.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
443 B
TypeScript
Raw Normal View History

2021-07-16 15:24:14 +02:00
import { Pipe, PipeTransform } from "@angular/core";
interface User {
name?: string;
email?: string;
2021-07-16 15:24:14 +02:00
}
@Pipe({
name: "userName",
})
export class UserNamePipe implements PipeTransform {
transform(user?: User): string {
if (user == null) {
return null;
}
2021-12-16 13:36:21 +01:00
if (user.name == null && user.email == null) {
return null;
}
2021-07-16 15:24:14 +02:00
return user.name == null || user.name.trim() === "" ? user.email : user.name;
2021-12-16 13:36:21 +01:00
}
2021-07-16 15:24:14 +02:00
}