@olmokit/browser
Other
GtmPageviewArgs
Ƭ GtmPageviewArgs: [page_path?: string, page_title?: string, page_location?: string]
Defined in
analytics-google
gtagPageview
▸ gtagPageview(...args): void
Parameters
| Name | Type |
|---|---|
...args | GtmPageviewArgs |
Returns
void
Defined in
date
getZonedDate
▸ getZonedDate(dateString?, timeZone?): Date
It returns a Date object from a date string adjusted on the user timeZone,
if a timeZone is not provided we try getting it from the Intl browwser native
API. It gracefully falls back returning a non-timezone-based Date.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
dateString | string | "" | A parseable date as string, Z is automatically suffixed if not present to correctly get time zone based time from a UTC date. |
timeZone? | string | undefined | Optionally pass a timeZone (e.g. from user preference or from the server), it falls back trying to read it from the Intl browwser native API. |
Returns
Date
Resources
- to get the timeZone client side see this article
- for converting the date based on the time zone date-fns docs and date-fns-tz docs
Defined in
detect
isIE
▸ isIE(ssrValue?): boolean
Parameters
| Name | Type | Default value |
|---|---|---|
ssrValue | boolean | true |
Returns
boolean
See
https://stackoverflow.com/a/21712356/12285349
Defined in
isMobile
▸ isMobile(ssrValue?): boolean
Parameters
| Name | Type | Default value |
|---|---|---|
ssrValue | boolean | true |
Returns
boolean
See
https://stackoverflow.com/a/3540295
Defined in
events
listenUrlSearch
▸ listenUrlSearch(handler): () => void
Here we extend and mutate the native window.history object so that multiple
scripts can add url change handlers without interfering each other and using
the same single listener.
Parameters
| Name | Type |
|---|---|
handler | Handler |
Returns
fn
A de-register function to remove the handler
▸ (): void
Returns
void
Borrows
Defined in
listenUrlSearchParams
▸ listenUrlSearchParams(paramName, handler): () => void
Parameters
| Name | Type |
|---|---|
paramName | string |
handler | (paramNewValue: null | string) => void |
Returns
fn
▸ (): void
Returns
void
Defined in
browser/listenUrlSearchParams.ts:8
is
isIE
▸ isIE(ssrValue?): boolean
Parameters
| Name | Type | Default value |
|---|---|---|
ssrValue | boolean | true |
Returns
boolean
See
https://stackoverflow.com/a/21712356/12285349
Defined in
isMobile
▸ isMobile(ssrValue?): boolean
Parameters
| Name | Type | Default value |
|---|---|---|
ssrValue | boolean | true |
Returns
boolean
See
https://stackoverflow.com/a/3540295
Defined in
location
listenUrlSearch
▸ listenUrlSearch(handler): () => void
Here we extend and mutate the native window.history object so that multiple
scripts can add url change handlers without interfering each other and using
the same single listener.
Parameters
| Name | Type |
|---|---|
handler | Handler |
Returns
fn
A de-register function to remove the handler
▸ (): void
Returns
void
Borrows
Defined in
navigateToHash
▸ navigateToHash(hash?): void
It updates the browser's location hash by replacing the history state.
The non-silent standard way would simply be location.hash = "#new-hash"
Parameters
| Name | Type | Default value |
|---|---|---|
hash | string | "" |
Returns
void
Defined in
navigateToHashParams
▸ navigateToHashParams(params?, hash?): string
It updates the location.hash with the given query params, it uses location.hash
if a second argument hash is not provded
Parameters
| Name | Type | Default value |
|---|---|---|
params | string | AnyQueryParams | {} |
hash | string | "" |
Returns
string
Defined in
browser/navigateToHashParams.ts:13
navigateToMergedHashParams
▸ navigateToMergedHashParams(params?, hash?): string
It updates the "query params" within the location.hash, it uses location
Parameters
| Name | Type | Default value |
|---|---|---|
params | Record<string | number, unknown> | {} |
hash | string | "" |
Returns
string
Defined in
browser/navigateToMergedHashParams.ts:13
navigateToMergedParams
▸ navigateToMergedParams(params?, replace?): string
Merge current URL query parameters with the given ones, it uses history.
Parameters
| Name | Type | Description |
|---|---|---|
params | Record<string | number, unknown> | - |
replace? | boolean | Replace URL instead of pushing it in the history stack. By default it pushes it. |
Returns
string
Defined in
browser/navigateToMergedParams.ts:14
navigateToParams
▸ navigateToParams(params?, replace?): string
Change current URL query parameters, it uses history.
Parameters
| Name | Type | Description |
|---|---|---|
params | string | AnyQueryParams | - |
replace? | boolean | Replace URL instead of pushing it in the history stack. By default it pushes it. |
Returns
string
The query string with initial ?
Defined in
browser/navigateToParams.ts:15
navigateToUrl
▸ navigateToUrl(url?, replace?): void
It updates the browser's location URL with global history object
Parameters
| Name | Type | Default value |
|---|---|---|
url | string | "" |
replace? | boolean | undefined |
Returns
void
Defined in
navigateWithoutUrlParam
▸ navigateWithoutUrlParam(paramName?, replace?): string
Remove URL query parameter, it uses history
Parameters
| Name | Type | Description |
|---|---|---|
paramName? | string | - |
replace? | boolean | Replace URL instead of pushing it in the history stack. By default it pushes it. |
Returns
string
Defined in
browser/navigateWithoutUrlParam.ts:10
redirectTo
▸ redirectTo(url, params?): void
Redirect to url with params {optionally}, removes eventual trailing question
marks from the given URL, it uses location
Parameters
| Name | Type |
|---|---|
url | string |
params? | AnyQueryParams |
Returns
void
Defined in
navigation
listenUrlSearch
▸ listenUrlSearch(handler): () => void
Here we extend and mutate the native window.history object so that multiple
scripts can add url change handlers without interfering each other and using
the same single listener.
Parameters
| Name | Type |
|---|---|
handler | Handler |
Returns
fn
A de-register function to remove the handler
▸ (): void
Returns
void
Borrows
Defined in
listenUrlSearchParams
▸ listenUrlSearchParams(paramName, handler): () => void
Parameters
| Name | Type |
|---|---|
paramName | string |
handler | (paramNewValue: null | string) => void |
Returns
fn
▸ (): void
Returns
void
Defined in
browser/listenUrlSearchParams.ts:8
storage
CreateStorageConfig
Ƭ CreateStorageConfig: Record<string, any>
Defined in
StorageClientConfig
Ƭ StorageClientConfig: Record<string, any>
Defined in
storage
• Const storage: Object
Storage, for localStorage and sessionStorage
Type declaration
| Name | Type |
|---|---|
l | { get: <TKey, TValue>(key: TKey, transform?: (value: string) => TValue, defaultValue?: null | TValue) => null | NonNullable<TValue> ; has: <TKey, TValue>(key: TKey, defaultValue?: TValue) => boolean | NonNullable<TValue> ; remove: <TKey>(key: TKey) => void ; set: <TKey, TValue>(key: TKey, value?: TValue, transform: (value: any) => string) => void } |
l.get | <TKey, TValue>(key: TKey, transform?: (value: string) => TValue, defaultValue?: null | TValue) => null | NonNullable<TValue> |
l.has | <TKey, TValue>(key: TKey, defaultValue?: TValue) => boolean | NonNullable<TValue> |
l.remove | <TKey>(key: TKey) => void |
l.set | <TKey, TValue>(key: TKey, value?: TValue, transform: (value: any) => string) => void |
s | { get: <TKey, TValue>(key: TKey, transform?: (value: string) => TValue, defaultValue?: null | TValue) => null | NonNullable<TValue> ; has: <TKey, TValue>(key: TKey, defaultValue?: TValue) => boolean | NonNullable<TValue> ; remove: <TKey>(key: TKey) => void ; set: <TKey, TValue>(key: TKey, value?: TValue, transform: (value: any) => string) => void } |
s.get | <TKey, TValue>(key: TKey, transform?: (value: string) => TValue, defaultValue?: null | TValue) => null | NonNullable<TValue> |
s.has | <TKey, TValue>(key: TKey, defaultValue?: TValue) => boolean | NonNullable<TValue> |
s.remove | <TKey>(key: TKey) => void |
s.set | <TKey, TValue>(key: TKey, value?: TValue, transform: (value: any) => string) => void |
Defined in
createStorage
▸ createStorage<T>(config, useSessionStorage?): Object
Utility to create a storage instance to interact with localStorage using
encrypted (encoded) key/values.
Type parameters
| Name | Type |
|---|---|
T | extends CreateStorageConfig |
Parameters
| Name | Type |
|---|---|
config | Partial<T> |
useSessionStorage? | boolean |
Returns
Object
| Name | Type |
|---|---|
watch | <TKey>(keyToWatch: TKey, onRemoved?: () => void, onAdded?: () => void) => () => undefined | void |
clear | () => void |
get | <TKey>(key: TKey, defaultValue?: null | T[TKey]) => null | T[TKey] |
getAll | (defaultValues?: Partial<T>) => T |
has | <TKey>(key: TKey) => any |
remove | <TKey>(key: TKey) => void |
set | <TKey>(key: TKey, value?: T[TKey]) => void |
setMany | (newValues: Partial<T>) => void |
Defined in
storageClient
▸ storageClient<TConfig>(useSessionStorage?): Object
Super minifiable local/session Storage client creator with SSR safety
Type parameters
| Name | Type |
|---|---|
TConfig | extends StorageClientConfig = StorageClientConfig |
Parameters
| Name | Type |
|---|---|
useSessionStorage? | boolean |
Returns
Object
| Name | Type |
|---|---|
get | <TKey, TValue>(key: TKey, transform?: (value: string) => TValue, defaultValue?: null | TValue) => null | NonNullable<TValue> |
has | <TKey, TValue>(key: TKey, defaultValue?: TValue) => boolean | NonNullable<TValue> |
remove | <TKey>(key: TKey) => void |
set | <TKey, TValue>(key: TKey, value?: TValue, transform: (value: any) => string) => void |