@expo/image-utils
Advanced tools
Comparing version 0.4.0 to 0.4.1
/// <reference types="node" /> | ||
import { ImageOptions } from './Image.types'; | ||
export declare function getMimeType(srcPath: string): string | null; | ||
export declare function generateImageAsync(options: { | ||
@@ -4,0 +5,0 @@ projectRoot: string; |
@@ -29,7 +29,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getPngInfo = exports.compositeImagesAsync = exports.generateFaviconAsync = exports.generateImageAsync = void 0; | ||
exports.getPngInfo = exports.compositeImagesAsync = exports.generateFaviconAsync = exports.generateImageAsync = exports.getMimeType = void 0; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const mime_1 = __importDefault(require("mime")); | ||
const parse_png_1 = __importDefault(require("parse-png")); | ||
const path_1 = __importDefault(require("path")); | ||
const Cache = __importStar(require("./Cache")); | ||
@@ -41,3 +41,2 @@ const Download = __importStar(require("./Download")); | ||
const Sharp = __importStar(require("./sharp")); | ||
const supportedMimeTypes = ['image/png', 'image/jpeg', 'image/webp', 'image/gif']; | ||
let hasWarned = false; | ||
@@ -129,2 +128,29 @@ async function resizeImagesAsync(buffer, sizes) { | ||
} | ||
const types = { | ||
png: 'image/png', | ||
jpeg: 'image/jpeg', | ||
jpg: 'image/jpeg', | ||
jpe: 'image/jpeg', | ||
webp: 'image/webp', | ||
gif: 'image/gif', | ||
}; | ||
const inverseMimeTypes = { | ||
'image/png': 'png', | ||
'image/jpeg': 'jpg', | ||
'image/webp': 'webp', | ||
'image/gif': 'gif', | ||
}; | ||
function getMimeType(srcPath) { | ||
if (typeof srcPath !== 'string') | ||
return null; | ||
try { | ||
// If the path is a URL, use the pathname | ||
const url = new URL(srcPath); | ||
srcPath = url.pathname; | ||
} | ||
catch { } | ||
const ext = path_1.default.extname(srcPath).replace(/^\./, ''); | ||
return types[ext] ?? null; | ||
} | ||
exports.getMimeType = getMimeType; | ||
async function ensureImageOptionsAsync(imageOptions) { | ||
@@ -139,11 +165,8 @@ const icon = { | ||
} | ||
const mimeType = mime_1.default.getType(icon.src); | ||
const mimeType = getMimeType(icon.src); | ||
if (!mimeType) { | ||
throw new Error(`Invalid mimeType for image with source: ${icon.src}`); | ||
} | ||
if (!supportedMimeTypes.includes(mimeType)) { | ||
throw new Error(`Supplied image is not a supported image type: ${imageOptions.src}`); | ||
} | ||
if (!icon.name) { | ||
icon.name = `icon_${getDimensionsId(imageOptions)}.${mime_1.default.getExtension(mimeType)}`; | ||
icon.name = `icon_${getDimensionsId(imageOptions)}.${inverseMimeTypes[mimeType]}`; | ||
} | ||
@@ -150,0 +173,0 @@ return icon; |
{ | ||
"name": "@expo/image-utils", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "A package used by Expo CLI for processing images", | ||
@@ -39,3 +39,2 @@ "main": "build/index.js", | ||
"jimp-compact": "0.16.1", | ||
"mime": "^2.4.4", | ||
"node-fetch": "^2.6.0", | ||
@@ -50,3 +49,2 @@ "parse-png": "^2.1.0", | ||
"@types/getenv": "^0.7.0", | ||
"@types/mime": "^2.0.3", | ||
"@types/node-fetch": "^2.6.5", | ||
@@ -59,3 +57,3 @@ "@types/semver": "^6.0.0", | ||
}, | ||
"gitHead": "2763e9cc6f2317b40da73382fe2595f8deebff46" | ||
"gitHead": "43f1b4f8a5a9bca649e4e7ca6e4155482a162431" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75090
10
5
1064
- Removedmime@^2.4.4
- Removedmime@2.6.0(transitive)