jcinfo-utils 1.0.17 → 1.0.19
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/index.d.ts +2 -0
- package/index.js +29 -0
- package/package.json +3 -2
- package/testar.js +4 -28
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -131,6 +131,34 @@ function random(max = 99999999) {
|
|
|
131
131
|
return Math.floor(Math.random() * max + 1)
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
function getHash(value = '') {
|
|
135
|
+
// String que você deseja hash
|
|
136
|
+
const minhaString = value + new Date().toISOString()
|
|
137
|
+
|
|
138
|
+
// Função para calcular o hash CRC32
|
|
139
|
+
function calcularCRC32(str) {
|
|
140
|
+
const table = new Array(256)
|
|
141
|
+
const poly = 0xedb88320
|
|
142
|
+
for (let i = 0; i < 256; i++) {
|
|
143
|
+
let crc = i
|
|
144
|
+
for (let j = 0; j < 8; j++) {
|
|
145
|
+
crc = crc & 1 ? (crc >>> 1) ^ poly : crc >>> 1
|
|
146
|
+
}
|
|
147
|
+
table[i] = crc
|
|
148
|
+
}
|
|
149
|
+
let crc = 0xffffffff
|
|
150
|
+
const bytes = new TextEncoder().encode(str)
|
|
151
|
+
for (const byte of bytes) {
|
|
152
|
+
crc = (crc >>> 8) ^ table[(crc ^ byte) & 0xff]
|
|
153
|
+
}
|
|
154
|
+
return (crc ^ 0xffffffff) >>> 0
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// gerar e devolver o hash
|
|
158
|
+
const hash = calcularCRC32(minhaString)
|
|
159
|
+
return hash.toString(16)
|
|
160
|
+
}
|
|
161
|
+
|
|
134
162
|
export {
|
|
135
163
|
addLog,
|
|
136
164
|
addUserSelectNoneInMobile,
|
|
@@ -144,6 +172,7 @@ export {
|
|
|
144
172
|
getFirstDay,
|
|
145
173
|
getLastDay,
|
|
146
174
|
getMonthName,
|
|
175
|
+
getHash,
|
|
147
176
|
isDarkMode,
|
|
148
177
|
isDesktop,
|
|
149
178
|
isMobile,
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jcinfo-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"description": "Pacote de funções utilitárias",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "nodemon testar.js"
|
|
8
|
+
"test": "nodemon testar.js",
|
|
9
|
+
"pub": "yarn publish"
|
|
9
10
|
},
|
|
10
11
|
"keywords": [],
|
|
11
12
|
"author": "JC",
|
package/testar.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { getDateStr } from './dates.js'
|
|
1
2
|
import * as jc from './index.js'
|
|
2
3
|
|
|
3
4
|
console.log(
|
|
4
5
|
jc.formatValor(123, 3, false),
|
|
5
6
|
jc.formatData(new Date(1973, 8, 19)),
|
|
6
|
-
JSON.stringify(jc.calcularIdade('
|
|
7
|
-
|
|
7
|
+
JSON.stringify(jc.calcularIdade('1973-09-19', getDateStr())),
|
|
8
|
+
|
|
8
9
|
jc.getDateStr(),
|
|
9
10
|
jc.getDateTimeStr(),
|
|
10
11
|
jc.getFirstDay(),
|
|
@@ -13,29 +14,4 @@ console.log(
|
|
|
13
14
|
jc.trunc(123.99889889),
|
|
14
15
|
)
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
if (typeof data == 'string') {
|
|
18
|
-
data = new Date(data)
|
|
19
|
-
}
|
|
20
|
-
return Intl.DateTimeFormat('pt-br', { dateStyle: 'short' }).format(data)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function formatDataHora(data) {
|
|
24
|
-
if (typeof data == 'string') {
|
|
25
|
-
data = new Date(data)
|
|
26
|
-
}
|
|
27
|
-
let result = Intl.DateTimeFormat('pt-br', {
|
|
28
|
-
dateStyle: 'short',
|
|
29
|
-
timeStyle: 'short',
|
|
30
|
-
}).format(data)
|
|
31
|
-
result = result.split(', ').join(' ')
|
|
32
|
-
return result
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let data = new Date(1973, 8, 19, 2, 15, 45, 123)
|
|
36
|
-
// console.log(formatData(data))
|
|
37
|
-
// console.log(formatDataHora(data))
|
|
38
|
-
|
|
39
|
-
data = '2023-07-14T18:08:45'
|
|
40
|
-
console.log(formatData(data))
|
|
41
|
-
console.log(formatDataHora(data))
|
|
17
|
+
console.log(jc.getHash('jose'))
|