@lfsoftwares/native-util 0.0.2

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 (103) hide show
  1. package/README.md +61 -0
  2. package/index.ts +1 -0
  3. package/lib/index.js +2 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/src/DateUtils/index.js +2 -0
  6. package/lib/src/DateUtils/index.js.map +1 -0
  7. package/lib/src/DateUtils/util.dates.js +293 -0
  8. package/lib/src/DateUtils/util.dates.js.map +1 -0
  9. package/lib/src/FormatUtils/index.js +2 -0
  10. package/lib/src/FormatUtils/index.js.map +1 -0
  11. package/lib/src/FormatUtils/util.format.js +118 -0
  12. package/lib/src/FormatUtils/util.format.js.map +1 -0
  13. package/lib/src/GeneralConsts/consts.general.js +135 -0
  14. package/lib/src/GeneralConsts/consts.general.js.map +1 -0
  15. package/lib/src/GeneralConsts/index.js +2 -0
  16. package/lib/src/GeneralConsts/index.js.map +1 -0
  17. package/lib/src/GeneralUtils/index.js +2 -0
  18. package/lib/src/GeneralUtils/index.js.map +1 -0
  19. package/lib/src/GeneralUtils/util.general.js +71 -0
  20. package/lib/src/GeneralUtils/util.general.js.map +1 -0
  21. package/lib/src/MaskUtils/index.js +2 -0
  22. package/lib/src/MaskUtils/index.js.map +1 -0
  23. package/lib/src/MaskUtils/util.masks.js +58 -0
  24. package/lib/src/MaskUtils/util.masks.js.map +1 -0
  25. package/lib/src/NetworkUtils/index.js +2 -0
  26. package/lib/src/NetworkUtils/index.js.map +1 -0
  27. package/lib/src/NetworkUtils/util.network.js +11 -0
  28. package/lib/src/NetworkUtils/util.network.js.map +1 -0
  29. package/lib/src/NumberUtils/index.js +2 -0
  30. package/lib/src/NumberUtils/index.js.map +1 -0
  31. package/lib/src/NumberUtils/util.numbers.js +212 -0
  32. package/lib/src/NumberUtils/util.numbers.js.map +1 -0
  33. package/lib/src/RegexConsts/consts.regex.js +8 -0
  34. package/lib/src/RegexConsts/consts.regex.js.map +1 -0
  35. package/lib/src/RegexConsts/index.js +2 -0
  36. package/lib/src/RegexConsts/index.js.map +1 -0
  37. package/lib/src/ValidationUtils/index.js +2 -0
  38. package/lib/src/ValidationUtils/index.js.map +1 -0
  39. package/lib/src/ValidationUtils/util.validation.js +175 -0
  40. package/lib/src/ValidationUtils/util.validation.js.map +1 -0
  41. package/lib/src/index.js +10 -0
  42. package/lib/src/index.js.map +1 -0
  43. package/lib/types/index.d.ts +2 -0
  44. package/lib/types/index.d.ts.map +1 -0
  45. package/lib/types/src/DateUtils/index.d.ts +2 -0
  46. package/lib/types/src/DateUtils/index.d.ts.map +1 -0
  47. package/lib/types/src/DateUtils/util.dates.d.ts +19 -0
  48. package/lib/types/src/DateUtils/util.dates.d.ts.map +1 -0
  49. package/lib/types/src/FormatUtils/index.d.ts +2 -0
  50. package/lib/types/src/FormatUtils/index.d.ts.map +1 -0
  51. package/lib/types/src/FormatUtils/util.format.d.ts +10 -0
  52. package/lib/types/src/FormatUtils/util.format.d.ts.map +1 -0
  53. package/lib/types/src/GeneralConsts/consts.general.d.ts +11 -0
  54. package/lib/types/src/GeneralConsts/consts.general.d.ts.map +1 -0
  55. package/lib/types/src/GeneralConsts/index.d.ts +2 -0
  56. package/lib/types/src/GeneralConsts/index.d.ts.map +1 -0
  57. package/lib/types/src/GeneralUtils/index.d.ts +2 -0
  58. package/lib/types/src/GeneralUtils/index.d.ts.map +1 -0
  59. package/lib/types/src/GeneralUtils/util.general.d.ts +9 -0
  60. package/lib/types/src/GeneralUtils/util.general.d.ts.map +1 -0
  61. package/lib/types/src/MaskUtils/index.d.ts +2 -0
  62. package/lib/types/src/MaskUtils/index.d.ts.map +1 -0
  63. package/lib/types/src/MaskUtils/util.masks.d.ts +11 -0
  64. package/lib/types/src/MaskUtils/util.masks.d.ts.map +1 -0
  65. package/lib/types/src/NetworkUtils/index.d.ts +2 -0
  66. package/lib/types/src/NetworkUtils/index.d.ts.map +1 -0
  67. package/lib/types/src/NetworkUtils/util.network.d.ts +5 -0
  68. package/lib/types/src/NetworkUtils/util.network.d.ts.map +1 -0
  69. package/lib/types/src/NumberUtils/index.d.ts +2 -0
  70. package/lib/types/src/NumberUtils/index.d.ts.map +1 -0
  71. package/lib/types/src/NumberUtils/util.numbers.d.ts +15 -0
  72. package/lib/types/src/NumberUtils/util.numbers.d.ts.map +1 -0
  73. package/lib/types/src/RegexConsts/consts.regex.d.ts +8 -0
  74. package/lib/types/src/RegexConsts/consts.regex.d.ts.map +1 -0
  75. package/lib/types/src/RegexConsts/index.d.ts +2 -0
  76. package/lib/types/src/RegexConsts/index.d.ts.map +1 -0
  77. package/lib/types/src/ValidationUtils/index.d.ts +2 -0
  78. package/lib/types/src/ValidationUtils/index.d.ts.map +1 -0
  79. package/lib/types/src/ValidationUtils/util.validation.d.ts +8 -0
  80. package/lib/types/src/ValidationUtils/util.validation.d.ts.map +1 -0
  81. package/lib/types/src/index.d.ts +10 -0
  82. package/lib/types/src/index.d.ts.map +1 -0
  83. package/package.json +56 -0
  84. package/src/DateUtils/index.ts +1 -0
  85. package/src/DateUtils/util.dates.ts +337 -0
  86. package/src/FormatUtils/index.ts +1 -0
  87. package/src/FormatUtils/util.format.ts +151 -0
  88. package/src/GeneralConsts/consts.general.ts +138 -0
  89. package/src/GeneralConsts/index.ts +1 -0
  90. package/src/GeneralUtils/index.ts +1 -0
  91. package/src/GeneralUtils/util.general.ts +76 -0
  92. package/src/MaskUtils/index.ts +1 -0
  93. package/src/MaskUtils/util.masks.ts +78 -0
  94. package/src/NetworkUtils/index.ts +1 -0
  95. package/src/NetworkUtils/util.network.ts +15 -0
  96. package/src/NumberUtils/index.ts +1 -0
  97. package/src/NumberUtils/util.numbers.ts +250 -0
  98. package/src/RegexConsts/consts.regex.ts +10 -0
  99. package/src/RegexConsts/index.ts +1 -0
  100. package/src/ValidationUtils/index.ts +1 -0
  101. package/src/ValidationUtils/util.validation.ts +215 -0
  102. package/src/index.ts +9 -0
  103. package/tsconfig.json +23 -0
@@ -0,0 +1,151 @@
1
+ import GeneralConsts from '../GeneralConsts'
2
+ import NumberUtils from '../NumberUtils'
3
+ import RegexConsts from '../RegexConsts'
4
+
5
+ class RNFormatUtils {
6
+ static formatCelPhoneToWhatsApp(
7
+ cellPhone?: string,
8
+ uf?: string,
9
+ presentationFormat?: boolean,
10
+ invalidText?: string,
11
+ ) {
12
+ if (!cellPhone) {
13
+ return
14
+ }
15
+
16
+ cellPhone = NumberUtils.extractNumbers(cellPhone)
17
+
18
+ if (cellPhone.length === 0) {
19
+ return invalidText
20
+ }
21
+
22
+ cellPhone = parseInt(cellPhone).toString()
23
+
24
+ if (cellPhone.length === 9 && uf) {
25
+ uf = uf.toLocaleUpperCase()
26
+
27
+ const ufIndex = GeneralConsts.DDD_BRASIL_UF.findIndex((siglaUf) => siglaUf === uf)
28
+
29
+ if (ufIndex >= 0) {
30
+ cellPhone = GeneralConsts.DDD_PRINCIPAL_UF[ufIndex] + cellPhone
31
+ }
32
+ }
33
+
34
+ if (cellPhone.length === 11) {
35
+ const formatedPhone = '55' + cellPhone
36
+
37
+ if (presentationFormat) {
38
+ return (
39
+ '(' +
40
+ formatedPhone.substring(2, 4) +
41
+ ') ' +
42
+ formatedPhone.substring(4, 9) +
43
+ '-' +
44
+ formatedPhone.substring(9, 13)
45
+ )
46
+ } else {
47
+ return formatedPhone
48
+ }
49
+ } else {
50
+ return invalidText
51
+ }
52
+ }
53
+
54
+ static formatPhoneNumber(phone?: string, uf?: string) {
55
+ if (!phone) {
56
+ return
57
+ }
58
+
59
+ phone = NumberUtils.extractNumbers(phone)
60
+
61
+ if (phone.length === 0) {
62
+ return
63
+ }
64
+
65
+ phone = parseInt(phone).toString()
66
+
67
+ if ((phone.length === 8 || phone.length === 9) && uf) {
68
+ uf = uf.toLocaleUpperCase()
69
+
70
+ const ufIndex = GeneralConsts.DDD_BRASIL_UF.findIndex((siglaUf) => siglaUf === uf)
71
+
72
+ if (ufIndex >= 0) {
73
+ phone = GeneralConsts.DDD_PRINCIPAL_UF[ufIndex] + phone
74
+ }
75
+ }
76
+
77
+ if (phone.length === 10) {
78
+ return (
79
+ '(' +
80
+ phone.substring(0, 2) +
81
+ ') ' +
82
+ phone.substring(2, 6) +
83
+ '-' +
84
+ phone.substring(6, 10)
85
+ )
86
+ } else if (phone.length === 11) {
87
+ return (
88
+ '(' +
89
+ phone.substring(0, 2) +
90
+ ') ' +
91
+ phone.substring(2, 7) +
92
+ '-' +
93
+ phone.substring(7, 11)
94
+ )
95
+ }
96
+ }
97
+
98
+ static formatIpAdress(ip: string) {
99
+ const isHttps = ip.toLocaleLowerCase().includes('https')
100
+ const onlyIp = ip
101
+ .replace('http://', '')
102
+ .replace('https://', '')
103
+ .replace('/', '')
104
+ .trim()
105
+ const isValid = RegexConsts.REGEX_IP.test(onlyIp)
106
+
107
+ if (isValid) {
108
+ return (isHttps ? 'https://' : 'http://') + onlyIp.trim()
109
+ } else {
110
+ return ''
111
+ }
112
+ }
113
+
114
+ static formatUrlAdress(url: string) {
115
+ let urlFormated = url.toLocaleLowerCase().trim()
116
+
117
+ if (!urlFormated.includes('http://') && !urlFormated.includes('https://')) {
118
+ urlFormated = 'http://' + urlFormated
119
+ }
120
+
121
+ if (RegexConsts.REGEX_URL.test(urlFormated)) {
122
+ return urlFormated
123
+ } else {
124
+ return ''
125
+ }
126
+ }
127
+
128
+ static formatUserName(fullName: string) {
129
+ if (!fullName) {
130
+ return
131
+ }
132
+
133
+ const nameParts = fullName.toLocaleLowerCase().split(' ')
134
+
135
+ if (nameParts.length > 1) {
136
+ return (
137
+ this.firstLetterUpper(nameParts[0]) +
138
+ ' ' +
139
+ this.firstLetterUpper(nameParts[nameParts.length - 1])
140
+ )
141
+ } else if (nameParts.length === 1) {
142
+ return this.firstLetterUpper(nameParts[0])
143
+ }
144
+ }
145
+
146
+ static firstLetterUpper(text: string) {
147
+ return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase()
148
+ }
149
+ }
150
+
151
+ export default RNFormatUtils
@@ -0,0 +1,138 @@
1
+ const GeneralConsts = {
2
+ DEFAULT_OPACITY_CLICK: 0.8,
3
+ MAX_ACCESSIBILITY_MULTIPLIER: 1.1,
4
+ BASE64_PREFIX: 'data:application/pdf;base64,',
5
+ EMPTY_DATE_TEXT: '__ /__ /____',
6
+
7
+ DDD_BRASIL_UF: [
8
+ 'DF',
9
+ 'GO',
10
+ 'MT',
11
+ 'MS',
12
+ 'AL',
13
+ 'BA',
14
+ 'CE',
15
+ 'MA',
16
+ 'PB',
17
+ 'PE',
18
+ 'PI',
19
+ 'RN',
20
+ 'SE',
21
+ 'AC',
22
+ 'AP',
23
+ 'AM',
24
+ 'PA',
25
+ 'RO',
26
+ 'RR',
27
+ 'TO',
28
+ 'ES',
29
+ 'MG',
30
+ 'RJ',
31
+ 'SP',
32
+ 'PN',
33
+ 'RS',
34
+ 'SC',
35
+ ],
36
+
37
+ DDD_PRINCIPAL_UF: [
38
+ '61',
39
+ '62',
40
+ '65',
41
+ '67',
42
+ '82',
43
+ '71',
44
+ '85',
45
+ '98',
46
+ '83',
47
+ '81',
48
+ '86',
49
+ '84',
50
+ '79',
51
+ '68',
52
+ '96',
53
+ '92',
54
+ '91',
55
+ '69',
56
+ '95',
57
+ '63',
58
+ '27',
59
+ '31',
60
+ '21',
61
+ '11',
62
+ '41',
63
+ '51',
64
+ '47',
65
+ ],
66
+
67
+ DDD_BRASIL: [
68
+ '11',
69
+ '12',
70
+ '13',
71
+ '14',
72
+ '15',
73
+ '16',
74
+ '17',
75
+ '18',
76
+ '19',
77
+ '21',
78
+ '22',
79
+ '24',
80
+ '27',
81
+ '28',
82
+ '31',
83
+ '32',
84
+ '33',
85
+ '34',
86
+ '35',
87
+ '37',
88
+ '38',
89
+ '41',
90
+ '42',
91
+ '43',
92
+ '44',
93
+ '45',
94
+ '46',
95
+ '47',
96
+ '48',
97
+ '49',
98
+ '51',
99
+ '53',
100
+ '54',
101
+ '55',
102
+ '61',
103
+ '62',
104
+ '63',
105
+ '64',
106
+ '65',
107
+ '66',
108
+ '67',
109
+ '68',
110
+ '69',
111
+ '71',
112
+ '73',
113
+ '74',
114
+ '75',
115
+ '77',
116
+ '79',
117
+ '81',
118
+ '82',
119
+ '83',
120
+ '84',
121
+ '85',
122
+ '86',
123
+ '87',
124
+ '88',
125
+ '89',
126
+ '91',
127
+ '92',
128
+ '93',
129
+ '94',
130
+ '95',
131
+ '96',
132
+ '97',
133
+ '98',
134
+ '99',
135
+ ]
136
+ }
137
+
138
+ export default GeneralConsts
@@ -0,0 +1 @@
1
+ export { default } from './consts.general'
@@ -0,0 +1 @@
1
+ export { default } from './util.general'
@@ -0,0 +1,76 @@
1
+ import * as Clipboard from 'expo-clipboard'
2
+ import * as SplashScreen from 'expo-splash-screen'
3
+ import { Platform } from 'react-native'
4
+ import * as Device from 'expo-device'
5
+ import Constants from 'expo-constants'
6
+ import { randomUUID } from 'expo-crypto'
7
+
8
+ class GeneralUtils {
9
+ static async hideSplash() {
10
+ try {
11
+ await SplashScreen.hideAsync()
12
+ } catch (error) {
13
+ console.log(error)
14
+ }
15
+ }
16
+
17
+ static getUUID() {
18
+ return randomUUID()
19
+ }
20
+
21
+ static getDeviceDetails() {
22
+ let deviceDetails = ''
23
+
24
+ if (Device.manufacturer) {
25
+ deviceDetails = Device.manufacturer
26
+ }
27
+ if (Platform.OS !== 'ios' && Device.brand) {
28
+ deviceDetails += ' ' + Device.brand
29
+ }
30
+ if (Device.modelName) {
31
+ deviceDetails += ' ' + Device.modelName
32
+ }
33
+ if (Device.osVersion) {
34
+ deviceDetails += ' ' + Device.osVersion
35
+ }
36
+ if (deviceDetails === '') {
37
+ deviceDetails = 'Não identificado'
38
+ }
39
+
40
+ return deviceDetails
41
+ }
42
+
43
+ static getAppVersion(fullVersion?: boolean) {
44
+ let appVersion = ''
45
+
46
+ if (Constants.expoConfig?.version) {
47
+ appVersion = Constants.expoConfig.version
48
+ } else if (Constants.manifest?.version) {
49
+ appVersion = Constants.manifest.version
50
+ } else if (Constants.manifest2?.extra?.expoClient?.version) {
51
+ appVersion = Constants.manifest2.extra.expoClient.version
52
+ }
53
+
54
+ if (appVersion) {
55
+ if (fullVersion) {
56
+ if (Platform.OS === 'ios') {
57
+ if (Constants.expoConfig?.ios?.buildNumber) {
58
+ appVersion += '.' + Constants.expoConfig.ios.buildNumber
59
+ }
60
+ } else if (Constants.expoConfig?.android?.versionCode) {
61
+ appVersion += '.' + Constants.expoConfig.android.versionCode
62
+ }
63
+ }
64
+ } else {
65
+ appVersion = '0.0.0.0'
66
+ }
67
+
68
+ return appVersion
69
+ }
70
+
71
+ static async copyToClipboard(value: string) {
72
+ await Clipboard.setStringAsync(value)
73
+ }
74
+ }
75
+
76
+ export default GeneralUtils
@@ -0,0 +1 @@
1
+ export { default } from './util.masks'
@@ -0,0 +1,78 @@
1
+ type MASK_TYPES =
2
+ | 'numbers'
3
+ | 'cep'
4
+ | 'telephone'
5
+ | 'currency'
6
+ | 'cpf'
7
+ | 'cnpj'
8
+ | 'cpfcnpj'
9
+
10
+ class MaskUtils {
11
+ static maskCEP(value: string) {
12
+ value = value.replace(/\D/g, '')
13
+ value = value.replace(/^(\d{5})(\d)/, '$1-$2')
14
+ return value
15
+ }
16
+
17
+ static maskPhone(value: string) {
18
+ value = value.replace(/\D/g, '')
19
+ value = value.replace(/^(\d{2})(\d)/, '($1)$2')
20
+ value = value.replace(/(\d)(\d{4})$/, '$1-$2')
21
+ return value
22
+ }
23
+
24
+ static maskCurrency(value: string, putSymbol: boolean) {
25
+ value = value.replace(/\D/g, '')
26
+ value = value.replace(/(\d)(\d{2})$/, '$1,$2')
27
+ value = value.replace(/(?=(\d{3})+(\D))\B/g, '.')
28
+ return putSymbol ? 'R$ ' + value : value
29
+ }
30
+
31
+ static maskCPF(value: string) {
32
+ value = value.replace(/\D/g, '')
33
+
34
+ if (value.length > 11) {
35
+ value = value.substring(0, 11)
36
+ }
37
+
38
+ value = value.replace(/(\d{3})(\d)/, '$1.$2')
39
+ value = value.replace(/(\d{3})(\d)/, '$1.$2')
40
+ value = value.replace(/(\d{3})(\d{1,2})$/, '$1-$2')
41
+ return value
42
+ }
43
+
44
+ static maskCNPJ(value: string) {
45
+ value = value.replace(/\D/g, '')
46
+
47
+ if (value.length > 14) {
48
+ value = value.substring(0, 14)
49
+ }
50
+
51
+ value = value.replace(/^(\d{2})(\d)/, '$1.$2')
52
+ value = value.replace(/^(\d{2})\.(\d{3})(\d)/, '$1.$2.$3')
53
+ value = value.replace(/\.(\d{3})(\d)/, '.$1/$2')
54
+ value = value.replace(/(\d{4})(\d)/, '$1-$2')
55
+ return value
56
+ }
57
+
58
+ static maskCPFCNPJ(value: string) {
59
+ value = value.replace(/\D/g, '')
60
+
61
+ if (value.length > 14) {
62
+ value = value.substring(0, 14)
63
+ }
64
+
65
+ if (value.length <= 11) {
66
+ return this.maskCPF(value)
67
+ } else {
68
+ return this.maskCNPJ(value)
69
+ }
70
+ }
71
+
72
+ static maskNumbers(value: string) {
73
+ value = value.replace(/\D/g, '')
74
+ return value
75
+ }
76
+ }
77
+
78
+ export default MaskUtils
@@ -0,0 +1 @@
1
+ export { default } from './util.network'
@@ -0,0 +1,15 @@
1
+ import NumberUtils from "../NumberUtils"
2
+
3
+ class NetworkUtils {
4
+ static isInternalNetwork(baseURL: string) {
5
+ const baseURLNumbers = NumberUtils.numbersAndDots(baseURL)
6
+
7
+ return (
8
+ baseURLNumbers.startsWith('10.') ||
9
+ baseURLNumbers.startsWith('172.') ||
10
+ baseURLNumbers.startsWith('192.')
11
+ )
12
+ }
13
+ }
14
+
15
+ export default NetworkUtils
@@ -0,0 +1 @@
1
+ export { default } from './util.numbers'