Function isLt2M

Checks if the given file size is less than 2 MB.

This function is commonly used to validate file uploads by ensuring the file size does not exceed the 2 MB limit.

const fileSize = 1.5 * 1024 * 1024; // 1.5 MB in bytes
console.log(isLt2M(fileSize)); // true

const largeFileSize = 3 * 1024 * 1024; // 3 MB in bytes
console.log(isLt2M(largeFileSize)); // false
  • Parameters

    • size: number

      The size of the file in bytes.

    Returns boolean

    true if the file size is less than 2 MB, otherwise false.