zavadil-ts-common 1.2.63 → 1.2.65

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.
@@ -7,3 +7,4 @@ export { PagingUtil } from './PagingUtil';
7
7
  export { DateUtil } from './DateUtil';
8
8
  export { NumberUtil } from './NumberUtil';
9
9
  export { JsonUtil } from './JsonUtil';
10
+ export { HashUtil } from './HashUtil';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zavadil-ts-common",
3
- "version": "1.2.63",
3
+ "version": "1.2.65",
4
4
  "description": "Common types and components for Typescript UI apps.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -0,0 +1,26 @@
1
+ export class HashUtil {
2
+
3
+ static crc32hex(str: string): string {
4
+ // Encode string to UTF-8 bytes
5
+ const encoder = new TextEncoder();
6
+ const data = encoder.encode(str);
7
+
8
+ // Generate CRC32 table once
9
+ const table = new Uint32Array(256);
10
+ for (let i = 0; i < 256; i++) {
11
+ let c = i;
12
+ for (let j = 0; j < 8; j++) {
13
+ c = (c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1);
14
+ }
15
+ table[i] = c >>> 0;
16
+ }
17
+
18
+ let crc = 0 ^ -1;
19
+ for (let i = 0; i < data.length; i++) {
20
+ crc = (crc >>> 8) ^ table[(crc ^ data[i]) & 0xFF];
21
+ }
22
+ crc = (crc ^ -1) >>> 0;
23
+
24
+ return crc.toString(16);
25
+ }
26
+ }
package/src/util/index.ts CHANGED
@@ -7,3 +7,4 @@ export { PagingUtil } from './PagingUtil';
7
7
  export { DateUtil } from './DateUtil';
8
8
  export { NumberUtil } from './NumberUtil';
9
9
  export { JsonUtil } from './JsonUtil';
10
+ export { HashUtil } from './HashUtil';