index.ts 475 Bytes
Newer Older
1
2
import type { File } from "formidable";

3
export { asyncWrap } from "./asyncWrap";
Yoon, Daeki's avatar
Yoon, Daeki committed
4
5
6

export const isEmpty = (obj: any) => {
  return (
Jiwon Yoon's avatar
Jiwon Yoon committed
7
8
    !obj || // 👈 null and undefined check
    Object.keys(obj).length === 0 ||
Yoon, Daeki's avatar
Yoon, Daeki committed
9
10
11
    Object.getPrototypeOf(obj) === Object.prototype
  );
};
12
13
14
15
16
17
18
19
20
21

export const formidableFilesToArray = (files: File | File[]): File[] | null => {
  if (Array.isArray(files)) {
    return files;
  }
  if (isEmpty(files)) {
    return null;
  }
  return [files];
};