-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathValidatePolyFilling.ts
30 lines (28 loc) · 1.24 KB
/
ValidatePolyFilling.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
/**
* @constant
* @function
* Validates availability of Promise and fetch in global context
* @returns The true in case the Promise and fetch available, otherwise throws error
*/
export const validatePolyFilling = (): boolean => {
if (typeof Promise === "undefined" && typeof fetch === "undefined") {
const error = new Error("Library cannot function without Promise and fetch. So, please provide polyfill for them.");
error.name = "PolyFillNotAvailable";
throw error;
} else if (typeof Promise === "undefined") {
const error = new Error("Library cannot function without Promise. So, please provide polyfill for it.");
error.name = "PolyFillNotAvailable";
throw error;
} else if (typeof fetch === "undefined") {
const error = new Error("Library cannot function without fetch. So, please provide polyfill for it.");
error.name = "PolyFillNotAvailable";
throw error;
}
return true;
};