Skip to content

Commit

Permalink
Use mime object import
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiber committed Jul 29, 2024
1 parent eaa6ecf commit 67dc9c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render as renderTemplate } from 'ejs';
import jszip, { generateAsync, JSZipGeneratorOptions } from 'jszip';
import { getExtension, getType } from 'mime/lite';
import mime from 'mime/lite';
import { Chapter, chapterDefaults, Content, Font, Image, isString, NormChapter, NormOptions, Options, optionsDefaults, retryFetch, type, uuid, validateAndNormalizeChapters, validateAndNormalizeOptions, validateIsOptionsOrTitle, validateIsVarargArray } from './util';


Expand Down Expand Up @@ -39,8 +39,8 @@ export class EPub {

if (this.options.cover) {
const fname = isString(this.options.cover) ? this.options.cover : this.options.cover.name;
const mediaType = getType(fname);
const extension = getExtension(mediaType || '');
const mediaType = mime.getType(fname);
const extension = mime.getExtension(mediaType || '');
if (mediaType && extension)
this.cover = { mediaType, extension };
else this.warn('Could not detect cover image type from file', fname);
Expand Down
6 changes: 3 additions & 3 deletions lib/util/html.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getExtension, getType } from 'mime/lite';
import mime from 'mime/lite';
import type { EPub } from '..';
import { fixHTML } from './html-parse';
import { uuid } from './other';
Expand All @@ -15,12 +15,12 @@ export type Image = {
function imgSrc(this: EPub, url: string) {
let image = this.images.find(i => i.url === url);
if (!image) {
const mediaType = getType(url.replace(/\?.*/, "")) || '';
const mediaType = mime.getType(url.replace(/\?.*/, "")) || '';
image = {
url,
mediaType,
id: uuid(),
extension: getExtension(mediaType) || '',
extension: mime.getExtension(mediaType) || '',
};
this.images.push(image);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { remove as removeDiacritics } from 'diacritics';
import { getType } from 'mime/lite';
import mime from 'mime/lite';
import slugify from 'slugify';
import chapterXHTML2 from 'templates/epub2/chapter.xhtml.ejs';
import contentOPF2 from 'templates/epub2/content.opf.ejs';
Expand Down Expand Up @@ -63,7 +63,7 @@ export const validateAndNormalizeOptions = (options: Options) => {
...options,
} as NormOptions;
opt.author = normName(opt.author);
opt.fonts = opt.fonts.map(font => ({ ...font, filename: font.filename.replace(/\s/g, '_').replace(/[^-._A-Za-z0-9]/g, ''), mediaType: getType(font.filename)! }));
opt.fonts = opt.fonts.map(font => ({ ...font, filename: font.filename.replace(/\s/g, '_').replace(/[^-._A-Za-z0-9]/g, ''), mediaType: mime.getType(font.filename)! }));
opt.date = new Date(opt.date).toISOString();
opt.lang = removeDiacritics(opt.lang);
return opt;
Expand Down

0 comments on commit 67dc9c5

Please sign in to comment.