the-react 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "the-react",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "A React library for TheBugs Project",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.ts",
@@ -5,7 +5,7 @@ import type {
5
5
  JSX,
6
6
  JSXElement,
7
7
  JSXElementType
8
- } from "../types/jsx"
8
+ } from "./../types/jsx"
9
9
 
10
10
  /**
11
11
  * Нормализует children в плоский массив JSX-элементов и строк.
@@ -93,9 +93,21 @@ function jsx<PropsType extends ComponentPropsType>(
93
93
  }
94
94
  }
95
95
  function stableHash(obj: any): string {
96
- return btoa(
97
- JSON.stringify(obj, Object.keys(obj).sort())
98
- ).slice(0, 8);
96
+ const computeHash = (str: string): string => {
97
+ let hash = 5381;
98
+ for (let i = 0; i < str.length; i++) {
99
+ hash = (hash * 33) ^ str.charCodeAt(i);
100
+ }
101
+ return (hash >>> 0).toString(16).slice(0, 8);
102
+ };
103
+
104
+ try {
105
+ const json = JSON.stringify(obj, Object.keys(obj).sort());
106
+ return computeHash(json);
107
+ } catch (err) {
108
+ const fallbackStr = `error:${err ?? 'unknown'}:${typeof obj}:${String(obj)}`;
109
+ return computeHash(fallbackStr);
110
+ }
99
111
  }
100
112
 
101
113
  export type { JSX };