pax_global_header00006660000000000000000000000064125512572650014524gustar00rootroot0000000000000052 comment=b9d19a324f5a10417b42c9e8bf76d2f52d05b3d7 hash-sum-1.0.2/000077500000000000000000000000001255125726500132515ustar00rootroot00000000000000hash-sum-1.0.2/.editorconfig000066400000000000000000000003171255125726500157270ustar00rootroot00000000000000# editorconfig.org root = true [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false hash-sum-1.0.2/.gitignore000066400000000000000000000000331255125726500152350ustar00rootroot00000000000000node_modules npm-debug.log hash-sum-1.0.2/.jshintignore000066400000000000000000000000151255125726500157510ustar00rootroot00000000000000node_modules hash-sum-1.0.2/.jshintrc000066400000000000000000000005311255125726500150750ustar00rootroot00000000000000{ "curly": true, "eqeqeq": true, "newcap": true, "noarg": true, "noempty": true, "nonew": true, "sub": true, "validthis": true, "undef": true, "trailing": true, "boss": true, "eqnull": true, "strict": true, "immed": true, "expr": true, "latedef": "nofunc", "quotmark": "single", "indent": 2, "node": true } hash-sum-1.0.2/changelog.markdown000066400000000000000000000002721255125726500167450ustar00rootroot00000000000000# 1.0.2 Quick Sort - Sorts object keys so that property order doesn't affect outcome # 1.0.1 Perfect Circle - Guard against circular references # 1.0.0 IPO - Initial Public Release hash-sum-1.0.2/hash-sum.js000066400000000000000000000023231255125726500153340ustar00rootroot00000000000000'use strict'; function pad (hash, len) { while (hash.length < len) { hash = '0' + hash; } return hash; } function fold (hash, text) { var i; var chr; var len; if (text.length === 0) { return hash; } for (i = 0, len = text.length; i < len; i++) { chr = text.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; } return hash < 0 ? hash * -2 : hash; } function foldObject (hash, o, seen) { return Object.keys(o).sort().reduce(foldKey, hash); function foldKey (hash, key) { return foldValue(hash, o[key], key, seen); } } function foldValue (input, value, key, seen) { var hash = fold(fold(fold(input, key), toString(value)), typeof value); if (value === null) { return fold(hash, 'null'); } if (value === undefined) { return fold(hash, 'undefined'); } if (typeof value === 'object') { if (seen.indexOf(value) !== -1) { return fold(hash, '[Circular]' + key); } seen.push(value); return foldObject(hash, value, seen); } return fold(hash, value.toString()); } function toString (o) { return Object.prototype.toString.call(o); } function sum (o) { return pad(foldValue(0, o, '', []).toString(16), 8); } module.exports = sum; hash-sum-1.0.2/license000066400000000000000000000020721255125726500146170ustar00rootroot00000000000000The MIT License (MIT) Copyright © 2014 Nicolas Bevacqua Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. hash-sum-1.0.2/package.json000066400000000000000000000011571255125726500155430ustar00rootroot00000000000000{ "name": "hash-sum", "description": "Blazing fast unique hash generator", "version": "1.0.2", "homepage": "https://github.com/bevacqua/hash-sum", "authors": [ "Nicolas Bevacqua " ], "license": "MIT", "repository": { "type": "git", "url": "git://github.com/bevacqua/hash-sum.git" }, "bugs": { "url": "https://github.com/bevacqua/hash-sum/issues" }, "main": "hash-sum.js", "scripts": { "test": "jshint . && tape test.js" }, "dependencies": {}, "devDependencies": { "jshint": "2.5.0", "jshint-stylish": "0.2.0", "tape": "3.0.3" } } hash-sum-1.0.2/readme.md000066400000000000000000000027711255125726500150370ustar00rootroot00000000000000# hash-sum > blazing fast unique hash generator # install ```shell npm i hash-sum -S ``` # features - no dependencies - minimal footprint - works in all of node.js, io.js, and the browser - hashes functions based on their source code - produces different hashes for different object types - support for circular references in objects - ignores property assignment order # `sum(value)` yields a four-byte hexadecimal hash based off of `value`. ``` # creates unique hashes creates unique hashes 4d237d49 from: [ 0, 1, 2, 3 ] 766ec173 from: { url: 12 } 2f473108 from: { headers: 12 } 23308836 from: { headers: 122 } 062bce44 from: { headers: '122' } acb9f66e from: { headers: { accept: 'text/plain' } } 1c365a2d from: { payload: [ 0, 1, 2, 3 ], headers: [ { a: 'b' } ] } 7319ae9d from: { a: [Function] } 8a3a0e86 from: { b: [Function] } b6d7f5d4 from: { b: [Function] } 6c95fc65 from: function () {} 2941766e from: function (a) {} 294f8def from: function (b) {} 2d9c0cb8 from: function (a) { return a;} ed5c63fc from: function (a) {return a;} bba68bf6 from: '' 2d27667d from: 'null' 774b96ed from: 'false' 2d2a1684 from: 'true' 8daa1a0c from: '0' 8daa1a0a from: '1' e38f07cc from: 'void 0' 6037ea1a from: 'undefined' 9b7df12e from: null 3c206f76 from: false 01e34ba8 from: true 1a96284a from: 0 1a96284b from: 1 29172c1a from: undefined 4505230f from: {} 3718c6e8 from: { a: {}, b: {} } 5d844489 from: [] 938eaaf0 from: Tue Jul 14 2015 15:35:36 GMT-0300 (ART) dfe5fb2e from: global ok 1 should be equal ``` # license MIT hash-sum-1.0.2/test.js000066400000000000000000000023351255125726500145710ustar00rootroot00000000000000'use strict'; var _ = require('lodash'); var test = require('tape'); var sum = require('./'); test('creates unique hashes', function (t) { var results = []; sub([0,1,2,3]); sub({url:12}); sub({headers:12}); sub({headers:122}); sub({headers:'122'}); sub({headers:{accept:'text/plain'}}); sub({payload:[0,1,2,3],headers:[{a:'b'}]}); sub({a:function () {}}); sub({b:function () {}}); sub({b:function (a) {}}); sub(function () {}); sub(function (a) {}); sub(function (b) {}); sub(function (a) { return a;}); sub(function (a) {return a;}); sub(''); sub('null'); sub('false'); sub('true'); sub('0'); sub('1'); sub('void 0'); sub('undefined'); sub(null); sub(false); sub(true); sub(0); sub(1); sub(void 0); sub({}); sub({a:{},b:{}}); sub([]); sub(new Date()); sub(global, 'global'); t.equal(results.length, _.uniq(results).length); t.end(); function sub (value, name) { var hash = sum(value); results.push(hash); console.log('%s from:', hash, name || value); } }); test('hashes clash if same properties', function (t) { equals({a:'1'},{a:'1'}); equals({a:'1',b:1},{b:1,a:'1'}); t.end(); function equals (a, b) { t.equal(sum(a), sum(b)); } });