@barchart/common-js
Version:
Library of common JavaScript utilities
31 lines (25 loc) • 665 B
JavaScript
import * as is from './../is.js';
/**
* Determines whether the current browser context is using a secure protocol.
*
* @public
* @param {boolean=} secure
* @returns {boolean}
*/
export function getIsSecure(secure) {
let returnVal;
if (is.boolean(secure)) {
returnVal = secure;
} else {
let protocol;
if (window && window.location && is.string(window.location.protocol)) {
protocol = window.location.protocol;
} else if (document && document.location && is.string(document.location.protocol)) {
protocol = document.location.protocol;
} else {
protocol = '';
}
returnVal = protocol.indexOf('https') === 0;
}
return returnVal;
}