@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/utils.d.ts CHANGED
@@ -1,65 +1,189 @@
1
1
  import dayjs from "dayjs";
2
2
  import React from "react";
3
-
4
3
  export function resetAuthTokens(): void;
5
-
6
- export function withEventTargetValue(
7
- func: (value: string) => void,
8
- event: React.ChangeEventHandler<HTMLInputElement>
9
- ): void;
10
-
11
- export function withEventTargetValue(
12
- func: (value: string) => void
13
- ): (event: React.ChangeEventHandler<HTMLInputElement>) => void;
14
-
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
+ */
15
60
  export function getSubdomain(): string;
16
-
17
- export function simulateApiCall<T>(
18
- result: T,
19
- error?: any,
20
- errorProbability?: number,
21
- delayMs?: number
22
- ): Promise<T>;
23
-
24
- export function copyToClipboard(
25
- text: string,
26
- configs?: { showToastr?: boolean; message?: string }
27
- ): void;
28
-
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
+ */
29
136
  export function buildUrl(route: string, params: object): string;
30
-
31
137
  type DateTimeType = string | number | dayjs.Dayjs | Date | null | undefined;
32
-
33
138
  export const timeFormat: {
34
139
  fromNow: (time: DateTimeType) => string;
35
140
  time: (time: DateTimeType) => string;
141
+ timeWithSeconds: (time: DateTimeType) => string;
36
142
  date: (time: DateTimeType) => string;
37
143
  dateWeek: (time: DateTimeType) => string;
38
144
  dateWeekWithoutYear: (time: DateTimeType) => string;
39
145
  dateTime: (time: DateTimeType) => string;
146
+ dateTimeWithSeconds: (time: DateTimeType) => string;
40
147
  dateWeekTime: (time: DateTimeType) => string;
41
148
  extended: (time: DateTimeType) => string;
42
149
  };
43
-
44
150
  export const dateFormat: typeof timeFormat;
45
-
46
- export function toLocale(
47
- number: string | number,
48
- options?: Intl.NumberFormatOptions
49
- ): string;
50
-
151
+ /**
152
+ *
153
+ * Curried: false
154
+ *
155
+ * Converts the given number to a locale string (converts to a comma separated
156
+ *
157
+ * string). It automatically identifies the locale using globalProps. If a valid
158
+ *
159
+ * value isn't present in globalProps, it will rely on the current browser's
160
+ *
161
+ * locale.
162
+ *
163
+ * The function also accepts options, which will be forwarded to
164
+ *
165
+ * Number.prototype.toLocaleString, which can be used for additional
166
+ *
167
+ * configurations like rounding, currency, units etc.
168
+ *
169
+ * @example
170
+ *
171
+ * toLocale(1000000); // "1,000,000" when locale is "en-US"
172
+ * toLocale(1000000); // "10,00,000" when locale is "en-IN"
173
+ * toLocale(1000000.987, { maximumFractionDigits: 2 }); // "1,000,000.99"
174
+ * toLocale(1000000.987, {
175
+ * currencyDisplay: "narrowSymbol",
176
+ * style: "currency",
177
+ * currency: "INR",
178
+ * }); // "₹1,000,000.99"
179
+ * @endexample
180
+ */
181
+ export function toLocale(number: string | number, options?: Intl.NumberFormatOptions): string;
51
182
  type qsOptionsType = {
52
183
  comma?: boolean | undefined;
53
184
  delimiter?: string | RegExp | undefined;
54
185
  depth?: number | false | undefined;
55
- decoder?:
56
- | ((
57
- str: string,
58
- defaultDecoder: any,
59
- charset: string,
60
- type: "key" | "value"
61
- ) => any)
62
- | undefined;
186
+ decoder?: ((str: string, defaultDecoder: any, charset: string, type: "key" | "value") => any) | undefined;
63
187
  arrayLimit?: number | undefined;
64
188
  parseArrays?: boolean | undefined;
65
189
  allowDots?: boolean | undefined;
@@ -72,15 +196,108 @@ type qsOptionsType = {
72
196
  charsetSentinel?: boolean | undefined;
73
197
  interpretNumericEntities?: boolean | undefined;
74
198
  };
75
-
76
- type QueryParamsType = { [key: string]: any };
77
-
199
+ type QueryParamsType = {
200
+ [key: string]: any;
201
+ };
202
+ /**
203
+ *
204
+ * Curried: false
205
+ *
206
+ * This function returns all the query parameters of the current URL as an object.
207
+ *
208
+ * Usage:
209
+ *
210
+ * @example
211
+ *
212
+ * // Let the current url be "https://example.com?search=something&sort=date".
213
+ * getQueryParams();
214
+ *
215
+ * // output: { search: "something", sort: "date" }
216
+ * @endexample
217
+ */
78
218
  export function getQueryParams(options?: qsOptionsType): QueryParamsType;
79
-
219
+ /**
220
+ *
221
+ * Curried: false
222
+ *
223
+ * This function joins the given strings with hyphen.
224
+ *
225
+ * Usage:
226
+ *
227
+ * @example
228
+ *
229
+ * joinHyphenCase("hello", "world"); // output: "hello-world"
230
+ * @endexample
231
+ */
80
232
  export function joinHyphenCase(...args: string[]): string;
81
-
233
+ /**
234
+ *
235
+ * Curried: false
236
+ *
237
+ * Creates a debounced function that will execute the given function after the
238
+ *
239
+ * stated wait time in milliseconds has elapsed since the last time it was invoked.
240
+ *
241
+ * It accepts the function to be debounced as the first argument, the delay in
242
+ *
243
+ * milliseconds as the second argument.
244
+ *
245
+ * Usage:
246
+ *
247
+ * @example
248
+ *
249
+ * const searchForProducts = debounce(async key => {
250
+ * // this function will be triggered once after user stops typing for 300ms
251
+ * const products = await productsApi.fetch(key);
252
+ * // do something with the products
253
+ * }, 300);
254
+ * <input onChange={e => searchForProducts(e.target.value)} />;
255
+ * @endexample
256
+ */
82
257
  export function debounce<F extends Function>(func: F, delay?: number): F;
83
-
258
+ /**
259
+ *
260
+ * Curried: false
261
+ *
262
+ * This function will return true if the current user has the given permission.
263
+ *
264
+ * Usage:
265
+ *
266
+ * @example
267
+ *
268
+ * hasPermission("user.view_settings");
269
+ * @endexample
270
+ */
84
271
  export function hasPermission(permission: string): boolean;
272
+ /**
273
+ *
274
+ * Curried: false
275
+ *
276
+ * This function will return true if the current user has any of the given
277
+ *
278
+ * permissions.
279
+ *
280
+ * Usage:
281
+ *
282
+ * @example
283
+ *
284
+ * hasAnyPermission("user.view_settings", "user.edit_settings");
285
+ * @endexample
286
+ */
85
287
  export function hasAnyPermission(...permissions: string[]): boolean;
86
- export function hasAllPermissions(...permissions: string[]): boolean;
288
+ /**
289
+ *
290
+ * Curried: false
291
+ *
292
+ * This function will return true if the current user has all of the given
293
+ *
294
+ * permissions.
295
+ *
296
+ * Usage:
297
+ *
298
+ * @example
299
+ *
300
+ * hasAllPermissions("user.view_settings", "user.edit_settings");
301
+ * @endexample
302
+ */
303
+ export function hasAllPermissions(...permissions: string[]): boolean;