Skip to content

Instantly share code, notes, and snippets.

@romgrk
Last active April 2, 2026 23:03
Show Gist options
  • Select an option

  • Save romgrk/fccab9852df0aeceb05b321a5296ad7f to your computer and use it in GitHub Desktop.

Select an option

Save romgrk/fccab9852df0aeceb05b321a5296ad7f to your computer and use it in GitHub Desktop.
function devmodeStringHash(input: object | string | number | null) {
let nextId = 0;
const seen = new WeakMap<any, number>();
return JSON.stringify(input, (_, v) => {
if (v !== null && typeof v === 'object') {
const id = seen.get(v);
if (id !== undefined) {
return `__object__:${id}`;
}
seen.set(v, nextId);
nextId += 1;
}
return v;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment