Comment
Author: Admin | 2025-04-28
}). default: trueexcludeKeys optional function for excluding specific key(s) from hashing, if true is returned then exclude from hash. default: include all keyshash.sha1(value)Hash using the sha1 algorithm.Note that SHA-1 is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.Sugar method, equivalent to hash(value, {algorithm: 'sha1'})hash.keys(value)Hash object keys using the sha1 algorithm, values ignored.Sugar method, equivalent to hash(value, {excludeValues: true})hash.MD5(value)Hash using the md5 algorithm.Note that the MD5 algorithm is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.Sugar method, equivalent to hash(value, {algorithm: 'md5'})hash.keysMD5(value)Hash object keys using the md5 algorithm, values ignored.Note that the MD5 algorithm is not considered secure, and a stronger algorithm should be used if a cryptographical hash is desired.Sugar method, equivalent to hash(value, {algorithm: 'md5', excludeValues: true})hash.writeToStream(value, [options,] stream)Write the information that would otherwise have been hashed to a stream, e.g.: e.g. 'object:a:number:42foo:string:bar'">hash.writeToStream({foo: 'bar', a: 42}, {respectType: false}, process.stdout)// => e.g. 'object:a:number:42foo:string:bar'Installationnode:browser: /dist/object_hash.js var hash = objectHash.sha1({foo:'bar'}); console.log(hash); // e003c89cdf35cdf46d8239b4692436364b7259f9">script src="object_hash.js" type="text/javascript">script>script> var hash = objectHash.sha1({foo:'bar'}); console.log(hash); // e003c89cdf35cdf46d8239b4692436364b7259f9script>Example usagevar hash = require('object-hash');var peter = { name: 'Peter', stapler: false, friends: ['Joanna', 'Michael', 'Samir'] };var michael = { name: 'Michael', stapler: false, friends: ['Peter', 'Samir'] };var bob = { name: 'Bob', stapler: true, friends: [] };/*** * sha1 hex encoding (default) */hash(peter);// 14fa461bf4b98155e82adc86532938553b4d33a9hash(michael);// 4b2b30e27699979ce46714253bc2213010db039chash(bob);// 38d96106bc8ef3d8bd369b99bb6972702c9826d5/*** * hash object keys, values ignored */hash(peter, { excludeValues: true });// 48f370a772c7496f6c9d2e6d92e920c87dd00a5chash(michael, { excludeValues: true });// 48f370a772c7496f6c9d2e6d92e920c87dd00a5chash.keys(bob);// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c/*** * hash object, ignore specific key(s) */hash(peter, { excludeKeys: function(key) { if ( key === 'friends') { return true; } return false; }});// 66b7d7e64871aa9fda1bdc8e88a28df797648d80/*** * md5 base64 encoding */hash(peter, { algorithm: 'md5', encoding: 'base64' });// 6rkWaaDiG3NynWw4svGH7g==hash(michael, { algorithm: 'md5', encoding: 'base64' });// djXaWpuWVJeOF8Sb6SFFNg==hash(bob, { algorithm: 'md5', encoding: 'base64' });// lFzkw/IJ8/12jZI0rQeS3w==Legacy Browser SupportIE Developmentgit clone https://github.com/puleos/object-hashNode Docker WrapperIf you want to
Add Comment