UNPKG

@officesdk/web

Version:

Web JS SDK for the Office SDK

58 lines (57 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertFileType = exports.mapToPreviewType = exports.FileType = void 0; /** * Supported file types for the Office SDK. */ var FileType; (function (FileType) { FileType[FileType["Document"] = 0] = "Document"; FileType[FileType["Spreadsheet"] = 1] = "Spreadsheet"; FileType[FileType["Presentation"] = 2] = "Presentation"; FileType[FileType["LiteDoc"] = 3] = "LiteDoc"; FileType[FileType["DBTable"] = 4] = "DBTable"; FileType[FileType["Pdf"] = 5] = "Pdf"; })(FileType || (exports.FileType = FileType = {})); /** * 映射成预览类型 * * @export * @param {FileType} type */ function mapToPreviewType(type) { var _a; var map = (_a = {}, _a[FileType.Document] = 'docx', _a[FileType.Spreadsheet] = 'sheet', _a[FileType.Pdf] = 'pdf', _a[FileType.Presentation] = 'presentation', // TODO: 轻文档和应用表格 _a[FileType.DBTable] = 'table', _a[FileType.LiteDoc] = 'unsupported', _a); return map[type]; } exports.mapToPreviewType = mapToPreviewType; /** * 断言传入值是否为支持的文件类型 */ function assertFileType(input) { if (typeof input !== 'number' || isNaN(input)) { // TODO: 抛出自定义错误 throw new Error("Unsupported file type: ".concat(input)); } var supportedFileTypes = [ FileType.Document, FileType.Spreadsheet, FileType.Presentation, FileType.LiteDoc, FileType.DBTable, FileType.Pdf, ]; if (!supportedFileTypes.includes(input)) { // TODO: 抛出自定义错误 throw new Error("Unsupported file type: ".concat(input)); } } exports.assertFileType = assertFileType;