1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 13:53:34 +00:00
Files
browser/libs/common/src/models/export/folder.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

31 lines
879 B
TypeScript

import { EncString } from "../../platform/models/domain/enc-string";
import { Folder as FolderDomain } from "../../vault/models/domain/folder";
import { FolderView } from "../../vault/models/view/folder.view";
import { safeGetString } from "./utils";
export class FolderExport {
static template(): FolderExport {
const req = new FolderExport();
req.name = "Folder name";
return req;
}
static toView(req: FolderExport, view = new FolderView()) {
view.name = req.name;
return view;
}
static toDomain(req: FolderExport, domain = new FolderDomain()) {
domain.name = req.name != null ? new EncString(req.name) : null;
return domain;
}
name: string;
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: FolderView | FolderDomain) {
this.name = safeGetString(o.name);
}
}