1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 09:43:23 +00:00
Files
browser/libs/common/src/models/export/field.export.ts
Daniel James Smith dba910d0b9 Create and use safeGetString() instead of instanceof checks to determine type (#8906)
`safeGetString` takes a `string` or `EncString` and return the appropiate value based on it's type

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
2024-04-24 23:41:35 +02:00

49 lines
1.3 KiB
TypeScript

import { EncString } from "../../platform/models/domain/enc-string";
import { FieldType, LinkedIdType } from "../../vault/enums";
import { Field as FieldDomain } from "../../vault/models/domain/field";
import { FieldView } from "../../vault/models/view/field.view";
import { safeGetString } from "./utils";
export class FieldExport {
static template(): FieldExport {
const req = new FieldExport();
req.name = "Field name";
req.value = "Some value";
req.type = FieldType.Text;
return req;
}
static toView(req: FieldExport, view = new FieldView()) {
view.type = req.type;
view.value = req.value;
view.name = req.name;
view.linkedId = req.linkedId;
return view;
}
static toDomain(req: FieldExport, domain = new FieldDomain()) {
domain.type = req.type;
domain.value = req.value != null ? new EncString(req.value) : null;
domain.name = req.name != null ? new EncString(req.name) : null;
domain.linkedId = req.linkedId;
return domain;
}
name: string;
value: string;
type: FieldType;
linkedId: LinkedIdType;
constructor(o?: FieldView | FieldDomain) {
if (o == null) {
return;
}
this.name = safeGetString(o.name);
this.value = safeGetString(o.value);
this.type = o.type;
this.linkedId = o.linkedId;
}
}