For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/predicate/isFile.md.

isFile es-toolkit

Checks if a value is a File object.

const result = isFile(value);

Usage

isFile(value)

Use isFile when you want to check if a value is a File instance. A File object represents a file uploaded by a user or obtained from the file system as part of the web API. Unlike Blob objects, it contains additional information such as the filename and last modified time.

import { isFile } from 'es-toolkit/predicate';

// Checking File objects
const file = new File(['hello'], 'example.txt', { type: 'text/plain' });
console.log(isFile(file)); // true

// Blob objects are not Files
const blob = new Blob(['hello'], { type: 'text/plain' });
console.log(isFile(blob)); // false

// Regular objects
console.log(isFile({})); // false
console.log(isFile([])); // false
console.log(isFile('text')); // false
console.log(isFile(null)); // false
console.log(isFile(undefined)); // false

Can be used to validate if a given argument is a valid file.

// File upload handler
function handleFileUpload(input: unknown) {
  if (isFile(input)) {
    console.log(`Filename: ${input.name}`);
    console.log(`File size: ${input.size} bytes`);
    console.log(`File type: ${input.type}`);
    console.log(`Last modified: ${input.lastModified}`);

    // Since it's confirmed to be a File, can safely access file-related properties
    return input;
  }

  throw new Error('Not a valid file');
}

Safely handles environments where File is not supported in JavaScript.

// Safe in Node.js environment or environments without File support
console.log(isFile(new Date())); // false

// Does not error even in environments where File is not defined
if (typeof File === 'undefined') {
  console.log(isFile({})); // false
}

Parameters

valueunknownrequired

The value to check if it's a File object.

Returns

Returns true if the value is a File object, false otherwise.

value is File
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.