-
-
Save un33k/db8f0f804d50f671be7ca6663bef1969 to your computer and use it in GitHub Desktop.
Create an md5 hash string of a javascript object using crypto createHash, update, and digest hex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
exports.hashObject = function (object) { | |
var hash = crypto.createHash('md5') | |
.update(JSON.stringify(object, function (k, v) { | |
if (k[0] === "_") return undefined; // remove api stuff | |
else if (typeof v === "function") // consider functions | |
return v.toString(); | |
else return v; | |
})) | |
.digest('hex'); | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment