@turnai/turn-shared 1.0.3

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 ADDED
@@ -0,0 +1,536 @@
1
+ # Turn Shared
2
+
3
+ Library used to share code between mobile and web apps.
4
+
5
+ ## Getting Started
6
+
7
+ This package depends on the private npm package `@turnai/validate-us-drivers-license`. You must be authenticated to npm (same registry as this package) to install:
8
+
9
+ ```bash
10
+ npm login
11
+ # or set NODE_AUTH_TOKEN when installing in CI
12
+ npm install --save @turnai/turn-shared
13
+ ```
14
+
15
+ ## Building
16
+
17
+ Node 10 or higher is required for development and building. Use `nvm use` if you use nvm (see `.nvmrc`).
18
+
19
+ Make your changes in the src files, when you're ready to push your changes run `yarn build`.
20
+
21
+ ## Services included
22
+ ### BaseAPI
23
+ API with turn endpoints, created with apisauce.
24
+
25
+
26
+ ## Styles included
27
+ ### constants
28
+ Includes the main palette used in apps.
29
+
30
+
31
+ ## Utils included
32
+ ### formatDate
33
+ Takes a unix timestamp and returns a string with format MM/DD/YYYY.
34
+
35
+ **Arguments**
36
+
37
+ date (number): The unix timestamp to format.
38
+
39
+ **Returns**
40
+
41
+ (string): Returns string with format MM/DD/YYYY if `date` is valid, else "N/A".
42
+
43
+
44
+
45
+ _________
46
+
47
+ ### formatEmail
48
+ Replaces each contiguous string of space characters with an empty string.
49
+
50
+ **Arguments**
51
+
52
+ email(string): The email to format.
53
+
54
+ **Returns**
55
+
56
+ (string): Returns string without spaces if email is a string, else an empty string.
57
+
58
+
59
+
60
+ _________
61
+
62
+ ### formatName
63
+ Replaces each contiguous string of tabs, spaces and line breaks with a space.
64
+
65
+ **Arguments**
66
+
67
+ name(string): The name to format.
68
+
69
+ **Returns**
70
+
71
+ (string): Returns string without tabs spaces or line breaks if `name` is a string, else an empty string.
72
+
73
+
74
+
75
+ _________
76
+
77
+ ### formatPhone
78
+ Formats a number to a valid US phone number.
79
+
80
+ **Arguments**
81
+
82
+ phone(string): The phone number to format.
83
+ [ encrypted=false ] (boolean): Indicates wether the phone should be encrypted.
84
+
85
+ **Returns**
86
+
87
+ (string): Returns string spaced every three digits, if encrypted adds a '-' in between the 6th and 7th character if `phone` is a string, else "N/A".
88
+
89
+
90
+
91
+ _________
92
+
93
+ ### formatSSN
94
+ Replaces all non-numeric charactes for empty strings.
95
+
96
+ **Arguments**
97
+
98
+ ssn(string): The ssn to format.
99
+
100
+ **Returns**
101
+
102
+ (string): Returns a stirng spaced with a '-' every three and five characters if `ssn` is a string, else "N\A".
103
+
104
+
105
+
106
+ _________
107
+
108
+ ### formatZipcode
109
+ Replaces all non-numeric characters for empty strings.
110
+
111
+ **Arguments**
112
+
113
+ zipcode(string): The zipcode to format.
114
+
115
+ **Returns**
116
+
117
+ (string): Returns string without non-numeric characters and only the first 5 characters if `zipcode` is a string, else an empty string.
118
+
119
+
120
+
121
+ _________
122
+
123
+ ### getRejectMessage
124
+ Returns the reject message of the specified partner.
125
+
126
+ **Arguments**
127
+
128
+ partner_type(string): The partner to check.
129
+
130
+ **Returns**
131
+
132
+ (string): Reject message of specified partner.
133
+
134
+
135
+
136
+ _________
137
+
138
+ ### getStatus
139
+ Translates the specified status.
140
+
141
+ **Arguments**
142
+
143
+ status(string): The status to translate.
144
+
145
+ **Returns**
146
+
147
+ (string): Returns translated status.
148
+
149
+
150
+
151
+ _________
152
+
153
+ ### isDate
154
+ Checks if value is a valid date.
155
+
156
+ **Arguments**
157
+
158
+ value(*): Value to check.
159
+
160
+ **Returns**
161
+
162
+ (boolean): Returns true if `value` can be transformed to a valid date, else false.
163
+
164
+
165
+
166
+ _________
167
+
168
+ ### isObject
169
+ Checks if value is type Object.
170
+
171
+ **Arguments**
172
+
173
+ value(*): The value to check.
174
+
175
+ **Returns**
176
+
177
+ (boolean): Returns true if `value` is an object, else false.
178
+
179
+
180
+
181
+ _________
182
+
183
+ ### isUrl
184
+ Checks if value is valid url.
185
+
186
+ **Arguments**
187
+
188
+ urlString(string): The value to check.
189
+
190
+ **Returns**
191
+
192
+ (boolean): Returns true if `urlString` is a valid url, else false.
193
+
194
+
195
+
196
+ _________
197
+
198
+ ### legalReplace
199
+ Replaces matches in string `original` with `replacement`.
200
+
201
+ **Arguments**
202
+
203
+ [ original="" ] (string): The string to modify.
204
+ [ replacement="" ] (string): The match to replace.
205
+
206
+ **Returns**
207
+
208
+ (string): Returns the modified string with matches replaced with `replacement` if `original` is a string, else an empty string.
209
+
210
+
211
+
212
+ _________
213
+
214
+ ### maskName
215
+ Creates a slice of a given string.
216
+
217
+ **Arguments**
218
+
219
+ name(string): The string to modify.
220
+
221
+ **Returns**
222
+
223
+ (string): Returns a string containing the first character.
224
+
225
+
226
+
227
+ _________
228
+
229
+ ### objectToQuery
230
+ Converts an object to a query using its keys as name and values as values.
231
+
232
+ **Arguments**
233
+
234
+ query(object): The object to transform.
235
+
236
+ **Returns**
237
+
238
+ (string): Returns a query composed of the keys used as names and values as values.
239
+
240
+
241
+
242
+ _________
243
+
244
+ ### parsePythonDate
245
+ Transforms a python date to regular Date.
246
+
247
+ **Arguments**
248
+
249
+ date(): The date to transform.
250
+
251
+ **Returns**
252
+
253
+ (Date): Returns a valid date if `date` is a valid date, else null.
254
+
255
+
256
+
257
+ _________
258
+
259
+ ### parseQuery
260
+ Transforms a query to an object using the names as keys and values as values.
261
+
262
+ **Arguments**
263
+
264
+ query(string): The query to transform.
265
+
266
+ **Returns**
267
+
268
+ (string): Returns an object using the names of the query as keys and its values as values.
269
+
270
+
271
+
272
+ _________
273
+
274
+ ### pickColor
275
+ Localizes the color of a given status.
276
+
277
+ **Arguments**
278
+
279
+ status(string): The status to find the color of.
280
+
281
+ **Returns**
282
+
283
+ (string): Returns the hex color of the given `status`.
284
+
285
+
286
+
287
+ _________
288
+
289
+ ### pickScoreColor
290
+ Localizes the color of a given score.
291
+
292
+ **Arguments**
293
+
294
+ status(number): The score to find the color of.
295
+
296
+ **Returns**
297
+
298
+ (string): Returns the hex color of the given `status`.
299
+
300
+
301
+
302
+ _________
303
+
304
+ ### prettifyDate
305
+ Transforms a regular date string (YYYY/MM/DD) to a pretty date.
306
+
307
+ **Arguments**
308
+
309
+ dateString(string): The date to transform.
310
+
311
+ **Returns**
312
+
313
+ (string): Returns a string with format MM DD, YYYY.
314
+
315
+
316
+
317
+ _________
318
+
319
+ ### renderDetailValue
320
+ Transforms an object to a string using the values separated by a slash.
321
+
322
+ **Arguments**
323
+
324
+ value(*): The value to be transformed.
325
+ [ deep=false ] (boolean): Indicates wether to use use the values of nested values.
326
+
327
+ **Returns**
328
+
329
+ Returns a string formed by values of `value` separated by a slash if `value` is an object, else returns `value`.
330
+
331
+
332
+
333
+ _________
334
+
335
+ ### selectMasterKey
336
+ Looks for a key in an object.
337
+
338
+ **Arguments**
339
+
340
+ data(*): The object or array from which to get the master key.
341
+ property(string): The property name with which to search master key.
342
+
343
+ **Returns**
344
+
345
+ (string): The name of the masterkey.
346
+
347
+
348
+
349
+ _________
350
+
351
+ ### Setter
352
+ Class with factory properties. More details in file.
353
+
354
+ **Factories included**
355
+ * setStringFactory
356
+ * setNumberFactory
357
+ * setBoolFactory
358
+ * setTruthyFactory
359
+ * setFalsyFactory
360
+ * setOptionFactory
361
+ * toggleBoolFactory
362
+
363
+
364
+
365
+ _________
366
+
367
+ ### storageMock
368
+ Object with simulated properties as storage.
369
+
370
+ **Properties simulated**
371
+ * setItem.
372
+ * getItem.
373
+ * removeItem.
374
+ * length.
375
+ * key.
376
+
377
+
378
+
379
+ _________
380
+
381
+ ### toBoolean
382
+ Checks if `value` can be classified as a boolean.
383
+
384
+ **Arguments**
385
+
386
+ value(*): Value to be checked.
387
+
388
+ **Returns**
389
+
390
+ (boolean): Returns true if `value` is truthy based on its type.
391
+
392
+
393
+
394
+ _________
395
+
396
+ ### toRelativeDate
397
+ Formats a regular date to a formatted string.
398
+
399
+ **Arguments**
400
+
401
+ date(number): The date to be formatted.
402
+
403
+ **Returns**
404
+
405
+ (string): Returns a formatted date with M/DD/YYYY format if date is a string, else "N/A".
406
+
407
+
408
+
409
+ _________
410
+
411
+ ### toRelativeFromISO
412
+ Formats a regular date to a formatted string.
413
+
414
+ **Arguments**
415
+
416
+ date(string): The date to be formatted.
417
+
418
+ **Returns**
419
+
420
+ (string): Returns a formatted date with M/DD/YYYY format if `date` is a string, else "N/A".
421
+
422
+
423
+
424
+ _________
425
+
426
+ ### toSentenceCase
427
+ Formats a string to upper first every start, period, exclamation and question mark.
428
+
429
+ **Arguments**
430
+
431
+ str(string): The string to be formatted.
432
+
433
+ **Returns**
434
+
435
+ (string): Returns the formatted string.
436
+
437
+
438
+
439
+
440
+ _________
441
+
442
+ ### toTitleCase
443
+ Transforms a string first letters of every word to upper case.
444
+
445
+ **Arguments**
446
+
447
+ str(string): The string to transform.
448
+
449
+ **Returns**
450
+
451
+ (string): Returns the string upper cased.
452
+
453
+
454
+
455
+ _________
456
+
457
+ ### translateStatus
458
+ Translates a given status
459
+
460
+ **Arguments**
461
+
462
+ status(string): The status to translate.
463
+ adverse_action(string): Indicates whether there's adverse action.
464
+
465
+ **Returns**
466
+
467
+ (string): Returns the translated status.
468
+
469
+
470
+
471
+ _________
472
+
473
+ ### validateDriversLicense
474
+ Checks if license is valid based on its state.
475
+
476
+ **Arguments**
477
+
478
+ license(string): The license to check.
479
+ [ state="" ] (string): The state to check the licenese with.
480
+
481
+ **Returns**
482
+
483
+ (object): Object containing wether the license is valid and resons why.
484
+
485
+
486
+
487
+ _________
488
+
489
+ ### validateSSN
490
+ Checks if `ssn` is a valid ssn.
491
+
492
+ **Arguments**
493
+
494
+ ssn(string): The ssn to check.
495
+
496
+ **Returns**
497
+
498
+ (boolean): Returns true if `ssn` is valid, else false.
499
+
500
+
501
+
502
+ _________
503
+
504
+ ### validators
505
+ Each validator checks if value is valid.
506
+
507
+ **Validators included**
508
+ * validateEmail
509
+ * validatePhone
510
+ * validateSSN
511
+ * validateCheck
512
+ * containsAtSymbol
513
+ * containsNumber
514
+ * validateName
515
+ * validateCustomInput
516
+ * validateZipcode
517
+ * isArray
518
+ * validateMVRCheck
519
+ * validatePhoneVerification
520
+ * disable_check
521
+ * validateEmailId
522
+ * validateTurnId
523
+
524
+
525
+ _________
526
+
527
+ ### valueExists
528
+ Checks if `value` exists.
529
+
530
+ **Arguments**
531
+
532
+ value(string): The value to be check.
533
+
534
+ **Returns**
535
+
536
+ (boolean): Returns true if `value` exists, else false.