Migrate utils.js to TypeScript

Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
David Mehren 2020-04-11 10:22:06 +02:00
parent e87c8f04e5
commit 03ae37055d
No known key found for this signature in database
GPG key ID: 6017AF117F9756CB
2 changed files with 30 additions and 27 deletions

View file

@ -1,27 +0,0 @@
'use strict'
exports.isSQLite = function isSQLite (sequelize) {
return sequelize.options.dialect === 'sqlite'
}
exports.getImageMimeType = function getImageMimeType (imagePath) {
var fileExtension = /[^.]+$/.exec(imagePath)
switch (fileExtension[0]) {
case 'bmp':
return 'image/bmp'
case 'gif':
return 'image/gif'
case 'jpg':
case 'jpeg':
return 'image/jpeg'
case 'png':
return 'image/png'
case 'tiff':
return 'image/tiff'
case 'svg':
return 'image/svg+xml'
default:
return undefined
}
}

30
lib/utils.ts Normal file
View file

@ -0,0 +1,30 @@
export module Utils {
export function isSQLite(sequelize) {
return sequelize.options.dialect === 'sqlite'
}
export function getImageMimeType(imagePath: string) {
const fileExtension = /[^.]+$/.exec(imagePath)
switch (fileExtension?.[0]) {
case 'bmp':
return 'image/bmp'
case 'gif':
return 'image/gif'
case 'jpg':
case 'jpeg':
return 'image/jpeg'
case 'png':
return 'image/png'
case 'tiff':
return 'image/tiff'
case 'svg':
return 'image/svg+xml'
default:
return undefined
}
}
}