1.0.1 • Published 7 months ago

file-to-url v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago
// Handle an image with optimization
const optimizedImage = await FileHandler.handle('image.jpg');
await optimizedImage.toFile('optimized.jpg');

// Handle an image but skip optimization
const unoptimizedImage = await FileHandler.handle('image.jpg', {
  skipImageOptimization: true
});
const imageBase64 = unoptimizedImage.toBase64URL();

// Handle a PDF or any other file type
const pdfHandler = await FileHandler.handle('document.pdf');
const pdfStream = pdfHandler.toStream();

// Handle an image with custom options
const customImage = await FileHandler.handle('large-image.png', {
  maxWidth: 1200,
  maxHeight: 1200,
  quality: 85,
  format: 'webp'
});
const webpBlob = customImage.toBlob();

// Check if file is an image before doing image-specific operations
const handler = await FileHandler.handle('unknown-file');
if (handler.isImage()) {
  console.log('Processing image...');
} else {
  console.log('Processing other file type...');
}

// check if a string is base64 or a isBase64DataURL

FileHandler.isBase64(str)
FileHandler.isBase64DataURL(str)
1.0.1

7 months ago

1.0.0

7 months ago