UNPKG

@rpldy/uploader

Version:

the processing and queuing engine for react-uploady

33 lines 1.16 kB
import { hasWindow, isProduction } from "@rpldy/shared"; import { unwrap, isProxiable, isProxy } from "@rpldy/simple-state"; import { DEFAULT_OPTIONS } from "./defaults"; const FILE_LIST_SUPPORT = hasWindow() && "FileList" in window; const getMandatoryDestination = dest => { return { params: {}, ...dest }; }; const getMandatoryOptions = options => { return { ...DEFAULT_OPTIONS, ...options, destination: options && options.destination ? getMandatoryDestination(options.destination) : null }; }; const getIsFileList = files => FILE_LIST_SUPPORT && files instanceof FileList || files.toString() === "[object FileList]"; const deepProxyUnwrap = (obj, level = 0) => { let result = obj; if (!isProduction()) { if (level < 3 && isProxy(obj)) { result = unwrap(obj); } else if (level < 3 && isProxiable(obj)) { result = Array.isArray(obj) ? obj.map(sub => deepProxyUnwrap(sub, level + 1)) : Object.keys(obj).reduce((res, key) => { res[key] = deepProxyUnwrap(obj[key], level + 1); return res; }, {}); } } return result; }; export { getMandatoryOptions, getIsFileList, deepProxyUnwrap };