UNPKG

4.77 kBJavaScriptView Raw
1// copyright (c) Microsoft Corporation. All rights reserved.
2// licensed under the MIT license.
3Object.defineProperty(exports, "__esModule", { value: true });
4/**
5 * The Office apps which can host Office Add-ins.
6 */
7var OfficeApp;
8(function (OfficeApp) {
9 // the string values should be lowercase
10 OfficeApp["Excel"] = "excel";
11 OfficeApp["OneNote"] = "onenote";
12 OfficeApp["Outlook"] = "outlook";
13 OfficeApp["PowerPoint"] = "powerpoint";
14 OfficeApp["Project"] = "project";
15 OfficeApp["Word"] = "word";
16 // when adding new entries, update the toOfficeApp() function
17 // since there isn't an automatic reverse mapping from string to enum values
18})(OfficeApp = exports.OfficeApp || (exports.OfficeApp = {}));
19// initialized once since this list won't change
20const officeApps = Object.keys(OfficeApp).map(key => parseOfficeApp(key));
21/**
22 * Get the Office app for the manifest Host name
23 * @param host Host name
24 */
25function getOfficeAppForManifestHost(host) {
26 switch (host.toLowerCase()) {
27 case "document":
28 return OfficeApp.Word;
29 case "mailbox":
30 return OfficeApp.Outlook;
31 case "notebook":
32 return OfficeApp.OneNote;
33 case "presentation":
34 return OfficeApp.PowerPoint;
35 case "project":
36 return OfficeApp.Project;
37 case "workbook":
38 return OfficeApp.Excel;
39 default:
40 return undefined;
41 }
42}
43exports.getOfficeAppForManifestHost = getOfficeAppForManifestHost;
44/**
45 * Gets the Office application name suitable for display.
46 * @param app Office app
47 */
48function getOfficeAppName(app) {
49 switch (app) {
50 case OfficeApp.Excel:
51 return "Excel";
52 case OfficeApp.OneNote:
53 return "OneNote";
54 case OfficeApp.Outlook:
55 return "Outlook";
56 case OfficeApp.PowerPoint:
57 return "PowerPoint";
58 case OfficeApp.Project:
59 return "Project";
60 case OfficeApp.Word:
61 return "Word";
62 default:
63 throw new Error(`Unable to provide name for Office app "${app}"`);
64 }
65}
66exports.getOfficeAppName = getOfficeAppName;
67/**
68 * Gets the Office application names suitable for display.
69 * @param apps Office apps
70 */
71function getOfficeAppNames(apps) {
72 return apps.map(app => getOfficeAppName(app));
73}
74exports.getOfficeAppNames = getOfficeAppNames;
75/**
76 * Returns the Office apps that support Office add-ins.
77 */
78function getOfficeApps() {
79 return officeApps;
80}
81exports.getOfficeApps = getOfficeApps;
82/**
83 * Get the Office apps for the manifest Host names.
84 * @param hosts Host names specified in the manifest.
85 */
86function getOfficeAppsForManifestHosts(hosts) {
87 const apps = [];
88 if (hosts) {
89 hosts.forEach(host => {
90 const app = getOfficeAppForManifestHost(host);
91 if (app) {
92 apps.push(app);
93 }
94 });
95 }
96 return apps;
97}
98exports.getOfficeAppsForManifestHosts = getOfficeAppsForManifestHosts;
99/**
100 * Converts the string to the OfficeApp enum value.
101 * @param value string
102 * @throws Error if the value is not a valid Office app.
103 */
104function parseOfficeApp(value) {
105 const officeApp = toOfficeApp(value);
106 if (!officeApp) {
107 throw new Error(`"${value}" is not a valid Office app.`);
108 }
109 return officeApp;
110}
111exports.parseOfficeApp = parseOfficeApp;
112/**
113 * Converts the strings to the OfficeApp enum values.
114 * @param input "all" for all Office apps, or a comma-separated list of one or more Office apps.
115 * @throws Error if a value is not a valid Office app.
116 */
117function parseOfficeApps(input) {
118 if (input.trim().toLowerCase() === "all") {
119 return getOfficeApps();
120 }
121 else {
122 return input.split(",").map(appString => parseOfficeApp(appString));
123 }
124}
125exports.parseOfficeApps = parseOfficeApps;
126/**
127 * Returns the OfficeApp enum for the value, or undefined if not valid.
128 * @param value Office app string
129 */
130function toOfficeApp(value) {
131 switch (value ? value.trim().toLowerCase() : value) {
132 case OfficeApp.Excel:
133 return OfficeApp.Excel;
134 case OfficeApp.OneNote:
135 return OfficeApp.OneNote;
136 case OfficeApp.Outlook:
137 return OfficeApp.Outlook;
138 case OfficeApp.PowerPoint:
139 return OfficeApp.PowerPoint;
140 case OfficeApp.Project:
141 return OfficeApp.Project;
142 case OfficeApp.Word:
143 return OfficeApp.Word;
144 default:
145 return undefined;
146 }
147}
148exports.toOfficeApp = toOfficeApp;
149//# sourceMappingURL=officeApp.js.map
\No newline at end of file