@aws-amplify/core
Version:
Core category of aws-amplify
53 lines (51 loc) • 1.63 kB
JavaScript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAtob = exports.getBtoa = exports.getCrypto = void 0;
const errors_1 = require("../../errors");
const getCrypto = () => {
if (typeof window === 'object' && typeof window.crypto === 'object') {
return window.crypto;
}
// Next.js global polyfill
if (typeof crypto === 'object') {
return crypto;
}
throw new errors_1.AmplifyError({
name: 'MissingPolyfill',
message: 'Cannot resolve the `crypto` function from the environment.',
});
};
exports.getCrypto = getCrypto;
const getBtoa = () => {
// browser
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
return window.btoa;
}
// Next.js global polyfill
if (typeof btoa === 'function') {
return btoa;
}
throw new errors_1.AmplifyError({
name: 'Base64EncoderError',
message: 'Cannot resolve the `btoa` function from the environment.',
});
};
exports.getBtoa = getBtoa;
const getAtob = () => {
// browser
if (typeof window !== 'undefined' && typeof window.atob === 'function') {
return window.atob;
}
// Next.js global polyfill
if (typeof atob === 'function') {
return atob;
}
throw new errors_1.AmplifyError({
name: 'Base64EncoderError',
message: 'Cannot resolve the `atob` function from the environment.',
});
};
exports.getAtob = getAtob;
//# sourceMappingURL=index.js.map
;