modern-image-extensions
v1.0.1
Published
Modern image file extension list, including bitmap and vector formats
Maintainers
Readme
modern-image-extensions
Modern image file extension list, including the latest bitmap and vector formats.
Features
- Includes the latest image format extensions (such as WebP, AVIF, HEIF, JXL, etc.)
- Distinguishes between bitmap and vector formats
- Provides useful helper functions
- Written in TypeScript with complete type definitions
- Zero dependencies
Installation
# Using npm
npm install modern-image-extensions
# Using yarn
yarn add modern-image-extensions
# Using pnpm
pnpm add modern-image-extensionsUsage
Basic Usage
// ESM import
import imageExtensions from 'modern-image-extensions';
console.log(imageExtensions);
// ['jpg', 'jpeg', 'png', 'gif', 'svg', ...]
// CommonJS import
const imageExtensions = require('modern-image-extensions');
console.log(imageExtensions);
// ['jpg', 'jpeg', 'png', 'gif', 'svg', ...]Get Specific Types of Extensions
import { bitmapExtensions, vectorExtensions } from 'modern-image-extensions';
console.log(bitmapExtensions);
// ['jpg', 'jpeg', 'png', 'gif', 'webp', ...]
console.log(vectorExtensions);
// ['svg', 'ai', 'eps', 'pdf', ...]Check File Extensions
import { isImageExtension, isImage } from 'modern-image-extensions';
// Check if an extension is an image format
console.log(isImageExtension('jpg')); // true
console.log(isImageExtension('txt')); // false
// Check if a file path is an image
console.log(isImage('path/to/image.png')); // true
console.log(isImage('path/to/document.txt')); // falseAPI Reference
imageExtensions
An array of all image format extensions (bitmap and vector formats).
bitmapExtensions
An array of bitmap format extensions.
vectorExtensions
An array of vector format extensions.
isImageExtension(extension: string): boolean
Checks if the given extension is an image format.
extension: File extension (without dot)
isImage(filePath: string): boolean
Checks if the given file path is an image.
filePath: File path
Comparison with the original image-extensions
Compared to the original image-extensions package, this package has the following advantages:
- More comprehensive format support: Includes more modern image formats such as WebP, AVIF, HEIF, JXL, etc.
- Format categorization: Distinguishes between bitmap and vector formats for easier use as needed
- Utility functions: Provides useful functions like
isImageExtensionandisImage - TypeScript support: Written in TypeScript with complete type definitions
- Continuous maintenance: The original package hasn't been updated in 10 years; this package will be continuously maintained and updated
License
MIT © Zhengpengxin
Author
Created with ❤️ by tiepolo ai
