Skip to content

Commit

Permalink
feat: Support ES module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 14, 2022
1 parent e7b66f7 commit e479a8b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"homepage": "https://jaywcjlove.github.io/image2uri/",
"license": "MIT",
"author": "Kenny <wowohoo@qq.com>",
"main": "lib/index.js",
"type": "module",
"exports": "./lib/index.js",
"main": "./lib/index.js",
"scripts": {
"prepare": "npm run build",
"watch": "tsbb watch --disable-babel",
Expand All @@ -21,7 +23,11 @@
"lib",
"src"
],
"jest": {},
"jest": {
"transformIgnorePatterns": [
"<rootDir>/node_modules/?!(.*)"
]
},
"keywords": [
"image",
"uri",
Expand All @@ -31,9 +37,10 @@
"image2uri"
],
"dependencies": {
"node-fetch": "~2.6.1"
"node-fetch": "^3.2.3"
},
"devDependencies": {
"@types/node": "~17.0.24",
"tsbb": "^3.7.2"
}
}
14 changes: 2 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,9 @@ export const extTypeMap = {
'.svg': 'image/svg+xml'
}

export type ExtType = '.png'
| '.apng'
| '.gif'
| '.jpg'
| '.jpeg'
| '.bm'
| '.bmp'
| '.webp'
| '.ico'
| '.svg';

export type ExtType = keyof typeof extTypeMap;
export default function image2uri(file: string, options: { ext?: string } = {}): string | Promise<string> {
const ext = options.ext || path.extname(file) as ExtType;
const ext: ExtType = (options.ext || path.extname(file)) as ExtType;
const contentType = extTypeMap[ext]
if (validUrl(file)) {
return fetch(file).then((response) => response.buffer()).then((buffer) => {
Expand Down
16 changes: 13 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{
"compilerOptions": {
"module": "CommonJS",
"esModuleInterop": true,
"declaration": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"sourceMap": true,
"declaration": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"strictBindCallApply": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"stripInternal": true,
"esModuleInterop": false,
"noImplicitAny": true,
"outDir": "lib",
"baseUrl": "."
},
Expand Down

0 comments on commit e479a8b

Please sign in to comment.