@koine/browser 2.0.0-beta.131 → 2.0.0-beta.133
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/createStorage.d.ts +47 -0
- package/getZonedDate.d.ts +14 -0
- package/gtag.d.ts +11 -0
- package/gtagPageview.d.ts +3 -0
- package/isIE.d.ts +5 -0
- package/isMobile.d.ts +5 -0
- package/listenUrlSearch.d.ts +17 -0
- package/listenUrlSearchParams.d.ts +5 -0
- package/navigateToHash.d.ts +6 -0
- package/navigateToHashParams.d.ts +6 -0
- package/navigateToMergedHashParams.d.ts +5 -0
- package/navigateToMergedParams.d.ts +6 -0
- package/navigateToParams.d.ts +7 -0
- package/navigateToUrl.d.ts +5 -0
- package/navigateWithoutUrlParam.d.ts +6 -0
- package/package.json +3 -3
- package/redirectTo.d.ts +6 -0
- package/storage.d.ts +5 -0
- package/storageClient.d.ts +8 -0
package/createStorage.d.ts
CHANGED
|
@@ -1,12 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category storage
|
|
3
|
+
*/
|
|
1
4
|
export type CreateStorageConfig = Record<string, any>;
|
|
5
|
+
/**
|
|
6
|
+
* Utility to create a storage instance to interact with `localStorage` using
|
|
7
|
+
* encrypted (encoded) key/values.
|
|
8
|
+
*
|
|
9
|
+
* @category storage
|
|
10
|
+
*/
|
|
2
11
|
export declare let createStorage: <T extends CreateStorageConfig>(config: Partial<T>, useSessionStorage?: boolean) => {
|
|
12
|
+
/**
|
|
13
|
+
* Get all storage value (it uses `localStorage.get()`).
|
|
14
|
+
*
|
|
15
|
+
* Unparseable values with `JSON.parse()` return their value as it is.
|
|
16
|
+
* On ssr or if the given `key` argument is not found `defaultValue` is
|
|
17
|
+
* returned, otherwise `null`.
|
|
18
|
+
*/
|
|
3
19
|
get<TKey extends Extract<keyof T, string>>(key: TKey, defaultValue?: null | T[TKey]): T[TKey] | null;
|
|
20
|
+
/**
|
|
21
|
+
* Get all storage values (it uses `localStorage.get()`).
|
|
22
|
+
*
|
|
23
|
+
* `undefined` and `null` values are not returned.
|
|
24
|
+
*/
|
|
4
25
|
getAll(defaultValues?: Partial<T>): T;
|
|
26
|
+
/**
|
|
27
|
+
* Set a storage value (it uses `localStorage.set()`).
|
|
28
|
+
*
|
|
29
|
+
* Non-string values are stringified with `JSON.stringify()`
|
|
30
|
+
*/
|
|
5
31
|
set<TKey extends Extract<keyof T, string>>(key: TKey, value?: T[TKey]): void;
|
|
32
|
+
/**
|
|
33
|
+
* Set all given storage values (it uses `localStorage.set()`).
|
|
34
|
+
*
|
|
35
|
+
* Non-string values are stringified with `JSON.stringify()`, `undefined`
|
|
36
|
+
* and `null` values are removed from the storage
|
|
37
|
+
*/
|
|
6
38
|
setMany(newValues: Partial<T>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Check if a storage value is _truthy_ (it uses `localStorage.get()`).
|
|
41
|
+
*/
|
|
7
42
|
has<TKey extends Extract<keyof T, string>>(key: TKey): any;
|
|
43
|
+
/**
|
|
44
|
+
* Remove a storage value (it uses `localStorage.remove()`).
|
|
45
|
+
*/
|
|
8
46
|
remove<TKey extends Extract<keyof T, string>>(key: TKey): void;
|
|
47
|
+
/**
|
|
48
|
+
* Clear all storage values (it uses `localStorage.remove()`).
|
|
49
|
+
*/
|
|
9
50
|
clear(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Watch a storage value changes, this needs to be executed only in browser
|
|
53
|
+
* context (it uses `window.addEventListener("storage")`).
|
|
54
|
+
*
|
|
55
|
+
* Inspiration from [Multi Tab Logout in React — Redux](https://medium.com/front-end-weekly/multi-tab-logout-in-react-redux-4715f071c7fa)
|
|
56
|
+
*/
|
|
10
57
|
watch: <TKey extends keyof T>(keyToWatch: TKey, onRemoved?: () => void, onAdded?: () => void) => () => void | undefined;
|
|
11
58
|
};
|
|
12
59
|
export default createStorage;
|
package/getZonedDate.d.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* It returns a `Date` object from a date `string` adjusted on the user timeZone,
|
|
3
|
+
* if a timeZone is not provided we try getting it from the `Intl` browwser native
|
|
4
|
+
* API. It gracefully falls back returning a _non-timezone-based_ `Date`.
|
|
5
|
+
*
|
|
6
|
+
* @category date
|
|
7
|
+
*
|
|
8
|
+
* @resources
|
|
9
|
+
* - to get the timeZone client side see [this article](https://attacomsian.com/blog/javascript-current-timezone)
|
|
10
|
+
* - for converting the date based on the time zone [date-fns docs](https://date-fns.org/v2.27.0/docs/Time-Zones) and [date-fns-tz docs](https://github.com/marnusw/date-fns-tz)
|
|
11
|
+
*
|
|
12
|
+
* @param dateString A parseable date as string, `Z` is automatically suffixed if not present to correctly get time zone based time from a UTC date.
|
|
13
|
+
* @param timeZone 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.
|
|
14
|
+
*/
|
|
1
15
|
export declare let getZonedDate: (dateString?: string, timeZone?: string) => Date;
|
|
2
16
|
export default getZonedDate;
|
package/gtag.d.ts
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category analytics-google
|
|
3
|
+
*
|
|
4
|
+
* If you like you could add to your globals `.d.ts` types:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* declare interface Window {
|
|
8
|
+
* gtag: <T extends unknown[]>(...args: T) => void;
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
1
12
|
export declare let gtag: <T extends unknown[]>(...args: T) => void;
|
|
2
13
|
export default gtag;
|
package/gtagPageview.d.ts
CHANGED
|
@@ -3,5 +3,8 @@ export type GtmPageviewArgs = [
|
|
|
3
3
|
page_title?: string,
|
|
4
4
|
page_location?: string
|
|
5
5
|
];
|
|
6
|
+
/**
|
|
7
|
+
* @category analytics-google
|
|
8
|
+
*/
|
|
6
9
|
export declare let gtagPageview: (page_path?: string | undefined, page_title?: string | undefined, page_location?: string | undefined) => void;
|
|
7
10
|
export default gtagPageview;
|
package/isIE.d.ts
CHANGED
package/isMobile.d.ts
CHANGED
package/listenUrlSearch.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param prevLocationSearch The previous URL search query e.g. `?myparam=mvalue`
|
|
3
|
+
* @param newLocationSearch The previous URL search query e.g. `?myparam=mvalue`
|
|
4
|
+
*/
|
|
1
5
|
type Handler = (prevLocationSearch: string, newLocationSearch: string) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Here we extend and mutate the native `window.history` object so that multiple
|
|
8
|
+
* scripts can add url change handlers without interfering each other and using
|
|
9
|
+
* the same single listener.
|
|
10
|
+
*
|
|
11
|
+
* @borrows [SO answer](https://stackoverflow.com/a/42727249/1938970)
|
|
12
|
+
*
|
|
13
|
+
* @category location
|
|
14
|
+
* @category navigation
|
|
15
|
+
* @category events
|
|
16
|
+
*
|
|
17
|
+
* @returns A de-register function to remove the handler
|
|
18
|
+
*/
|
|
2
19
|
export declare let listenUrlSearch: (handler: Handler) => () => void;
|
|
3
20
|
export default listenUrlSearch;
|
package/navigateToHash.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* It updates the browser's location hash by replacing the history state.
|
|
3
|
+
* The non-silent standard way would simply be `location.hash = "#new-hash"`
|
|
4
|
+
*
|
|
5
|
+
* @category location
|
|
6
|
+
*/
|
|
1
7
|
export declare let navigateToHash: (hash?: string) => void;
|
|
2
8
|
export default navigateToHash;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { type AnyQueryParams } from "@koine/utils";
|
|
2
|
+
/**
|
|
3
|
+
* It updates the `location.hash` with the given query params, it uses `location.hash`
|
|
4
|
+
* if a second argument `hash` is not provded
|
|
5
|
+
*
|
|
6
|
+
* @category location
|
|
7
|
+
*/
|
|
2
8
|
export declare let navigateToHashParams: (params?: string | AnyQueryParams, hash?: string) => string;
|
|
3
9
|
export default navigateToHashParams;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { type AnyQueryParams } from "@koine/utils";
|
|
2
|
+
/**
|
|
3
|
+
* It updates the "query params" within the `location.hash`, it uses `location`
|
|
4
|
+
*
|
|
5
|
+
* @category location
|
|
6
|
+
*/
|
|
2
7
|
export declare let navigateToMergedHashParams: (params?: NonNullable<AnyQueryParams>, hash?: string) => string;
|
|
3
8
|
export default navigateToMergedHashParams;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { type AnyQueryParams } from "@koine/utils";
|
|
2
|
+
/**
|
|
3
|
+
* Merge current URL query parameters with the given ones, it uses `history`.
|
|
4
|
+
*
|
|
5
|
+
* @category location
|
|
6
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
7
|
+
*/
|
|
2
8
|
export declare let navigateToMergedParams: (params?: NonNullable<AnyQueryParams>, replace?: boolean) => string;
|
|
3
9
|
export default navigateToMergedParams;
|
package/navigateToParams.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { type AnyQueryParams } from "@koine/utils";
|
|
2
|
+
/**
|
|
3
|
+
* Change current URL query parameters, it uses `history`.
|
|
4
|
+
*
|
|
5
|
+
* @category location
|
|
6
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
7
|
+
* @returns The query string with initial `?`
|
|
8
|
+
*/
|
|
2
9
|
export declare let navigateToParams: (params?: string | AnyQueryParams, replace?: boolean) => string;
|
|
3
10
|
export default navigateToParams;
|
package/navigateToUrl.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remove URL query parameter, it uses `history`
|
|
3
|
+
*
|
|
4
|
+
* @category location
|
|
5
|
+
* @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
|
|
6
|
+
*/
|
|
1
7
|
export declare let navigateWithoutUrlParam: (paramName?: string, replace?: boolean) => string;
|
|
2
8
|
export default navigateWithoutUrlParam;
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "@koine/browser",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@koine/dom": "2.0.0-beta.
|
|
6
|
-
"@koine/utils": "2.0.0-beta.
|
|
5
|
+
"@koine/dom": "2.0.0-beta.133",
|
|
6
|
+
"@koine/utils": "2.0.0-beta.133"
|
|
7
7
|
},
|
|
8
8
|
"peerDependenciesMeta": {
|
|
9
9
|
"date-fns-tz": {
|
|
@@ -130,5 +130,5 @@
|
|
|
130
130
|
"module": "./index.esm.js",
|
|
131
131
|
"main": "./index.cjs.js",
|
|
132
132
|
"types": "./index.esm.d.ts",
|
|
133
|
-
"version": "2.0.0-beta.
|
|
133
|
+
"version": "2.0.0-beta.133"
|
|
134
134
|
}
|
package/redirectTo.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { type AnyQueryParams } from "@koine/utils";
|
|
2
|
+
/**
|
|
3
|
+
* Redirect to url with params {optionally}, removes eventual trailing question
|
|
4
|
+
* marks from the given URL, it uses `location`
|
|
5
|
+
*
|
|
6
|
+
* @category location
|
|
7
|
+
*/
|
|
2
8
|
export declare let redirectTo: (url: string, params?: AnyQueryParams) => void;
|
|
3
9
|
export default redirectTo;
|
package/storage.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage, for `localStorage` and `sessionStorage`
|
|
3
|
+
*
|
|
4
|
+
* @category storage
|
|
5
|
+
*/
|
|
1
6
|
export declare let storage: {
|
|
2
7
|
l: {
|
|
3
8
|
get: <TKey extends string, TValue = any>(key: TKey, transform?: ((value: string) => TValue) | undefined, defaultValue?: TValue | null | undefined) => NonNullable<TValue> | null;
|
package/storageClient.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category storage
|
|
3
|
+
*/
|
|
1
4
|
export type StorageClientConfig = Record<string, any>;
|
|
5
|
+
/**
|
|
6
|
+
* Super minifiable `local/session Storage` client creator with SSR safety
|
|
7
|
+
*
|
|
8
|
+
* @category storage
|
|
9
|
+
*/
|
|
2
10
|
export declare let storageClient: <TConfig extends StorageClientConfig = StorageClientConfig>(useSessionStorage?: boolean) => {
|
|
3
11
|
get: <TKey extends Extract<keyof TConfig, string>, TValue = TConfig[TKey]>(key: TKey, transform?: (value: string) => TValue, defaultValue?: null | TValue) => NonNullable<TValue> | null;
|
|
4
12
|
set: <TKey extends Extract<keyof TConfig, string>, TValue_1 = TConfig[TKey]>(key: TKey, value?: TValue_1, transform?: (value: any) => string) => void;
|