Skip to content

Commit e4d3025

Browse files
committed
update README
1 parent b24c75d commit e4d3025

File tree

6 files changed

+55
-101
lines changed

6 files changed

+55
-101
lines changed

DEV_ONLY/index.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import 'regenerator-runtime/runtime';
2-
31
import React from 'react';
4-
import { render } from 'react-dom';
2+
import { createRoot } from 'react-dom/client';
3+
import hashIt from '../src';
54
import hash from '../src';
65

76
document.body.style.backgroundColor = '#1d1d1d';
@@ -230,8 +229,16 @@ const visualValidation = () => {
230229
visualValidation();
231230
// hashOnlyValidation();
232231

232+
const promise = Promise.resolve(123);
233+
234+
console.log(hash(promise));
235+
console.log(hash(promise));
236+
console.log(hash(Promise.resolve(123)));
237+
233238
const div = document.createElement('div');
234239

235-
render(<div>Check the console for more details!</div>, div);
240+
const root = createRoot(div);
236241

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

README.md

+12-74
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ Fast and consistent hashCode for any object type
88
- [Table of contents](#table-of-contents)
99
- [Usage](#usage)
1010
- [Overview](#overview)
11-
- [Equality methods](#equality-methods)
12-
- [hash.is](#hashis)
13-
- [hash.is.all](#hashisall)
14-
- [hash.is.any](#hashisany)
15-
- [hash.is.not](#hashisnot)
1611
- [Note](#note)
1712
- [Support](#support)
1813
- [Browsers](#browsers)
@@ -54,9 +49,19 @@ Well ... sadly, no, there are a few exceptions.
5449
- `WeakMap` / `WeakSet`
5550
- The spec explicitly forbids iteration over them, so the unique values cannot be discovered
5651

57-
In each of these cases, no matter what the values of the object, they will always yield the same hash result, which is unique to each object type. If you have any ideas about how these can be uniquely hashed, they are welcome!
52+
For each of these object types, the object will have a unique hash based on the object reference itself:
5853

59-
Here is the list of object classes that produce unique hashes:
54+
```ts
55+
const promise = Promise.resolve(123);
56+
57+
console.log(hash(promise)); // 16843037491939
58+
console.log(hash(promise)); // 16843037491939
59+
console.log(hash(Promise.resolve(123))); // 4622327363876
60+
```
61+
62+
Notice even if the internal values of the object are the same, the hash is different. This is because the values of the above object types cannot be introspected.
63+
64+
Here is the list of object classes that produce consistent, unique hashes based on their value:
6065

6166
- `Arguments`
6267
- `Array`
@@ -100,73 +105,6 @@ Here is the list of object classes that produce unique hashes:
100105

101106
If there is an object class or data type that is missing, please submit an issue.
102107

103-
## Equality methods
104-
105-
### hash.is
106-
107-
`hash.is(value1: any, value2: any): boolean`
108-
109-
Compares the two objects to determine equality.
110-
111-
```javascript
112-
console.log(hash.is(null, 123)); // false
113-
console.log(hash.is(null, null)); // true
114-
```
115-
116-
### hash.is.all
117-
118-
`hash.is.all(value1: any, value2: any[, value3: any[, ...valueN]]): boolean`
119-
120-
Compares the first object to all other objects passed to determine if all are equal based on hashCode
121-
122-
```javascript
123-
const foo = {
124-
foo: 'bar',
125-
};
126-
const alsoFoo = {
127-
foo: 'bar',
128-
};
129-
const stillFoo = {
130-
foo: 'bar',
131-
};
132-
133-
console.log(hash.is.all(foo, alsoFoo)); // true
134-
console.log(hash.is.all(foo, alsoFoo, stillFoo)); // true
135-
```
136-
137-
### hash.is.any
138-
139-
`hash.is.any(value1: any, value2: any[, value3: any[, ...valueN]]): boolean`
140-
141-
Compares the first object to all other objects passed to determine if any are equal based on hashCode
142-
143-
```javascript
144-
const foo = {
145-
foo: 'bar',
146-
};
147-
const alsoFoo = {
148-
foo: 'bar',
149-
};
150-
const nopeBar = {
151-
bar: 'baz',
152-
};
153-
154-
console.log(hash.is.any(foo, alsoFoo)); // true
155-
console.log(hash.is.any(foo, nopeBar)); // false
156-
console.log(hash.is.any(foo, alsoFoo, nopeBar)); // true
157-
```
158-
159-
### hash.is.not
160-
161-
`hash.is.not(value1: any, value2: any): boolean`
162-
163-
Compares the two objects to determine non-equality.
164-
165-
```javascript
166-
console.log(hash.is.not(null, 123)); // true
167-
console.log(hash.is.not(null, null)); // false
168-
```
169-
170108
## Note
171109

172110
While the hashes will be consistent when calculated within the same environment, there is no guarantee that the resulting hash will be the same across different environments due to environment-specific or browser-specific implementations of features. This is limited to extreme edge cases, such as hashing the `window` object, but should be considered if being used with persistence over different environments.

build/webpack.config.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22

3-
import ESLintWebpackPlugin from "eslint-webpack-plugin";
4-
import HtmlWebpackPlugin from "html-webpack-plugin";
5-
import path from "path";
3+
import ESLintWebpackPlugin from 'eslint-webpack-plugin';
4+
import HtmlWebpackPlugin from 'html-webpack-plugin';
5+
import path from 'path';
66
import { fileURLToPath } from 'url';
77
import webpack from 'webpack';
88

@@ -13,46 +13,45 @@ export default {
1313
cache: true,
1414

1515
devServer: {
16-
host: "localhost",
16+
host: 'localhost',
1717
port: PORT,
1818
},
1919

20-
devtool: "source-map",
20+
devtool: 'source-map',
2121

22-
entry: [path.resolve(ROOT, "DEV_ONLY", "index.tsx")],
22+
entry: [path.resolve(ROOT, 'DEV_ONLY', 'index.tsx')],
2323

24-
mode: "development",
24+
mode: 'development',
2525

2626
module: {
2727
rules: [
2828
{
29-
include: [path.resolve(ROOT, "src"), path.resolve(ROOT, "DEV_ONLY")],
30-
loader: "babel-loader",
29+
include: [path.resolve(ROOT, 'src'), path.resolve(ROOT, 'DEV_ONLY')],
30+
loader: 'ts-loader',
3131
options: {
32-
cacheDirectory: true,
33-
presets: ["@babel/preset-react"],
32+
reportFiles: ['src/*.{ts|tsx}'],
3433
},
35-
test: /\.(js|ts|tsx)$/,
34+
test: /\.(ts|tsx)$/,
3635
},
3736
],
3837
},
3938

4039
output: {
41-
filename: "moize.js",
42-
library: "moize",
43-
libraryTarget: "umd",
44-
path: path.resolve(ROOT, "dist"),
40+
filename: 'hash-it.js',
41+
library: 'hashIt',
42+
libraryTarget: 'umd',
43+
path: path.resolve(ROOT, 'dist'),
4544
publicPath: `http://localhost:${PORT}/`,
4645
umdNamedDefine: true,
4746
},
4847

4948
plugins: [
5049
new ESLintWebpackPlugin(),
51-
new webpack.EnvironmentPlugin(["NODE_ENV"]),
50+
new webpack.EnvironmentPlugin(['NODE_ENV']),
5251
new HtmlWebpackPlugin(),
5352
],
5453

5554
resolve: {
56-
extensions: [".tsx", ".ts", ".js"],
55+
extensions: ['.tsx', '.ts', '.js'],
5756
},
5857
};

jest.init.js

-1
This file was deleted.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"rimraf": "^3.0.2",
4646
"rollup": "^3.9.0",
4747
"ts-jest": "^29.0.3",
48+
"ts-loader": "^9.4.2",
4849
"tslib": "^2.4.1",
4950
"typescript": "^4.9.4",
5051
"webpack": "^5.75.0",

yarn.lock

+14-4
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ chalk@^2.0.0, chalk@^2.0.1:
18701870
escape-string-regexp "^1.0.5"
18711871
supports-color "^5.3.0"
18721872

1873-
chalk@^4.0.0:
1873+
chalk@^4.0.0, chalk@^4.1.0:
18741874
version "4.1.2"
18751875
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
18761876
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
@@ -2463,7 +2463,7 @@ encodeurl@~1.0.2:
24632463
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59"
24642464
integrity sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==
24652465

2466-
enhanced-resolve@^5.10.0:
2466+
enhanced-resolve@^5.0.0, enhanced-resolve@^5.10.0:
24672467
version "5.12.0"
24682468
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.12.0.tgz#300e1c90228f5b570c4d35babf263f6da7155634"
24692469
integrity sha512-QHTXI/sZQmko1cbDoNAa3mJ5qhWUUNAq3vR0/YiD379fWQrcfuoX1+HW2S0MTt7XmoPLapdaDKUtelUSPic7hQ==
@@ -4665,7 +4665,7 @@ methods@~1.1.2:
46654665
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
46664666
integrity sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==
46674667

4668-
micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5:
4668+
micromatch@^4.0.0, micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5:
46694669
version "4.0.5"
46704670
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6"
46714671
integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==
@@ -5724,7 +5724,7 @@ semver-diff@^4.0.0:
57245724
dependencies:
57255725
semver "^7.3.5"
57265726

5727-
5727+
[email protected], [email protected], semver@^7.3.4, semver@^7.3.7:
57285728
version "7.3.8"
57295729
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798"
57305730
integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==
@@ -6221,6 +6221,16 @@ ts-jest@^29.0.3:
62216221
semver "7.x"
62226222
yargs-parser "^21.0.1"
62236223

6224+
ts-loader@^9.4.2:
6225+
version "9.4.2"
6226+
resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.4.2.tgz#80a45eee92dd5170b900b3d00abcfa14949aeb78"
6227+
integrity sha512-OmlC4WVmFv5I0PpaxYb+qGeGOdm5giHU7HwDDUjw59emP2UYMHy9fFSDcYgSNoH8sXcj4hGCSEhlDZ9ULeDraA==
6228+
dependencies:
6229+
chalk "^4.1.0"
6230+
enhanced-resolve "^5.0.0"
6231+
micromatch "^4.0.0"
6232+
semver "^7.3.4"
6233+
62246234
tslib@^1.8.1:
62256235
version "1.14.1"
62266236
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"

0 commit comments

Comments
 (0)