klawtil 0.0.2 → 0.0.6

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.
Files changed (2) hide show
  1. package/README.md +410 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -0,0 +1,410 @@
1
+ # klawtil
2
+
3
+ Util functions library
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ # Usando yarn
9
+ yarn add klawtil
10
+
11
+ ## OU
12
+ # Usando npm
13
+ npm install klawtil
14
+
15
+ ```
16
+
17
+ ## Import
18
+
19
+ ```js
20
+ // Modules
21
+ const { isCPF, isCNPJ } = require("klawtil");
22
+
23
+ // ES6
24
+ import { isCPF, isCNPJ } from "klawtil";
25
+ ```
26
+
27
+ ## Content Table
28
+
29
+ [**Comparation**](#Comparation)
30
+
31
+ - [empty](#empty)
32
+ - [isArray](#isArray)
33
+ - [isObject](#isObject)
34
+ - [isString](#isString)
35
+ - [isInteger](#isInteger)
36
+ - [isFloat](#isFloat)
37
+ - [isNumeric](#isNumeric)
38
+ - [checkTypes](#checkTypes)
39
+ - [isEmail](#isEmail)
40
+ - [isDate](#isDate)
41
+ - [isDateBR](#isDateBR)
42
+ - [isTime](#isTime)
43
+ - [isFalsy](#isFalsy)
44
+ - [isTruthy](#isTruthy)
45
+
46
+ [**Object**](#Object)
47
+
48
+ - [intersect](#intersect)
49
+ - [objectPath](#objectPath)
50
+ - [groupBy](#groupBy)
51
+ - [prefixObjectKeys](#prefixObjectKeys)
52
+ - [whiteList](#whiteList)
53
+
54
+ [**String**](#String)
55
+
56
+ - [slug](#slug)
57
+ - [currencyBR](#currencyBR)
58
+ - [upperFirst](#upperFirst)
59
+ - [removeAccent](#removeAccent)
60
+ - [clearNumber](#clearNumber)
61
+ - [insertAtPosition](#insertAtPosition)
62
+ - [removeFromPosition](#removeFromPosition)
63
+ - [applyMask](#applyMask)
64
+
65
+ [**Random**](#Random)
66
+
67
+ - [keyGenerator](#keyGenerator)
68
+ - [randomNumber](#randomNumber)
69
+ - [randomLetter](#randomLetter)
70
+
71
+ ## Comparation
72
+
73
+ ### empty
74
+
75
+ ```js
76
+ empty(""); // -> true
77
+ empty(null); // -> true
78
+ empty(false); // -> false
79
+ empty(undefined); // -> true
80
+ ```
81
+
82
+ ### isArray
83
+
84
+ ```js
85
+ isArray([]); // -> true
86
+ isArray({}); // -> false
87
+ isArray(0); // -> false
88
+ isArray("claudio"); // -> false
89
+ ```
90
+
91
+ ### isObject
92
+
93
+ ```js
94
+ isObject({}); // ->true
95
+ isObject([]); // ->true
96
+ isObject("claudio"); // ->false
97
+ isObject(1); // ->false
98
+ isObject(new Date()); // ->true
99
+ ```
100
+
101
+ ### isString
102
+
103
+ ```js
104
+ isString("claudio"); // -> true
105
+ isString("12"); // -> true
106
+ isString(12); // -> false
107
+ isString([12]); // -> false
108
+ isString({}); // -> false
109
+ ```
110
+
111
+ ### isInteger
112
+
113
+ ```js
114
+ isInteger("1"); // -> true
115
+ isInteger("1", true); // -> false
116
+ isInteger(1); // -> true
117
+ isInteger(1.2); // -> false
118
+ isInteger(1, true); // -> true
119
+ isInteger("1", true); // -> false
120
+ isInteger("claudio"); // -> false
121
+ ```
122
+
123
+ ### isFloat
124
+
125
+ ```js
126
+ isFloat("1"); // -> true
127
+ isFloat(1, true); // -> true
128
+ isFloat("1", true); // -> false
129
+ isFloat(1); // -> true
130
+ isFloat(1.2); // -> true
131
+ isFloat("1.2"); // -> true
132
+ isFloat("1.2", true); // -> false
133
+ isFloat("claudio"); // -> false
134
+ isFloat(false); // -> false
135
+ ```
136
+
137
+ ### isNumeric
138
+
139
+ ```js
140
+ isNumeric("1"); // -> true
141
+ isNumeric(1, true); // -> true
142
+ isNumeric("1", true); // -> false
143
+ isNumeric(1); // -> true
144
+ isNumeric(1.2); // -> true
145
+ isNumeric("1.2"); // -> true
146
+ isNumeric("1.2", true); // -> false
147
+ isNumeric("claudio"); // -> false
148
+ isNumeric(false); // -> false
149
+ ```
150
+
151
+ ### checkTypes
152
+
153
+ ```js
154
+ checkTypes(1, String); // -> false
155
+ checkTypes("1", String); // -> true
156
+ checkTypes(1, Number); // -> true
157
+ checkTypes("1", Number); // -> false
158
+ checkTypes(1, [String, Number]); // -> true
159
+ checkTypes("a", [String, Number]); // -> true
160
+ checkTypes({}, [String, Number]); // -> false
161
+ checkTypes([], [String, Number]); // -> false
162
+ checkTypes([], [String, Number, Array]); // -> true
163
+ checkTypes({}, [String, Number, Array]); // -> false
164
+ checkTypes({}, [String, Number, Array, Object]); // -> true
165
+ ```
166
+
167
+ ### isEmail
168
+
169
+ ```js
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
+
180
+ ### isDate
181
+
182
+ ```js
183
+ isDate("12/12/29"); // -> true
184
+ isDate("31/12/29"); // -> false
185
+ isDate("12/31/29"); // -> true
186
+ isDate("12/12/2029"); // -> true
187
+ isDate("2029-12-12"); // -> true
188
+ ```
189
+
190
+ ### isDateBR
191
+
192
+ ```js
193
+ isDateBR("31/07/2020"); // true
194
+ isDateBR("32/07/2020"); // false
195
+ isDateBR("7/7/2020"); // false
196
+ ```
197
+
198
+ ### isTime
199
+
200
+ ```js
201
+ isTime("12:00"); // -> true
202
+ isTime("23:00"); // -> true
203
+ isTime("23:59"); // -> true
204
+ isTime("24:00"); // -> false
205
+ isTime("00:00"); // -> true
206
+ isTime("-12:00"); // -> false
207
+ isTime("aa:pp"); // -> false
208
+ isTime("23:60"); // -> false
209
+ isTime("00:00:00", true); // -> true
210
+ isTime("23:59:59", true); // -> true
211
+ isTime("24:59:59", true); // -> false
212
+ isTime("23:60:59", true); // -> false
213
+ isTime("23:59:65", true); // -> false
214
+ isTime("aa:bb:dd", true); // -> false
215
+ ```
216
+
217
+ ### isFalsy
218
+
219
+ ```js
220
+ isFalsy(0); // -> true
221
+ isFalsy(""); // -> true
222
+ isFalsy("0"); // -> true
223
+ isFalsy(NaN); // -> true
224
+ isFalsy(null); // -> true
225
+ isFalsy("NaN"); // -> true
226
+ isFalsy(false); // -> true
227
+ isFalsy("null"); // -> true
228
+ isFalsy("false"); // -> true
229
+ isFalsy(undefined); // -> true
230
+ isFalsy("undefined"); // -> true
231
+ ```
232
+
233
+ ### isTruthy
234
+
235
+ ```js
236
+ isTruthy(0); // -> false
237
+ isTruthy(""); // -> false
238
+ isTruthy("0"); // -> false
239
+ isTruthy(NaN); // -> false
240
+ isTruthy(null); // -> false
241
+ isTruthy("NaN"); // -> false
242
+ isTruthy(false); // -> false
243
+ isTruthy("null"); // -> false
244
+ isTruthy("false"); // -> false
245
+ isTruthy(undefined); // -> false
246
+ isTruthy("undefined"); // -> false
247
+ ```
248
+
249
+ ## Object
250
+
251
+ ### intersect
252
+
253
+ ```js
254
+ intersect([1, 2, 3], [3, 4, 5]); // -> [ 3 ]
255
+ ```
256
+
257
+ ### objectPath
258
+
259
+ ```js
260
+ let obj = { a: "1", b: { c: 10, d: 2, e: { f: "4", g: "5", h: { i: "6" } } } };
261
+ objectPath(obj, "b.e.h.i"); // -> '6'
262
+ ```
263
+
264
+ ### groupBy
265
+
266
+ ```js
267
+ const list = [
268
+ {"id":1,"name":"claudio","age":37,"city":"fortaleza"},
269
+ {"id":2,"name":"isa","age":9,"city":"natal"},
270
+ {"id":3,"name":"jose","age":37,"city":"fortaleza"},
271
+ {"id":4,"name":"marta","age":42,"city":"afonso bezerra"},
272
+ {"id":5,"name":"joelma","age":42,"city":"afonso bezerra"},
273
+ {"id":6,"name":"jose","age":24,"city":"assu"}
274
+ ]
275
+ groupBy( list, 'name' )
276
+ {
277
+ "claudio":[
278
+ {"id":1,"name":"claudio","age":37,"city":"fortaleza"}
279
+ ],
280
+ "isa":[
281
+ {"id":2,"name":"isa","age":9,"city":"natal"}
282
+ ],
283
+ "jose":[
284
+ {"id":3,"name":"jose","age":37,"city":"fortaleza"},
285
+ {"id":6,"name":"jose","age":24,"city":"assu"}
286
+ ],
287
+ "marta":[
288
+ {"id":4,"name":"marta","age":42,"city":"afonso bezerra"}
289
+ ],
290
+ "joelma":[
291
+ {"id":5,"name":"joelma","age":42,"city":"afonso bezerra"}
292
+ ]
293
+ }
294
+
295
+ ```
296
+
297
+ ### prefixObjectKeys
298
+
299
+ ```js
300
+ const original = {
301
+ name: "ze",
302
+ age: 23,
303
+ };
304
+
305
+ prefixObjectKeys(original, "people.*.");
306
+ // -> { 'people.*.name': 'ze', 'people.*.age': 23}
307
+ ```
308
+
309
+ ### whiteList
310
+
311
+ ```js
312
+ const address = {
313
+ id: 1,
314
+ description: "decrição",
315
+ city_id: 123,
316
+ city: { id: 123, name: "açu" },
317
+ };
318
+
319
+ whiteList(address, ["id", "description", "city_id"]);
320
+ // -> { id: 1, description: 'decrição', city_id: 123 }
321
+
322
+ whiteList([address, address], ["id", "city_id"]);
323
+ // -> [ { id: 1, city_id: '123' }, { id: 1, city_id: '123' } ]
324
+ ```
325
+
326
+ ## String
327
+
328
+ ### slug
329
+
330
+ ```js
331
+ slug("José Cláudio + "); // -> 'jose-claudio
332
+ slug("José -- /|<>Cláu=dio "); // -> 'jose-claudio
333
+ ```
334
+
335
+ ### currencyBR
336
+
337
+ ```js
338
+ currencyBR(12.34); // -> 'R$ 12,34'
339
+ currencyBR("12.34"); // -> 'R$ 12,34'
340
+ currencyBR("12,34"); // -> null
341
+ ```
342
+
343
+ ### upperFirst
344
+
345
+ ```js
346
+ upperFirst("jose claudio medeiros de lima"); // -> Jose Claudio Medeiros de Lima
347
+ upperFirst("JOSE CLAUDIO MEDEIROS DE LIMA"); // -> Jose Claudio Medeiros de Lima
348
+ upperFirst("JoSe cLaUdIo MeDeIrOs De LiMa"); // -> Jose Claudio Medeiros de Lima
349
+ ```
350
+
351
+ ### removeAccent
352
+
353
+ ```js
354
+ removeAccent("Açu"); // -> Acu
355
+ removeAccent("José Cláudio"); // -> Jose Claudio
356
+ ```
357
+
358
+ ### clearNumber
359
+
360
+ ```js
361
+ clearNumber(12345 - 6, 6); // -> 123456
362
+ clearNumber(12345678, 3); // -> 123
363
+ clearNumber(12345, 10); // -> 0000001234
364
+ ```
365
+
366
+ ### insertAtPosition
367
+
368
+ ```js
369
+ insertAtPosition("AAABBB", "-", 3); // -> AAA-BBB
370
+ insertAtPosition("000011122223445555", "->", 7); // -> 0000111->22223445555
371
+ ```
372
+
373
+ ### removeFromPosition
374
+
375
+ ```js
376
+ removeFromPosition("00001119922223445555", 7, v9); // -> 000011122223445555
377
+ removeFromPosition("AAACBBB", 3, 4); // -> AAABBB
378
+ ```
379
+
380
+ ### applyMask
381
+
382
+ ```js
383
+ applyMask("59650000", "00.000-000"); // -> 59.650-000
384
+ applyMask("99877665544", "(00) 0 0000-0000"); // -> (99) 8 7766-5544
385
+ ```
386
+
387
+ ## Random
388
+
389
+ ### keyGenerator
390
+
391
+ ```js
392
+ keyGenerator(5); // -> 11S9P
393
+ keyGenerator(5, false); // -> HrmTF
394
+ keyGenerator(5, false, false); // -> RHCWJ
395
+ keyGenerator(5, false, true, false); // -> vzuyn
396
+ ```
397
+
398
+ ### randomNumber
399
+
400
+ ```js
401
+ randomNumber(8, true); // -> 00083159
402
+ randomNumber(4); // -> 831
403
+ ```
404
+
405
+ ### randomLetter
406
+
407
+ ```js
408
+ randomLetter(); // -> A
409
+ randomLetter(); // -> S
410
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "klawtil",
3
- "version": "0.0.2",
3
+ "version": "0.0.6",
4
4
  "description": "Biblioteca de funções úteis",
5
5
  "author": "Cláudio Medeiros <contato@klawdyo.com>",
6
6
  "license": "MIT",