@siberiacancode/reactuse 0.2.9 → 0.2.11
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/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
- package/dist/cjs/hooks/useCookies/useCookies.cjs +1 -1
- package/dist/cjs/hooks/useCookies/useCookies.cjs.map +1 -1
- package/dist/cjs/hooks/useShare/useShare.cjs +1 -1
- package/dist/cjs/hooks/useShare/useShare.cjs.map +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.cjs +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs +2 -0
- package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -0
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
- package/dist/esm/hooks/useCookies/useCookies.mjs +31 -35
- package/dist/esm/hooks/useCookies/useCookies.mjs.map +1 -1
- package/dist/esm/hooks/useShare/useShare.mjs +9 -9
- package/dist/esm/hooks/useShare/useShare.mjs.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.mjs +30 -30
- package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs +72 -0
- package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -0
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs +43 -58
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
- package/dist/esm/index.mjs +251 -251
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/useCookie/useCookie.d.ts +18 -6
- package/dist/types/hooks/useCookies/useCookies.d.ts +10 -10
- package/dist/types/hooks/useShare/useShare.d.ts +2 -2
- package/dist/types/hooks/useUrlSearchParam/useUrlSearchParam.d.ts +70 -0
- package/dist/types/hooks/useUrlSearchParams/useUrlSearchParams.d.ts +36 -13
- package/package.json +1 -1
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { RemoveCookieParams, SetCookieParams } from '../useCookie/useCookie';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/** The cookies params type */
|
|
3
|
+
export type CookieParams = Record<string, any>;
|
|
4
|
+
export interface UseCookiesOptions<Value> {
|
|
5
|
+
deserializer?: (value: string) => Value[keyof Value];
|
|
6
|
+
serializer?: (value: Value[keyof Value]) => string;
|
|
7
|
+
}
|
|
5
8
|
export declare const clearCookies: () => void;
|
|
6
9
|
/**
|
|
7
10
|
* @name useCookies
|
|
@@ -10,18 +13,15 @@ export declare const clearCookies: () => void;
|
|
|
10
13
|
*
|
|
11
14
|
* @overload
|
|
12
15
|
* @template {object} Value The type of the cookie values
|
|
13
|
-
* @param {string} key The key of the cookie
|
|
14
16
|
* @returns {UseCookieReturn<Value>} The value and the set function
|
|
15
17
|
*
|
|
16
18
|
* @example
|
|
17
19
|
* const { value, set, remove, getAll, clear } = useCookies();
|
|
18
20
|
*/
|
|
19
|
-
export declare const useCookies: <Value>() => {
|
|
21
|
+
export declare const useCookies: <Value extends CookieParams>(options?: UseCookiesOptions<Value>) => {
|
|
20
22
|
value: Value;
|
|
21
|
-
set: (key:
|
|
22
|
-
remove: (key:
|
|
23
|
-
getAll: () =>
|
|
24
|
-
[k: string]: any;
|
|
25
|
-
};
|
|
23
|
+
set: <Key extends keyof Value>(key: Key, value: Value[Key], options?: SetCookieParams) => void;
|
|
24
|
+
remove: <Key extends keyof Value>(key: Key, options?: RemoveCookieParams) => void;
|
|
25
|
+
getAll: () => any;
|
|
26
26
|
clear: () => void;
|
|
27
27
|
};
|
|
@@ -14,7 +14,7 @@ export interface UseShareReturn {
|
|
|
14
14
|
/** Whether the Web Share API is supported in the current environment */
|
|
15
15
|
supported: boolean;
|
|
16
16
|
/** Function to trigger the native share dialog */
|
|
17
|
-
|
|
17
|
+
trigger: (shareParams: ShareData) => Promise<void>;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* @name useShare
|
|
@@ -30,6 +30,6 @@ export interface UseShareReturn {
|
|
|
30
30
|
* const { share, supported } = useShare();
|
|
31
31
|
*/
|
|
32
32
|
export declare const useShare: (params?: UseShareParams) => {
|
|
33
|
-
|
|
33
|
+
trigger: (shareParams: ShareData) => Promise<void>;
|
|
34
34
|
supported: boolean;
|
|
35
35
|
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** The url search params mode type */
|
|
2
|
+
export type UrlSearchParamMode = 'hash-params' | 'hash' | 'history';
|
|
3
|
+
/** The use url search param options type */
|
|
4
|
+
export interface UseUrlSearchParamOptions<Value> {
|
|
5
|
+
/** The initial value of the search param */
|
|
6
|
+
initialValue?: Value;
|
|
7
|
+
/** The mode to use for writing to the URL */
|
|
8
|
+
mode?: UrlSearchParamMode;
|
|
9
|
+
/** The mode to use for writing to the URL */
|
|
10
|
+
write?: 'push' | 'replace';
|
|
11
|
+
/** The deserializer function to be invoked */
|
|
12
|
+
deserializer?: (value: string) => Value;
|
|
13
|
+
/** The serializer function to be invoked */
|
|
14
|
+
serializer?: (value: Value) => string;
|
|
15
|
+
}
|
|
16
|
+
/** The use url search params set options type */
|
|
17
|
+
export interface UseUrlSearchParamsActionOptions {
|
|
18
|
+
/** The mode to use for writing to the URL */
|
|
19
|
+
write?: 'push' | 'replace';
|
|
20
|
+
}
|
|
21
|
+
/** The use url search param return type */
|
|
22
|
+
export interface UseUrlSearchParamReturn<Value> {
|
|
23
|
+
/** Current search param value */
|
|
24
|
+
value: Value | undefined;
|
|
25
|
+
/** Function to remove the search param */
|
|
26
|
+
remove: (options?: UseUrlSearchParamsActionOptions) => void;
|
|
27
|
+
/** Function to update search param */
|
|
28
|
+
set: (value: Value, options?: UseUrlSearchParamsActionOptions) => void;
|
|
29
|
+
}
|
|
30
|
+
export declare const URL_SEARCH_PARAMS_EVENT = "reactuse-url-search-params-event";
|
|
31
|
+
export declare const getUrlSearchParams: (mode?: UrlSearchParamMode) => URLSearchParams;
|
|
32
|
+
export declare const createQueryString: (searchParams: URLSearchParams, mode: UrlSearchParamMode) => string;
|
|
33
|
+
export declare const dispatchUrlSearchParamsEvent: () => boolean;
|
|
34
|
+
export interface UseUrlSearchParam {
|
|
35
|
+
<Value>(key: string, options: UseUrlSearchParamOptions<Value> & {
|
|
36
|
+
initialValue: Value;
|
|
37
|
+
}): UseUrlSearchParamReturn<Value>;
|
|
38
|
+
<Value>(key: string, options?: UseUrlSearchParamOptions<Value>): UseUrlSearchParamReturn<Value | undefined>;
|
|
39
|
+
<Value>(key: string, initialValue: Value): UseUrlSearchParamReturn<Value>;
|
|
40
|
+
<Value>(key: string): UseUrlSearchParamReturn<Value | undefined>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @name useUrlSearchParam
|
|
44
|
+
* @description - Hook that provides reactive URLSearchParams for a single key
|
|
45
|
+
* @category Browser
|
|
46
|
+
*
|
|
47
|
+
* @overload
|
|
48
|
+
* @template Value The type of the url param values
|
|
49
|
+
* @param {string} key The key of the url param
|
|
50
|
+
* @param {UseUrlSearchParamOptions<Value> & { initialValue: Value }} options The options object with required initialValue
|
|
51
|
+
* @param {Value} options.initialValue The initial value for the url param
|
|
52
|
+
* @param {UrlSearchParamsMode} [options.mode='history'] The mode to use for the URL ('history' | 'hash-params' | 'hash')
|
|
53
|
+
* @param {'push' | 'replace'} [options.write='replace'] The mode to use for writing to the URL
|
|
54
|
+
* @param {(value: Value) => string} [options.serializer] Custom serializer function to convert value to string
|
|
55
|
+
* @param {(value: string) => Value} [options.deserializer] Custom deserializer function to convert string to value
|
|
56
|
+
* @returns {UseUrlSearchParamReturn<Value>} The object with value and function for change value
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const { value, set } = useUrlSearchParam('page', { initialValue: 1 });
|
|
60
|
+
*
|
|
61
|
+
* @overload
|
|
62
|
+
* @template Value The type of the url param values
|
|
63
|
+
* @param {string} key The key of the url param
|
|
64
|
+
* @param {Value} [initialValue] The initial value for the url param
|
|
65
|
+
* @returns {UseUrlSearchParamReturn<Value>} The object with value and function for change value
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* const { value, set } = useUrlSearchParam('page', 1);
|
|
69
|
+
*/
|
|
70
|
+
export declare const useUrlSearchParam: UseUrlSearchParam;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const createQueryString: (searchParams: URLSearchParams, mode: UrlSearchParamsMode) => string;
|
|
3
|
-
export declare const URL_SEARCH_PARAMS_EVENT = "reactuse-url-search-params-event";
|
|
4
|
-
export declare const dispatchUrlSearchParamsEvent: () => boolean;
|
|
5
|
-
export declare const setUrlSearchParams: <Params extends UrlParams>(mode: UrlSearchParamsMode, params: Partial<Params>, write?: "push" | "replace") => URLSearchParams;
|
|
1
|
+
import { createQueryString, dispatchUrlSearchParamsEvent, getUrlSearchParams } from '../useUrlSearchParam/useUrlSearchParam';
|
|
6
2
|
/** The url params type */
|
|
7
3
|
export type UrlParams = Record<string, any>;
|
|
8
4
|
/** The url search params mod */
|
|
@@ -12,17 +8,31 @@ export interface UseUrlSearchParamsSetOptions {
|
|
|
12
8
|
/** The mode to use for writing to the URL */
|
|
13
9
|
write?: 'push' | 'replace';
|
|
14
10
|
}
|
|
11
|
+
export type UseUrlSearchParamsInitialValue<Value> = (() => Value) | Value;
|
|
15
12
|
/** The use url search params options type */
|
|
16
|
-
export interface UseUrlSearchParamsOptions {
|
|
13
|
+
export interface UseUrlSearchParamsOptions<Value> {
|
|
14
|
+
initialValue?: UseUrlSearchParamsInitialValue<string | URLSearchParams | Value>;
|
|
17
15
|
/** The mode to use for writing to the URL */
|
|
18
16
|
mode?: UrlSearchParamsMode;
|
|
19
17
|
/** The mode to use for writing to the URL */
|
|
20
18
|
write?: 'push' | 'replace';
|
|
19
|
+
deserializer?: (value: string) => Value[keyof Value];
|
|
20
|
+
serializer?: (value: Value[keyof Value]) => string;
|
|
21
21
|
}
|
|
22
22
|
/** The use url search params return type */
|
|
23
|
-
export interface UseUrlSearchParamsReturn<
|
|
24
|
-
value
|
|
25
|
-
|
|
23
|
+
export interface UseUrlSearchParamsReturn<Value> {
|
|
24
|
+
/** The value of the url search params */
|
|
25
|
+
value: Value;
|
|
26
|
+
/** The set function */
|
|
27
|
+
set: (value: Partial<Value>, options?: UseUrlSearchParamsSetOptions) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface UseUrlSearchParams {
|
|
30
|
+
<Value>(key: string, options: UseUrlSearchParamsOptions<Value> & {
|
|
31
|
+
initialValue: UseUrlSearchParamsInitialValue<Value>;
|
|
32
|
+
}): UseUrlSearchParamsReturn<Value>;
|
|
33
|
+
<Value>(options?: UseUrlSearchParamsOptions<Value>): UseUrlSearchParamsReturn<Value | undefined>;
|
|
34
|
+
<Value>(initialValue: UseUrlSearchParamsInitialValue<Value>): UseUrlSearchParamsReturn<Value>;
|
|
35
|
+
<Value>(key: string): UseUrlSearchParamsReturn<Value | undefined>;
|
|
26
36
|
}
|
|
27
37
|
/**
|
|
28
38
|
* @name useUrlSearchParams
|
|
@@ -31,11 +41,24 @@ export interface UseUrlSearchParamsReturn<Params extends UrlParams> {
|
|
|
31
41
|
*
|
|
32
42
|
* @overload
|
|
33
43
|
* @template Value The type of the url param values
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {
|
|
44
|
+
* @param {UseUrlSearchParamsOptions<Value> & { initialValue: UseUrlSearchParamsInitialValue<Value> }} options The options object with required initialValue
|
|
45
|
+
* @param {UseUrlSearchParamsInitialValue<Value>} [options.initialValue] The initial value for the url params
|
|
46
|
+
* @param {UrlSearchParamsMode} [options.mode='history'] The mode to use for the URL ('history' | 'hash-params' | 'hash')
|
|
47
|
+
* @param {'push' | 'replace'} [options.write='replace'] The mode to use for writing to the URL
|
|
48
|
+
* @param {(value: Value[keyof Value]) => string} [options.serializer] Custom serializer function to convert value to string
|
|
49
|
+
* @param {(value: string) => Value[keyof Value]} [options.deserializer] Custom deserializer function to convert string to value
|
|
50
|
+
* @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* const { value, set } = useUrlSearchParams({ initialValue: { page: 1 } });
|
|
54
|
+
*
|
|
55
|
+
* @overload
|
|
56
|
+
* @template Value The type of the url param values
|
|
57
|
+
* @param {UseUrlSearchParamsInitialValue<Value>} [initialValue] The initial value for the url params
|
|
36
58
|
* @returns {UseUrlSearchParamsReturn<Value>} The object with value and function for change value
|
|
37
59
|
*
|
|
38
60
|
* @example
|
|
39
|
-
* const { value, set } = useUrlSearchParams(
|
|
61
|
+
* const { value, set } = useUrlSearchParams({ page: 1 });
|
|
40
62
|
*/
|
|
41
|
-
export declare const useUrlSearchParams:
|
|
63
|
+
export declare const useUrlSearchParams: UseUrlSearchParams;
|
|
64
|
+
export { createQueryString, dispatchUrlSearchParamsEvent, getUrlSearchParams };
|