guardz
Version:
A simple and lightweight TypeScript type guard library for runtime type validation.
34 lines (33 loc) • 1.02 kB
TypeScript
import type { TypeGuardFn } from './isType';
/**
* Checks if a value is a Blob object.
*
* This type guard is useful for validating Blob objects in both browser and Node.js
* environments (where Blob is available).
*
* @param value - The value to check
* @param config - Optional configuration for error handling
* @returns True if the value is a Blob object, false otherwise
*
* @example
* ```typescript
* import { isBlob } from 'guardz';
*
* // Browser environment
* const fileInput = document.querySelector('input[type="file"]');
* if (fileInput?.files?.[0] && isBlob(fileInput.files[0])) {
* // file is typed as Blob (File extends Blob)
* console.log('Blob size:', file.size);
* console.log('Blob type:', file.type);
* }
*
* // With error handling
* const data: unknown = getBlobData();
* if (!isBlob(data, { identifier: 'imageData' })) {
* console.error('Invalid blob data');
* return;
* }
* // data is now typed as Blob
* ```
*/
export declare const isBlob: TypeGuardFn<Blob>;