chore: fix duplicate file name error when exporting notes and refactor file name utils (#2877) [skip e2e]

This commit is contained in:
Aman Harwara
2024-05-07 15:45:50 +05:30
committed by GitHub
parent 71d2dbca6c
commit c3265d7930
16 changed files with 61 additions and 56 deletions

View File

@@ -1,4 +1,5 @@
import { formatSizeToReadableString, parseFileName } from './utils'
import { formatSizeToReadableString } from './utils'
import { parseFileName } from '@standardnotes/utils'
describe('utils', () => {
describe('parseFileName', () => {

View File

@@ -10,18 +10,6 @@ export async function readFile(file: File): Promise<Uint8Array> {
})
}
export function parseFileName(fileName: string): {
name: string
ext: string
} {
const pattern = /(?:\.([^.]+))?$/
const extMatches = pattern.exec(fileName)
const ext = extMatches?.[1] || ''
const name = fileName.includes('.') ? fileName.substring(0, fileName.lastIndexOf('.')) : fileName
return { name, ext }
}
export function saveFile(name: string, bytes: Uint8Array): void {
const link = document.createElement('a')
const blob = new Blob([bytes], {