UNPKG

@rpldy/uploader

Version:

the processing and queuing engine for react-uploady

41 lines (40 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMandatoryOptions = exports.getIsFileList = exports.deepProxyUnwrap = void 0; var _shared = require("@rpldy/shared"); var _simpleState = require("@rpldy/simple-state"); var _defaults = require("./defaults"); const FILE_LIST_SUPPORT = (0, _shared.hasWindow)() && "FileList" in window; const getMandatoryDestination = dest => { return { params: {}, ...dest }; }; const getMandatoryOptions = options => { return { ..._defaults.DEFAULT_OPTIONS, ...options, destination: options && options.destination ? getMandatoryDestination(options.destination) : null }; }; exports.getMandatoryOptions = getMandatoryOptions; const getIsFileList = files => FILE_LIST_SUPPORT && files instanceof FileList || files.toString() === "[object FileList]"; exports.getIsFileList = getIsFileList; const deepProxyUnwrap = (obj, level = 0) => { let result = obj; if (!(0, _shared.isProduction)()) { if (level < 3 && (0, _simpleState.isProxy)(obj)) { result = (0, _simpleState.unwrap)(obj); } else if (level < 3 && (0, _simpleState.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; }; exports.deepProxyUnwrap = deepProxyUnwrap;