nitro-web 0.0.39 → 0.0.41

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/types/util.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Returns an address monastery schema which Google autocomplete should return
3
+ */
1
4
  export function addressSchema(): {
2
5
  city: {
3
6
  type: string;
@@ -42,139 +45,645 @@ export function addressSchema(): {
42
45
  type: string;
43
46
  default: string;
44
47
  };
45
- coordinates: any;
48
+ coordinates: [];
46
49
  };
47
50
  };
48
- export function axios(): import("@hokify/axios").AxiosStatic;
49
- export function buildUrl(url: any, parameters: any): string;
50
- export function camelCase(str: any, capitaliseFirst: any, allowNumber: any): any;
51
- export function camelCaseToTitle(str: any, captialiseFirstOnly: any): any;
52
- export function camelCaseToHypen(str: any): any;
53
- export function capitalise(str: any): any;
54
- export function currency(cents: any, decimals: number, decimalsMinimum: any): string;
55
- export function currencyToCents(currency: any): string;
56
- export function date(date: any, format: any, timezone: any): any;
57
- export function debounce(func: any, wait: any, options: any): {
58
- (...args: any[]): any;
51
+ /**
52
+ * Returns an axios instance
53
+ * @returns {import('axios').AxiosStatic}
54
+ */
55
+ export function axios(): import("axios").AxiosStatic;
56
+ /**
57
+ * Builds the url with params
58
+ * @param {string} url
59
+ * @param {{[key: string]: string}} parameters - Key value parameters
60
+ * @returns {string}, e.g. 'https://example.com?param1=value1&param2=value2'
61
+ */
62
+ export function buildUrl(url: string, parameters: {
63
+ [key: string]: string;
64
+ }): string;
65
+ /**
66
+ * Converts a string to camel case
67
+ * @param {string} str
68
+ * @param {boolean} [capitaliseFirst] - Capitalise the first letter
69
+ * @param {boolean} [allowNumber] - Allow numbers
70
+ * @returns {string}
71
+ */
72
+ export function camelCase(str: string, capitaliseFirst?: boolean, allowNumber?: boolean): string;
73
+ /**
74
+ * Converts camel case to title case
75
+ * @param {string} str
76
+ * @param {boolean} [captialiseFirstOnly] - Capitalise the first letter only
77
+ * @returns {string}
78
+ */
79
+ export function camelCaseToTitle(str: string, captialiseFirstOnly?: boolean): string;
80
+ /**
81
+ * Converts camel case to hypen case
82
+ * @param {string} str
83
+ * @returns {string}
84
+ */
85
+ export function camelCaseToHypen(str: string): string;
86
+ /**
87
+ * Capitalises a string
88
+ * @param {string} [str]
89
+ * @returns {string}
90
+ */
91
+ export function capitalise(str?: string): string;
92
+ /**
93
+ * Formats a currency string
94
+ * @param {number} cents
95
+ * @param {number} [decimals=2]
96
+ * @param {number} [decimalsMinimum]
97
+ * @returns {string}
98
+ */
99
+ export function currency(cents: number, decimals?: number, decimalsMinimum?: number): string;
100
+ /**
101
+ * Converts a currency string to cents
102
+ * @param {string} currency string, e.g. '$1,234.00'
103
+ * @returns {string}
104
+ */
105
+ export function currencyToCents(currency: string): string;
106
+ /**
107
+ * Returns a formatted date string
108
+ * @param {number|Date} date - number can be in seconds or milliseconds (UTC)
109
+ * @param {string} [format] - e.g. "dd mmmm yy" (https://github.com/felixge/node-dateformat#mask-options)
110
+ * @param {string} [timezone] - convert a UTC date to a particular timezone.
111
+ * @returns {string}
112
+ *
113
+ * Note on the timezone conversion:
114
+ * Timezone conversion relies on parsing the toLocaleString result, e.g. 4/10/2012, 5:10:30 PM.
115
+ * A older browser may not accept en-US formatted date string to its Date constructor, and it may
116
+ * return unexpected result (it may ignore daylight saving).
117
+ */
118
+ export function date(date: number | Date, format?: string, timezone?: string): string;
119
+ /**
120
+ * Creates a debounced function that delays invoking `func` until after `wait`
121
+ * milliseconds have elapsed since the last time the debounced function was invoked.
122
+ *
123
+ * @param {Function} func - The function to debounce.
124
+ * @param {number} [wait=0] - Number of milliseconds to delay.
125
+ * @param {{
126
+ * leading?: boolean, // invoke on the leading edge of the timeout (default: false)
127
+ * maxWait?: number, // maximum time `func` is allowed to be delayed before it's invoked
128
+ * trailing?: boolean, // invoke on the trailing edge of the timeout (default: true)
129
+ * }} [options] - Options to control behavior.
130
+ * @returns {(...args: any[]) => any & {
131
+ * cancel: () => void,
132
+ * flush: () => any
133
+ * }} - A new debounced function with `cancel` and `flush` methods.
134
+ *
135
+ * @see https://lodash.com/docs/4.17.15#debounce
136
+ */
137
+ export function debounce(func: Function, wait?: number, options?: {
138
+ leading?: boolean;
139
+ maxWait?: number;
140
+ trailing?: boolean;
141
+ }): (...args: any[]) => any & {
59
142
  cancel: () => void;
60
143
  flush: () => any;
61
144
  };
62
- export function deepCopy(obj: any): any;
63
- export function deepFind(obj: any, path: any): any;
64
- export function deepSave(obj: any, path: any, value: any): any;
65
- export function each(obj: any, iteratee: any, context: any): any;
66
- export function fileDownload(data: any, filename: any, mime: any, bom: any): void;
67
- export function formatName(string: any, ignoreHyphen: any): any;
68
- export function formatSlug(string: any): any;
69
- export function formData(obj: any, cfg: any, fd: any, pre: any): any;
70
- export function fullName(object: any): string;
71
- export function fullNameSplit(string: any): any[];
72
- export function getCountryOptions(countries: any): {
145
+ /**
146
+ * Deep clones an object or array, preserving its type
147
+ * @template T
148
+ * @param {T} obj - Object or array to deep clone
149
+ * @returns {T}
150
+ */
151
+ export function deepCopy<T>(obj: T): T;
152
+ /**
153
+ * Retrieves a nested value from an object or array from a dot-separated path.
154
+ * @param {object|any[]} obj - The source object or array.
155
+ * @param {string} path - Dot-separated path (e.g. "owner.houses.0.color").
156
+ * @returns {unknown}
157
+ */
158
+ export function deepFind(obj: object | any[], path: string): unknown;
159
+ /**
160
+ * Saves a deeply nested value without mutating the original object.
161
+ * @template T
162
+ * @param {T} obj - The source object or array.
163
+ * @param {string} path - Dot-separated path to the nested property.
164
+ * @param {unknown|function} value - The value to set, or a function to compute it from the current value.
165
+ * @returns {T}
166
+ */
167
+ export function deepSave<T>(obj: T, path: string, value: unknown | Function): T;
168
+ /**
169
+ * Iterates over an object or array
170
+ * @param {{[key: string]: any}|[]|null} obj
171
+ * @param {function} iteratee
172
+ * @param {object} [context]
173
+ * @returns {object|[]|null}
174
+ */
175
+ export function each(obj: {
176
+ [key: string]: any;
177
+ } | [] | null, iteratee: Function, context?: object): object | [] | null;
178
+ /**
179
+ * Downloads a file
180
+ * @param {string|Blob|File} data
181
+ * @param {string} filename
182
+ * @param {string} [mime]
183
+ * @param {string} [bom]
184
+ * @returns {void}
185
+ *
186
+ * @link https://github.com/kennethjiang/js-file-download
187
+ */
188
+ export function fileDownload(data: string | Blob | File, filename: string, mime?: string, bom?: string): void;
189
+ /**
190
+ * Formats a string into a name
191
+ * @param {string} string
192
+ * @param {boolean} [ignoreHyphen]
193
+ * @returns {string}
194
+ */
195
+ export function formatName(string: string, ignoreHyphen?: boolean): string;
196
+ /**
197
+ * Formats a string into a slug
198
+ * @param {string} string
199
+ * @returns {string}
200
+ */
201
+ export function formatSlug(string: string): string;
202
+ /**
203
+ * Serializes objects to FormData instances
204
+ * @param {object} obj
205
+ * @param {{ allowEmptyArrays?: boolean, indices?: boolean, nullsAsUndefineds?: boolean, booleansAsIntegers?: boolean }} [cfg] - config
206
+ * @param {FormData} [existingFormData]
207
+ * @param {string} [keyPrefix]
208
+ * @returns {FormData}
209
+ * @link https://github.com/therealparmesh/object-to-formdata
210
+ */
211
+ export function formData(obj: object, cfg?: {
212
+ allowEmptyArrays?: boolean;
213
+ indices?: boolean;
214
+ nullsAsUndefineds?: boolean;
215
+ booleansAsIntegers?: boolean;
216
+ }, existingFormData?: FormData, keyPrefix?: string): FormData;
217
+ /**
218
+ * Returns capitalized full name
219
+ * @param {{firstName: string, lastName: string}} object
220
+ * @returns {string}
221
+ */
222
+ export function fullName(object: {
223
+ firstName: string;
224
+ lastName: string;
225
+ }): string;
226
+ /**
227
+ * Splits a full name into first and last names
228
+ * @param {string} string
229
+ * @returns {string[]} e.g. ['John', 'Smith']
230
+ */
231
+ export function fullNameSplit(string: string): string[];
232
+ /**
233
+ * Returns a list of country options
234
+ * @param {{ [key: string]: { name: string } }} countries
235
+ * @returns {{ value: string, label: string, flag: string }[]}
236
+ */
237
+ export function getCountryOptions(countries: {
238
+ [key: string]: {
239
+ name: string;
240
+ };
241
+ }): {
73
242
  value: string;
74
- label: any;
243
+ label: string;
75
244
  flag: string;
76
245
  }[];
77
- export function getCurrencyOptions(currencies: any): {
246
+ /**
247
+ * Returns a list of currency options
248
+ * @param {{ [iso: string]: { name: string } }} currencies
249
+ * @returns {{ value: string, label: string }[]}
250
+ */
251
+ export function getCurrencyOptions(currencies: {
252
+ [iso: string]: {
253
+ name: string;
254
+ };
255
+ }): {
78
256
  value: string;
79
- label: any;
257
+ label: string;
80
258
  }[];
81
259
  /**
82
260
  * Get the width of a prefix
83
261
  * @param {string} prefix
84
- * @param {number} paddingRight
262
+ * @param {number} [paddingRight=0]
85
263
  * @returns {number}
86
264
  */
87
265
  export function getPrefixWidth(prefix: string, paddingRight?: number): number;
88
- export function getDirectories(path: any, pwd: any): {
89
- clientDir: any;
90
- componentsDir: any;
91
- distDir: any;
92
- emailTemplateDir: any;
93
- imgsDir: any;
94
- tmpDir: any;
95
- };
96
- export function getLink(obj: any, query: any): string;
97
- export function getStripeClientPromise(stripePublishableKey: any): any;
98
- export function getResponseErrors(errs: any): any;
99
- export function inArray(array: any, key: any, value: any): any;
100
- export function isArray(variable: any): variable is any[];
101
- export function isDate(variable: any): boolean;
102
- export function isDefined(variable: any): boolean;
103
- export function isEmail(email: any): boolean;
104
- export function isEmpty(obj: any, truthyValuesOnly: any): boolean;
105
- export function isFunction(variable: any): boolean;
106
- export function isHex24(value: any): boolean;
107
- export function isNumber(variable: any): boolean;
266
+ /**
267
+ * Returns a list of project directories
268
+ * @param {{ join: (...args: string[]) => string }} path - e.g. `import path from 'path'`
269
+ * @param {string} [pwd]
270
+ * @returns {object}
271
+ */
272
+ export function getDirectories(path: {
273
+ join: (...args: string[]) => string;
274
+ }, pwd?: string): object;
275
+ /**
276
+ * Returns a Stripe client promise
277
+ * @param {string} stripePublishableKey
278
+ * @returns {Promise<import('@stripe/stripe-js').Stripe|null>}
279
+ */
280
+ export function getStripeClientPromise(stripePublishableKey: string): Promise<import("@stripe/stripe-js").Stripe | null>;
281
+ /**
282
+ * Returns a list of response errors
283
+ *
284
+ * @typedef {{ title: string, detail: string }} NitroError
285
+ * @typedef {{ toJSON: () => { message: string } }} MongoError
286
+ * @typedef {{ response: { data: { errors?: NitroError[], error?: string, error_description?: string } } }} AxiosWithErrors
287
+ *
288
+ * @typedef {Error|NitroError[]|MongoError|AxiosWithErrors|string|any} NitroErrorRaw
289
+ *
290
+ * @param {NitroErrorRaw} errs
291
+ * @returns {NitroError[]}
292
+ */
293
+ export function getResponseErrors(errs: NitroErrorRaw): NitroError[];
294
+ /**
295
+ * Checks if a value is in an array (todo, update this to not use optional key)
296
+ * @param {any[]} array
297
+ * @param {unknown} [value]
298
+ * @param {string} [key] - optional, to match across on a colleciton of objects
299
+ * @returns {boolean}
300
+ */
301
+ export function inArray(array: any[], value?: unknown, key?: string): boolean;
302
+ /**
303
+ * Checks if a variable is an array
304
+ * @param {unknown} variable
305
+ * @returns {boolean}
306
+ */
307
+ export function isArray(variable: unknown): boolean;
308
+ /**
309
+ * Checks if a variable is a date
310
+ * @param {unknown} variable
311
+ * @returns {boolean}
312
+ */
313
+ export function isDate(variable: unknown): boolean;
314
+ /**
315
+ * Checks if a variable is defined
316
+ * @param {unknown} variable
317
+ * @returns {boolean}
318
+ */
319
+ export function isDefined(variable: unknown): boolean;
320
+ /**
321
+ * Checks if a variable is an email
322
+ * @param {string} email
323
+ * @returns {boolean}
324
+ */
325
+ export function isEmail(email: string): boolean;
326
+ /**
327
+ * Checks if an object is empty
328
+ * @param {{[key: string]: unknown}|null} [obj]
329
+ * @param {boolean} [truthyValuesOnly]
330
+ * @returns {boolean}
331
+ */
332
+ export function isEmpty(obj?: {
333
+ [key: string]: unknown;
334
+ } | null, truthyValuesOnly?: boolean): boolean;
335
+ /**
336
+ * Checks if a variable is a function
337
+ * @param {unknown} variable
338
+ * @returns {boolean}
339
+ */
340
+ export function isFunction(variable: unknown): boolean;
341
+ /**
342
+ * Checks if a variable is a hex string
343
+ * @param {unknown} value
344
+ * @returns {boolean}
345
+ */
346
+ export function isHex24(value: unknown): boolean;
347
+ /**
348
+ * Checks if a variable is a number
349
+ * @param {unknown} variable
350
+ * @returns {boolean}
351
+ */
352
+ export function isNumber(variable: unknown): boolean;
108
353
  /**
109
354
  * Checks if a variable is an object
110
355
  * @param {unknown} variable
111
356
  * @returns {boolean}
112
357
  */
113
358
  export function isObject(variable: unknown): boolean;
114
- export function isRegex(variable: any): boolean;
115
- export function isString(variable: any): boolean;
116
- export function lcFirst(string: any): any;
117
- export function maxLength(string: any, len: any, showEllipsis: any): any;
118
- export function mongoAddKmsToBox(km: any, bottomLeft: any, topRight: any): any[][];
119
- export function mongoDocWithinPassedAddress(address: any, km: any, prefix: any): {
120
- $geoNear: {
121
- near: {
122
- type: string;
123
- coordinates: any[];
124
- };
125
- distanceField: string;
126
- maxDistance: number;
127
- spherical: boolean;
128
- };
129
- } | {
130
- [x: string]: {
131
- $geoWithin: {
132
- $box: any[][];
133
- };
359
+ /**
360
+ * Checks if a variable is a regex
361
+ * @param {unknown} variable
362
+ * @returns {boolean}
363
+ */
364
+ export function isRegex(variable: unknown): boolean;
365
+ /**
366
+ * Checks if a variable is a string
367
+ * @param {unknown} variable
368
+ * @returns {boolean}
369
+ */
370
+ export function isString(variable: unknown): boolean;
371
+ /**
372
+ * Converts the first character of a string to lowercase
373
+ * @param {string} string
374
+ * @returns {string}
375
+ */
376
+ export function lcFirst(string: string): string;
377
+ /**
378
+ * Trims a string to a maximum length, and removes any partial words at the end
379
+ * @param {string} string
380
+ * @param {number} [len=100]
381
+ * @param {boolean} [showEllipsis=true]
382
+ * @returns {string}
383
+ */
384
+ export function maxLength(string: string, len?: number, showEllipsis?: boolean): string;
385
+ /**
386
+ * Expands a mongodb lng/lat box in kms, and returns the expanded box
387
+ * @typedef {[number, number]} Point - lng/lat
388
+ * @typedef {{bottomLeft: Point, topRight: Point}} Box
389
+ *
390
+ * @param {number} km
391
+ * @param {Point|Box} bottomLeftOrBox
392
+ * @param {Point} [topRight]
393
+ * @returns {[Point, Point]|null} (e.g. [bottomLeft, topRight])
394
+ *
395
+ * Handy box tester
396
+ * https://www.keene.edu/campus/maps/tool/
397
+ *
398
+ * Returned Google places viewport (i.e. `place.geometry.viewport`)
399
+ * {
400
+ * Qa: {g: 174.4438160493033, h: 174.9684260722261} == [btmLng, topLng]
401
+ * zb: {g: -37.05901990116617, h: -36.66060184426172} == [btmLat, topLat]
402
+ * }
403
+ *
404
+ * We then convert above into `address.area.bottomLeft|topRight`
405
+ *
406
+ * Rangiora box
407
+ * [[172.5608731356091,-43.34484397837406] (btm left)
408
+ * [172.6497429548984,-43.28025140057695]] (top right)
409
+ *
410
+ * Auckland box
411
+ * [[174.4438160493033,-37.05901990116617] (btm left)
412
+ * [174.9684260722261,-36.66060184426172]] (top right)
413
+ */
414
+ export function mongoAddKmsToBox(km: number, bottomLeftOrBox: Point | Box, topRight?: Point): [Point, Point] | null;
415
+ /**
416
+ * Returns a mongo query to find documents within a passed address
417
+ * @param {{
418
+ * area?: {bottomLeft: [number, number], topRight: [number, number]}
419
+ * location?: {coordinates: [number, number]}
420
+ * }} address
421
+ * @param {number} km
422
+ * @param {string} prefix
423
+ * @returns {Object}
424
+ */
425
+ export function mongoDocWithinPassedAddress(address: {
426
+ area?: {
427
+ bottomLeft: [number, number];
428
+ topRight: [number, number];
134
429
  };
135
- $geoNear?: undefined;
136
- } | {
137
- [x: string]: {
138
- $geoWithin: {
139
- $centerSphere: (number | any[])[];
140
- };
430
+ location?: {
431
+ coordinates: [number, number];
141
432
  };
142
- $geoNear?: undefined;
433
+ }, km: number, prefix: string): any;
434
+ /**
435
+ * Find the distance in km between to points
436
+ * @param {number[]} point1 - [lng, lat] ([192.2132.., 212.23323..])
437
+ * @param {number[]} point2 - [lng, lat] ([192.2132.., 212.23323..])
438
+ * @return {number} kms
439
+ */
440
+ export function mongoPointDifference(point1: number[], point2: number[]): number;
441
+ /**
442
+ * Maps over an object
443
+ * @param {{ [key: string]: any }} object
444
+ * @param {(value: any, key: string) => any} fn
445
+ */
446
+ export function objectMap(object: {
447
+ [key: string]: any;
448
+ }, fn: (value: any, key: string) => any): {
449
+ [key: string]: any;
450
+ };
451
+ /**
452
+ * Omits fields from an object
453
+ * @param {{ [key: string]: unknown }} obj
454
+ * @param {string[]} fields
455
+ * @returns {{ [key: string]: unknown }}
456
+ */
457
+ export function omit(obj: {
458
+ [key: string]: unknown;
459
+ }, fields: string[]): {
460
+ [key: string]: unknown;
143
461
  };
144
- export function mongoPointDifference(point1: any, point2: any): string;
145
- export function objectMap(object: any, fn: any): {};
146
- export function omit(obj: any, fields: any): any;
147
462
  /**
148
463
  * Updates state from an input event, you can also update deep state properties
149
- * @param {Event|Array[{string},{string|number|fn}]}
150
- * {Event} - pass the event object e.g. <input onChange={(e) => onChange.call(setState, e)}>
151
- * {Array} - pass an array with [path, value] e.g. <input onChange={(e) => onChange.call(setState, e, ['name', 'Joe'])}>
464
+ * @param {(
465
+ * ChangeEvent | // e.g. <input onChange={(e) => onChange.call(setState, e)}>
466
+ * PathValue // e.g. <input onChange={(e) => onChange.call(setState, e, ['address.name', 'Joe'])}> // [id, value]
467
+ * )} eventOrPathValue
152
468
  * @param {Function} [beforeSetState] - optional function to run before setting the state
153
- * @this {Function} setState
154
- * @return {Promise({state, chunks, target})}
155
- */
156
- export function onChange(this: Function, event: any, beforeSetState?: Function): Promise<any>;
157
- export function pad(num: any, padLeft: any, fixedRight: any): any;
158
- export function pick(obj: any, keys: any): {};
159
- export function queryObject(search: any, assignTrue: any): any;
160
- export function queryString(obj: any): string;
161
- export function request(route: any, data: any, event: any, isLoading: any): Promise<any>;
162
- export function removeUndefined(variable: any): any;
163
- export function s3Image(awsUrl: any, image: any, size: string, i: any): any;
164
- export function sanitizeHTML(string: any): string;
165
- export function scrollbar(paddingClass: any, marginClass: any, maxWidth: any): any;
166
- export function secondsToTime(seconds: any, padMinute: any): string;
167
- export function setTimeoutPromise(func: any, milliseconds: any): Promise<any>;
168
- export function showError(setStore: any, errs: any): void;
169
- export function sortByKey(objects: any, key: any): any;
170
- export function sortFromQuery(req: any, sortMap: any, sortByDefault?: string): any;
171
- export function throttle(func: any, wait: any, options: any): {
172
- (...args: any[]): any;
173
- cancel: () => void;
174
- flush: () => any;
469
+ * @returns {Promise<object>}
470
+ * @this {function}
471
+ *
472
+ * @typedef {import('react').ChangeEvent} ChangeEvent
473
+ * @typedef {[
474
+ * string, // can be a path (e.g. 'name.first')
475
+ * function|unknown, // value or function to set the value to
476
+ * ]} PathValue
477
+ */
478
+ export function onChange(this: Function, eventOrPathValue: (ChangeEvent | // e.g. <input onChange={(e) => onChange.call(setState, e)}>
479
+ PathValue), beforeSetState?: Function): Promise<object>;
480
+ /**
481
+ * Pads a number
482
+ * @param {number} [num=0]
483
+ * @param {number} [padLeft=0]
484
+ * @param {number} [fixedRight]
485
+ * @returns {string}
486
+ */
487
+ export function pad(num?: number, padLeft?: number, fixedRight?: number): string;
488
+ /**
489
+ * Picks fields from an object
490
+ * @param {{ [key: string]: any }} obj
491
+ * @param {string|RegExp|string[]|RegExp[]} keys
492
+ */
493
+ export function pick(obj: {
494
+ [key: string]: any;
495
+ }, keys: string | RegExp | string[] | RegExp[]): {
496
+ [key: string]: unknown;
497
+ };
498
+ /**
499
+ *
500
+ * Parses a query string into an object, or returns the last known matching cache
501
+ * @param {string} searchString - location.search or location.href, e.g. '?page=1', 'https://...co.nz?page=1'
502
+ * @param {boolean} [trueDefaults] - assign true to empty values
503
+ * @returns {{[key: string]: string|true}} - e.g. { page: '1' }
504
+ * UPDATE: removed array values, e.g. '?page=1&page=2' will return { page: '2' }
505
+ */
506
+ export function queryObject(searchString: string, trueDefaults?: boolean): {
507
+ [key: string]: string | true;
508
+ };
509
+ /**
510
+ * Parses an object and returns a query string
511
+ * @param {{[key: string]: unknown}} [obj] - query object
512
+ * @returns {string}
513
+ */
514
+ export function queryString(obj?: {
515
+ [key: string]: unknown;
516
+ }): string;
517
+ /**
518
+ * Axios request to the route
519
+ * @param {string} route - e.g. 'post /api/user'
520
+ * @param {{ [key: string]: any }} [data] - payload
521
+ * @param {{preventDefault?: function}} [event] - event to prevent default
522
+ * @param {[boolean, (value: boolean) => void]} [isLoading] - [isLoading, setIsLoading]
523
+ * @returns {Promise<any>}
524
+ */
525
+ export function request(route: string, data?: {
526
+ [key: string]: any;
527
+ }, event?: {
528
+ preventDefault?: Function;
529
+ }, isLoading?: [boolean, (value: boolean) => void]): Promise<any>;
530
+ /**
531
+ * Removes undefined from an array or object
532
+ * @param {[]|{[key: string]: any}} variable
533
+ * @returns {[]|{[key: string]: any}}
534
+ */
535
+ export function removeUndefined(variable: [] | {
536
+ [key: string]: any;
537
+ }): [] | {
538
+ [key: string]: any;
539
+ };
540
+ /**
541
+ * Build image URL from image array or object
542
+ * @typedef {{path: string, bucket: string, base64?: string, date?: number}} Image
543
+ * @param {string} awsUrl - e.g. 'https://s3.amazonaws.com/...'
544
+ * @param {Image[]|Image} imageOrArray - file object/array
545
+ * @param {string} [size] - overrides to 'full' when the image sizes are still processing
546
+ * @param {number} [i] - array index
547
+ * @returns {string}
548
+ */
549
+ export function s3Image(awsUrl: string, imageOrArray: Image[] | Image, size?: string, i?: number): string;
550
+ /**
551
+ * Sanitize and encode all HTML in a user-submitted string
552
+ * @param {string} string
553
+ * @returns {string}
554
+ */
555
+ export function sanitizeHTML(string: string): string;
556
+ /**
557
+ * Process scrollbar width once.
558
+ * @param {string} paddingClass - class name to give padding to
559
+ * @param {string} marginClass - class name to give margin to
560
+ * @param {number} maxWidth - enclose css in a max-width media query
561
+ * @returns {number}
562
+ *
563
+ */
564
+ export function scrollbar(paddingClass: string, marginClass: string, maxWidth: number): number;
565
+ /**
566
+ * Convert seconds to time
567
+ * @param {number} seconds
568
+ * @param {boolean} [padMinute]
569
+ * @returns {string}
570
+ */
571
+ export function secondsToTime(seconds: number, padMinute?: boolean): string;
572
+ /**
573
+ * Promise wrapper for setTimeout
574
+ * @param {function} func
575
+ * @param {number} milliseconds
576
+ * @returns {Promise<void>}
577
+ */
578
+ export function setTimeoutPromise(func: Function, milliseconds: number): Promise<void>;
579
+ /**
580
+ * Shows a global error
581
+ * @param {function} setStore
582
+ * @param {NitroErrorRaw} errs
583
+ */
584
+ export function showError(setStore: Function, errs: NitroErrorRaw): void;
585
+ /**
586
+ * Sort an array of objects by a key
587
+ * @param {{[key: string]: any}[]} collection
588
+ * @param {string} key
589
+ * @returns {object[]}
590
+ */
591
+ export function sortByKey(collection: {
592
+ [key: string]: any;
593
+ }[], key: string): object[];
594
+ /**
595
+ * Creates a throttled function that only invokes `func` at most once per every `wait` milliseconds
596
+ * @param {function} func
597
+ * @param {number} [wait=0] - the number of milliseconds to throttle invocations to
598
+ * @param {{
599
+ * leading?: boolean, // invoke on the leading edge of the timeout
600
+ * trailing?: boolean, // invoke on the trailing edge of the timeout
601
+ * }} [options] - options object
602
+ * @returns {function}
603
+ * @example const throttled = util.throttle(updatePosition, 100)
604
+ * @see lodash
605
+ */
606
+ export function throttle(func: Function, wait?: number, options?: {
607
+ leading?: boolean;
608
+ trailing?: boolean;
609
+ }): Function;
610
+ /**
611
+ * Convert a variable to an array, if not already an array.
612
+ * @template T
613
+ * @param {T | undefined} variable
614
+ * @returns {(T extends any[] ? T : T[])}
615
+ */
616
+ export function toArray<T>(variable: T | undefined): (T extends any[] ? T : T[]);
617
+ /**
618
+ * Trim a string and replace multiple newlines with double newlines
619
+ * @param {string} string
620
+ * @returns {string}
621
+ */
622
+ export function trim(string: string): string;
623
+ /**
624
+ * Capitalize the first letter of a string
625
+ * @param {string} string
626
+ * @returns {string}
627
+ */
628
+ export function ucFirst(string: string): string;
629
+ /**
630
+ * Returns a list of response errors
631
+ */
632
+ export type NitroError = {
633
+ title: string;
634
+ detail: string;
635
+ };
636
+ /**
637
+ * Returns a list of response errors
638
+ */
639
+ export type MongoError = {
640
+ toJSON: () => {
641
+ message: string;
642
+ };
643
+ };
644
+ /**
645
+ * Returns a list of response errors
646
+ */
647
+ export type AxiosWithErrors = {
648
+ response: {
649
+ data: {
650
+ errors?: NitroError[];
651
+ error?: string;
652
+ error_description?: string;
653
+ };
654
+ };
655
+ };
656
+ /**
657
+ * Returns a list of response errors
658
+ */
659
+ export type NitroErrorRaw = Error | NitroError[] | MongoError | AxiosWithErrors | string | any;
660
+ /**
661
+ * - lng/lat
662
+ */
663
+ export type Point = [number, number];
664
+ /**
665
+ * Expands a mongodb lng/lat box in kms, and returns the expanded box
666
+ */
667
+ export type Box = {
668
+ bottomLeft: Point;
669
+ topRight: Point;
670
+ };
671
+ /**
672
+ * Updates state from an input event, you can also update deep state properties
673
+ */
674
+ export type ChangeEvent = import("react").ChangeEvent;
675
+ /**
676
+ * Updates state from an input event, you can also update deep state properties
677
+ */
678
+ export type PathValue = [string, // can be a path (e.g. 'name.first')
679
+ Function | unknown];
680
+ /**
681
+ * Build image URL from image array or object
682
+ */
683
+ export type Image = {
684
+ path: string;
685
+ bucket: string;
686
+ base64?: string;
687
+ date?: number;
175
688
  };
176
- export function toArray(variable: any): any[];
177
- export function trim(string: any): any;
178
- export function ucFirst(string: any): any;
179
- export const dateFormat: any;
180
689
  //# sourceMappingURL=util.d.ts.map