UNPKG

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