Skip to main content

@olmokit/browser

Other​

GtmPageviewArgs​

Ƭ GtmPageviewArgs: [page_path?: string, page_title?: string, page_location?: string]

Defined in​

browser/gtagPageview.ts:3

analytics-google​

gtagPageview​

▸ gtagPageview(...args): void

Parameters​

NameType
...argsGtmPageviewArgs

Returns​

void

Defined in​

browser/gtagPageview.ts:13

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​

NameTypeDefault valueDescription
dateStringstring""A parseable date as string, Z is automatically suffixed if not present to correctly get time zone based time from a UTC date.
timeZone?stringundefinedOptionally 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

Defined in​

browser/getZonedDate.ts:18

detect​

isIE​

▸ isIE(ssrValue?): boolean

Parameters​

NameTypeDefault value
ssrValuebooleantrue

Returns​

boolean

See

https://stackoverflow.com/a/21712356/12285349

Defined in​

browser/isIE.ts:8


isMobile​

▸ isMobile(ssrValue?): boolean

Parameters​

NameTypeDefault value
ssrValuebooleantrue

Returns​

boolean

See

https://stackoverflow.com/a/3540295

Defined in​

browser/isMobile.ts:8

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​

NameType
handlerHandler

Returns​

fn

A de-register function to remove the handler

▸ (): void

Returns​

void

Borrows

SO answer

Defined in​

browser/listenUrlSearch.ts:67


listenUrlSearchParams​

▸ listenUrlSearchParams(paramName, handler): () => void

Parameters​

NameType
paramNamestring
handler(paramNewValue: null | string) => void

Returns​

fn

▸ (): void

Returns​

void

Defined in​

browser/listenUrlSearchParams.ts:8

is​

isIE​

▸ isIE(ssrValue?): boolean

Parameters​

NameTypeDefault value
ssrValuebooleantrue

Returns​

boolean

See

https://stackoverflow.com/a/21712356/12285349

Defined in​

browser/isIE.ts:8


isMobile​

▸ isMobile(ssrValue?): boolean

Parameters​

NameTypeDefault value
ssrValuebooleantrue

Returns​

boolean

See

https://stackoverflow.com/a/3540295

Defined in​

browser/isMobile.ts:8

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​

NameType
handlerHandler

Returns​

fn

A de-register function to remove the handler

▸ (): void

Returns​

void

Borrows

SO answer

Defined in​

browser/listenUrlSearch.ts:67


▸ 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​

NameTypeDefault value
hashstring""

Returns​

void

Defined in​

browser/navigateToHash.ts:9


▸ 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​

NameTypeDefault value
paramsstring | AnyQueryParams{}
hashstring""

Returns​

string

Defined in​

browser/navigateToHashParams.ts:13


▸ navigateToMergedHashParams(params?, hash?): string

It updates the "query params" within the location.hash, it uses location

Parameters​

NameTypeDefault value
paramsRecord<string | number, unknown>{}
hashstring""

Returns​

string

Defined in​

browser/navigateToMergedHashParams.ts:13


▸ navigateToMergedParams(params?, replace?): string

Merge current URL query parameters with the given ones, it uses history.

Parameters​

NameTypeDescription
paramsRecord<string | number, unknown>-
replace?booleanReplace URL instead of pushing it in the history stack. By default it pushes it.

Returns​

string

Defined in​

browser/navigateToMergedParams.ts:14


▸ navigateToParams(params?, replace?): string

Change current URL query parameters, it uses history.

Parameters​

NameTypeDescription
paramsstring | AnyQueryParams-
replace?booleanReplace 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(url?, replace?): void

It updates the browser's location URL with global history object

Parameters​

NameTypeDefault value
urlstring""
replace?booleanundefined

Returns​

void

Defined in​

browser/navigateToUrl.ts:6


▸ navigateWithoutUrlParam(paramName?, replace?): string

Remove URL query parameter, it uses history

Parameters​

NameTypeDescription
paramName?string-
replace?booleanReplace 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​

NameType
urlstring
params?AnyQueryParams

Returns​

void

Defined in​

browser/redirectTo.ts:13

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​

NameType
handlerHandler

Returns​

fn

A de-register function to remove the handler

▸ (): void

Returns​

void

Borrows

SO answer

Defined in​

browser/listenUrlSearch.ts:67


listenUrlSearchParams​

▸ listenUrlSearchParams(paramName, handler): () => void

Parameters​

NameType
paramNamestring
handler(paramNewValue: null | string) => void

Returns​

fn

▸ (): void

Returns​

void

Defined in​

browser/listenUrlSearchParams.ts:8

storage​

CreateStorageConfig​

Ƭ CreateStorageConfig: Record<string, any>

Defined in​

browser/createStorage.ts:14


StorageClientConfig​

Ƭ StorageClientConfig: Record<string, any>

Defined in​

browser/storageClient.ts:6


storage​

• Const storage: Object

Storage, for localStorage and sessionStorage

Type declaration​

NameType
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​

browser/storage.ts:8


createStorage​

▸ createStorage<T>(config, useSessionStorage?): Object

Utility to create a storage instance to interact with localStorage using encrypted (encoded) key/values.

Type parameters​

NameType
Textends CreateStorageConfig

Parameters​

NameType
configPartial<T>
useSessionStorage?boolean

Returns​

Object

NameType
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​

browser/createStorage.ts:22


storageClient​

▸ storageClient<TConfig>(useSessionStorage?): Object

Super minifiable local/session Storage client creator with SSR safety

Type parameters​

NameType
TConfigextends StorageClientConfig = StorageClientConfig

Parameters​

NameType
useSessionStorage?boolean

Returns​

Object

NameType
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

Defined in​

browser/storageClient.ts:15