UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

54 lines (42 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.appendFormData = appendFormData; exports.formatFileSize = formatFileSize; exports.sortAttachments = sortAttachments; function appendFormData(formData, data) { Object.keys(data).forEach(function (key) { return formData.append(key, data[key]); }); } var units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; function formatFileSize(size) { var unitIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; if (size < 1024) { return "".concat(size).concat(units[unitIndex]); } return formatFileSize(Math.round(size / 1024), unitIndex + 1); } function sortAttachments(attachments, sort) { if (attachments) { if (!sort.custom) { var type = sort.type, order = sort.order; return attachments.sort(function (a, b) { if (type === 'name') { if (order === 'desc') { return b.name.localeCompare(a.name); } return a.name.localeCompare(b.name); } if (order === 'desc') { return b.creationDate.getTime() - a.creationDate.getTime(); } return a.creationDate.getTime() - b.creationDate.getTime(); }); } return attachments; } } //# sourceMappingURL=utils.js.map