@bigbinary/neeto-commons-frontend 2.0.59 → 2.0.61
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/README.md +1 -0
- package/configs/scripts/jsdoc-builder/constants.mjs +42 -0
- package/configs/scripts/jsdoc-builder/index.mjs +67 -0
- package/configs/scripts/jsdoc-builder/utils.mjs +218 -0
- package/cypress-utils.d.ts +99 -103
- package/initializers.d.ts +20 -9
- package/package.json +9 -4
- package/pure.d.ts +1895 -270
- package/react-utils.cjs.js +5 -5
- package/react-utils.d.ts +338 -115
- package/react-utils.js +5 -5
- package/utils.cjs.js +1 -1
- package/utils.d.ts +265 -48
- package/utils.js +1 -1
package/react-utils.d.ts
CHANGED
|
@@ -1,120 +1,343 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
1
2
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
export function resetAuthTokens(): void;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* Curried: true
|
|
7
|
+
*
|
|
8
|
+
* It is a curried function that accepts a function as the first parameter and an
|
|
9
|
+
*
|
|
10
|
+
* event as the second, and executes the given function with event.target.value
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* const onChange = val => console.log(`Value = ${val}`);
|
|
17
|
+
*
|
|
18
|
+
* <input onChange={withEventTargetValue(onChange)} />;
|
|
19
|
+
*
|
|
20
|
+
* // For example, in this case when user types "1" in the input field, "Value = 1" will be printed in the console.
|
|
21
|
+
* @endexample
|
|
22
|
+
*/
|
|
23
|
+
export function withEventTargetValue(func: (value: string) => void, event: React.ChangeEventHandler<HTMLInputElement>): void;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* Curried: true
|
|
27
|
+
*
|
|
28
|
+
* It is a curried function that accepts a function as the first parameter and an
|
|
29
|
+
*
|
|
30
|
+
* event as the second, and executes the given function with event.target.value
|
|
31
|
+
*
|
|
32
|
+
* Usage:
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
*
|
|
36
|
+
* const onChange = val => console.log(`Value = ${val}`);
|
|
37
|
+
*
|
|
38
|
+
* <input onChange={withEventTargetValue(onChange)} />;
|
|
39
|
+
*
|
|
40
|
+
* // For example, in this case when user types "1" in the input field, "Value = 1" will be printed in the console.
|
|
41
|
+
* @endexample
|
|
42
|
+
*/
|
|
43
|
+
export function withEventTargetValue(func: (value: string) => void): (event: React.ChangeEventHandler<HTMLInputElement>) => void;
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* Curried: false
|
|
47
|
+
*
|
|
48
|
+
* This function returns the subdomain of the current URL.
|
|
49
|
+
*
|
|
50
|
+
* Usage:
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
*
|
|
54
|
+
* // Let the current url be "https://spinkart.example.com".
|
|
55
|
+
* getSubdomain();
|
|
56
|
+
*
|
|
57
|
+
* // output: spinkart
|
|
58
|
+
* @endexample
|
|
59
|
+
*/
|
|
60
|
+
export function getSubdomain(): string;
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* Curried: false
|
|
64
|
+
*
|
|
65
|
+
* Returns the specified hardcoded data after some delay for simulating an API
|
|
66
|
+
*
|
|
67
|
+
* call.
|
|
68
|
+
*
|
|
69
|
+
* This function will simulate an API call and retrieve the hardcoded success/error
|
|
70
|
+
*
|
|
71
|
+
* responses after some delay based on the given error probability. This function
|
|
72
|
+
*
|
|
73
|
+
* is helpful when we are building the frontend before the backend is ready.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
*
|
|
77
|
+
* simulateApiCall(hardCodedResponseData, hardCodedErrorResponse);
|
|
78
|
+
* @endexample
|
|
79
|
+
*/
|
|
80
|
+
export function simulateApiCall<T>(result: T, error?: any, errorProbability?: number, delayMs?: number): Promise<T>;
|
|
81
|
+
/**
|
|
82
|
+
*
|
|
83
|
+
* Curried: false
|
|
84
|
+
*
|
|
85
|
+
* Copies the given string to clipboard and shows a success toaster message.
|
|
86
|
+
*
|
|
87
|
+
* This function accepts a string as an argument and copies it to the clipboard.
|
|
88
|
+
*
|
|
89
|
+
* Also, it accepts two optional arguments: a boolean flag to indicate whether a
|
|
90
|
+
*
|
|
91
|
+
* toaster should be shown and a message to be shown in the toaster. By default the
|
|
92
|
+
*
|
|
93
|
+
* show toaster flag is set to true and the toaster message is set to "Copied to
|
|
94
|
+
*
|
|
95
|
+
* clipboard!". You can override these defaults by passing the appropriate values
|
|
96
|
+
*
|
|
97
|
+
* to the function.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
*
|
|
101
|
+
* copyToClipboard("https://spinkart.example.com", {
|
|
102
|
+
* showToastr: true,
|
|
103
|
+
* message: "URL copied successfully!",
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* // If the URL is copied to the clipboard, a toaster message will be shown with the message "URL copied successfully!"
|
|
107
|
+
* @endexample
|
|
108
|
+
*/
|
|
109
|
+
export function copyToClipboard(text: string, configs?: {
|
|
110
|
+
showToastr?: boolean;
|
|
111
|
+
message?: string;
|
|
112
|
+
}): void;
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* Curried: false
|
|
116
|
+
*
|
|
117
|
+
* Builds a URL by inflating route like template string (example:
|
|
118
|
+
*
|
|
119
|
+
* /products/:productId/variants/:id) using the given params. Any extra
|
|
120
|
+
*
|
|
121
|
+
* properties in the params will be attached as query parameters to the URL.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
*
|
|
125
|
+
* buildUrl("/products/:id", { id: "123" }); // output "/products/123"
|
|
126
|
+
* buildUrl("/products", { search: "abc" }); // output "/products?search=abc"
|
|
127
|
+
* buildUrl("/products/:productId/variants/:variantId/attributes", {
|
|
128
|
+
* productId: "123",
|
|
129
|
+
* variantId: "456",
|
|
130
|
+
* search: "abc",
|
|
131
|
+
* page: 1,
|
|
132
|
+
* per_page: 10,
|
|
133
|
+
* }); // output "/products/123/variants/456/attributes?page=1&per_page=10&search=abc"
|
|
134
|
+
* @endexample
|
|
135
|
+
*/
|
|
136
|
+
export function buildUrl(route: string, params: object): string;
|
|
137
|
+
type TimerType = {
|
|
138
|
+
lastUpdated: number;
|
|
139
|
+
interval: number;
|
|
25
140
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
): any;
|
|
75
|
-
(): any;
|
|
141
|
+
/**
|
|
142
|
+
*
|
|
143
|
+
* The useTimer hook re-renders in the specified time interval. This can
|
|
144
|
+
*
|
|
145
|
+
* auto-update the rendered elapsed time in components without requiring the
|
|
146
|
+
*
|
|
147
|
+
* application to be manually refreshed.
|
|
148
|
+
*
|
|
149
|
+
* This hook accepts a single argument timerIntervalInSeconds, which is the
|
|
150
|
+
*
|
|
151
|
+
* number of seconds after which the component will re-render. The default value is
|
|
152
|
+
*
|
|
153
|
+
* 60 seconds.
|
|
154
|
+
*
|
|
155
|
+
* All invocations of useTimer hooks are attached to a single setInterval call
|
|
156
|
+
*
|
|
157
|
+
* which ticks every 1 second. So using that hook in multiple components won't
|
|
158
|
+
*
|
|
159
|
+
* cause any performance drop.
|
|
160
|
+
*
|
|
161
|
+
* Note that the maximum precision for useTimer hook is one second. In other
|
|
162
|
+
*
|
|
163
|
+
* words, there is a possibility that your component will take at most one more
|
|
164
|
+
*
|
|
165
|
+
* second than the scheduled time interval to re-render.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
*
|
|
169
|
+
* import { useTimer } from "neetocommons/react-utils";
|
|
170
|
+
*
|
|
171
|
+
* const Component = () => {
|
|
172
|
+
* useTimer(timerIntervalInSeconds);
|
|
173
|
+
*
|
|
174
|
+
* // Rest of the component
|
|
175
|
+
* };
|
|
176
|
+
* @endexample
|
|
177
|
+
*/
|
|
178
|
+
export function useTimer(interval: number): TimerType;
|
|
179
|
+
type DateTimeType = string | number | dayjs.Dayjs | Date | null | undefined;
|
|
180
|
+
export const timeFormat: {
|
|
181
|
+
fromNow: (time: DateTimeType) => string;
|
|
182
|
+
time: (time: DateTimeType) => string;
|
|
183
|
+
date: (time: DateTimeType) => string;
|
|
184
|
+
dateWeek: (time: DateTimeType) => string;
|
|
185
|
+
dateWeekWithoutYear: (time: DateTimeType) => string;
|
|
186
|
+
dateTime: (time: DateTimeType) => string;
|
|
187
|
+
dateWeekTime: (time: DateTimeType) => string;
|
|
188
|
+
extended: (time: DateTimeType) => string;
|
|
76
189
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
190
|
+
export const dateFormat: typeof timeFormat;
|
|
191
|
+
/**
|
|
192
|
+
*
|
|
193
|
+
* Curried: false
|
|
194
|
+
*
|
|
195
|
+
* Converts the given number to a locale string (converts to a comma separated
|
|
196
|
+
*
|
|
197
|
+
* string). It automatically identifies the locale using globalProps. If a valid
|
|
198
|
+
*
|
|
199
|
+
* value isn't present in globalProps, it will rely on the current browser's
|
|
200
|
+
*
|
|
201
|
+
* locale.
|
|
202
|
+
*
|
|
203
|
+
* The function also accepts options, which will be forwarded to
|
|
204
|
+
*
|
|
205
|
+
* Number.prototype.toLocaleString, which can be used for additional
|
|
206
|
+
*
|
|
207
|
+
* configurations like rounding, currency, units etc.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
*
|
|
211
|
+
* toLocale(1000000); // "1,000,000" when locale is "en-US"
|
|
212
|
+
* toLocale(1000000); // "10,00,000" when locale is "en-IN"
|
|
213
|
+
* toLocale(1000000.987, { maximumFractionDigits: 2 }); // "1,000,000.99"
|
|
214
|
+
* toLocale(1000000.987, {
|
|
215
|
+
* currencyDisplay: "narrowSymbol",
|
|
216
|
+
* style: "currency",
|
|
217
|
+
* currency: "INR",
|
|
218
|
+
* }); // "₹1,000,000.99"
|
|
219
|
+
* @endexample
|
|
220
|
+
*/
|
|
221
|
+
export function toLocale(number: string | number, options?: Intl.NumberFormatOptions): string;
|
|
222
|
+
type qsOptionsType = {
|
|
223
|
+
comma?: boolean | undefined;
|
|
224
|
+
delimiter?: string | RegExp | undefined;
|
|
225
|
+
depth?: number | false | undefined;
|
|
226
|
+
decoder?: ((str: string, defaultDecoder: any, charset: string, type: "key" | "value") => any) | undefined;
|
|
227
|
+
arrayLimit?: number | undefined;
|
|
228
|
+
parseArrays?: boolean | undefined;
|
|
229
|
+
allowDots?: boolean | undefined;
|
|
230
|
+
plainObjects?: boolean | undefined;
|
|
231
|
+
allowPrototypes?: boolean | undefined;
|
|
232
|
+
parameterLimit?: number | undefined;
|
|
233
|
+
strictNullHandling?: boolean | undefined;
|
|
234
|
+
ignoreQueryPrefix?: boolean | undefined;
|
|
235
|
+
charset?: "utf-8" | "iso-8859-1" | undefined;
|
|
236
|
+
charsetSentinel?: boolean | undefined;
|
|
237
|
+
interpretNumericEntities?: boolean | undefined;
|
|
80
238
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
Component: () => JSX.Element,
|
|
84
|
-
title?: string
|
|
85
|
-
): (props) => JSX.Element;
|
|
86
|
-
|
|
87
|
-
export async function registerBrowserNotifications(): Promise<void>;
|
|
88
|
-
|
|
89
|
-
export async function destroyBrowserSubscription(): Promise<void>;
|
|
90
|
-
|
|
91
|
-
export function handleMetaClick(
|
|
92
|
-
history: History,
|
|
93
|
-
params: string | object,
|
|
94
|
-
event: React.MouseEvent<HTMLElement, MouseEvent>
|
|
95
|
-
): void;
|
|
96
|
-
export function handleMetaClick(
|
|
97
|
-
history: History,
|
|
98
|
-
params: string | object
|
|
99
|
-
): (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
|
100
|
-
export function handleMetaClick(
|
|
101
|
-
history: History
|
|
102
|
-
): (
|
|
103
|
-
params: string | object,
|
|
104
|
-
event: React.MouseEvent<HTMLElement, MouseEvent>
|
|
105
|
-
) => void;
|
|
106
|
-
|
|
107
|
-
export function isMetaKeyPressed(
|
|
108
|
-
event: React.MouseEvent<HTMLElement, MouseEvent>
|
|
109
|
-
): boolean;
|
|
110
|
-
|
|
111
|
-
type ConfigType = {
|
|
112
|
-
mode?: "default" | "global" | "scoped";
|
|
113
|
-
unbindOnUnmount?: boolean;
|
|
114
|
-
enabled?: boolean;
|
|
239
|
+
type QueryParamsType = {
|
|
240
|
+
[key: string]: any;
|
|
115
241
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
242
|
+
/**
|
|
243
|
+
*
|
|
244
|
+
* Curried: false
|
|
245
|
+
*
|
|
246
|
+
* This function returns all the query parameters of the current URL as an object.
|
|
247
|
+
*
|
|
248
|
+
* Usage:
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
*
|
|
252
|
+
* // Let the current url be "https://example.com?search=something&sort=date".
|
|
253
|
+
* getQueryParams();
|
|
254
|
+
*
|
|
255
|
+
* // output: { search: "something", sort: "date" }
|
|
256
|
+
* @endexample
|
|
257
|
+
*/
|
|
258
|
+
export function getQueryParams(options?: qsOptionsType): QueryParamsType;
|
|
259
|
+
/**
|
|
260
|
+
*
|
|
261
|
+
* Curried: false
|
|
262
|
+
*
|
|
263
|
+
* This function joins the given strings with hyphen.
|
|
264
|
+
*
|
|
265
|
+
* Usage:
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
*
|
|
269
|
+
* joinHyphenCase("hello", "world"); // output: "hello-world"
|
|
270
|
+
* @endexample
|
|
271
|
+
*/
|
|
272
|
+
export function joinHyphenCase(...args: string[]): string;
|
|
273
|
+
/**
|
|
274
|
+
*
|
|
275
|
+
* Curried: false
|
|
276
|
+
*
|
|
277
|
+
* Creates a debounced function that will execute the given function after the
|
|
278
|
+
*
|
|
279
|
+
* stated wait time in milliseconds has elapsed since the last time it was invoked.
|
|
280
|
+
*
|
|
281
|
+
* It accepts the function to be debounced as the first argument, the delay in
|
|
282
|
+
*
|
|
283
|
+
* milliseconds as the second argument.
|
|
284
|
+
*
|
|
285
|
+
* Usage:
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
*
|
|
289
|
+
* const searchForProducts = debounce(async key => {
|
|
290
|
+
* // this function will be triggered once after user stops typing for 300ms
|
|
291
|
+
* const products = await productsApi.fetch(key);
|
|
292
|
+
* // do something with the products
|
|
293
|
+
* }, 300);
|
|
294
|
+
* <input onChange={e => searchForProducts(e.target.value)} />;
|
|
295
|
+
* @endexample
|
|
296
|
+
*/
|
|
297
|
+
export function debounce<F extends Function>(func: F, delay?: number): F;
|
|
298
|
+
/**
|
|
299
|
+
*
|
|
300
|
+
* Curried: false
|
|
301
|
+
*
|
|
302
|
+
* This function will return true if the current user has the given permission.
|
|
303
|
+
*
|
|
304
|
+
* Usage:
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
*
|
|
308
|
+
* hasPermission("user.view_settings");
|
|
309
|
+
* @endexample
|
|
310
|
+
*/
|
|
311
|
+
export function hasPermission(permission: string): boolean;
|
|
312
|
+
/**
|
|
313
|
+
*
|
|
314
|
+
* Curried: false
|
|
315
|
+
*
|
|
316
|
+
* This function will return true if the current user has any of the given
|
|
317
|
+
*
|
|
318
|
+
* permissions.
|
|
319
|
+
*
|
|
320
|
+
* Usage:
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
*
|
|
324
|
+
* hasAnyPermission("user.view_settings", "user.edit_settings");
|
|
325
|
+
* @endexample
|
|
326
|
+
*/
|
|
327
|
+
export function hasAnyPermission(...permissions: string[]): boolean;
|
|
328
|
+
/**
|
|
329
|
+
*
|
|
330
|
+
* Curried: false
|
|
331
|
+
*
|
|
332
|
+
* This function will return true if the current user has all of the given
|
|
333
|
+
*
|
|
334
|
+
* permissions.
|
|
335
|
+
*
|
|
336
|
+
* Usage:
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
*
|
|
340
|
+
* hasAllPermissions("user.view_settings", "user.edit_settings");
|
|
341
|
+
* @endexample
|
|
342
|
+
*/
|
|
343
|
+
export function hasAllPermissions(...permissions: string[]): boolean;
|