everyutil
Version:
A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.
21 lines (20 loc) • 591 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayFingerprint = void 0;
/**
* Hash-style signature of an array for quick diffing.
* @author @dailker
* @param {any[]} array
* @returns {string}
*/
function arrayFingerprint(array) {
// Simple hash: djb2
let hash = 5381;
const str = JSON.stringify(array);
for (let i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash) + str.charCodeAt(i);
hash = hash & hash;
}
return hash.toString(16);
}
exports.arrayFingerprint = arrayFingerprint;