@leanbase-giangnd/js 0.0.7 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2791 -265
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5439 -172
- package/dist/index.mjs +2792 -266
- package/dist/index.mjs.map +1 -1
- package/dist/leanbase.iife.js +3427 -276
- package/dist/leanbase.iife.js.map +1 -1
- package/package.json +6 -5
- package/src/extensions/replay/extension-shim.ts +35 -0
- package/src/extensions/replay/external/config.ts +33 -25
- package/src/extensions/replay/external/lazy-loaded-session-recorder.ts +78 -71
- package/src/extensions/replay/external/mutation-throttler.ts +4 -1
- package/src/extensions/replay/external/network-plugin.ts +10 -3
- package/src/extensions/replay/external/triggerMatching.ts +13 -13
- package/src/extensions/replay/rrweb-plugins/patch.ts +0 -7
- package/src/extensions/replay/session-recording.ts +29 -58
- package/src/leanbase.ts +35 -48
- package/src/types/fflate.d.ts +5 -0
- package/src/types/rrweb-record.d.ts +8 -0
- package/src/types.ts +130 -117
- package/src/utils/logger.ts +13 -51
- package/src/version.ts +1 -1
- package/src/extensions/replay/external/README.md +0 -5
- package/src/extensions/utils/stylesheet-loader.ts +0 -27
- package/src/posthog-core.ts +0 -12
- package/src/utils/globals.ts +0 -239
- package/src/utils/request-router.ts +0 -77
- package/src/utils/type-utils.ts +0 -139
package/src/utils/globals.ts
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import type { PostHog } from '../posthog-core'
|
|
2
|
-
import { SessionIdManager } from '../sessionid'
|
|
3
|
-
import {
|
|
4
|
-
DeadClicksAutoCaptureConfig,
|
|
5
|
-
ExternalIntegrationKind,
|
|
6
|
-
Properties,
|
|
7
|
-
RemoteConfig,
|
|
8
|
-
SiteAppLoader,
|
|
9
|
-
SessionStartReason,
|
|
10
|
-
} from '../types'
|
|
11
|
-
// only importing types here, so won't affect the bundle
|
|
12
|
-
// eslint-disable-next-line posthog-js/no-external-replay-imports
|
|
13
|
-
import type { SessionRecordingStatus, TriggerType } from '../extensions/replay/external/triggerMatching'
|
|
14
|
-
import { eventWithTime } from '../extensions/replay/types/rrweb-types'
|
|
15
|
-
import { ErrorTracking } from '@posthog/core'
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
* Global helpers to protect access to browser globals in a way that is safer for different targets
|
|
19
|
-
* like DOM, SSR, Web workers etc.
|
|
20
|
-
*
|
|
21
|
-
* NOTE: Typically we want the "window" but globalThis works for both the typical browser context as
|
|
22
|
-
* well as other contexts such as the web worker context. Window is still exported for any bits that explicitly require it.
|
|
23
|
-
* If in doubt - export the global you need from this file and use that as an optional value. This way the code path is forced
|
|
24
|
-
* to handle the case where the global is not available.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
// eslint-disable-next-line no-restricted-globals
|
|
28
|
-
const win: (Window & typeof globalThis) | undefined = typeof window !== 'undefined' ? window : undefined
|
|
29
|
-
|
|
30
|
-
export type AssignableWindow = Window &
|
|
31
|
-
typeof globalThis & {
|
|
32
|
-
/*
|
|
33
|
-
* Main PostHog instance
|
|
34
|
-
*/
|
|
35
|
-
posthog: any
|
|
36
|
-
|
|
37
|
-
/*
|
|
38
|
-
* This is our contract between (potentially) lazily loaded extensions and the SDK
|
|
39
|
-
*/
|
|
40
|
-
__PosthogExtensions__?: PostHogExtensions
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* When loading remote config, we assign it to this global configuration
|
|
44
|
-
* for ease of sharing it with the rest of the SDK
|
|
45
|
-
*/
|
|
46
|
-
_POSTHOG_REMOTE_CONFIG?: Record<
|
|
47
|
-
string,
|
|
48
|
-
{
|
|
49
|
-
config: RemoteConfig
|
|
50
|
-
siteApps: SiteAppLoader[]
|
|
51
|
-
}
|
|
52
|
-
>
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* If this is set on the window, our logger will log to the console
|
|
56
|
-
* for ease of debugging. Used for testing purposes only.
|
|
57
|
-
*
|
|
58
|
-
* @see {Config.DEBUG} from config.ts
|
|
59
|
-
*/
|
|
60
|
-
POSTHOG_DEBUG: any
|
|
61
|
-
|
|
62
|
-
// Exposed by the browser
|
|
63
|
-
doNotTrack: any
|
|
64
|
-
|
|
65
|
-
// See entrypoints/customizations.full.ts
|
|
66
|
-
posthogCustomizations: any
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* This is a legacy way to expose these functions, but we still need to support it for backwards compatibility
|
|
70
|
-
* Can be removed once we drop support for 1.161.1
|
|
71
|
-
*
|
|
72
|
-
* See entrypoints/exception-autocapture.ts
|
|
73
|
-
*
|
|
74
|
-
* @deprecated use `__PosthogExtensions__.errorWrappingFunctions` instead
|
|
75
|
-
*/
|
|
76
|
-
posthogErrorWrappingFunctions: any
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* This is a legacy way to expose these functions, but we still need to support it for backwards compatibility
|
|
80
|
-
* Can be removed once we drop support for 1.161.1
|
|
81
|
-
*
|
|
82
|
-
* See entrypoints/posthog-recorder.ts
|
|
83
|
-
*
|
|
84
|
-
* @deprecated use `__PosthogExtensions__.rrweb` instead
|
|
85
|
-
*/
|
|
86
|
-
rrweb: any
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* This is a legacy way to expose these functions, but we still need to support it for backwards compatibility
|
|
90
|
-
* Can be removed once we drop support for 1.161.1
|
|
91
|
-
*
|
|
92
|
-
* See entrypoints/posthog-recorder.ts
|
|
93
|
-
*
|
|
94
|
-
* @deprecated use `__PosthogExtensions__.rrwebConsoleRecord` instead
|
|
95
|
-
*/
|
|
96
|
-
rrwebConsoleRecord: any
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* This is a legacy way to expose these functions, but we still need to support it for backwards compatibility
|
|
100
|
-
* Can be removed once we drop support for 1.161.1
|
|
101
|
-
*
|
|
102
|
-
* See entrypoints/posthog-recorder.ts
|
|
103
|
-
*
|
|
104
|
-
* @deprecated use `__PosthogExtensions__.getRecordNetworkPlugin` instead
|
|
105
|
-
*/
|
|
106
|
-
getRecordNetworkPlugin: any
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* This is a legacy way to expose these functions, but we still need to support it for backwards compatibility
|
|
110
|
-
* Can be removed once we drop support for 1.161.1
|
|
111
|
-
*
|
|
112
|
-
* See entrypoints/web-vitals.ts
|
|
113
|
-
*
|
|
114
|
-
* @deprecated use `__PosthogExtensions__.postHogWebVitalsCallbacks` instead
|
|
115
|
-
*/
|
|
116
|
-
postHogWebVitalsCallbacks: any
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* This is a legacy way to expose these functions, but we still need to support it for backwards compatibility
|
|
120
|
-
* Can be removed once we drop support for 1.161.1
|
|
121
|
-
*
|
|
122
|
-
* See entrypoints/tracing-headers.ts
|
|
123
|
-
*
|
|
124
|
-
* @deprecated use `__PosthogExtensions__.postHogTracingHeadersPatchFns` instead
|
|
125
|
-
*/
|
|
126
|
-
postHogTracingHeadersPatchFns: any
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* This is a legacy way to expose these functions, but we still need to support it for backwards compatibility
|
|
130
|
-
* Can be removed once we drop support for 1.161.1
|
|
131
|
-
*
|
|
132
|
-
* See entrypoints/surveys.ts
|
|
133
|
-
*
|
|
134
|
-
* @deprecated use `__PosthogExtensions__.generateSurveys` instead
|
|
135
|
-
*/
|
|
136
|
-
extendPostHogWithSurveys: any
|
|
137
|
-
|
|
138
|
-
/*
|
|
139
|
-
* These are used to handle our toolbar state.
|
|
140
|
-
* @see {Toolbar} from extensions/toolbar.ts
|
|
141
|
-
*/
|
|
142
|
-
ph_load_toolbar: any
|
|
143
|
-
ph_load_editor: any
|
|
144
|
-
ph_toolbar_state: any
|
|
145
|
-
} & Record<`__$$ph_site_app_${string}`, any>
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* This is our contract between (potentially) lazily loaded extensions and the SDK
|
|
149
|
-
* changes to this interface can be breaking changes for users of the SDK
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
export type ExternalExtensionKind = 'intercom-integration' | 'crisp-chat-integration'
|
|
153
|
-
|
|
154
|
-
export type PostHogExtensionKind =
|
|
155
|
-
| 'toolbar'
|
|
156
|
-
| 'exception-autocapture'
|
|
157
|
-
| 'web-vitals'
|
|
158
|
-
| 'recorder'
|
|
159
|
-
| 'lazy-recorder'
|
|
160
|
-
| 'tracing-headers'
|
|
161
|
-
| 'surveys'
|
|
162
|
-
| 'dead-clicks-autocapture'
|
|
163
|
-
| 'remote-config'
|
|
164
|
-
| ExternalExtensionKind
|
|
165
|
-
|
|
166
|
-
export interface LazyLoadedSessionRecordingInterface {
|
|
167
|
-
start: (startReason?: SessionStartReason) => void
|
|
168
|
-
stop: () => void
|
|
169
|
-
sessionId: string
|
|
170
|
-
status: SessionRecordingStatus
|
|
171
|
-
onRRwebEmit: (rawEvent: eventWithTime) => void
|
|
172
|
-
log: (message: string, level: 'log' | 'warn' | 'error') => void
|
|
173
|
-
sdkDebugProperties: Properties
|
|
174
|
-
overrideLinkedFlag: () => void
|
|
175
|
-
overrideSampling: () => void
|
|
176
|
-
overrideTrigger: (triggerType: TriggerType) => void
|
|
177
|
-
isStarted: boolean
|
|
178
|
-
tryAddCustomEvent(tag: string, payload: any): boolean
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export interface LazyLoadedDeadClicksAutocaptureInterface {
|
|
182
|
-
start: (observerTarget: Node) => void
|
|
183
|
-
stop: () => void
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
interface PostHogExtensions {
|
|
187
|
-
loadExternalDependency?: (
|
|
188
|
-
posthog: PostHog,
|
|
189
|
-
kind: PostHogExtensionKind,
|
|
190
|
-
callback: (error?: string | Event, event?: Event) => void
|
|
191
|
-
) => void
|
|
192
|
-
|
|
193
|
-
loadSiteApp?: (posthog: PostHog, appUrl: string, callback: (error?: string | Event, event?: Event) => void) => void
|
|
194
|
-
|
|
195
|
-
errorWrappingFunctions?: {
|
|
196
|
-
wrapOnError: (captureFn: (props: ErrorTracking.ErrorProperties) => void) => () => void
|
|
197
|
-
wrapUnhandledRejection: (captureFn: (props: ErrorTracking.ErrorProperties) => void) => () => void
|
|
198
|
-
wrapConsoleError: (captureFn: (props: ErrorTracking.ErrorProperties) => void) => () => void
|
|
199
|
-
}
|
|
200
|
-
rrweb?: { record: any; version: string }
|
|
201
|
-
rrwebPlugins?: { getRecordConsolePlugin: any; getRecordNetworkPlugin?: any }
|
|
202
|
-
generateSurveys?: (posthog: PostHog, isSurveysEnabled: boolean) => any | undefined
|
|
203
|
-
postHogWebVitalsCallbacks?: {
|
|
204
|
-
onLCP: (metric: any) => void
|
|
205
|
-
onCLS: (metric: any) => void
|
|
206
|
-
onFCP: (metric: any) => void
|
|
207
|
-
onINP: (metric: any) => void
|
|
208
|
-
}
|
|
209
|
-
tracingHeadersPatchFns?: {
|
|
210
|
-
_patchFetch: (hostnames: string[], distinctId: string, sessionManager?: SessionIdManager) => () => void
|
|
211
|
-
_patchXHR: (hostnames: string[], distinctId: string, sessionManager?: SessionIdManager) => () => void
|
|
212
|
-
}
|
|
213
|
-
initDeadClicksAutocapture?: (
|
|
214
|
-
ph: PostHog,
|
|
215
|
-
config: DeadClicksAutoCaptureConfig
|
|
216
|
-
) => LazyLoadedDeadClicksAutocaptureInterface
|
|
217
|
-
integrations?: {
|
|
218
|
-
[K in ExternalIntegrationKind]?: { start: (posthog: PostHog) => void; stop: () => void }
|
|
219
|
-
}
|
|
220
|
-
initSessionRecording?: (ph: PostHog) => LazyLoadedSessionRecordingInterface
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const global: typeof globalThis | undefined = typeof globalThis !== 'undefined' ? globalThis : win
|
|
224
|
-
|
|
225
|
-
export const ArrayProto = Array.prototype
|
|
226
|
-
export const nativeForEach = ArrayProto.forEach
|
|
227
|
-
export const nativeIndexOf = ArrayProto.indexOf
|
|
228
|
-
|
|
229
|
-
export const navigator = global?.navigator
|
|
230
|
-
export const document = global?.document
|
|
231
|
-
export const location = global?.location
|
|
232
|
-
export const fetch = global?.fetch
|
|
233
|
-
export const XMLHttpRequest =
|
|
234
|
-
global?.XMLHttpRequest && 'withCredentials' in new global.XMLHttpRequest() ? global.XMLHttpRequest : undefined
|
|
235
|
-
export const AbortController = global?.AbortController
|
|
236
|
-
export const userAgent = navigator?.userAgent
|
|
237
|
-
export const assignableWindow: AssignableWindow = win ?? ({} as any)
|
|
238
|
-
|
|
239
|
-
export { win as window }
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { PostHog } from '../posthog-core'
|
|
2
|
-
|
|
3
|
-
export enum RequestRouterRegion {
|
|
4
|
-
US = 'us',
|
|
5
|
-
EU = 'eu',
|
|
6
|
-
CUSTOM = 'custom',
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type RequestRouterTarget = 'api' | 'ui' | 'assets'
|
|
10
|
-
|
|
11
|
-
const ingestionDomain = 'i.posthog.com'
|
|
12
|
-
|
|
13
|
-
export class RequestRouter {
|
|
14
|
-
instance: PostHog
|
|
15
|
-
private _regionCache: Record<string, RequestRouterRegion> = {}
|
|
16
|
-
|
|
17
|
-
constructor(instance: PostHog) {
|
|
18
|
-
this.instance = instance
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get apiHost(): string {
|
|
22
|
-
const host = this.instance.config.api_host.trim().replace(/\/$/, '')
|
|
23
|
-
if (host === 'https://app.posthog.com') {
|
|
24
|
-
return 'https://us.i.posthog.com'
|
|
25
|
-
}
|
|
26
|
-
return host
|
|
27
|
-
}
|
|
28
|
-
get uiHost(): string | undefined {
|
|
29
|
-
let host = this.instance.config.ui_host?.replace(/\/$/, '')
|
|
30
|
-
|
|
31
|
-
if (!host) {
|
|
32
|
-
host = this.apiHost.replace(`.${ingestionDomain}`, '.posthog.com')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (host === 'https://app.posthog.com') {
|
|
36
|
-
return 'https://us.posthog.com'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return host
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get region(): RequestRouterRegion {
|
|
43
|
-
if (!this._regionCache[this.apiHost]) {
|
|
44
|
-
if (/https:\/\/(app|us|us-assets)(\\.i)?\\.posthog\\.com/i.test(this.apiHost)) {
|
|
45
|
-
this._regionCache[this.apiHost] = RequestRouterRegion.US
|
|
46
|
-
} else if (/https:\/\/(eu|eu-assets)(\\.i)?\\.posthog\\.com/i.test(this.apiHost)) {
|
|
47
|
-
this._regionCache[this.apiHost] = RequestRouterRegion.EU
|
|
48
|
-
} else {
|
|
49
|
-
this._regionCache[this.apiHost] = RequestRouterRegion.CUSTOM
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return this._regionCache[this.apiHost]
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
endpointFor(target: RequestRouterTarget, path: string = ''): string {
|
|
56
|
-
if (path) {
|
|
57
|
-
path = path[0] === '/' ? path : `/${path}`
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (target === 'ui') {
|
|
61
|
-
return this.uiHost + path
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (this.region === RequestRouterRegion.CUSTOM) {
|
|
65
|
-
return this.apiHost + path
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const suffix = ingestionDomain + path
|
|
69
|
-
|
|
70
|
-
switch (target) {
|
|
71
|
-
case 'assets':
|
|
72
|
-
return `https://${this.region}-assets.${suffix}`
|
|
73
|
-
case 'api':
|
|
74
|
-
return `https://${this.region}.${suffix}`
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/utils/type-utils.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { knownUnsafeEditableEvent, KnownUnsafeEditableEvent } from '@posthog/core'
|
|
2
|
-
import { includes } from '@posthog/core'
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line posthog-js/no-direct-array-check
|
|
5
|
-
const nativeIsArray = Array.isArray
|
|
6
|
-
const ObjProto = Object.prototype
|
|
7
|
-
export const hasOwnProperty = ObjProto.hasOwnProperty
|
|
8
|
-
const toString = ObjProto.toString
|
|
9
|
-
|
|
10
|
-
export const isArray =
|
|
11
|
-
nativeIsArray ||
|
|
12
|
-
function (obj: any): obj is any[] {
|
|
13
|
-
return toString.call(obj) === '[object Array]'
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// from a comment on http://dbj.org/dbj/?p=286
|
|
17
|
-
// fails on only one very rare and deliberate custom object:
|
|
18
|
-
// let bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
|
|
19
|
-
export const isFunction = (x: unknown): x is (...args: any[]) => any => {
|
|
20
|
-
// eslint-disable-next-line posthog-js/no-direct-function-check
|
|
21
|
-
return typeof x === 'function'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const isNativeFunction = (x: unknown): x is (...args: any[]) => any =>
|
|
25
|
-
isFunction(x) && x.toString().indexOf('[native code]') !== -1
|
|
26
|
-
|
|
27
|
-
// Underscore Addons
|
|
28
|
-
export const isObject = (x: unknown): x is Record<string, any> => {
|
|
29
|
-
// eslint-disable-next-line posthog-js/no-direct-object-check
|
|
30
|
-
return x === Object(x) && !isArray(x)
|
|
31
|
-
}
|
|
32
|
-
export const isEmptyObject = (x: unknown) => {
|
|
33
|
-
if (isObject(x)) {
|
|
34
|
-
for (const key in x) {
|
|
35
|
-
if (hasOwnProperty.call(x, key)) {
|
|
36
|
-
return false
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return true
|
|
40
|
-
}
|
|
41
|
-
return false
|
|
42
|
-
}
|
|
43
|
-
export const isUndefined = (x: unknown): x is undefined => x === void 0
|
|
44
|
-
|
|
45
|
-
export const isString = (x: unknown): x is string => {
|
|
46
|
-
// eslint-disable-next-line posthog-js/no-direct-string-check
|
|
47
|
-
return toString.call(x) == '[object String]'
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const isEmptyString = (x: unknown): boolean => isString(x) && x.trim().length === 0
|
|
51
|
-
|
|
52
|
-
export const isNull = (x: unknown): x is null => {
|
|
53
|
-
// eslint-disable-next-line posthog-js/no-direct-null-check
|
|
54
|
-
return x === null
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/*
|
|
58
|
-
sometimes you want to check if something is null or undefined
|
|
59
|
-
that's what this is for
|
|
60
|
-
*/
|
|
61
|
-
export const isNullish = (x: unknown): x is null | undefined => isUndefined(x) || isNull(x)
|
|
62
|
-
|
|
63
|
-
export const isNumber = (x: unknown): x is number => {
|
|
64
|
-
// eslint-disable-next-line posthog-js/no-direct-number-check
|
|
65
|
-
return toString.call(x) == '[object Number]'
|
|
66
|
-
}
|
|
67
|
-
export const isBoolean = (x: unknown): x is boolean => {
|
|
68
|
-
// eslint-disable-next-line posthog-js/no-direct-boolean-check
|
|
69
|
-
return toString.call(x) === '[object Boolean]'
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const isFormData = (x: unknown): x is FormData => {
|
|
73
|
-
// eslint-disable-next-line posthog-js/no-direct-form-data-check
|
|
74
|
-
return x instanceof FormData
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const isFile = (x: unknown): x is File => {
|
|
78
|
-
// eslint-disable-next-line posthog-js/no-direct-file-check
|
|
79
|
-
return x instanceof File
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const isPlainError = (x: unknown): x is Error => {
|
|
83
|
-
return x instanceof Error
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export const isKnownUnsafeEditableEvent = (x: unknown): x is KnownUnsafeEditableEvent => {
|
|
87
|
-
return includes(knownUnsafeEditableEvent as unknown as string[], x)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function isInstanceOf(candidate: unknown, base: any): boolean {
|
|
91
|
-
try {
|
|
92
|
-
return candidate instanceof base
|
|
93
|
-
} catch {
|
|
94
|
-
return false
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function isPrimitive(value: unknown): boolean {
|
|
99
|
-
return isNull(value) || typeof value !== 'object'
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function isBuiltin(candidate: unknown, className: string): boolean {
|
|
103
|
-
return Object.prototype.toString.call(candidate) === `[object ${className}]`
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function isError(candidate: unknown): candidate is Error {
|
|
107
|
-
switch (Object.prototype.toString.call(candidate)) {
|
|
108
|
-
case '[object Error]':
|
|
109
|
-
case '[object Exception]':
|
|
110
|
-
case '[object DOMException]':
|
|
111
|
-
case '[object DOMError]':
|
|
112
|
-
case '[object WebAssembly.Exception]':
|
|
113
|
-
return true
|
|
114
|
-
default:
|
|
115
|
-
return isInstanceOf(candidate, Error)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function isErrorEvent(event: unknown): boolean {
|
|
120
|
-
return isBuiltin(event, 'ErrorEvent')
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function isEvent(candidate: unknown): candidate is Event {
|
|
124
|
-
return !isUndefined(Event) && isInstanceOf(candidate, Event)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export const isDocument = (x: unknown): x is Document => {
|
|
128
|
-
// eslint-disable-next-line posthog-js/no-direct-document-check
|
|
129
|
-
return typeof Document !== 'undefined' && isInstanceOf(x, Document)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function isPlainObject(candidate: unknown): candidate is Record<string, unknown> {
|
|
133
|
-
return isBuiltin(candidate, 'Object')
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export const yesLikeValues = [true, 'true', 1, '1', 'yes']
|
|
137
|
-
export const isYesLike = (val: string | boolean | number): boolean => includes(yesLikeValues, val)
|
|
138
|
-
export const noLikeValues = [false, 'false', 0, '0', 'no']
|
|
139
|
-
export const isNoLike = (val: string | boolean | number): boolean => includes(noLikeValues, val)
|