UNPKG

@perceptr/web-sdk

Version:

Perceptr Web SDK for recording and monitoring user sessions

76 lines (75 loc) 2.72 kB
// eslint-disable-next-line posthog-js/no-direct-array-check const nativeIsArray = Array.isArray; const ObjProto = Object.prototype; export const hasOwnProperty = ObjProto.hasOwnProperty; const toString = ObjProto.toString; export const 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!"; }}; export const isFunction = (x) => { // eslint-disable-next-line posthog-js/no-direct-function-check return typeof x === "function"; }; export const isNativeFunction = (x) => isFunction(x) && x.toString().indexOf("[native code]") !== -1; // When angular patches functions they pass the above `isNativeFunction` check (at least the MutationObserver) export const isAngularZonePresent = () => { return !!window.Zone; }; // Underscore Addons export const isObject = (x) => { // eslint-disable-next-line posthog-js/no-direct-object-check return x === Object(x) && !isArray(x); }; export const isEmptyObject = (x) => { if (isObject(x)) { for (const key in x) { if (hasOwnProperty.call(x, key)) { return false; } } return true; } return false; }; export const isUndefined = (x) => x === void 0; export const isString = (x) => { // eslint-disable-next-line posthog-js/no-direct-string-check return toString.call(x) == "[object String]"; }; export const isEmptyString = (x) => isString(x) && x.trim().length === 0; export const isNull = (x) => { // eslint-disable-next-line posthog-js/no-direct-null-check return x === null; }; /* sometimes you want to check if something is null or undefined that's what this is for */ export const isNullish = (x) => isUndefined(x) || isNull(x); export const isNumber = (x) => { // eslint-disable-next-line posthog-js/no-direct-number-check return toString.call(x) == "[object Number]"; }; export const isBoolean = (x) => { // eslint-disable-next-line posthog-js/no-direct-boolean-check return toString.call(x) === "[object Boolean]"; }; export const isDocument = (x) => { // eslint-disable-next-line posthog-js/no-direct-document-check return x instanceof Document; }; export const isFormData = (x) => { // eslint-disable-next-line posthog-js/no-direct-form-data-check return x instanceof FormData; }; export const isFile = (x) => { // eslint-disable-next-line posthog-js/no-direct-file-check return x instanceof File; }; export const isError = (x) => { return x instanceof Error; };