klawtil 0.17.0-rc4 → 1.0.0
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/main.d.ts +667 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +701 -24
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -1,46 +1,713 @@
|
|
|
1
|
+
/***************************************************
|
|
2
|
+
* UTILS
|
|
3
|
+
* Funções soltas de cunho geral que servem em outros locais do app
|
|
4
|
+
*
|
|
5
|
+
****************************************************/
|
|
6
|
+
/*************************************************************************
|
|
7
|
+
*
|
|
8
|
+
* TYPES
|
|
9
|
+
*/
|
|
1
10
|
type ApplyVarsOptions = {
|
|
2
11
|
start: string;
|
|
3
12
|
end: string;
|
|
4
13
|
};
|
|
14
|
+
/*************************************************************************
|
|
15
|
+
*
|
|
16
|
+
* COMPARAÇÃO DE VALORES
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Verifica se um valor é vazio, null, array vazio ou objeto vazio.
|
|
20
|
+
* Não considera 0 ou false como vazio.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
*
|
|
24
|
+
* empty('') // -> true
|
|
25
|
+
* empty(null) // -> true
|
|
26
|
+
* empty(false) // -> false
|
|
27
|
+
* empty(undefined) // -> true
|
|
28
|
+
*
|
|
29
|
+
* @param {*} value
|
|
30
|
+
* @returns {Boolean}
|
|
31
|
+
*/
|
|
5
32
|
export declare const empty: (value: any) => boolean;
|
|
33
|
+
/*************************************************************************
|
|
34
|
+
*
|
|
35
|
+
* VERIFICAÇÃO DE TIPOS
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Verifica se o valor passado é do tipo array
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
*
|
|
42
|
+
* isArray([]) // -> true
|
|
43
|
+
* isArray({}) // -> false
|
|
44
|
+
* isArray(0) // -> false
|
|
45
|
+
* isArray('claudio') // -> false
|
|
46
|
+
*
|
|
47
|
+
* @param {*} value
|
|
48
|
+
* @returns {Boolean}
|
|
49
|
+
*/
|
|
6
50
|
export declare const isArray: (value: any) => boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Verifica se o valor passado é do tipo objeto
|
|
53
|
+
*/
|
|
7
54
|
export declare const isObject: (value: any) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Verifica se o valor passado é do tipo string
|
|
57
|
+
*
|
|
58
|
+
*
|
|
59
|
+
*/
|
|
8
60
|
export declare const isString: (value: any) => boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Verifica se é um número inteiro.
|
|
63
|
+
*
|
|
64
|
+
* @examples
|
|
65
|
+
|
|
66
|
+
* isInteger('1') // -> true
|
|
67
|
+
* isInteger('1', true) // -> false
|
|
68
|
+
* isInteger(1) // -> true
|
|
69
|
+
* isInteger(1.2) // -> false
|
|
70
|
+
* isInteger(1, true) // -> true
|
|
71
|
+
* isInteger('1', true) // -> false
|
|
72
|
+
* isInteger('claudio') // -> false
|
|
73
|
+
|
|
74
|
+
*
|
|
75
|
+
* @param {Any} value: Valor que será comparado
|
|
76
|
+
* @param {Boolean} forceType: Define se deve verificar o tipo, e não apenas o número
|
|
77
|
+
*/
|
|
9
78
|
export declare const isInteger: (value: any, forceType?: boolean) => boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Verifica se é no formato de float, independente do tipo
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
*
|
|
84
|
+
* isFloat('1') // -> true
|
|
85
|
+
* isFloat(1, true) // -> true
|
|
86
|
+
* isFloat('1', true) // -> false
|
|
87
|
+
* isFloat(1) // -> true
|
|
88
|
+
* isFloat(1.2) // -> true
|
|
89
|
+
* isFloat('1.2') // -> true
|
|
90
|
+
* isFloat('1.2', true) // -> false
|
|
91
|
+
* isFloat('claudio') // -> false
|
|
92
|
+
* isFloat(false) // -> false
|
|
93
|
+
*
|
|
94
|
+
* @param {*} value
|
|
95
|
+
* @returns {Boolean} *
|
|
96
|
+
*/
|
|
10
97
|
export declare const isFloat: (value: any, forceType?: boolean) => boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Verifica se é no formato de float, independente do tipo
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
*
|
|
103
|
+
* isNumeric('1') // -> true
|
|
104
|
+
* isNumeric(1, true) // -> true
|
|
105
|
+
* isNumeric('1', true) // -> false
|
|
106
|
+
* isNumeric(1) // -> true
|
|
107
|
+
* isNumeric(1.2) // -> true
|
|
108
|
+
* isNumeric('1.2') // -> true
|
|
109
|
+
* isNumeric('1.2', true) // -> false
|
|
110
|
+
* isNumeric('claudio') // -> false
|
|
111
|
+
* isNumeric(false) // -> false
|
|
112
|
+
*
|
|
113
|
+
* @param {*} value
|
|
114
|
+
* @returns {Boolean}
|
|
115
|
+
*/
|
|
11
116
|
export declare const isNumeric: (value: any, forceType?: boolean) => boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Verifica se um dado valor é um objeto JSON
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
*
|
|
122
|
+
* isJSON( true ) // -> false
|
|
123
|
+
* isJSON( false ) // -> false
|
|
124
|
+
* isJSON( '' ) // -> false
|
|
125
|
+
* isJSON( null ) // -> false
|
|
126
|
+
* isJSON( undefined ) // -> false
|
|
127
|
+
* isJSON( NaN ) // -> false
|
|
128
|
+
* isJSON( 'claudio' ) // -> false
|
|
129
|
+
* isJSON( 4654 ) // -> false
|
|
130
|
+
* isJSON( 0 ) // -> false
|
|
131
|
+
* isJSON( [1,2,3] ) // -> false
|
|
132
|
+
* isJSON( new Date() ) // -> false
|
|
133
|
+
* isJSON( "{ age: 21 }" ) // -> false
|
|
134
|
+
* isJSON( { age: 21 } ) // -> true
|
|
135
|
+
*
|
|
136
|
+
*
|
|
137
|
+
* @param {*} value
|
|
138
|
+
* @returns {Boolean}
|
|
139
|
+
*/
|
|
12
140
|
export declare const isJSON: (value: any) => boolean;
|
|
141
|
+
/**
|
|
142
|
+
* checkTypes
|
|
143
|
+
* Verifica se o valor passado bate com algum dos tipos
|
|
144
|
+
* http://tobyho.com/2011/01/28/checking-types-in-javascript/
|
|
145
|
+
*
|
|
146
|
+
* checkTypes( 1, String ) // -> false
|
|
147
|
+
* checkTypes( '1', String ) // -> true
|
|
148
|
+
* checkTypes( 1, Number ) // -> true
|
|
149
|
+
* checkTypes( '1', Number ) // -> false
|
|
150
|
+
* checkTypes( 1, [String, Number] ) // -> true
|
|
151
|
+
* checkTypes( 'a', [String, Number] ) // -> true
|
|
152
|
+
* checkTypes( {}, [String, Number] ) // -> false
|
|
153
|
+
* checkTypes( [], [String, Number] ) // -> false
|
|
154
|
+
* checkTypes( [], [String, Number, Array] ) // -> true
|
|
155
|
+
* checkTypes( {}, [String, Number, Array] ) // -> false
|
|
156
|
+
* checkTypes( {}, [String, Number, Array, Object] ) // -> true
|
|
157
|
+
*
|
|
158
|
+
* @param {*} value
|
|
159
|
+
* @param {*|[*]} types
|
|
160
|
+
* @returns {Boolean}
|
|
161
|
+
*/
|
|
13
162
|
export declare const checkTypes: (value: any, types: any | any[]) => boolean;
|
|
163
|
+
/*************************************************************************
|
|
164
|
+
*
|
|
165
|
+
* COMPARAÇÃO DE FORMATOS
|
|
166
|
+
*/
|
|
167
|
+
/**
|
|
168
|
+
* Verifica se é um e-mail
|
|
169
|
+
*
|
|
170
|
+
* isEmail("claudio") // -> false
|
|
171
|
+
* isEmail("claudio@claudio.com") // -> true
|
|
172
|
+
* isEmail("") // -> false
|
|
173
|
+
* isEmail(null) // -> false
|
|
174
|
+
* isEmail(undefined) // -> false
|
|
175
|
+
* isEmail([]) // -> false
|
|
176
|
+
* isEmail({}) // -> false
|
|
177
|
+
* isEmail(123) // -> false
|
|
178
|
+
*
|
|
179
|
+
*/
|
|
14
180
|
export declare const isEmail: (value: any) => boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Verifica se é uma data em um formato aceito pelo javascript
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
*
|
|
186
|
+
* isDate('12/12/29') // -> true
|
|
187
|
+
* isDate('31/12/29') // -> false
|
|
188
|
+
* isDate('12/31/29') // -> true
|
|
189
|
+
* isDate('12/12/2029') // -> true
|
|
190
|
+
* isDate('2029-12-12') // -> true
|
|
191
|
+
*
|
|
192
|
+
* @param {String|Number|Date}
|
|
193
|
+
* @returns {Boolean}
|
|
194
|
+
*/
|
|
15
195
|
export declare const isDate: (value: string | number | Date) => boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Verifica se é uma data válida em portugues
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* isDateBR('31/07/2020') // true
|
|
201
|
+
* isDateBR('32/07/2020') // false
|
|
202
|
+
*
|
|
203
|
+
*
|
|
204
|
+
* @param {String}
|
|
205
|
+
* @returns {Boolean}
|
|
206
|
+
*/
|
|
16
207
|
export declare const isDateBR: (value: string) => boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Verifica se uma hora informada possui o formato de hora:
|
|
210
|
+
* 00:00 ou 00:00:00.
|
|
211
|
+
* Por padrão na verifica os segundos. Passe seconds=true para
|
|
212
|
+
* verificar também os segundos
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
*
|
|
216
|
+
* isTime('12:00') // -> true
|
|
217
|
+
* isTime('23:00') // -> true
|
|
218
|
+
* isTime('23:59') // -> true
|
|
219
|
+
* isTime('24:00') // -> false
|
|
220
|
+
* isTime('00:00') // -> true
|
|
221
|
+
* isTime('-12:00') // -> false
|
|
222
|
+
* isTime('aa:pp') // -> false
|
|
223
|
+
* isTime('23:60') // -> false
|
|
224
|
+
|
|
225
|
+
* isTime('00:00:00', true) // -> true
|
|
226
|
+
* isTime('23:59:59', true) // -> true
|
|
227
|
+
* isTime('24:59:59', true) // -> false
|
|
228
|
+
* isTime('23:60:59', true) // -> false
|
|
229
|
+
* isTime('23:59:65', true) // -> false
|
|
230
|
+
* isTime('aa:bb:dd', true) // -> false
|
|
231
|
+
*
|
|
232
|
+
*
|
|
233
|
+
*
|
|
234
|
+
* @param {String} value
|
|
235
|
+
* @param {Boolean} seconds
|
|
236
|
+
*
|
|
237
|
+
*
|
|
238
|
+
*/
|
|
17
239
|
export declare const isTime: (value: string, seconds?: boolean) => boolean;
|
|
240
|
+
/**
|
|
241
|
+
* Verifica se um valor é falsy, ou seja, mesmo convertido
|
|
242
|
+
* para string a intenção dele deveria ser falso
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
*
|
|
246
|
+
* isFalsy(0) // -> true
|
|
247
|
+
* isFalsy('') // -> true
|
|
248
|
+
* isFalsy('0') // -> true
|
|
249
|
+
* isFalsy(NaN) // -> true
|
|
250
|
+
* isFalsy(null) // -> true
|
|
251
|
+
* isFalsy('NaN') // -> true
|
|
252
|
+
* isFalsy(false) // -> true
|
|
253
|
+
* isFalsy('null') // -> true
|
|
254
|
+
* isFalsy('false') // -> true
|
|
255
|
+
* isFalsy(undefined) // -> true
|
|
256
|
+
* isFalsy('undefined') // -> true
|
|
257
|
+
*
|
|
258
|
+
* @param {any} value
|
|
259
|
+
*/
|
|
18
260
|
export declare const isFalsy: (value: any) => boolean;
|
|
261
|
+
/**
|
|
262
|
+
* Verifica se um valor é falsy, ou seja, mesmo convertido
|
|
263
|
+
* para string a intenção dele deveria ser falso
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
*
|
|
267
|
+
* isTruthy(0) // -> false
|
|
268
|
+
* isTruthy('') // -> false
|
|
269
|
+
* isTruthy('0') // -> false
|
|
270
|
+
* isTruthy(NaN) // -> false
|
|
271
|
+
* isTruthy(null) // -> false
|
|
272
|
+
* isTruthy('NaN') // -> false
|
|
273
|
+
* isTruthy(false) // -> false
|
|
274
|
+
* isTruthy('null') // -> false
|
|
275
|
+
* isTruthy('false') // -> false
|
|
276
|
+
* isTruthy(undefined) // -> false
|
|
277
|
+
* isTruthy('undefined') // -> false
|
|
278
|
+
*
|
|
279
|
+
* @param {any} value
|
|
280
|
+
*/
|
|
19
281
|
export declare const isTruthy: (value: any) => boolean;
|
|
282
|
+
/*************************************************************************
|
|
283
|
+
*
|
|
284
|
+
* CONVERSÃO DE FORMATOS
|
|
285
|
+
*/
|
|
286
|
+
/********************
|
|
287
|
+
* BUSCA
|
|
288
|
+
*/
|
|
289
|
+
/**
|
|
290
|
+
* Verifica 2 arrays e retorna os valores que estão em ambos
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
*
|
|
294
|
+
* intersect([1,2,3], [3,4,5]) // -> [ 3 ]
|
|
295
|
+
*
|
|
296
|
+
* @param {Array} array1
|
|
297
|
+
* @param {Array} array2
|
|
298
|
+
* @return {Array} Array contendo os valores que estão nos 2 arrays
|
|
299
|
+
*/
|
|
20
300
|
export declare const intersect: (array1: any[], array2: any[]) => any[];
|
|
301
|
+
/**
|
|
302
|
+
* Retorna o valor de uma chave em um objeto de múltiplos níveis
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* let obj = { a:'1', b:{ c:10, d:2, e:{ f:'4', g:'5', h:{ i:'6' } } } }
|
|
306
|
+
* objectPath( obj , 'b.e.h.i' ); // -> '6'
|
|
307
|
+
*
|
|
308
|
+
* @param {Object} obj
|
|
309
|
+
* @param {String} path Endereço no formato 'chave.subchave.outrasubchave'
|
|
310
|
+
* @returns {*} Valor de acordo com o caminho
|
|
311
|
+
*/
|
|
21
312
|
export declare function objectPath(obj: any, path: string): any;
|
|
313
|
+
/********************
|
|
314
|
+
* FUNÇÕES DE APOIO
|
|
315
|
+
*/
|
|
316
|
+
/**
|
|
317
|
+
* Agrupa um array de objetos por uma das chaves desse array.
|
|
318
|
+
*
|
|
319
|
+
* @todo Mesclar com o objectPath() acima e permitir agurpamentos multidimensionais
|
|
320
|
+
* com
|
|
321
|
+
*
|
|
322
|
+
* @exemplo
|
|
323
|
+
* const list = [
|
|
324
|
+
* {"id":1,"name":"claudio","age":37,"city":"fortaleza"},
|
|
325
|
+
* {"id":2,"name":"isa","age":9,"city":"natal"},
|
|
326
|
+
* {"id":3,"name":"jose","age":37,"city":"fortaleza"},
|
|
327
|
+
* {"id":4,"name":"marta","age":42,"city":"afonso bezerra"},
|
|
328
|
+
* {"id":5,"name":"joelma","age":42,"city":"afonso bezerra"},
|
|
329
|
+
* {"id":6,"name":"jose","age":24,"city":"assu"}
|
|
330
|
+
* ]
|
|
331
|
+
*
|
|
332
|
+
* groupBy( list, 'name' )
|
|
333
|
+
*
|
|
334
|
+
* {
|
|
335
|
+
* "claudio":[
|
|
336
|
+
* {"id":1,"name":"claudio","age":37,"city":"fortaleza"}
|
|
337
|
+
* ],
|
|
338
|
+
* "isa":[
|
|
339
|
+
* {"id":2,"name":"isa","age":9,"city":"natal"}
|
|
340
|
+
* ],
|
|
341
|
+
* "jose":[
|
|
342
|
+
* {"id":3,"name":"jose","age":37,"city":"fortaleza"},
|
|
343
|
+
* {"id":6,"name":"jose","age":24,"city":"assu"}
|
|
344
|
+
* ],
|
|
345
|
+
* "marta":[
|
|
346
|
+
* {"id":4,"name":"marta","age":42,"city":"afonso bezerra"}
|
|
347
|
+
* ],
|
|
348
|
+
* "joelma":[
|
|
349
|
+
* {"id":5,"name":"joelma","age":42,"city":"afonso bezerra"}
|
|
350
|
+
* ]
|
|
351
|
+
* }
|
|
352
|
+
*
|
|
353
|
+
*
|
|
354
|
+
* @param {Array} items Lista de objetos
|
|
355
|
+
* @param {String} key Nome da chave que agrupará os demais dados
|
|
356
|
+
*/
|
|
22
357
|
export declare const groupBy: (items: object[], key: any) => any;
|
|
358
|
+
/**
|
|
359
|
+
* Gerador de chaves aleatórias
|
|
360
|
+
* Pelo menos 1 dos parâmetros numbers, lower e upper precisa ser true.
|
|
361
|
+
* Para que haja a máxima proteção contra conflitos, os três podem ser true
|
|
362
|
+
* https://gist.github.com/6174/6062387#gistcomment-2742945
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
*
|
|
366
|
+
* keyGenerator(5) // -> 11S9P
|
|
367
|
+
* keyGenerator(5, false) // -> HrmTF
|
|
368
|
+
* keyGenerator(5, false, false) // -> RHCWJ
|
|
369
|
+
* keyGenerator(5, false, true, false) // -> vzuyn
|
|
370
|
+
*
|
|
371
|
+
* @param {Integer} length Tamanho gerado
|
|
372
|
+
* @param {Boolean} numbers Define se existirão números
|
|
373
|
+
* @param {Boolean} lower Define se existirão letras minúsculas
|
|
374
|
+
* @param {Boolean} upper Define se existirão letras maiúsculas
|
|
375
|
+
* @returns {String}
|
|
376
|
+
*/
|
|
23
377
|
export declare const keyGenerator: (length?: number, numbers?: boolean, lower?: boolean, upper?: boolean) => string;
|
|
378
|
+
/**
|
|
379
|
+
* Gerador de slug
|
|
380
|
+
* Create SLUG from a string
|
|
381
|
+
* This function rewrite the string prototype and also
|
|
382
|
+
* replace latin and other special characters.
|
|
383
|
+
*
|
|
384
|
+
* @link
|
|
385
|
+
* Forked by Gabriel Fróes - https://gist.github.com/gabrielfroes
|
|
386
|
+
* Original Author: Mathew Byrne - https://gist.github.com/mathewbyrne/1280286
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
*
|
|
390
|
+
* slug('José Cláudio + ') // -> 'jose-claudio
|
|
391
|
+
* slug('José -- /\|<>Cláu=dio ') // -> 'jose-claudio
|
|
392
|
+
*
|
|
393
|
+
* @param {String} value
|
|
394
|
+
* @returns {String} Valor convertido para slug
|
|
395
|
+
*/
|
|
24
396
|
export declare const slug: (value: string) => string;
|
|
397
|
+
/**
|
|
398
|
+
* Converte um número passado para o formato do Real Brasileiro
|
|
399
|
+
*
|
|
400
|
+
* https://stackoverflow.com/a/64909632/3240078
|
|
401
|
+
* NumberFormat use small non-breaking space (\u202f) for thousand separator
|
|
402
|
+
* and normal non-breaking space beforece currency (\xa0)
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* currencyBR(12.34) // -> 'R$ 12,34'
|
|
406
|
+
* currencyBR('12.34') // -> 'R$ 12,34'
|
|
407
|
+
* currencyBR('12,34') // -> null
|
|
408
|
+
*
|
|
409
|
+
* @param {Number|String} value
|
|
410
|
+
* @returns {String}
|
|
411
|
+
*/
|
|
25
412
|
export declare const currencyBR: (value: number | string) => string;
|
|
413
|
+
/**
|
|
414
|
+
* Converte um nome para as primeiras em maiúsculas, exceto as partes
|
|
415
|
+
* que normalmente continuam em minúsculas, tipo "de", "dos" etc.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* upperFirst('jose claudio medeiros de lima') // -> Jose Claudio Medeiros de Lima
|
|
419
|
+
* upperFirst('JOSE CLAUDIO MEDEIROS DE LIMA') // -> Jose Claudio Medeiros de Lima
|
|
420
|
+
* upperFirst('JoSe cLaUdIo MeDeIrOs De LiMa') // -> Jose Claudio Medeiros de Lima
|
|
421
|
+
*
|
|
422
|
+
* @param {String} value
|
|
423
|
+
* @returns {String}
|
|
424
|
+
*
|
|
425
|
+
*/
|
|
26
426
|
export declare const upperFirst: (value: string) => string;
|
|
427
|
+
/**
|
|
428
|
+
* Reescreve um objeto aplicando um prefixo definido às suas chaves
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* const original = {
|
|
432
|
+
* name: 'ze',
|
|
433
|
+
* age: 23
|
|
434
|
+
* }
|
|
435
|
+
*
|
|
436
|
+
* prefixObjectKeys( original, 'people.*.' )
|
|
437
|
+
* // ->
|
|
438
|
+
* {
|
|
439
|
+
* 'people.*.name': 'ze',
|
|
440
|
+
* 'people.*.age': 23,
|
|
441
|
+
* }
|
|
442
|
+
*
|
|
443
|
+
*
|
|
444
|
+
* @param {Object} obj Objecto original
|
|
445
|
+
* @param {String} prefix Prefixo que será aplicado
|
|
446
|
+
*/
|
|
27
447
|
export declare function prefixObjectKeys(obj: any, prefix?: string): any;
|
|
448
|
+
/**
|
|
449
|
+
* objectFlat()
|
|
450
|
+
* Recebe um objeto e o transforma em uma versão plana, com suas chaves
|
|
451
|
+
* multinível unidas por um ponto.
|
|
452
|
+
*
|
|
453
|
+
* @link https://stackoverflow.com/a/34514143/3240078
|
|
454
|
+
*
|
|
455
|
+
* @example
|
|
456
|
+
*
|
|
457
|
+
* const obj = {
|
|
458
|
+
* name: 'claudio'
|
|
459
|
+
* address: { street': 'Monkey St.' }
|
|
460
|
+
* }
|
|
461
|
+
*
|
|
462
|
+
* objectFlat( obj )
|
|
463
|
+
* // -> { name: 'claudio', 'address.street': 'Monkey St.' }
|
|
464
|
+
*
|
|
465
|
+
* objectFlat( obj, '_' )
|
|
466
|
+
* // -> { name: 'claudio', address_street: 'Monkey St.' }
|
|
467
|
+
*
|
|
468
|
+
* objectFlat( {name:'ze', info:{age:null}}, '_' )
|
|
469
|
+
* // -> { name: 'claudio', address_street: 'Monkey St.' }
|
|
470
|
+
*
|
|
471
|
+
* objectFlat( {name:'ze', info:{age:null}}, '_' )
|
|
472
|
+
* // -> { name: 'ze', info_age: null }
|
|
473
|
+
*
|
|
474
|
+
* objectFlat( {name:'ze', info:{age:null}}, '_' )
|
|
475
|
+
* // -> { name: 'ze', info_age: null }
|
|
476
|
+
*
|
|
477
|
+
* objectFlat({ birth: new Date('1982-07-31'), address: { number: null, } }, '_')
|
|
478
|
+
* // -> { birth: new Date('1982-07-31'), address_number: null }
|
|
479
|
+
*
|
|
480
|
+
* @param {Object} obj
|
|
481
|
+
* @param {String} separator Default "."
|
|
482
|
+
* @returns {Object}
|
|
483
|
+
*/
|
|
28
484
|
export declare function objectFlat(obj: Record<string, any>, separator?: string): Record<string, any>;
|
|
485
|
+
/**
|
|
486
|
+
* Mantém somente as chaves do objeto que estão na lista branca
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
*
|
|
490
|
+
*
|
|
491
|
+
* const address = {
|
|
492
|
+
* id: 1,
|
|
493
|
+
* description: 'decrição',
|
|
494
|
+
* city_id: 123,
|
|
495
|
+
* city: {
|
|
496
|
+
* id: 123,
|
|
497
|
+
* name: 'açu'
|
|
498
|
+
* }
|
|
499
|
+
* }
|
|
500
|
+
*
|
|
501
|
+
* whiteList(address, ['id', 'description', 'city_id'])
|
|
502
|
+
* // -> { id: 1, description: 'decrição', city_id: 123 }
|
|
503
|
+
*
|
|
504
|
+
* whiteList([address, address], ['id', 'description'])
|
|
505
|
+
* // -> [
|
|
506
|
+
* { id: 1, description: 'decrição' },
|
|
507
|
+
* { id: 1, description: 'decrição' }
|
|
508
|
+
* ]
|
|
509
|
+
*
|
|
510
|
+
* @param {Object|Array} obj Objeto inicial. Se for array, aplica um loop aos elementos
|
|
511
|
+
* @param {Array} keys Lista de chaves permitidas
|
|
512
|
+
*/
|
|
29
513
|
export declare const whiteList: (obj: any | any[], keys: any[]) => any;
|
|
514
|
+
/**
|
|
515
|
+
* Substitui os caracteres acentuados por semelhantes não acentuados respeitando
|
|
516
|
+
* maiúsculas e minúsculas
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* removeAccent('Açu') // -> Acu
|
|
520
|
+
*
|
|
521
|
+
* @param value
|
|
522
|
+
* @returns
|
|
523
|
+
*/
|
|
30
524
|
export declare const removeAccent: (value: string) => string;
|
|
525
|
+
/**
|
|
526
|
+
* randomNumber()
|
|
527
|
+
* Cria um número aleatório com o número de caracteres
|
|
528
|
+
*
|
|
529
|
+
* @example
|
|
530
|
+
* randomNumber(8, true) // -> 00083159
|
|
531
|
+
* randomNumber(4) // -> 831
|
|
532
|
+
*
|
|
533
|
+
* @param {Integer} length
|
|
534
|
+
* @param {Boolean} forceLength Adiciona zeros à esquerda para ter os números de caractes exatos
|
|
535
|
+
* @returns {String}
|
|
536
|
+
*/
|
|
31
537
|
export declare function randomNumber(length: number, forceLength?: boolean): number | string;
|
|
538
|
+
/**
|
|
539
|
+
* Limpa um número informado, retirando caracteres diferentes de números,
|
|
540
|
+
* preenchendo com zeros à esquerda se for menor que o tamanho exato e
|
|
541
|
+
* removendo uma parte do número se for maior que tamanho definido.
|
|
542
|
+
*
|
|
543
|
+
* 1) Retira caracteres não-numéricos
|
|
544
|
+
* 2) Preenche com zeros à esquerda se 'value' for menor que 'length'
|
|
545
|
+
* 3) Remove caracteres à direita se 'value' for maior que 'length'
|
|
546
|
+
*
|
|
547
|
+
* @example
|
|
548
|
+
* clearNumber(12345-6, 6) // -> 123456
|
|
549
|
+
* clearNumber(12345678, 3) // -> 123
|
|
550
|
+
* clearNumber(12345, 10) // -> 0000001234
|
|
551
|
+
*
|
|
552
|
+
* @param {Number|String} value
|
|
553
|
+
* @param {Number} length Tamanho exato. Se for null, só retira os caracteres não-numéricos
|
|
554
|
+
* @returns {String} Número com o tamanho exato
|
|
555
|
+
*/
|
|
32
556
|
export declare function clearNumber(value: string | number, length?: number | null): string;
|
|
557
|
+
/**
|
|
558
|
+
* Limpa os valores falsy do objeto informado
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* clearFalsy({ id:1, age:'0', idade: 'NaN', birth: '' }); // -> { id: 1 }
|
|
562
|
+
*
|
|
563
|
+
* @param {Object} value
|
|
564
|
+
* @returns {Object} Objeto sem os valores
|
|
565
|
+
*/
|
|
33
566
|
export declare function clearFalsy(value: Record<string, any>): Record<string, any>;
|
|
567
|
+
/**
|
|
568
|
+
* insertAtPosition()
|
|
569
|
+
* Insere um conjunto de caracteres em um local específico de uma string
|
|
570
|
+
*
|
|
571
|
+
* @example
|
|
572
|
+
* insertAtPosition('AAABBB', 'C', 3) // -> AAACBBB
|
|
573
|
+
* insertAtPosition('000011122223445555', 99, 7) // -> 00001119922223445555
|
|
574
|
+
*
|
|
575
|
+
* @param {String} value Valor original
|
|
576
|
+
* @param {String|Number} insertValue Valor que será inserido
|
|
577
|
+
* @param {Number} position Posição que receberá o novo valor
|
|
578
|
+
* @returns {String}
|
|
579
|
+
*
|
|
580
|
+
*/
|
|
34
581
|
export declare function insertAtPosition(value: string, insertValue: string | number, position: number): string;
|
|
582
|
+
/**
|
|
583
|
+
* removeFromPosition()
|
|
584
|
+
* Retira um conjunto de caracteres de um local específico de uma string
|
|
585
|
+
*
|
|
586
|
+
* @example
|
|
587
|
+
* removeFromPosition('00001119922223445555', 7,9) // -> 000011122223445555
|
|
588
|
+
* removeFromPosition('AAACBBB', 3,4) // -> AAABBB
|
|
589
|
+
*
|
|
590
|
+
* @param {String|Number} value Valor original
|
|
591
|
+
* @param {String|Number} startPosition
|
|
592
|
+
* @param {String|Number} endPosition
|
|
593
|
+
* @returns {String}
|
|
594
|
+
*
|
|
595
|
+
*/
|
|
35
596
|
export declare function removeFromPosition(value: string, startPosition: number, endPosition: number): string;
|
|
597
|
+
/**
|
|
598
|
+
* applyVars()
|
|
599
|
+
* Aplica variáveis a um texto
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* const values = { id: 1, name: 'claudio', age: 39, email: 'email@mail.com' }
|
|
603
|
+
*
|
|
604
|
+
* applyVars('Olá, :name. Seu e-mail ainda é :email?', values)
|
|
605
|
+
* applyVars('Olá, {name}. Seu e-mail ainda é {email}?', values, { start: '{', end: '}' })
|
|
606
|
+
* applyVars('Olá, {{name}}. Seu e-mail ainda é {{email}}?', values, { start: '{{', end: '}}'})
|
|
607
|
+
*
|
|
608
|
+
* @param {String} text
|
|
609
|
+
* @param {Object} vars
|
|
610
|
+
* @param {ApplyVarsOptions} options
|
|
611
|
+
*/
|
|
36
612
|
export declare function applyVars(value: string, vars: Record<string, any>, options?: Partial<ApplyVarsOptions>): string;
|
|
613
|
+
/**
|
|
614
|
+
* Remove specialChars
|
|
615
|
+
*/
|
|
37
616
|
export declare function removeSpecialChars(value: string): string;
|
|
617
|
+
/**
|
|
618
|
+
* applyMask()
|
|
619
|
+
* Aplica uma máscara a uma string
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* applyMask('59650000', '00.000-000') // -> 59.650-000
|
|
623
|
+
* applyMask('99877665544', '(00) 0 0000-0000') // -> (99) 8 7766-5544
|
|
624
|
+
*
|
|
625
|
+
* @param {String|Number} value Valor original
|
|
626
|
+
* @param {String} mask
|
|
627
|
+
* @returns {String}
|
|
628
|
+
*
|
|
629
|
+
*/
|
|
38
630
|
export declare function applyMask(value: string | number, mask: string): string;
|
|
631
|
+
/**
|
|
632
|
+
* randomLetter()
|
|
633
|
+
* Pega uma letra maiúscula aleatoriamente
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* randomLetter() // -> A
|
|
637
|
+
* randomLetter() // -> S
|
|
638
|
+
*
|
|
639
|
+
* @returns {String}
|
|
640
|
+
*/
|
|
39
641
|
export declare function randomLetter(): string;
|
|
642
|
+
/**
|
|
643
|
+
* Exibe uma quantidade como string numérica
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* quantity(0, 'mensagens', 'mensagem', 'nenhuma mensagem') // nenhuma mensagem
|
|
647
|
+
* quantity(0, 'mensagens', 'mensagem', null) // 0 mensagem
|
|
648
|
+
* quantity(1, 'mensagens', 'mensagem', 'nenhuma mensagem') // 1 mensagem
|
|
649
|
+
* quantity(2, 'mensagens', 'mensagem', 'nenhuma mensagem') // 2 mensagens
|
|
650
|
+
*
|
|
651
|
+
* @param {Number|'String} A quantidade
|
|
652
|
+
* @param {String} Sufixo que será usado quando a quantidade for mais de um
|
|
653
|
+
* @param {String} Sufixo que será usado quando a quantidade for 1
|
|
654
|
+
* @param {String|Null} Texto usado quando a quantidade for zero. Se estiver em branco,
|
|
655
|
+
* será usado o sufixo individual
|
|
656
|
+
*
|
|
657
|
+
* @return {String} Texto contendo as variações
|
|
658
|
+
*/
|
|
40
659
|
export declare const quantity: (qty: number | string, suffixMany: string, suffixOne: string, textEmpty: string | null) => string;
|
|
660
|
+
/**
|
|
661
|
+
* Converte bytes em um de seus múltiplos.
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* filesize(null) // -> 0 Kb
|
|
665
|
+
* filesize('') // -> 0 Kb
|
|
666
|
+
* filesize(12354353) // -> 11 mb
|
|
667
|
+
*
|
|
668
|
+
* @param {Number} bytes
|
|
669
|
+
* @return {String} Valor convertido para kb, mb etc
|
|
670
|
+
*/
|
|
41
671
|
export declare const filesize: (bytes: number | string) => string;
|
|
672
|
+
/**
|
|
673
|
+
* Ordena um array de objetos a partir de uma chave
|
|
674
|
+
*
|
|
675
|
+
* sortByKey( [{name: 'marta'}, {name: 'claudio'}, {name: 'isa'}], 'name' )
|
|
676
|
+
* // -> [ {name: 'claudio',}, {name: 'isa',}, {name: 'marta',} ]
|
|
677
|
+
*
|
|
678
|
+
* @param {Object[]} list
|
|
679
|
+
*/
|
|
42
680
|
export declare const sortByKey: (list: Array<Record<string, any>>, key: any) => Record<string, any>[];
|
|
681
|
+
/**
|
|
682
|
+
*
|
|
683
|
+
* Converte um valor boolean, analisando seu conteúdo, mesmo que seja uma string.
|
|
684
|
+
* Se for um valor possivelmente falsy, converte para falsy
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* toBoolean("a"); // -> true
|
|
688
|
+
* toBoolean(1); // -> true
|
|
689
|
+
* toBoolean("true"); // -> true
|
|
690
|
+
* toBoolean("0"); // -> false
|
|
691
|
+
* toBoolean(0); // -> false
|
|
692
|
+
* toBoolean("false"); // -> false
|
|
693
|
+
* toBoolean(false); // -> false
|
|
694
|
+
* toBoolean(""); // -> false
|
|
695
|
+
* toBoolean("undefined"); // -> false
|
|
696
|
+
* toBoolean(undefined); // -> false
|
|
697
|
+
* toBoolean("NaN"); // -> false
|
|
698
|
+
* toBoolean(NaN); // -> false
|
|
699
|
+
* toBoolean("null"); // -> false
|
|
700
|
+
* toBoolean(null); // -> false
|
|
701
|
+
*
|
|
702
|
+
* @param {*} value
|
|
703
|
+
* @returns {Boolean}
|
|
704
|
+
*/
|
|
43
705
|
export declare function toBoolean(value: any): boolean;
|
|
706
|
+
/**
|
|
707
|
+
*
|
|
708
|
+
* Gera um UUID V4 ordenável, usando a data atual como base
|
|
709
|
+
*
|
|
710
|
+
*/
|
|
44
711
|
export declare function timeUUID(): string;
|
|
45
712
|
export {};
|
|
46
713
|
//# sourceMappingURL=main.d.ts.map
|