From a2f2557679852330058600245f05e3399e42891e Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Mon, 23 Oct 2023 12:10:54 +0100 Subject: [PATCH] is null too --- src/autocapture-utils.ts | 4 ++-- src/autocapture.ts | 8 ++++---- src/extensions/exceptions/type-checking.ts | 4 ++-- src/utils.ts | 12 ++++++++---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/autocapture-utils.ts b/src/autocapture-utils.ts index abcb7c227..c0d3dc97f 100644 --- a/src/autocapture-utils.ts +++ b/src/autocapture-utils.ts @@ -4,7 +4,7 @@ * @returns {string} the element's class */ import { AutocaptureConfig } from 'types' -import { _each, _includes, _isString, _isUndefined, _trim, logger } from './utils' +import { _each, _includes, _isNull, _isString, _isUndefined, _trim, logger } from './utils' export function getClassName(el: Element): string { switch (typeof el.className) { @@ -264,7 +264,7 @@ export function isSensitiveElement(el: Element): boolean { * @returns {boolean} whether the element should be captured */ export function shouldCaptureValue(value: string): boolean { - if (value === null || _isUndefined(value)) { + if (_isNull(value) || _isUndefined(value)) { return false } diff --git a/src/autocapture.ts b/src/autocapture.ts index 935762c8d..a96bff61a 100644 --- a/src/autocapture.ts +++ b/src/autocapture.ts @@ -5,6 +5,7 @@ import { _includes, _isBoolean, _isFunction, + _isNull, _isUndefined, _register_event, _safewrap_instance_methods, @@ -43,10 +44,9 @@ const autocapture = { _isAutocaptureEnabled: false as boolean, _setIsAutocaptureEnabled: function (instance: PostHog): void { - const disabled_server_side = - this._isDisabledServerSide === null - ? !!instance.persistence?.props[AUTOCAPTURE_DISABLED_SERVER_SIDE] - : this._isDisabledServerSide + const disabled_server_side = _isNull(this._isDisabledServerSide) + ? !!instance.persistence?.props[AUTOCAPTURE_DISABLED_SERVER_SIDE] + : this._isDisabledServerSide const enabled_client_side = !!instance.config.autocapture this._isAutocaptureEnabled = enabled_client_side && !disabled_server_side }, diff --git a/src/extensions/exceptions/type-checking.ts b/src/extensions/exceptions/type-checking.ts index 2b01b83e6..e8f6f5abe 100644 --- a/src/extensions/exceptions/type-checking.ts +++ b/src/extensions/exceptions/type-checking.ts @@ -1,4 +1,4 @@ -import { _isFunction, _isObject, _isUndefined } from '../../utils' +import { _isFunction, _isNull, _isObject, _isUndefined } from '../../utils' export function isEvent(candidate: unknown): candidate is Event { return !_isUndefined(Event) && isInstanceOf(candidate, Event) @@ -19,7 +19,7 @@ export function isInstanceOf(candidate: unknown, base: any): boolean { export function isPrimitive( candidate: unknown ): candidate is number | string | boolean | bigint | symbol | null | undefined { - return candidate === null || (!_isObject(candidate) && !_isFunction(candidate)) + return _isNull(candidate) || (!_isObject(candidate) && !_isFunction(candidate)) } export function isError(candidate: unknown): candidate is Error { diff --git a/src/utils.ts b/src/utils.ts index 0cfef8e53..7d765f124 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -97,10 +97,10 @@ export function _eachArray( * @param {Object=} thisArg */ export function _each(obj: any, iterator: (value: any, key: any) => void | Breaker, thisArg?: any): void { - if (obj === null || obj === undefined) { + if (_isNull(obj) || _isUndefined(obj)) { return } - if (Array.isArray(obj)) { + if (_isArray(obj)) { return _eachArray(obj, iterator, thisArg) } for (const key in obj) { @@ -145,7 +145,7 @@ export const _include = function ( target: any ): boolean | Breaker { let found = false - if (obj === null) { + if (_isNull(obj)) { return found } if (nativeIndexOf && obj.indexOf === nativeIndexOf) { @@ -200,6 +200,10 @@ export const _isUndefined = function (obj: any): obj is undefined { return obj === void 0 } +export const _isNull = function (obj: any): obj is null { + return obj === null +} + export const _isString = function (obj: any): obj is string { return toString.call(obj) == '[object String]' } @@ -545,7 +549,7 @@ export const _getQueryParam = function (url: string, param: string): string { const regexS = '[\\?&]' + cleanParam + '=([^&#]*)' const regex = new RegExp(regexS) const results = regex.exec(url) - if (results === null || (results && !_isString(results[1]) && (results[1] as any).length)) { + if (_isNull(results) || (results && !_isString(results[1]) && (results[1] as any).length)) { return '' } else { let result = results[1]