Skip to content

Commit

Permalink
refactor typeof calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 15, 2024
1 parent 5875bf4 commit e0daf4d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions sysend.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
return sysend;
},
serializer: function(to, from) {
if (typeof to !== 'function' || typeof from !== 'function') {
if (!(is_function(to) && is_function(from))) {
throw new Error('sysend::serializer: Invalid argument, expecting' +
' function');
}
Expand All @@ -97,7 +97,7 @@
},
proxy: function(...args) {
args.forEach(function(url) {
if (typeof url === 'string' && host(url) !== window.location.host) {
if (is_string(url) && host(url) !== window.location.host) {
domains = domains || [];
domains.push(origin(url));
var iframe = document.createElement('iframe');
Expand Down Expand Up @@ -324,11 +324,6 @@
};
})();
// -------------------------------------------------------------------------
function is_promise(obj) {
return obj && typeof object == 'object' &&
typeof object.then === 'function';
}
// -------------------------------------------------------------------------
function unpromise(obj, callback, error = null) {
if (is_promise(obj)) {
var ret = obj.then(callback);
Expand Down Expand Up @@ -412,6 +407,18 @@
return uniq_prefix + name;
}
// -------------------------------------------------------------------------
function is_promise(obj) {
return obj && typeof object == 'object' && is_function(object.then);
}
// -------------------------------------------------------------------------
function is_function(o) {
return typeof o === 'function';
}
// -------------------------------------------------------------------------
function is_string(o) {
return typeof o === 'string';
}
// -------------------------------------------------------------------------
function is_internal(name) {
return name.match(prefix_re);
}
Expand Down Expand Up @@ -589,7 +596,7 @@
hidden = 'webkitHidden';
visibilityChange = 'webkitvisibilitychange';
}
if (typeof document.addEventListener === 'function' && hidden) {
if (is_function(document.addEventListener) && hidden) {
document.addEventListener(visibilityChange, function() {
trigger(handlers.visbility, !document[hidden]);
}, false);
Expand Down

0 comments on commit e0daf4d

Please sign in to comment.