@bigbinary/neeto-commons-frontend 2.1.5 → 2.1.7
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 +104 -94
- package/configs/scripts/jsdoc-builder/constants.mjs +1 -1
- package/configs/scripts/jsdoc-builder/utils.mjs +4 -3
- package/cypress-utils.d.ts +2 -2
- package/initializers.cjs.js +11 -2
- package/initializers.cjs.js.map +1 -1
- package/initializers.d.ts +7 -5
- package/initializers.js +11 -2
- package/initializers.js.map +1 -1
- package/package.json +2 -2
- package/pure.d.ts +325 -324
- package/react-utils.d.ts +674 -153
- package/utils.cjs.js +8 -2
- package/utils.cjs.js.map +1 -1
- package/utils.d.ts +145 -44
- package/utils.js +8 -2
- package/utils.js.map +1 -1
package/utils.d.ts
CHANGED
|
@@ -4,11 +4,15 @@ import React from "react";
|
|
|
4
4
|
export function resetAuthTokens(): void;
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* The withEventTargetValue function is a curried function that accepts a
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* function as its first parameter and an event object as its second parameter. It
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* executes the given function with the event.target.value as an argument, making
|
|
12
|
+
*
|
|
13
|
+
* it easier to extract and work with the value of form inputs or other elements
|
|
14
|
+
*
|
|
15
|
+
* that trigger events.
|
|
12
16
|
*
|
|
13
17
|
* @example
|
|
14
18
|
*
|
|
@@ -22,11 +26,15 @@ export function resetAuthTokens(): void;
|
|
|
22
26
|
export function withEventTargetValue(func: (value: string) => void, event: React.ChangeEvent): void;
|
|
23
27
|
/**
|
|
24
28
|
*
|
|
25
|
-
*
|
|
29
|
+
* The withEventTargetValue function is a curried function that accepts a
|
|
30
|
+
*
|
|
31
|
+
* function as its first parameter and an event object as its second parameter. It
|
|
26
32
|
*
|
|
27
|
-
*
|
|
33
|
+
* executes the given function with the event.target.value as an argument, making
|
|
28
34
|
*
|
|
29
|
-
*
|
|
35
|
+
* it easier to extract and work with the value of form inputs or other elements
|
|
36
|
+
*
|
|
37
|
+
* that trigger events.
|
|
30
38
|
*
|
|
31
39
|
* @example
|
|
32
40
|
*
|
|
@@ -40,9 +48,11 @@ export function withEventTargetValue(func: (value: string) => void, event: React
|
|
|
40
48
|
export function withEventTargetValue(func: (value: string) => void): React.ChangeEventHandler;
|
|
41
49
|
/**
|
|
42
50
|
*
|
|
43
|
-
*
|
|
51
|
+
* The getSubdomain function retrieves the subdomain of the current URL and
|
|
52
|
+
*
|
|
53
|
+
* returns it as a string. A subdomain is a prefix that appears before the main
|
|
44
54
|
*
|
|
45
|
-
*
|
|
55
|
+
* domain name in a URL.
|
|
46
56
|
*
|
|
47
57
|
* @example
|
|
48
58
|
*
|
|
@@ -55,13 +65,13 @@ export function withEventTargetValue(func: (value: string) => void): React.Chang
|
|
|
55
65
|
export function getSubdomain(): string;
|
|
56
66
|
/**
|
|
57
67
|
*
|
|
58
|
-
*
|
|
68
|
+
* The simulateApiCall function simulates an API call and returns a response
|
|
59
69
|
*
|
|
60
|
-
*
|
|
70
|
+
* object with a specified delay. This function is useful during frontend
|
|
61
71
|
*
|
|
62
|
-
*
|
|
72
|
+
* development when you need to mock API calls before the backend is fully
|
|
63
73
|
*
|
|
64
|
-
*
|
|
74
|
+
* implemented.
|
|
65
75
|
*
|
|
66
76
|
* @example
|
|
67
77
|
*
|
|
@@ -71,9 +81,11 @@ export function getSubdomain(): string;
|
|
|
71
81
|
export function simulateApiCall<T>(result: T, error?: any, errorProbability?: number, delayMs?: number): Promise<T>;
|
|
72
82
|
/**
|
|
73
83
|
*
|
|
74
|
-
*
|
|
84
|
+
* The copyToClipboard function copies the given string to the clipboard and
|
|
85
|
+
*
|
|
86
|
+
* displays a success message, typically a toaster notification, to indicate that
|
|
75
87
|
*
|
|
76
|
-
*
|
|
88
|
+
* the operation was successful.
|
|
77
89
|
*
|
|
78
90
|
* @example
|
|
79
91
|
*
|
|
@@ -91,13 +103,15 @@ export function copyToClipboard(text: string, configs?: {
|
|
|
91
103
|
}): void;
|
|
92
104
|
/**
|
|
93
105
|
*
|
|
94
|
-
*
|
|
106
|
+
* The buildUrl function builds a URL by inflating a route-like template string
|
|
95
107
|
*
|
|
96
|
-
*
|
|
108
|
+
* (e.g., /products/:productId/variants/:id) using the provided parameters. It
|
|
97
109
|
*
|
|
98
|
-
*
|
|
110
|
+
* allows you to create URLs dynamically based on a template and replace
|
|
99
111
|
*
|
|
100
|
-
*
|
|
112
|
+
* placeholders with actual values. Any additional properties in the parameters
|
|
113
|
+
*
|
|
114
|
+
* will be attached as query parameters to the URL.
|
|
101
115
|
*
|
|
102
116
|
* @example
|
|
103
117
|
*
|
|
@@ -129,19 +143,86 @@ export const timeFormat: {
|
|
|
129
143
|
dateWeekTimeDayExtended: (time: DateTimeType) => string;
|
|
130
144
|
extended: (time: DateTimeType) => string;
|
|
131
145
|
default: (time: DateTimeType) => string;
|
|
146
|
+
defaultWithTime: (time: DateTimeType) => string;
|
|
132
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
*
|
|
150
|
+
* The dateFormat and timeFormat functions are aliases of each other, and they
|
|
151
|
+
*
|
|
152
|
+
* are used for formatting dates and times in various ways. These functions provide
|
|
153
|
+
*
|
|
154
|
+
* a convenient way to format date and time values according to specific patterns
|
|
155
|
+
*
|
|
156
|
+
* and display them in a human-readable format.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
*
|
|
160
|
+
* const sourceDate = "2020-01-01T00:00:00.000Z"; // can be anything that dayjs can parse
|
|
161
|
+
*
|
|
162
|
+
* dateFormat.fromNow(date); // "3 years ago"
|
|
163
|
+
* timeFormat.fromNow(date); // "3 years ago"
|
|
164
|
+
*
|
|
165
|
+
* dateFormat.time(date); // "12:00 AM"
|
|
166
|
+
* timeFormat.time(date); // "12:00 AM"
|
|
167
|
+
*
|
|
168
|
+
* dateFormat.timeWithSeconds(date); // "12:00:00 AM"
|
|
169
|
+
* timeFormat.timeWithSeconds(date); // "12:00:00 AM"
|
|
170
|
+
*
|
|
171
|
+
* dateFormat.date(date); // "Jan 1, 2020"
|
|
172
|
+
* timeFormat.date(date); // "Jan 1, 2020"
|
|
173
|
+
*
|
|
174
|
+
* dateFormat.dateWeek(date); // "Jan 1, 2020 Wed"
|
|
175
|
+
* timeFormat.dateWeek(date); // "Jan 1, 2020 Wed"
|
|
176
|
+
*
|
|
177
|
+
* dateFormat.dateWeekDayExtended(date); // "Jan 1, 2020 Wednesday"
|
|
178
|
+
* timeFormat.dateWeekDayExtended(date); // "Jan 1, 2020 Wednesday"
|
|
179
|
+
*
|
|
180
|
+
* dateFormat.dateWeekWithoutYear(date); // "Jan 1, Wed"
|
|
181
|
+
* timeFormat.dateWeekWithoutYear(date); // "Jan 1, Wed"
|
|
182
|
+
*
|
|
183
|
+
* dateFormat.dateWeekWithoutYearDayExtended(date); // "Jan 1, Wednesday"
|
|
184
|
+
* timeFormat.dateWeekWithoutYearDayExtended(date); // "Jan 1, Wednesday"
|
|
185
|
+
*
|
|
186
|
+
* dateFormat.dateTime(date); // "Jan 1, 2020 12:00 AM"
|
|
187
|
+
* timeFormat.dateTime(date); // "Jan 1, 2020 12:00 AM"
|
|
188
|
+
*
|
|
189
|
+
* dateFormat.dateTimeWithSeconds(date); // "Jan 1, 2020 12:00:00 AM"
|
|
190
|
+
* timeFormat.dateTimeWithSeconds(date); // "Jan 1, 2020 12:00:00 AM"
|
|
191
|
+
*
|
|
192
|
+
* dateFormat.dateWeekTime(date); // "Jan 1, 2020 Wed 12:00 AM"
|
|
193
|
+
* timeFormat.dateWeekTime(date); // "Jan 1, 2020 Wed 12:00 AM"
|
|
194
|
+
*
|
|
195
|
+
* dateFormat.dateWeekTimeDayExtended(date); // "Jan 1, 2020 Wednesday 12:00 AM"
|
|
196
|
+
* timeFormat.dateWeekTimeDayExtended(date); // "Jan 1, 2020 Wednesday 12:00 AM"
|
|
197
|
+
*
|
|
198
|
+
* dateFormat.extended(date); // "Wednesday January 1, 2020 12:00 AM (3 years ago)"
|
|
199
|
+
* timeFormat.extended(date); // "Wednesday January 1, 2020 12:00 AM (3 years ago)"
|
|
200
|
+
*
|
|
201
|
+
* dateFormat.default(date); // This will return date in user date format in globalProps
|
|
202
|
+
* timeFormat.default(date); // This will return date in user date format in globalProps
|
|
203
|
+
*
|
|
204
|
+
* dateFormat.defaultWithTime(date); // This will return date time in user date format in globalProps
|
|
205
|
+
* timeFormat.defaultWithTime(date); // This will return date time in user date format in globalProps
|
|
206
|
+
* @endexample
|
|
207
|
+
* All neeto-applications should be using any one of these styles (according to the
|
|
208
|
+
*
|
|
209
|
+
* space available) to display date and time unless if the case is too specific to
|
|
210
|
+
*
|
|
211
|
+
* the project.
|
|
212
|
+
*
|
|
213
|
+
*/
|
|
133
214
|
export const dateFormat: typeof timeFormat;
|
|
134
215
|
/**
|
|
135
216
|
*
|
|
136
|
-
*
|
|
217
|
+
* The toLocale function converts a given number to a locale-specific string
|
|
137
218
|
*
|
|
138
|
-
*
|
|
219
|
+
* representation, formatting it with commas as thousands separators and respecting
|
|
139
220
|
*
|
|
140
|
-
*
|
|
221
|
+
* the appropriate decimal separator for the locale. It automatically detects the
|
|
141
222
|
*
|
|
142
|
-
*
|
|
223
|
+
* appropriate locale using globalProps and falls back to the user's browser
|
|
143
224
|
*
|
|
144
|
-
* locale.
|
|
225
|
+
* locale if necessary.
|
|
145
226
|
*
|
|
146
227
|
* @example
|
|
147
228
|
*
|
|
@@ -178,9 +259,13 @@ type QueryParamsType = {
|
|
|
178
259
|
};
|
|
179
260
|
/**
|
|
180
261
|
*
|
|
181
|
-
*
|
|
262
|
+
* The getQueryParams function retrieves all the query parameters from the
|
|
263
|
+
*
|
|
264
|
+
* current URL and returns them as an object. Query parameters are typically found
|
|
265
|
+
*
|
|
266
|
+
* in the URL following a "?" character and are used to pass data to a web page or
|
|
182
267
|
*
|
|
183
|
-
*
|
|
268
|
+
* API.
|
|
184
269
|
*
|
|
185
270
|
* @example
|
|
186
271
|
*
|
|
@@ -193,9 +278,9 @@ type QueryParamsType = {
|
|
|
193
278
|
export function getQueryParams(options?: qsOptionsType): QueryParamsType;
|
|
194
279
|
/**
|
|
195
280
|
*
|
|
196
|
-
*
|
|
281
|
+
* The joinHyphenCase function joins an array of strings using hyphens as the
|
|
197
282
|
*
|
|
198
|
-
*
|
|
283
|
+
* delimiter and returns the resulting string.
|
|
199
284
|
*
|
|
200
285
|
* Any number of string arguments.
|
|
201
286
|
*
|
|
@@ -207,11 +292,11 @@ export function getQueryParams(options?: qsOptionsType): QueryParamsType;
|
|
|
207
292
|
export function joinHyphenCase(...args: string[]): string;
|
|
208
293
|
/**
|
|
209
294
|
*
|
|
210
|
-
*
|
|
295
|
+
* The debounce function is used to create a debounced function that delays the
|
|
211
296
|
*
|
|
212
|
-
*
|
|
297
|
+
* execution of a given function until a specified wait time, in milliseconds, has
|
|
213
298
|
*
|
|
214
|
-
*
|
|
299
|
+
* elapsed since the last time it was invoked.
|
|
215
300
|
*
|
|
216
301
|
* @example
|
|
217
302
|
*
|
|
@@ -226,9 +311,15 @@ export function joinHyphenCase(...args: string[]): string;
|
|
|
226
311
|
export function debounce<F extends Function>(func: F, delay?: number): F;
|
|
227
312
|
/**
|
|
228
313
|
*
|
|
229
|
-
*
|
|
314
|
+
* The hasPermission function checks whether the current user has a specific
|
|
315
|
+
*
|
|
316
|
+
* permission. It returns true if the user has the specified permission and
|
|
317
|
+
*
|
|
318
|
+
* false if they do not. Permissions are typically used to control access to
|
|
319
|
+
*
|
|
320
|
+
* various features or actions within an application. The permissions corresponding
|
|
230
321
|
*
|
|
231
|
-
*
|
|
322
|
+
* to a particular user is taken from the globalProps.
|
|
232
323
|
*
|
|
233
324
|
* @example
|
|
234
325
|
*
|
|
@@ -238,11 +329,13 @@ export function debounce<F extends Function>(func: F, delay?: number): F;
|
|
|
238
329
|
export function hasPermission(permission: string): boolean;
|
|
239
330
|
/**
|
|
240
331
|
*
|
|
241
|
-
*
|
|
332
|
+
* The hasAnyPermission function checks whether the current user has any of the
|
|
242
333
|
*
|
|
243
|
-
*
|
|
334
|
+
* specified permissions. It returns true if the user has at least one of the
|
|
244
335
|
*
|
|
245
|
-
* permissions.
|
|
336
|
+
* permissions and false if the user has none of them. The permissions
|
|
337
|
+
*
|
|
338
|
+
* corresponding to a particular user is taken from the globalProps.
|
|
246
339
|
*
|
|
247
340
|
* permissions: Any number of permission strings.
|
|
248
341
|
*
|
|
@@ -254,11 +347,13 @@ export function hasPermission(permission: string): boolean;
|
|
|
254
347
|
export function hasAnyPermission(...permissions: string[]): boolean;
|
|
255
348
|
/**
|
|
256
349
|
*
|
|
257
|
-
*
|
|
350
|
+
* The hasAllPermissions function checks whether the current user has all of the
|
|
351
|
+
*
|
|
352
|
+
* specified permissions. It returns true if the user has all the permissions and
|
|
258
353
|
*
|
|
259
|
-
*
|
|
354
|
+
* false otherwise. The permissions corresponding to a particular user is taken
|
|
260
355
|
*
|
|
261
|
-
*
|
|
356
|
+
* from the globalProps.
|
|
262
357
|
*
|
|
263
358
|
* permissions: Any number of permission strings.
|
|
264
359
|
*
|
|
@@ -274,11 +369,15 @@ type ChannelNameWithParams = {
|
|
|
274
369
|
};
|
|
275
370
|
/**
|
|
276
371
|
*
|
|
277
|
-
*
|
|
372
|
+
* The createSubscription function is used to create a subscription in a web
|
|
373
|
+
*
|
|
374
|
+
* application where a consumer subscribes to a Rails
|
|
278
375
|
*
|
|
279
|
-
*
|
|
376
|
+
* Action Cable
|
|
280
377
|
*
|
|
281
|
-
*
|
|
378
|
+
* channel. This function facilitates the creation of subscriptions on the client
|
|
379
|
+
*
|
|
380
|
+
* side to listen for updates and events broadcasted on a specific channel.
|
|
282
381
|
*
|
|
283
382
|
* @example
|
|
284
383
|
*
|
|
@@ -294,11 +393,13 @@ type ChannelNameWithParams = {
|
|
|
294
393
|
export function createSubscription(channelName: string | ChannelNameWithParams, callbacks: Mixin): Subscription;
|
|
295
394
|
/**
|
|
296
395
|
*
|
|
297
|
-
*
|
|
396
|
+
* The getFromLocalStorage function retrieves a JSON-parsed value from the
|
|
397
|
+
*
|
|
398
|
+
* browser's localStorage for the specified key. If the stored value is not valid
|
|
298
399
|
*
|
|
299
|
-
*
|
|
400
|
+
* JSON or if the key does not exist in localStorage, the function returns
|
|
300
401
|
*
|
|
301
|
-
*
|
|
402
|
+
* null.
|
|
302
403
|
*
|
|
303
404
|
* @example
|
|
304
405
|
*
|
package/utils.js
CHANGED
|
@@ -2648,6 +2648,10 @@ var getFromLocalStorage = function getFromLocalStorage(key) {
|
|
|
2648
2648
|
|
|
2649
2649
|
dayjs.extend(relativeTime);
|
|
2650
2650
|
dayjs.extend(updateLocale);
|
|
2651
|
+
var getDefaultFormat = function getDefaultFormat() {
|
|
2652
|
+
var _globalProps$user$dat, _globalProps, _globalProps$user;
|
|
2653
|
+
return (_globalProps$user$dat = (_globalProps = globalProps) === null || _globalProps === void 0 ? void 0 : (_globalProps$user = _globalProps.user) === null || _globalProps$user === void 0 ? void 0 : _globalProps$user.dateFormat) !== null && _globalProps$user$dat !== void 0 ? _globalProps$user$dat : "DD/MM/YYYY";
|
|
2654
|
+
};
|
|
2651
2655
|
var timeFormat = {
|
|
2652
2656
|
fromNow: function fromNow(time) {
|
|
2653
2657
|
return dayjs(time).fromNow();
|
|
@@ -2691,8 +2695,10 @@ var timeFormat = {
|
|
|
2691
2695
|
return "".concat(dateTime, " (").concat(fromNow, ")");
|
|
2692
2696
|
},
|
|
2693
2697
|
"default": function _default(time) {
|
|
2694
|
-
|
|
2695
|
-
|
|
2698
|
+
return dayjs(time).format(getDefaultFormat());
|
|
2699
|
+
},
|
|
2700
|
+
defaultWithTime: function defaultWithTime(time) {
|
|
2701
|
+
return dayjs(time).format("".concat(getDefaultFormat(), " hh:mm:ss A"));
|
|
2696
2702
|
}
|
|
2697
2703
|
};
|
|
2698
2704
|
var dateFormat = timeFormat;
|