Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add file extension enum and util to get extension from mimeType #201

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions __tests__/files/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getExtensionFromMimeType } from '../../src/files'

describe('Files', () => {
it('Should correct file extension from mimeType', () => {
expect(getExtensionFromMimeType('video/mp4')).toEqual('mp4')
})

it('Should return null as mimeType is unkown', () => {
expect(getExtensionFromMimeType('log/banana')).toBeNull()
})
})
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adapcon-utils-js",
"version": "0.16.6",
"version": "0.16.7",
"description": "Utils library for Javascript",
"keywords": [],
"author": {
Expand Down
28 changes: 28 additions & 0 deletions src/files/extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export enum FILE_EXTENSIONS {
'video/mp4' = 'mp4',
'audio/ogg; codecs=opus' = 'ogg',
'image/gif' = 'gif',
'image/jpeg' = 'jpg',
'image/svg+xml' = 'svg',
'image/tiff' = 'tiff',
'image/png' = 'png',
'image/bmp' = 'bmp',
'text/html' = 'html',
'text/csv' = 'csv',
'text/css' = 'css',
'text/plain' = 'txt',
'text/xml' = 'xml',
'text/tab-separated-values' = 'tsv',
'application/pdf' = 'pdf',
'application/xml' = 'xml',
'application/zip' = 'zip',
'application/x-compressed-zip' = 'zip',
'application/vnd.ms-excel' = 'xls',
'application/x-bzip2' = 'bz2',
'application/msword' = 'doc',
'application/x-gzip' = 'gz',
'application/java-archive' = 'jar',
'application/x-javascript' = 'js',
'application/vnd.ms-powerpoint' = 'ppt',
'application/x-tar' = 'tar.gz'
}
2 changes: 2 additions & 0 deletions src/files/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './extensions'
export * from './utils'
5 changes: 5 additions & 0 deletions src/files/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FILE_EXTENSIONS } from '.'

export function getExtensionFromMimeType (mimeType: string): string | null {
return FILE_EXTENSIONS[mimeType] || null
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './date'
export * from './dynamoose'
export * from './email'
export * from './error'
export * from './files'
export * from './http'
export * from './image'
export * from './invoice'
Expand Down
Loading