jcinfo-utils 1.0.19 → 1.0.21
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 +31 -20
- package/package.json +1 -1
- package/testar.js +3 -0
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -131,34 +131,44 @@ function random(max = 99999999) {
|
|
|
131
131
|
return Math.floor(Math.random() * max + 1)
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
134
|
+
// Função para calcular o hash CRC32
|
|
135
|
+
function calcularCRC32(str) {
|
|
136
|
+
const table = new Array(256)
|
|
137
|
+
const poly = 0xedb88320
|
|
138
|
+
for (let i = 0; i < 256; i++) {
|
|
139
|
+
let crc = i
|
|
140
|
+
for (let j = 0; j < 8; j++) {
|
|
141
|
+
crc = crc & 1 ? (crc >>> 1) ^ poly : crc >>> 1
|
|
148
142
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
table[i] = crc
|
|
144
|
+
}
|
|
145
|
+
let crc = 0xffffffff
|
|
146
|
+
const bytes = new TextEncoder().encode(str)
|
|
147
|
+
for (const byte of bytes) {
|
|
148
|
+
crc = (crc >>> 8) ^ table[(crc ^ byte) & 0xff]
|
|
155
149
|
}
|
|
150
|
+
return (crc ^ 0xffffffff) >>> 0
|
|
151
|
+
}
|
|
156
152
|
|
|
153
|
+
function getHash(value = '') {
|
|
154
|
+
// String que você deseja hash
|
|
155
|
+
const minhaString = value + new Date().toISOString()
|
|
157
156
|
// gerar e devolver o hash
|
|
158
157
|
const hash = calcularCRC32(minhaString)
|
|
159
158
|
return hash.toString(16)
|
|
160
159
|
}
|
|
161
160
|
|
|
161
|
+
function scrollToTop(smooth = false) {
|
|
162
|
+
try {
|
|
163
|
+
document?.querySelector('main')?.scrollTo({
|
|
164
|
+
top: 0,
|
|
165
|
+
behavior: smooth ? 'smooth' : 'auto',
|
|
166
|
+
})
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.log('scrollToTop: "document" não existe neste escopo!')
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
162
172
|
export {
|
|
163
173
|
addLog,
|
|
164
174
|
addUserSelectNoneInMobile,
|
|
@@ -178,4 +188,5 @@ export {
|
|
|
178
188
|
isMobile,
|
|
179
189
|
random,
|
|
180
190
|
trunc,
|
|
191
|
+
scrollToTop,
|
|
181
192
|
}
|
package/package.json
CHANGED
package/testar.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getDateStr } from './dates.js'
|
|
2
2
|
import * as jc from './index.js'
|
|
3
|
+
import { scrollToTop } from './index.js'
|
|
3
4
|
|
|
4
5
|
console.log(
|
|
5
6
|
jc.formatValor(123, 3, false),
|
|
@@ -15,3 +16,5 @@ console.log(
|
|
|
15
16
|
)
|
|
16
17
|
|
|
17
18
|
console.log(jc.getHash('jose'))
|
|
19
|
+
|
|
20
|
+
scrollToTop()
|