@perceptr/web-sdk
Version:
Perceptr Web SDK for recording and monitoring user sessions
95 lines (94 loc) • 3.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isError = exports.isFile = exports.isFormData = exports.isDocument = exports.isBoolean = exports.isNumber = exports.isNullish = exports.isNull = exports.isEmptyString = exports.isString = exports.isUndefined = exports.isEmptyObject = exports.isObject = exports.isAngularZonePresent = exports.isNativeFunction = exports.isFunction = exports.isArray = exports.hasOwnProperty = void 0;
// eslint-disable-next-line posthog-js/no-direct-array-check
const nativeIsArray = Array.isArray;
const ObjProto = Object.prototype;
exports.hasOwnProperty = ObjProto.hasOwnProperty;
const toString = ObjProto.toString;
exports.isArray = nativeIsArray ||
function (obj) {
return toString.call(obj) === "[object Array]";
};
// from a comment on http://dbj.org/dbj/?p=286
// fails on only one very rare and deliberate custom object:
// let bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
const isFunction = (x) => {
// eslint-disable-next-line posthog-js/no-direct-function-check
return typeof x === "function";
};
exports.isFunction = isFunction;
const isNativeFunction = (x) => (0, exports.isFunction)(x) && x.toString().indexOf("[native code]") !== -1;
exports.isNativeFunction = isNativeFunction;
// When angular patches functions they pass the above `isNativeFunction` check (at least the MutationObserver)
const isAngularZonePresent = () => {
return !!window.Zone;
};
exports.isAngularZonePresent = isAngularZonePresent;
// Underscore Addons
const isObject = (x) => {
// eslint-disable-next-line posthog-js/no-direct-object-check
return x === Object(x) && !(0, exports.isArray)(x);
};
exports.isObject = isObject;
const isEmptyObject = (x) => {
if ((0, exports.isObject)(x)) {
for (const key in x) {
if (exports.hasOwnProperty.call(x, key)) {
return false;
}
}
return true;
}
return false;
};
exports.isEmptyObject = isEmptyObject;
const isUndefined = (x) => x === void 0;
exports.isUndefined = isUndefined;
const isString = (x) => {
// eslint-disable-next-line posthog-js/no-direct-string-check
return toString.call(x) == "[object String]";
};
exports.isString = isString;
const isEmptyString = (x) => (0, exports.isString)(x) && x.trim().length === 0;
exports.isEmptyString = isEmptyString;
const isNull = (x) => {
// eslint-disable-next-line posthog-js/no-direct-null-check
return x === null;
};
exports.isNull = isNull;
/*
sometimes you want to check if something is null or undefined
that's what this is for
*/
const isNullish = (x) => (0, exports.isUndefined)(x) || (0, exports.isNull)(x);
exports.isNullish = isNullish;
const isNumber = (x) => {
// eslint-disable-next-line posthog-js/no-direct-number-check
return toString.call(x) == "[object Number]";
};
exports.isNumber = isNumber;
const isBoolean = (x) => {
// eslint-disable-next-line posthog-js/no-direct-boolean-check
return toString.call(x) === "[object Boolean]";
};
exports.isBoolean = isBoolean;
const isDocument = (x) => {
// eslint-disable-next-line posthog-js/no-direct-document-check
return x instanceof Document;
};
exports.isDocument = isDocument;
const isFormData = (x) => {
// eslint-disable-next-line posthog-js/no-direct-form-data-check
return x instanceof FormData;
};
exports.isFormData = isFormData;
const isFile = (x) => {
// eslint-disable-next-line posthog-js/no-direct-file-check
return x instanceof File;
};
exports.isFile = isFile;
const isError = (x) => {
return x instanceof Error;
};
exports.isError = isError;