shuding / stable-hash Goto Github PK
View Code? Open in Web Editor NEWStable JS value hash
Stable JS value hash
const o1 = {}; o1.o = o1
const o2 = {}; o2.o = o2
hash(o1) !== hash(o2) // bug!
To fix this problem, we need an extra WeakMap
and a reference counter only for recursive hash executions.
The consistency of this lib is sometimes guaranteed by the singularity of the WeakMap instance. So we should add some notes that it might have issue of consistency with multiple instances, e.g. server/client or parent/worker.
Small question: I notice the code uses ==
in a number of places. I saw this article that says that ===
can be significantly faster, so I thought it would be worth asking if it should be changed.
It would by nice if there were TS intellisense. Since the lib is so simple, we could use a basic index.d.ts
file.
I created index.d.ts
file with following code:
declare module "stable-hash" {
export default function stablehash(key: unknown): string;
}
Also tried this:
declare module "stable-hash" {
function stablehash(key: unknown): string;
export = stablehash;
}
In both cases got error TypeError: default is not a function
when run unit tests using vitest. How to fix this error?
It would be great to have some unit tests, just one simple script file is enough.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.