index.ts 479 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 (
7
8
9
    !obj || // 👈 null and undefined check
    (Object.keys(obj).length === 0 &&
      Object.getPrototypeOf(obj) === Object.prototype)
Yoon, Daeki's avatar
Yoon, Daeki committed
10
11
  );
};
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];
};