diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/hash-sum | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/hash-sum')
| -rw-r--r-- | node_modules/hash-sum/.editorconfig | 13 | ||||
| -rw-r--r-- | node_modules/hash-sum/.jshintignore | 1 | ||||
| -rw-r--r-- | node_modules/hash-sum/.jshintrc | 21 | ||||
| -rw-r--r-- | node_modules/hash-sum/.npmignore | 2 | ||||
| -rw-r--r-- | node_modules/hash-sum/changelog.markdown | 11 | ||||
| -rw-r--r-- | node_modules/hash-sum/hash-sum.js | 58 | ||||
| -rw-r--r-- | node_modules/hash-sum/license | 20 | ||||
| -rw-r--r-- | node_modules/hash-sum/package.json | 27 | ||||
| -rw-r--r-- | node_modules/hash-sum/readme.md | 67 | ||||
| -rw-r--r-- | node_modules/hash-sum/test.js | 61 |
10 files changed, 281 insertions, 0 deletions
diff --git a/node_modules/hash-sum/.editorconfig b/node_modules/hash-sum/.editorconfig new file mode 100644 index 00000000..5d126348 --- /dev/null +++ b/node_modules/hash-sum/.editorconfig @@ -0,0 +1,13 @@ +# 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 diff --git a/node_modules/hash-sum/.jshintignore b/node_modules/hash-sum/.jshintignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/node_modules/hash-sum/.jshintignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/hash-sum/.jshintrc b/node_modules/hash-sum/.jshintrc new file mode 100644 index 00000000..63bccb7a --- /dev/null +++ b/node_modules/hash-sum/.jshintrc @@ -0,0 +1,21 @@ +{ + "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 +} diff --git a/node_modules/hash-sum/.npmignore b/node_modules/hash-sum/.npmignore new file mode 100644 index 00000000..93f13619 --- /dev/null +++ b/node_modules/hash-sum/.npmignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log diff --git a/node_modules/hash-sum/changelog.markdown b/node_modules/hash-sum/changelog.markdown new file mode 100644 index 00000000..990948e2 --- /dev/null +++ b/node_modules/hash-sum/changelog.markdown @@ -0,0 +1,11 @@ +# 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 diff --git a/node_modules/hash-sum/hash-sum.js b/node_modules/hash-sum/hash-sum.js new file mode 100644 index 00000000..77b2030d --- /dev/null +++ b/node_modules/hash-sum/hash-sum.js @@ -0,0 +1,58 @@ +'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; diff --git a/node_modules/hash-sum/license b/node_modules/hash-sum/license new file mode 100644 index 00000000..907e2911 --- /dev/null +++ b/node_modules/hash-sum/license @@ -0,0 +1,20 @@ +The 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. diff --git a/node_modules/hash-sum/package.json b/node_modules/hash-sum/package.json new file mode 100644 index 00000000..771ffc2a --- /dev/null +++ b/node_modules/hash-sum/package.json @@ -0,0 +1,27 @@ +{ + "name": "hash-sum", + "description": "Blazing fast unique hash generator", + "version": "1.0.2", + "homepage": "https://github.com/bevacqua/hash-sum", + "authors": [ + "Nicolas Bevacqua <nicolasbevacqua@gmail.com>" + ], + "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" + } +} diff --git a/node_modules/hash-sum/readme.md b/node_modules/hash-sum/readme.md new file mode 100644 index 00000000..70f18034 --- /dev/null +++ b/node_modules/hash-sum/readme.md @@ -0,0 +1,67 @@ +# 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 diff --git a/node_modules/hash-sum/test.js b/node_modules/hash-sum/test.js new file mode 100644 index 00000000..0960daf7 --- /dev/null +++ b/node_modules/hash-sum/test.js @@ -0,0 +1,61 @@ +'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)); + } +}); |
