Skip to content

Commit

Permalink
is null too
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Oct 23, 2023
1 parent e3adffd commit a2f2557
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/autocapture-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions src/autocapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
_includes,
_isBoolean,
_isFunction,
_isNull,
_isUndefined,
_register_event,
_safewrap_instance_methods,
Expand Down Expand Up @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/exceptions/type-checking.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 {
Expand Down
12 changes: 8 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ export function _eachArray<E = any>(
* @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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]'
}
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit a2f2557

Please sign in to comment.