Skip to content

Commit 0513e68

Browse files
authored
V6 (#51)
* first refactor * convert `enum` to `const` for filesize * update dependencies to latest * restore additional helper support * remove unused dependency * add prettier config * direct index assignment for `DocumentFragment` * restore old playground file * infrastructure cleanup * update with new benchmarks * quick attempt at using `JSON.stringify` * only use `JSON.stringify` when necessary * make element hash unique based on element type * use `String.prototype.match()` instead of `RegExp.prototype.exec` for simplicity * update dependencies * simplify logic and avoid layer in stack when stringifying * reduce code size by using `every` / `some` * guarantee an argument passed for consistency * code cleanup * move constants to dedicated file, and remove layer for simple stringification * remove no-longer-used `TO_STRING_CONSTANTS` * update benchmarks * have unique non-enumerable reference hashes, and eliminate unnecessary `JSON.stringify` * use decrementing loop and pre-size arrays * refactor build setup for better linting, typechecking, and use as a module * fix `prettier` boinking on ESM * update benchmarks to ESM * simplify object hash for faster iteration * enclose `Map` / `Set` in brackets for entries * add support for primitive wrappers * use string characters for hashable types, to avoid possible conflict with class values * clean up benchmarks * improve speed of `Event` hash * use pipe instead of colon, for better rarity * inline `sort` call for sets * add `release-it` infrastructure * clean up dependencies * avoid sourcemaps for min file * clean up fallback exposed types * update CHANGELOG * rerun benchmarks * force latest version of `decompress-response` * Release 6.0.0-beta.0 * refactor build setup to avoid separate `packageJson.js` file * use string concatenation manually to avoid `.concat()` in TSC output * simplify prefix creation * consolidate namespaced construction into utility * pass object class to `stringifyComplexType` to avoid local variable * Release 6.0.0-beta.1 * bespoke handling of object types to reduce work * update README * add `WeakRef` support * fix unused import * add support for bigint typed arrays, as well as shared array buffers * update README and CHANGELOG * Release 6.0.0-beta.2 * update dependencies to latest * update `.npmignore` * small documentation fixes
1 parent ca4f310 commit 0513e68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+5247
-5398
lines changed

.eslintrc

+3-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
"node": true,
55
"es6": true
66
},
7-
"extends": [
8-
"eslint:recommended",
9-
"plugin:@typescript-eslint/eslint-recommended",
10-
"plugin:@typescript-eslint/recommended"
11-
],
7+
"extends": ["plugin:@typescript-eslint/recommended"],
128
"parser": "@typescript-eslint/parser",
139
"parserOptions": {
1410
"ecmaVersion": 2021,
@@ -20,7 +16,8 @@
2016

2117
"@typescript-eslint/explicit-function-return-type": 0,
2218
"@typescript-eslint/explicit-module-boundary-types": 0,
23-
"@typescript-eslint/no-explicit-any": 0
19+
"@typescript-eslint/no-explicit-any": 0,
20+
"@typescript-eslint/no-non-null-assertion": 0
2421
},
2522
"settings": {
2623
"react": {

.npmignore

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
.idea
2-
.nyc_output
31
.babelrc
42
.eslintrc
53
.gitignore
64
.npmignore
5+
.prettierrc
6+
.release-it*.json
7+
__tests__
78
benchmarks
9+
build
810
coverage
911
DEV_ONLY
1012
node_modules
11-
rollup.config.js
1213
src
13-
test
14-
webpack
14+
jest.config.js
1515
*.csv
16-
yarn*
17-
__tests__
1816
results_*.txt
19-
jest.config.js
20-
jest.init.js
21-
webpack.config.js
2217
tsconfig.json
18+
yarn*

.prettierrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"arrowParens": "always",
3+
"bracketSpacing": true,
4+
"semi": true,
5+
"singleQuote": true,
6+
"tabWidth": 2,
7+
"trailingComma": "all"
8+
}

.release-it.beta.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"github": {
3+
"release": true,
4+
"tagName": "v${version}"
5+
},
6+
"npm": {
7+
"tag": "next"
8+
},
9+
"preReleaseId": "beta",
10+
"hooks": {
11+
"before:init": [
12+
"npm run lint",
13+
"npm run typecheck",
14+
"npm run test",
15+
"npm run build"
16+
]
17+
}
18+
}

.release-it.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"github": {
3+
"release": true,
4+
"tagName": "v${version}"
5+
},
6+
"hooks": {
7+
"before:init": [
8+
"npm run lint",
9+
"npm run typecheck",
10+
"npm run test",
11+
"npm run build"
12+
]
13+
}
14+
}

CHANGELOG.md

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# hash-it CHANGELOG
22

3+
## 6.0.0
4+
5+
**Breaking changes**
6+
7+
- Equality utilities (`is` / `is.any` / `is.all` / `is.not`) are no longer provided
8+
- `Error` type hashes now include the message (previously only included stack)
9+
- Non-enumerable type hashes (`Generator`, `Promise`, `WeakMap`, `WeakSet`) now hash uniquely based on reference
10+
- `WeakMap` is now required at runtime (used as cache for circular references)
11+
12+
**Enhancements**
13+
14+
- Better support for system-specific loading (ESM vs CJS vs UMD)
15+
- Added support for primitive wrappers (e.g. `new Number('123')`)
16+
- Added support for more object classes
17+
- `AsyncFunction`
18+
- `AsyncGeneratorFunction`
19+
- `BigInt64Array`
20+
- `BigUint64Array`
21+
- `GeneratorFunction`
22+
- `SharedArrayBuffer`
23+
- `WeakRef` (same limitations as those for `WeakMap` / `WeakSet`)
24+
325
## 5.0.2
426

527
- Reduce code size by 29.29% (19.42% gzipped size)

DEV_ONLY/index.tsx

+82-69
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import 'regenerator-runtime/runtime';
2-
31
import React from 'react';
4-
import { render } from 'react-dom';
2+
import { createRoot } from 'react-dom/client';
53
import hash from '../src';
64

75
document.body.style.backgroundColor = '#1d1d1d';
@@ -23,7 +21,7 @@ class StatefulComponent extends React.Component {
2321

2422
const StatelessComponent = () => <div>test</div>;
2523

26-
const a = {
24+
const a: Record<string, any> = {
2725
foo: 'bar',
2826
};
2927

@@ -33,13 +31,19 @@ const b = {
3331

3432
a.b = b;
3533

34+
function getArguments() {
35+
return arguments;
36+
}
37+
3638
const object = {
3739
ReactStatefulClass: StatefulComponent,
3840
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3941
// @ts-ignore
4042
ReactStatefulElement: <StatefulComponent />,
4143
ReactStatelessClass: StatelessComponent,
4244
ReactStatelessElement: <StatelessComponent />,
45+
// @ts-expect-error - arguments are not defined
46+
arguments: getArguments('foo', 'bar'),
4347
arr: ['foo', 'bar'],
4448
arrayBuffer: new Uint16Array([1, 2, 3]).buffer,
4549
bigint: BigInt(9007199254740991),
@@ -65,7 +69,7 @@ const object = {
6569
func() {
6670
alert('y');
6771
},
68-
*generator() {
72+
*generator(): Generator<any, any, any> {
6973
const value = yield 1;
7074

7175
yield value + 2;
@@ -97,28 +101,29 @@ const object = {
97101
win: window,
98102
};
99103

100-
const profile = (iterations = 100) => {
101-
let index = -1;
104+
// const profile = (iterations = 100) => {
105+
// let index = -1;
102106

103-
console.profile('hash timing');
107+
// console.profile('hash timing');
104108

105-
while (++index < iterations) {
106-
hash(object);
107-
hash(a);
109+
// while (++index < iterations) {
110+
// hash(object);
111+
// hash(a);
108112

109-
for (const key in object) {
110-
hash(object[key]);
111-
}
113+
// for (const key in object) {
114+
// // @ts-expect-error - not worth it
115+
// hash(object[key]);
116+
// }
112117

113-
hash(document.body);
114-
// this is the killer, so only profiled if you uncomment
115-
// hash(window);
116-
}
118+
// hash(document.body);
119+
// // this is the killer, so only profiled if you uncomment
120+
// // hash(window);
121+
// }
117122

118-
console.profileEnd('hash timing');
123+
// console.profileEnd('hash timing');
119124

120-
console.log('Check the Profiles tab in DevTools to see the output.');
121-
};
125+
// console.log('Check the Profiles tab in DevTools to see the output.');
126+
// };
122127

123128
// const benchmark = () => require('../benchmarks/index');
124129

@@ -170,61 +175,69 @@ const visualValidation = () => {
170175
console.log(object.win, hash(object.win));
171176
};
172177

173-
const hashOnlyValidation = () => {
174-
console.log(hash(object));
175-
console.log(hash(a));
176-
console.log(hash(object.string));
177-
console.log(hash(object.num));
178-
console.log(hash(object.bool));
179-
console.log(hash(object.func));
180-
console.log(hash(object.undef));
181-
console.log(hash(object.nil));
182-
console.log(hash(object.obj));
183-
console.log(hash(object.arr));
184-
console.log(hash(object.el));
185-
console.log(hash(object.fragment));
186-
console.log(hash(object.svg));
187-
console.log(hash(object.math));
188-
console.log(hash(object.regexp));
189-
console.log(hash(object.event));
190-
console.log(hash(object.nodeList));
191-
192-
// comment out for older browser testing
193-
console.log(hash(object.symbol));
194-
console.log(hash(object.err));
195-
console.log(hash(object.map));
196-
console.log(hash(object.set));
197-
console.log(hash(object.weakMap));
198-
console.log(hash(object.weakSet));
199-
console.log(hash(object.arrayBuffer));
200-
console.log(hash(object.dataView));
201-
console.log(hash(object.float32Array));
202-
console.log(hash(object.float64Array));
203-
console.log(hash(object.generator));
204-
console.log(hash(object.int8Array));
205-
console.log(hash(object.int16Array));
206-
console.log(hash(object.int32Array));
207-
console.log(hash(object.promise));
208-
console.log(hash(object.uint8Array));
209-
console.log(hash(object.uint8ClampedArray));
210-
console.log(hash(object.uint16Array));
211-
console.log(hash(object.uint32Array));
212-
213-
console.log(hash(object.ReactStatefulClass));
214-
console.log(hash(object.ReactStatefulElement));
215-
console.log(hash(object.ReactStatelessClass));
216-
console.log(hash(object.ReactStatelessElement));
217-
console.log(hash(document.body));
218-
console.log(hash(window));
219-
};
178+
// const hashOnlyValidation = () => {
179+
// console.log(hash(object));
180+
// console.log(hash(a));
181+
// console.log(hash(object.string));
182+
// console.log(hash(object.num));
183+
// console.log(hash(object.bool));
184+
// console.log(hash(object.func));
185+
// console.log(hash(object.undef));
186+
// console.log(hash(object.nil));
187+
// console.log(hash(object.obj));
188+
// console.log(hash(object.arr));
189+
// console.log(hash(object.el));
190+
// console.log(hash(object.fragment));
191+
// console.log(hash(object.svg));
192+
// console.log(hash(object.math));
193+
// console.log(hash(object.regexp));
194+
// console.log(hash(object.event));
195+
// console.log(hash(object.nodeList));
196+
197+
// // comment out for older browser testing
198+
// console.log(hash(object.symbol));
199+
// console.log(hash(object.err));
200+
// console.log(hash(object.map));
201+
// console.log(hash(object.set));
202+
// console.log(hash(object.weakMap));
203+
// console.log(hash(object.weakSet));
204+
// console.log(hash(object.arrayBuffer));
205+
// console.log(hash(object.dataView));
206+
// console.log(hash(object.float32Array));
207+
// console.log(hash(object.float64Array));
208+
// console.log(hash(object.generator));
209+
// console.log(hash(object.int8Array));
210+
// console.log(hash(object.int16Array));
211+
// console.log(hash(object.int32Array));
212+
// console.log(hash(object.promise));
213+
// console.log(hash(object.uint8Array));
214+
// console.log(hash(object.uint8ClampedArray));
215+
// console.log(hash(object.uint16Array));
216+
// console.log(hash(object.uint32Array));
217+
218+
// console.log(hash(object.ReactStatefulClass));
219+
// console.log(hash(object.ReactStatefulElement));
220+
// console.log(hash(object.ReactStatelessClass));
221+
// console.log(hash(object.ReactStatelessElement));
222+
// console.log(hash(document.body));
223+
// console.log(hash(window));
224+
// };
220225

221226
// benchmark();
222227
// profile(1000);
223228
visualValidation();
224229
// hashOnlyValidation();
225230

231+
const promise = Promise.resolve(123);
232+
233+
console.log(hash(promise));
234+
console.log(hash(promise));
235+
console.log(hash(Promise.resolve(123)));
236+
226237
const div = document.createElement('div');
227238

228-
render(<div>Check the console for more details!</div>, div);
239+
const root = createRoot(div);
229240

230241
document.body.appendChild(div);
242+
243+
root.render(<div>Check the console for more details!</div>);

0 commit comments

Comments
 (0)