feat: create and expose serializeLibraryAsJSON ()

Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
Achille Lacoin
2022-04-05 14:35:38 +02:00
committed by GitHub
parent 880e4feede
commit 873afdacd3
4 changed files with 19 additions and 3 deletions

@ -123,14 +123,18 @@ export const isValidLibrary = (json: any) => {
);
};
export const saveLibraryAsJSON = async (libraryItems: LibraryItems) => {
export const serializeLibraryAsJSON = (libraryItems: LibraryItems) => {
const data: ExportedLibraryData = {
type: EXPORT_DATA_TYPES.excalidrawLibrary,
version: VERSIONS.excalidrawLibrary,
source: EXPORT_SOURCE,
libraryItems,
};
const serialized = JSON.stringify(data, null, 2);
return JSON.stringify(data, null, 2);
};
export const saveLibraryAsJSON = async (libraryItems: LibraryItems) => {
const serialized = serializeLibraryAsJSON(libraryItems);
await fileSave(
new Blob([serialized], {
type: MIME_TYPES.excalidrawlib,