feat: Created a mini nodeJS server with NewMan for testing without PostMan GUI.

This will mimic a run in a CD/CI environment or docker container.
This commit is contained in:
Simon Priet
2021-09-08 14:01:19 +02:00
parent 5fbd7c88fa
commit e69a613a37
5610 changed files with 740417 additions and 3 deletions

19
node_modules/object-hash/.jshintrc generated vendored Normal file
View File

@@ -0,0 +1,19 @@
{
"curly": true,
"expr": true,
"eqeqeq": true,
"immed": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"unused": true,
"boss": true,
"eqnull": true,
"node": true,
"globals": {
"require": true,
"exports": true,
"console": true
}
}

35
node_modules/object-hash/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,35 @@
language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "6"
- "8"
sudo: false
# use g++-4.8 for karma
cache:
- apt
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- libstdc++-4.8-dev
firefox: "39.0"
before_install:
- export CXX="g++-4.8" CC="gcc-4.8"
- export "PATH=./node_modules/.bin:$PATH"
install: npm install
# start X server for firefox
before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
script:
- gulp lint
- gulp dist
- gulp test karma
after_success:
- gulp coveralls

22
node_modules/object-hash/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 object-hash contributors
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.

15
node_modules/object-hash/bower.json generated vendored Normal file
View File

@@ -0,0 +1,15 @@
{
"name": "object-hash",
"homepage": "https://github.com/puleos/object-hash",
"description": "Generate hashes from javascript objects in node and the browser",
"main": "dist/object_hash.js",
"author": "Scott Puleo <puleos@gmail.com>",
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}

2
node_modules/object-hash/dist/object_hash.js generated vendored Normal file

File diff suppressed because one or more lines are too long

1
node_modules/object-hash/dist/object_hash.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

4737
node_modules/object-hash/dist/object_hash_test.js generated vendored Normal file

File diff suppressed because one or more lines are too long

97
node_modules/object-hash/gulpfile.js generated vendored Normal file
View File

@@ -0,0 +1,97 @@
'use strict';
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var exec = require('gulp-exec');
var stylish = require('jshint-stylish');
var browserify = require('gulp-browserify');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var karma = require('karma');
var coveralls = require('gulp-coveralls');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');
var paths = {
index: './index.js',
tests: './test/**/*.js'
};
function preTest(src) {
return gulp.src(src)
.pipe(istanbul())
.pipe(istanbul.hookRequire());
}
function test(src){
return gulp.src(src)
.pipe(mocha())
.pipe(istanbul.writeReports());
}
function testKarma(done){
new karma.Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
}
function lint(src){
return gulp.src(src)
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter(stylish));
}
gulp.task('dist', function(){
gulp.src([paths.index])
.pipe(browserify({
insertGlobals : true,
debug: true,
standalone: 'objectHash'
}))
.pipe(rename('object_hash.js'))
.pipe(uglify({outSourceMap: true}))
.pipe(gulp.dest('./dist'));
// tests
gulp.src([paths.tests])
.pipe(browserify())
.pipe(rename('object_hash_test.js'))
.pipe(gulp.dest('./dist'));
});
gulp.task('pre-test', function() {
preTest([paths.index]);
});
gulp.task('test', ['pre-test'], function() {
test([paths.tests]);
});
gulp.task('karma', function() {
testKarma();
});
gulp.task('coveralls', function() {
gulp.src('coverage/**/lcov.info')
.pipe(coveralls());
});
gulp.task('lint', function () {
return lint([paths.index]);
});
gulp.task('watch', function () {
// watch and lint any files that are added or changed
gulp.watch([paths.index, paths.tests], function(event){
if(event.type !== 'deleted') {
lint([event.path]);
}
});
// run the tests when something changes
gulp.watch([paths.index, paths.tests], ['test', 'karma']);
});
gulp.task('default', ['watch']);

441
node_modules/object-hash/index.js generated vendored Normal file
View File

@@ -0,0 +1,441 @@
'use strict';
var crypto = require('crypto');
/**
* Exported function
*
* Options:
*
* - `algorithm` hash algo to be used by this instance: *'sha1', 'md5'
* - `excludeValues` {true|*false} hash object keys, values ignored
* - `encoding` hash encoding, supports 'buffer', '*hex', 'binary', 'base64'
* - `ignoreUnknown` {true|*false} ignore unknown object types
* - `replacer` optional function that replaces values before hashing
* - `respectFunctionProperties` {*true|false} consider function properties when hashing
* - `respectFunctionNames` {*true|false} consider 'name' property of functions for hashing
* - `respectType` {*true|false} Respect special properties (prototype, constructor)
* when hashing to distinguish between types
* - `unorderedArrays` {true|*false} Sort all arrays before hashing
* - `unorderedSets` {*true|false} Sort `Set` and `Map` instances before hashing
* * = default
*
* @param {object} object value to hash
* @param {object} options hashing options
* @return {string} hash value
* @api public
*/
exports = module.exports = objectHash;
function objectHash(object, options){
options = applyDefaults(object, options);
return hash(object, options);
}
/**
* Exported sugar methods
*
* @param {object} object value to hash
* @return {string} hash value
* @api public
*/
exports.sha1 = function(object){
return objectHash(object);
};
exports.keys = function(object){
return objectHash(object, {excludeValues: true, algorithm: 'sha1', encoding: 'hex'});
};
exports.MD5 = function(object){
return objectHash(object, {algorithm: 'md5', encoding: 'hex'});
};
exports.keysMD5 = function(object){
return objectHash(object, {algorithm: 'md5', encoding: 'hex', excludeValues: true});
};
// Internals
var hashes = crypto.getHashes ? crypto.getHashes().slice() : ['sha1', 'md5'];
hashes.push('passthrough');
var encodings = ['buffer', 'hex', 'binary', 'base64'];
function applyDefaults(object, options){
options = options || {};
options.algorithm = options.algorithm || 'sha1';
options.encoding = options.encoding || 'hex';
options.excludeValues = options.excludeValues ? true : false;
options.algorithm = options.algorithm.toLowerCase();
options.encoding = options.encoding.toLowerCase();
options.ignoreUnknown = options.ignoreUnknown !== true ? false : true; // default to false
options.respectType = options.respectType === false ? false : true; // default to true
options.respectFunctionNames = options.respectFunctionNames === false ? false : true;
options.respectFunctionProperties = options.respectFunctionProperties === false ? false : true;
options.unorderedArrays = options.unorderedArrays !== true ? false : true; // default to false
options.unorderedSets = options.unorderedSets === false ? false : true; // default to false
options.unorderedObjects = options.unorderedObjects === false ? false : true; // default to true
options.replacer = options.replacer || undefined;
options.excludeKeys = options.excludeKeys || undefined;
if(typeof object === 'undefined') {
throw new Error('Object argument required.');
}
// if there is a case-insensitive match in the hashes list, accept it
// (i.e. SHA256 for sha256)
for (var i = 0; i < hashes.length; ++i) {
if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {
options.algorithm = hashes[i];
}
}
if(hashes.indexOf(options.algorithm) === -1){
throw new Error('Algorithm "' + options.algorithm + '" not supported. ' +
'supported values: ' + hashes.join(', '));
}
if(encodings.indexOf(options.encoding) === -1 &&
options.algorithm !== 'passthrough'){
throw new Error('Encoding "' + options.encoding + '" not supported. ' +
'supported values: ' + encodings.join(', '));
}
return options;
}
/** Check if the given function is a native function */
function isNativeFunction(f) {
if ((typeof f) !== 'function') {
return false;
}
var exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;
return exp.exec(Function.prototype.toString.call(f)) != null;
}
function hash(object, options) {
var hashingStream;
if (options.algorithm !== 'passthrough') {
hashingStream = crypto.createHash(options.algorithm);
} else {
hashingStream = new PassThrough();
}
if (typeof hashingStream.write === 'undefined') {
hashingStream.write = hashingStream.update;
hashingStream.end = hashingStream.update;
}
var hasher = typeHasher(options, hashingStream);
hasher.dispatch(object);
if (!hashingStream.update)
hashingStream.end('')
if (hashingStream.digest) {
return hashingStream.digest(options.encoding === 'buffer' ? undefined : options.encoding);
}
var buf = hashingStream.read();
if (options.encoding === 'buffer') {
return buf;
}
return buf.toString(options.encoding);
}
/**
* Expose streaming API
*
* @param {object} object Value to serialize
* @param {object} options Options, as for hash()
* @param {object} stream A stream to write the serializiation to
* @api public
*/
exports.writeToStream = function(object, options, stream) {
if (typeof stream === 'undefined') {
stream = options;
options = {};
}
options = applyDefaults(object, options);
return typeHasher(options, stream).dispatch(object);
};
function typeHasher(options, writeTo, context){
context = context || [];
var write = function(str) {
if (writeTo.update)
return writeTo.update(str, 'utf8');
else
return writeTo.write(str, 'utf8');
}
return {
dispatch: function(value){
if (options.replacer) {
value = options.replacer(value);
}
var type = typeof value;
if (value === null) {
type = 'null';
}
//console.log("[DEBUG] Dispatch: ", value, "->", type, " -> ", "_" + type);
return this['_' + type](value);
},
_object: function(object) {
var pattern = (/\[object (.*)\]/i);
var objString = Object.prototype.toString.call(object);
var objType = pattern.exec(objString);
if (!objType) { // object type did not match [object ...]
objType = 'unknown:[' + objString + ']';
} else {
objType = objType[1]; // take only the class name
}
objType = objType.toLowerCase();
var objectNumber = null;
if ((objectNumber = context.indexOf(object)) >= 0) {
return this.dispatch('[CIRCULAR:' + objectNumber + ']');
} else {
context.push(object);
}
if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(object)) {
write('buffer:');
return write(object);
}
if(objType !== 'object' && objType !== 'function') {
if(this['_' + objType]) {
this['_' + objType](object);
} else if (options.ignoreUnknown) {
return write('[' + objType + ']');
} else {
throw new Error('Unknown object type "' + objType + '"');
}
}else{
var keys = Object.keys(object);
if (options.unorderedObjects) {
keys = keys.sort();
}
// Make sure to incorporate special properties, so
// Types with different prototypes will produce
// a different hash and objects derived from
// different functions (`new Foo`, `new Bar`) will
// produce different hashes.
// We never do this for native functions since some
// seem to break because of that.
if (options.respectType !== false && !isNativeFunction(object)) {
keys.splice(0, 0, 'prototype', '__proto__', 'constructor');
}
if (options.excludeKeys) {
keys = keys.filter(function(key) { return !options.excludeKeys(key); });
}
write('object:' + keys.length + ':');
var self = this;
return keys.forEach(function(key){
self.dispatch(key);
write(':');
if(!options.excludeValues) {
self.dispatch(object[key]);
}
write(',');
});
}
},
_array: function(arr, unordered){
unordered = typeof unordered !== 'undefined' ? unordered :
options.unorderedArrays !== false; // default to options.unorderedArrays
var self = this;
write('array:' + arr.length + ':');
if (!unordered || arr.length <= 1) {
return arr.forEach(function(entry) {
return self.dispatch(entry);
});
}
// the unordered case is a little more complicated:
// since there is no canonical ordering on objects,
// i.e. {a:1} < {a:2} and {a:1} > {a:2} are both false,
// we first serialize each entry using a PassThrough stream
// before sorting.
// also: we cant use the same context array for all entries
// since the order of hashing should *not* matter. instead,
// we keep track of the additions to a copy of the context array
// and add all of them to the global context array when were done
var contextAdditions = [];
var entries = arr.map(function(entry) {
var strm = new PassThrough();
var localContext = context.slice(); // make copy
var hasher = typeHasher(options, strm, localContext);
hasher.dispatch(entry);
// take only what was added to localContext and append it to contextAdditions
contextAdditions = contextAdditions.concat(localContext.slice(context.length));
return strm.read().toString();
});
context = context.concat(contextAdditions);
entries.sort();
return this._array(entries, false);
},
_date: function(date){
return write('date:' + date.toJSON());
},
_symbol: function(sym){
return write('symbol:' + sym.toString());
},
_error: function(err){
return write('error:' + err.toString());
},
_boolean: function(bool){
return write('bool:' + bool.toString());
},
_string: function(string){
write('string:' + string.length + ':');
write(string.toString());
},
_function: function(fn){
write('fn:');
if (isNativeFunction(fn)) {
this.dispatch('[native]');
} else {
this.dispatch(fn.toString());
}
if (options.respectFunctionNames !== false) {
// Make sure we can still distinguish native functions
// by their name, otherwise String and Function will
// have the same hash
this.dispatch("function-name:" + String(fn.name));
}
if (options.respectFunctionProperties) {
this._object(fn);
}
},
_number: function(number){
return write('number:' + number.toString());
},
_xml: function(xml){
return write('xml:' + xml.toString());
},
_null: function() {
return write('Null');
},
_undefined: function() {
return write('Undefined');
},
_regexp: function(regex){
return write('regex:' + regex.toString());
},
_uint8array: function(arr){
write('uint8array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_uint8clampedarray: function(arr){
write('uint8clampedarray:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_int8array: function(arr){
write('uint8array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_uint16array: function(arr){
write('uint16array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_int16array: function(arr){
write('uint16array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_uint32array: function(arr){
write('uint32array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_int32array: function(arr){
write('uint32array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_float32array: function(arr){
write('float32array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_float64array: function(arr){
write('float64array:');
return this.dispatch(Array.prototype.slice.call(arr));
},
_arraybuffer: function(arr){
write('arraybuffer:');
return this.dispatch(new Uint8Array(arr));
},
_url: function(url) {
return write('url:' + url.toString(), 'utf8');
},
_map: function(map) {
write('map:');
var arr = Array.from(map);
return this._array(arr, options.unorderedSets !== false);
},
_set: function(set) {
write('set:');
var arr = Array.from(set);
return this._array(arr, options.unorderedSets !== false);
},
_blob: function() {
if (options.ignoreUnknown) {
return write('[blob]');
}
throw Error('Hashing Blob objects is currently not supported\n' +
'(see https://github.com/puleos/object-hash/issues/26)\n' +
'Use "options.replacer" or "options.ignoreUnknown"\n');
},
_domwindow: function() { return write('domwindow'); },
/* Node.js standard native objects */
_process: function() { return write('process'); },
_timer: function() { return write('timer'); },
_pipe: function() { return write('pipe'); },
_tcp: function() { return write('tcp'); },
_udp: function() { return write('udp'); },
_tty: function() { return write('tty'); },
_statwatcher: function() { return write('statwatcher'); },
_securecontext: function() { return write('securecontext'); },
_connection: function() { return write('connection'); },
_zlib: function() { return write('zlib'); },
_context: function() { return write('context'); },
_nodescript: function() { return write('nodescript'); },
_httpparser: function() { return write('httpparser'); },
_dataview: function() { return write('dataview'); },
_signal: function() { return write('signal'); },
_fsevent: function() { return write('fsevent'); },
_tlswrap: function() { return write('tlswrap'); }
};
}
// Mini-implementation of stream.PassThrough
// We are far from having need for the full implementation, and we can
// make assumptions like "many writes, then only one final read"
// and we can ignore encoding specifics
function PassThrough() {
return {
buf: '',
write: function(b) {
this.buf += b;
},
end: function(b) {
this.buf += b;
},
read: function() {
return this.buf;
}
};
}

69
node_modules/object-hash/karma.conf.js generated vendored Normal file
View File

@@ -0,0 +1,69 @@
// Karma configuration
// Generated on Thu Dec 10 2015 03:01:27 GMT+0100 (CET)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha'],
// list of files / patterns to load in the browser
files: [
'dist/*.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS', 'Firefox'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultanous
concurrency: Infinity
})
}

51
node_modules/object-hash/package.json generated vendored Normal file
View File

@@ -0,0 +1,51 @@
{
"name": "object-hash",
"version": "1.3.1",
"description": "Generate hashes from javascript objects in node and the browser.",
"homepage": "https://github.com/puleos/object-hash",
"repository": {
"type": "git",
"url": "https://github.com/puleos/object-hash"
},
"keywords": [
"object",
"hash",
"sha1",
"md5"
],
"bugs": {
"url": "https://github.com/puleos/object-hash/issues"
},
"scripts": {
"test": "node ./node_modules/.bin/mocha test",
"prepublish": "gulp dist"
},
"author": "Scott Puleo <puleos@gmail.com>",
"license": "MIT",
"devDependencies": {
"browserify": "^13.0.0",
"gulp": "^3.9.0",
"gulp-browserify": "^0.5.1",
"gulp-coveralls": "^0.1.4",
"gulp-exec": "^2.1.2",
"gulp-istanbul": "^0.10.3",
"gulp-jshint": "^2.0.0",
"gulp-mocha": "^2.2.0",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.5.1",
"jshint": "^2.8.0",
"jshint-stylish": "^2.1.0",
"karma": "^0.13.15",
"karma-chrome-launcher": "^0.2.2",
"karma-firefox-launcher": "^0.1.7",
"karma-mocha": "^0.2.1",
"karma-phantomjs-launcher": "^0.2.1",
"mocha": "^2.3.4",
"phantomjs": "^1.9.19"
},
"engines": {
"node": ">= 0.10.0"
},
"main": "./index.js",
"browser": "./dist/object_hash.js"
}

169
node_modules/object-hash/readme.markdown generated vendored Normal file
View File

@@ -0,0 +1,169 @@
# object-hash
Generate hashes from objects and values in node and the browser. Uses node.js
crypto module for hashing. Supports SHA1 and many others (depending on the platform)
as well as custom streams (e.g. CRC32).
[![NPM](https://nodei.co/npm/object-hash.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/object-hash)
[![Travis CI](https://secure.travis-ci.org/puleos/object-hash.png?branch=master)](https://secure.travis-ci.org/puleos/object-hash?branch=master)
[![Coverage Status](https://coveralls.io/repos/puleos/object-hash/badge.svg?branch=master&service=github)](https://coveralls.io/github/puleos/object-hash?branch=master)
* Hash values of any type.
* Supports a keys only option for grouping similar objects with different values.
```js
var hash = require('object-hash');
hash({foo: 'bar'}) // => '67b69634f9880a282c14a0f0cb7ba20cf5d677e9'
hash([1, 2, 2.718, 3.14159]) // => '136b9b88375971dff9f1af09d7356e3e04281951'
```
## Versioning Disclaimer
Starting with version `1.1.8` (released April 2017), new versions will consider
the exact returned hash part of the API contract, i.e. changes that will affect
hash values will be considered `semver-major`. Previous versions may violate
that expectation.
For more information, see [this discussion](https://github.com/puleos/object-hash/issues/30).
## hash(value, options);
Generate a hash from any object or type. Defaults to sha1 with hex encoding.
* `algorithm` hash algo to be used: 'sha1', 'md5'. default: sha1
* `excludeValues` {true|false} hash object keys, values ignored. default: false
* `encoding` hash encoding, supports 'buffer', 'hex', 'binary', 'base64'. default: hex
* `ignoreUnknown` {true|*false} ignore unknown object types. default: false
* `replacer` optional function that replaces values before hashing. default: accept all values
* `respectFunctionProperties` {true|false} Whether properties on functions are considered when hashing. default: true
* `respectFunctionNames` {true|false} consider `name` property of functions for hashing. default: true
* `respectType` {true|false} Whether special type attributes (`.prototype`, `.__proto__`, `.constructor`)
are hashed. default: true
* `unorderedArrays` {true|false} Sort all arrays using before hashing. Note that this affects *all* collections,
i.e. including typed arrays, Sets, Maps, etc. default: false
* `unorderedSets` {true|false} Sort `Set` and `Map` instances before hashing, i.e. make
`hash(new Set([1, 2])) == hash(new Set([2, 1]))` return `true`. default: true
* `unorderedObjects` {true|false} Sort objects before hashing, i.e. make `hash({ x: 1, y: 2 }) === hash({ y: 2, x: 1 })`. default: true
* `excludeKeys` optional function for exclude specific key(s) from hashing, if returns true then exclude from hash. default: include all keys
## hash.sha1(value);
Hash using the sha1 algorithm.
*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.
*Sugar method, equivalent to hash(value, {algorithm: 'md5'})*
## hash.keysMD5(value);
Hash object keys using the md5 algorithm, values ignored.
*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.:
```js
hash.writeToStream({foo: 'bar', a: 42}, {respectType: false}, process.stdout)
// => e.g. 'object:a:number:42foo:string:bar'
```
## Installation
node:
```js
npm install object-hash
```
browser: */dist/object_hash.js*
```
<script src="object_hash.js" type="text/javascript"></script>
<script>
var hash = objectHash.sha1({foo:'bar'});
console.log(hash); // e003c89cdf35cdf46d8239b4692436364b7259f9
</script>
```
## Example usage
```js
var 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);
// 14fa461bf4b98155e82adc86532938553b4d33a9
hash(michael);
// 4b2b30e27699979ce46714253bc2213010db039c
hash(bob);
// 38d96106bc8ef3d8bd369b99bb6972702c9826d5
/***
* hash object keys, values ignored
*/
hash(peter, { excludeValues: true });
// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c
hash(michael, { excludeValues: true });
// 48f370a772c7496f6c9d2e6d92e920c87dd00a5c
hash.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 Support
IE <= 8 and Opera <= 11 support dropped in version 0.3.0. If you require
legacy browser support you must either use an ES5 shim or use version 0.2.5
of this module.
## Development
```
git clone https://github.com/puleos/object-hash
```
## Node Docker Wrapper
If you want to stand this up in a docker container, you should take at look
at the [![node-object-hash](https://github.com/bean5/node-object-hash)](https://github.com/bean5/node-object-hash) project.
### gulp tasks
* `gulp watch` (default) watch files, test and lint on change/add
* `gulp test` unit tests
* `gulp karma` browser unit tests
* `gulp lint` jshint
* `gulp dist` create browser version in /dist
## License
MIT

41
node_modules/object-hash/test/blob.js generated vendored Normal file
View File

@@ -0,0 +1,41 @@
'use strict';
var assert = require('assert');
var hash = require('../index');
if (typeof Blob !== 'undefined') {
describe('hash()ing Blob objects', function() {
var blob;
before('create blob', function() {
try {
blob = new Blob(['ABC']);
} catch(e) {
// https://github.com/ariya/phantomjs/issues/11013
if (!e.message.match(/'\[object BlobConstructor\]' is not a constructor/)) {
throw e;
}
var builder = new WebKitBlobBuilder();
builder.append('ABC');
blob = builder.getBlob();
}
});
it('should throw when trying to hash a blob', function() {
assert.throws(function() {
hash(blob);
}, /not supported/);
assert.throws(function() {
hash({abcdef: blob});
}, /not supported/);
});
it('should not throw when trying to hash a blob with ignoreUnknown', function() {
var opt = {ignoreUnknown: true};
assert.ok(validSha1.test(hash(blob, opt)), 'ignore Blob');
assert.ok(validSha1.test(hash({abcdef: blob}, opt)), 'ignore Blob');
});
});
}

290
node_modules/object-hash/test/index.js generated vendored Normal file
View File

@@ -0,0 +1,290 @@
'use strict';
var assert = require('assert');
var crypto = require('crypto');
var hash = require('../index');
var validSha1 = /^[0-9a-f]{40}$/i;
describe('hash', function() {
it('throws when nothing to hash', function () {
assert.throws(hash, 'no arguments');
assert.throws(function() {
hash(undefined, {algorithm: 'md5'});
}, 'undefined');
});
it('throws when passed an invalid options', function() {
assert.throws(function() {
hash({foo: 'bar'}, {algorithm: 'shalala'});
}, 'bad algorithm');
assert.throws(function() {
hash({foo: 'bar'}, {encoding: 'base16'});
}, 'bad encoding');
});
it('hashes a simple object', function() {
assert.ok(validSha1.test(hash({foo: 'bar', bar: 'baz'})), 'hash object');
});
if (typeof Buffer !== 'undefined') {
it('can return buffers', function() {
assert.ok(Buffer.isBuffer(hash({foo: 'bar', bar: 'baz'}, {encoding: 'buffer'})), 'hash object');
});
}
it('hashes identical objects with different key ordering', function() {
var hash1 = hash({foo: 'bar', bar: 'baz'});
var hash2 = hash({bar: 'baz', foo: 'bar'});
var hash3 = hash({bar: 'foo', foo: 'baz'});
assert.equal(hash1, hash2, 'hashes are equal');
assert.notEqual(hash1, hash3, 'different objects not equal');
});
it('respects object key ordering when unorderedObjects = false', function() {
var hash1 = hash({foo: 'bar', bar: 'baz'}, { unorderedObjects: false });
var hash2 = hash({bar: 'baz', foo: 'bar'}, { unorderedObjects: false });
assert.notEqual(hash1, hash2, 'hashes are not equal');
});
it('hashes only object keys when excludeValues option is set', function() {
var hash1 = hash({foo: false, bar: 'OK'}, { excludeValues: true });
var hash2 = hash({foo: true, bar: 'NO'}, { excludeValues: true });
var hash3 = hash({foo: true, bar: 'OK', baz: false}, { excludeValues: true });
assert.equal(hash1, hash2, 'values not in hash digest');
assert.notEqual(hash1, hash3, 'different keys not equal');
});
it('array values are hashed', function() {
var hash1 = hash({foo: ['bar', 'baz'], bax: true });
var hash2 = hash({foo: ['baz', 'bar'], bax: true });
assert.notEqual(hash1, hash2, 'different array orders are unique');
});
it('nested object values are hashed', function() {
var hash1 = hash({foo: {bar: true, bax: 1}});
var hash2 = hash({foo: {bar: true, bax: 1}});
var hash3 = hash({foo: {bar: false, bax: 1}});
assert.equal(hash1, hash2, 'hashes are equal');
assert.notEqual(hash1, hash3, 'different objects not equal');
});
it('sugar methods should be equivalent', function() {
var obj = {foo: 'bar', baz: true};
assert.equal(hash.keys(obj), hash(obj, {excludeValues: true}), 'keys');
assert.equal(hash.sha1(obj), hash(obj, {algorithm: 'sha1'}), 'sha1');
assert.equal(hash.MD5(obj), hash(obj, {algorithm: 'md5'}), 'md5');
assert.equal(hash.keysMD5(obj),
hash(obj, {algorithm: 'md5', excludeValues: true}), 'keys md5');
});
it('array of nested object values are hashed', function() {
var hash1 = hash({foo: [ {bar: true, bax: 1}, {bar: false, bax: 2} ] });
var hash2 = hash({foo: [ {bar: true, bax: 1}, {bar: false, bax: 2} ] });
var hash3 = hash({foo: [ {bar: false, bax: 2} ] });
assert.equal(hash1, hash2, 'hashes are equal');
assert.notEqual(hash1, hash3, 'different objects not equal');
});
it("recursive objects don't blow up stack", function() {
var hash1 = {foo: 'bar'};
hash1.recursive = hash1;
assert.doesNotThrow(function() {hash(hash1);}, /Maximum call stack size exceeded/, 'Should not throw an stack size exceeded exception');
});
it("recursive arrays don't blow up stack", function() {
var hash1 = ['foo', 'bar'];
hash1.push(hash1);
assert.doesNotThrow(function() {hash(hash1);}, /Maximum call stack size exceeded/, 'Should not throw an stack size exceeded exception');
});
it("recursive arrays don't blow up stack with unorderedArrays", function() {
var hash1 = ['foo', 'bar'];
hash1.push(hash1);
assert.doesNotThrow(function() {hash(hash1, {unorderedArrays: true});}, /Maximum call stack size exceeded/, 'Should not throw an stack size exceeded exception');
});
it("recursive handling tracks identity", function() {
var hash1 = {k1: {k: 'v'}, k2: {k: 'k2'}};
hash1.k1.r1 = hash1.k1;
hash1.k2.r2 = hash1.k2;
var hash2 = {k1: {k: 'v'}, k2: {k: 'k2'}};
hash2.k1.r1 = hash2.k2;
hash2.k2.r2 = hash2.k1;
assert.notEqual(hash(hash1), hash(hash2), "order of recursive objects should matter");
});
it("object types are hashed", function() {
var hash1 = hash({foo: 'bar'});
var hash2 = hash(['foo', 'bar']);
assert.notEqual(hash1, hash2, "arrays and objects should not produce identical hashes");
});
it("utf8 strings are hashed correctly", function() {
var hash1 = hash('\u03c3'); // cf 83 in utf8
var hash2 = hash('\u01c3'); // c7 83 in utf8
assert.notEqual(hash1, hash2, "different strings with similar utf8 encodings should produce different hashes");
});
it("strings passed as new String are hashed correctly", function() {
var hash1 = hash(new String('foo'));
assert.equal(hash1, '7cd3edacc4c9dd43908177508c112608a398bb9a');
var hash2 = hash({foo: new String('bar')});
assert.equal(hash2, 'a75c05bdca7d704bdfcd761913e5a4e4636e956b');
});
it("various hashes in crypto.getHashes() should be supported", function() {
var hashes = ['sha1', 'md5'];
if (crypto.getHashes) {
// take all hashes from crypto.getHashes() starting with MD or SHA
hashes = crypto.getHashes().filter(RegExp.prototype.test.bind(/^(md|sha)/i));
}
var obj = {randomText: 'bananas'};
for (var i = 0; i < hashes.length; i++) {
assert.ok(hash(obj, {algorithm: hashes[i]}), 'Algorithm ' + hashes[i] + ' should be supported');
}
});
it("null and 'Null' string produce different hashes", function() {
var hash1 = hash({foo: null});
var hash2 = hash({foo: 'Null'});
assert.notEqual(hash1, hash2, "null and 'Null' should not produce identical hashes");
});
it('Distinguish functions based on their properties', function() {
var a, b, c, d;
function Foo() {}
a = hash(Foo);
Foo.foo = 22;
b = hash(Foo);
Foo.bar = "42";
c = hash(Foo);
Foo.foo = "22";
d = hash(Foo);
assert.notEqual(a,b, 'adding a property changes the hash');
assert.notEqual(b,c, 'adding another property changes the hash');
assert.notEqual(c,d, 'changing a property changes the hash');
});
it('respectFunctionProperties = false', function() {
var a, b;
function Foo() {}
a = hash(Foo, {respectFunctionProperties: false});
Foo.foo = 22;
b = hash(Foo, {respectFunctionProperties: false});
assert.equal(a,b, 'function properties are ignored');
});
it('Distinguish functions based on prototype properties', function() {
var a, b, c, d;
function Foo() {}
a = hash(Foo);
Foo.prototype.foo = 22;
b = hash(Foo);
Foo.prototype.bar = "42";
c = hash(Foo);
Foo.prototype.foo = "22";
d = hash(Foo);
assert.notEqual(a,b, 'adding a property to the prototype changes the hash');
assert.notEqual(b,c, 'adding another property to the prototype changes the hash');
assert.notEqual(c,d, 'changing a property in the prototype changes the hash');
});
it('Distinguish objects based on their type', function() {
function Foo() {}
function Bar() {}
var f = new Foo(), b = new Bar();
assert.notEqual(hash(Foo), hash(Bar), 'Functions with different names should produce a different Hash.');
assert.notEqual(hash(f), hash(b), 'Objects with different constructor should have a different Hash.');
});
it('respectType = false', function() {
var opt = { respectType: false };
function Foo() {}
function Bar() {}
var f = new Foo(), b = new Bar();
assert.equal(hash(f, opt), hash(b, opt), 'Hashing should disregard the different constructor');
var ha, hb;
function F() {}
ha = hash(F, opt);
F.prototype.meaningOfLife = 42;
hb = hash(F, opt);
assert.equal(ha, hb, 'Hashing should disregard changes in the function\'s prototype');
});
it('unorderedArrays = false', function() {
var ha, hb;
ha = hash([1, 2, 3]);
hb = hash([3, 2, 1]);
assert.notEqual(ha, hb, 'Hashing should respect the order of array entries');
});
it('unorderedArrays = true', function() {
var opt = { unorderedArrays: true };
var ha, hb;
ha = hash([1, 2, 3], opt);
hb = hash([3, 2, 1], opt);
assert.equal(ha, hb, 'Hashing should not respect the order of array entries');
ha = hash([{a: 1}, {a: 2}], opt);
hb = hash([{a: 2}, {a: 1}], opt);
assert.equal(ha, hb, 'Hashing should not respect the order of array entries');
});
it('excludeKeys works', function() {
var ha, hb;
ha = hash({a: 1, b: 4}, { excludeKeys: function(key) { return key === 'b' } });
hb = hash({a: 1});
assert.equal(ha, hb, 'Hashing should ignore key `b`');
});
if (typeof Set !== 'undefined') {
it('unorderedSets = false', function() {
var opt = { unorderedSets: false };
var ha, hb;
ha = hash(new Set([1, 2, 3]), opt);
hb = hash(new Set([3, 2, 1]), opt);
assert.notEqual(ha, hb, 'Hashing should respect the order of Set entries');
});
it('unorderedSets = true', function() {
var ha, hb;
ha = hash(new Set([1, 2, 3]));
hb = hash(new Set([3, 2, 1]));
assert.equal(ha, hb, 'Hashing should not respect the order of Set entries');
});
}
});

106
node_modules/object-hash/test/object-classes.js generated vendored Normal file
View File

@@ -0,0 +1,106 @@
'use strict';
var assert = require('assert');
var crypto = require('crypto');
var stream = require('stream');
var hash = require('../index');
var validSha1 = /^[0-9a-f]{40}$/i;
describe('hash() objects with custom class names', function() {
var builtinToString;
beforeEach(function() {
builtinToString = Object.prototype.toString;
Object.prototype.toString = function() {
if (this && typeof this.__className !== 'undefined') {
return this.__className;
}
return builtinToString.apply(this, arguments);
};
});
afterEach(function() {
Object.prototype.toString = builtinToString;
});
it('should throw when trying to hash an unknown object', function() {
assert.throws(function() {
hash({a:1, __className: '[object Foo]'});
}, /Unknown object type "foo"/);
assert.throws(function() {
hash({a:1, __className: 'Foo'});
}, /Unknown object type/);
});
it('should not throw when trying to hash an unknown object with ignoreUnknown', function() {
var opt = {ignoreUnknown: true};
assert.ok(validSha1.test(hash({a:1, __className: '[object Foo]'}, opt)));
});
it('should not throw when trying to hash a weirdly-named object with ignoreUnknown', function() {
var opt = {ignoreUnknown: true};
assert.ok(validSha1.test(hash({a:1, __className: 'Foo'}, opt)));
});
it('should not delve further into a number of native types', function() {
var nativeTypes = [
'domwindow',
'process', 'timer', 'pipe', 'tcp', 'udp', 'tty', 'statwatcher',
'securecontext', 'connection', 'zlib', 'context', 'nodescript',
'httpparser', 'dataview', 'signal', 'fsevent', 'tlswrap'
];
for (var i = 0; i < nativeTypes.length; i++) {
var obj = { foobar: 1, __className: '[object ' + nativeTypes[i] + ']' };
var serialized = hash(obj, { algorithm: 'passthrough', encoding: 'utf8' });
assert.strictEqual(serialized, nativeTypes[i]);
}
});
it('should hash xml based on its string representation', function() {
var obj = {
__className: '[object xml]',
toString: function() { return 'Bananä' }
};
var serialized = hash(obj, { algorithm: 'passthrough', encoding: 'utf8' });
assert.strictEqual(serialized, 'xml:Bananä');
});
it('should hash URLs based on its string representation', function() {
var obj = {
__className: '[object url]',
toString: function() { return 'https://example.com/' }
};
var serialized = hash(obj, { algorithm: 'passthrough', encoding: 'utf8' });
assert.strictEqual(serialized, 'url:https://example.com/');
});
it('should not hash blobs without ignoreUnknown', function() {
var obj = {
__className: '[object blob]'
};
assert.throws(function() {
hash(obj);
}, /not supported/);
});
it('should ignore blobs with ignoreUnknown', function() {
var obj = {
__className: '[object blob]'
};
var serialized = hash(obj, {
algorithm: 'passthrough',
encoding: 'utf8',
ignoreUnknown: true
});
assert.strictEqual(serialized, '[blob]');
});
});

60
node_modules/object-hash/test/old-crypto.js generated vendored Normal file
View File

@@ -0,0 +1,60 @@
'use strict';
var assert = require('assert');
var crypto = require('crypto');
var hash = require('../index');
var validSha1 = /^[0-9a-f]{40}$/i;
var validBase64 = /^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/==]{4})$/;
describe('hash() without crypto.getHashes', function() {
var getHashes_;
beforeEach(function() {
getHashes_ = crypto.getHashes;
delete crypto.getHashes;
});
afterEach(function() {
crypto.getHashes = getHashes_;
});
it('should work fine for SHA1', function() {
assert.ok(validSha1.test(hash(42)), 'hash some value');
assert.ok(validSha1.test(hash(NaN)), 'hash some value');
});
});
describe('hash() without Duplex streams', function() {
var createHash_;
beforeEach(function() {
createHash_ = crypto.createHash;
crypto.createHash = function(algorithm) {
var strm = createHash_(algorithm);
return {
update: strm.write.bind(strm),
digest: strm.digest.bind(strm)
};
};
});
afterEach(function() {
crypto.createHash = createHash_;
});
it('should work fine for SHA1 without .write()/.read()', function() {
assert.ok(validSha1.test(hash(42)), 'hash some value');
assert.ok(validSha1.test(hash(NaN)), 'hash some value');
});
it('should work fine for SHA1 without .write()/.read() with base64', function() {
assert.ok(validBase64.test(hash(42, {encoding: 'base64'})), 'hash some value');
assert.ok(validBase64.test(hash(NaN, {encoding: 'base64'})), 'hash some value');
});
if (typeof Buffer !== 'undefined') {
it('should work fine for SHA1 without .write()/.read() with buffer', function() {
assert.ok(Buffer.isBuffer(hash(42, {encoding: 'buffer'})), 'hash some value');
assert.ok(Buffer.isBuffer(hash(NaN, {encoding: 'buffer'})), 'hash some value');
});
}
});

36
node_modules/object-hash/test/replacer.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
'use strict';
var assert = require('assert');
var stream = require('stream');
var hash = require('../index');
describe('replacer option', function() {
it('should emit information about an object to a stream', function() {
var strm = new stream.PassThrough();
var replacer = function(value) {
try {
return JSON.stringify(value);
} catch (e) {
return value;
}
};
var obj = {foo: 'bar'};
hash.writeToStream(obj, {replacer: replacer}, strm);
var result = strm.read().toString();
assert.strictEqual(typeof result, 'string');
assert.notStrictEqual(result.indexOf(JSON.stringify(obj)), -1);
});
it('should not reach property values when excludeValues = true', function() {
var strm = new stream.PassThrough();
var replacer = function(k) {
assert.notStrictEqual(k, 'bar');
return k;
};
hash.writeToStream({foo: 'bar'}, {excludeValues: true}, strm);
});
});

174
node_modules/object-hash/test/types.js generated vendored Normal file
View File

@@ -0,0 +1,174 @@
'use strict';
var assert = require('assert');
var crypto = require('crypto');
var hash = require('../index');
var validSha1 = /^[0-9a-f]{40}$/i;
describe('hash()ing different types', function() {
it('hashes non-object types', function() {
var func = function(a){ return a + 1; };
assert.ok(validSha1.test(hash('Shazbot!')), 'hash string');
assert.ok(validSha1.test(hash(42)), 'hash number');
assert.ok(validSha1.test(hash(NaN)), 'hash bool');
assert.ok(validSha1.test(hash(true)), 'hash bool');
assert.ok(validSha1.test(hash(func)), 'hash function');
});
it('hashes special object types', function() {
var dt = new Date();
dt.setDate(dt.getDate() + 1);
assert.ok(validSha1.test(hash([1,2,3,4])), 'hash array');
assert.notEqual(hash([1,2,3,4]), hash([4,3,2,1]), 'different arrays not equal');
assert.ok(validSha1.test(hash(new Date())), 'hash date');
assert.notEqual(hash(new Date()), hash(dt), 'different dates not equal');
assert.ok(validSha1.test(hash(null)), 'hash Null');
assert.ok(validSha1.test(hash(Number.NaN)), 'hash NaN');
assert.ok(validSha1.test(hash({ foo: undefined })), 'hash Undefined value');
assert.ok(validSha1.test(hash(new RegExp())), 'hash regex');
assert.ok(validSha1.test(hash(new Error())), 'hash error');
});
it('hashes node.js-internal object types', function() {
if (typeof process !== 'undefined') {
assert.ok(validSha1.test(hash(process)), 'hash process');
}
var timer = setTimeout(function() {}, 0);
assert.ok(validSha1.test(hash(timer)), 'hash timer');
});
if (typeof Symbol !== 'undefined') {
it('hashes Symbols', function() {
assert.ok(validSha1.test(hash(Symbol('Banana'))), 'hash error');
});
}
if (typeof Buffer !== 'undefined') {
it("Buffers can be hashed", function() {
assert.ok(validSha1.test(hash(new Buffer('Banana'))), 'hashes Buffers');
});
}
if (typeof Uint8Array !== 'undefined') {
it("Typed arrays can be hashed", function() {
assert.ok(validSha1.test(hash(new Uint8Array([1,2,3,4]))), 'hashes Uint8Array');
assert.ok(validSha1.test(hash(new Int8Array([1,2,3,4]))), 'hashes Int8Array');
assert.ok(validSha1.test(hash(new Uint16Array([1,2,3,4]))), 'hashes Uint16Array');
assert.ok(validSha1.test(hash(new Int16Array([1,2,3,4]))), 'hashes Int16Array');
assert.ok(validSha1.test(hash(new Uint32Array([1,2,3,4]))), 'hashes Uint32Array');
assert.ok(validSha1.test(hash(new Int32Array([1,2,3,4]))), 'hashes Int32Array');
assert.ok(validSha1.test(hash(new Float32Array([1,2,3,4]))), 'hashes Float32Array');
if (typeof Float64Array !== 'undefined')
assert.ok(validSha1.test(hash(new Float64Array([1,2,3,4]))), 'hashes Float64Array');
if (typeof Uint8ClampedArray !== 'undefined')
assert.ok(validSha1.test(hash(new Uint8ClampedArray([1,2,3,4]))), 'hashes Uint8ClampedArray');
assert.ok(validSha1.test(hash(new Uint8Array([1,2,3,4]).buffer)), 'hashes ArrayBuffer');
});
}
if (typeof Map !== 'undefined') {
it("Maps can be hashed", function() {
var map = new Map([['a',1],['b',2]]);
assert.ok(validSha1.test(hash(map)), 'hashes Maps');
});
}
if (typeof WeakMap !== 'undefined') {
it("WeakMaps cant be hashed", function() {
var map = new WeakMap([[{foo: 'bar'},1]]);
assert.throws(function() {
validSha1.test(hash(map))
}, 'does not hash WeakMaps');
});
}
if (typeof Set !== 'undefined') {
it("Sets can be hashed", function() {
var set = new Set(['you', 'du', 'tu', 'あなた', '您']);
assert.ok(validSha1.test(hash(set)), 'hashes Sets');
});
}
if (typeof WeakSet !== 'undefined') {
it("WeakSets cant be hashed", function() {
var obj = {foo: 'bar'};
var set = new WeakSet([obj]);
assert.throws(function() {
validSha1.test(hash(set))
}, 'does not hash WeakSets');
});
}
it("Builtin types themselves can be hashed", function() {
var hashcount = {};
var types = [Object, Date, Number, String, Function, RegExp,
Error, 0, null, NaN];
if (typeof WeakSet !== 'undefined') types.push(WeakSet);
if (typeof Set !== 'undefined') types.push(Set);
if (typeof WeakMap !== 'undefined') types.push(WeakMap);
if (typeof Map !== 'undefined') types.push(Map);
if (typeof Symbol !== 'undefined') types.push(Symbol);
if (typeof Uint8Array !== 'undefined') types.push(Uint8Array);
// Hash each type
for (var idx in types) {
var h = hash(types[idx]);
assert.ok(validSha1.test(h));
hashcount[h] = (hashcount[h] || 0) + 1;
}
// Check for collisions
var no = 0;
for (var h in hashcount) {
assert.equal(hashcount[h], 1);
no++;
}
// Self check; did we really hash all the types?
assert.equal(no, types.length);
});
it("Builtin types might result in identical hashes with respectFunctionNames = false", function() {
var hashcount = {};
var types = [Object, Date, Number, String, Function, RegExp,
Error, 0, null, NaN];
if (typeof WeakSet !== 'undefined') types.push(WeakSet);
if (typeof Set !== 'undefined') types.push(Set);
if (typeof WeakMap !== 'undefined') types.push(WeakMap);
if (typeof Map !== 'undefined') types.push(Map);
if (typeof Symbol !== 'undefined') types.push(Symbol);
if (typeof Uint8Array !== 'undefined') types.push(Uint8Array);
// Hash each type
for (var idx in types) {
var h = hash(types[idx], { respectFunctionNames: false });
assert.ok(validSha1.test(h));
hashcount[h] = (hashcount[h] || 0) + 1;
}
// Check for collisions
var no = 0;
for (var h in hashcount) {
assert.ok(hashcount[h] >= 1);
no += hashcount[h];
}
// Self check; did we really hash all the types?
assert.equal(no, types.length);
});
it("Functions with identical bodies and different names result in identical hashes with respectFunctionNames = false", function() {
var fn1 = function a() {};
var fn2 = function b() {};
var toStringDummy = function() { return '...'; };
fn1.toString = toStringDummy;
fn2.toString = toStringDummy;
var h1 = hash(fn1, { respectFunctionNames: false });
var h2 = hash(fn2, { respectFunctionNames: false });
assert.strictEqual(h1, h2);
});
});

27
node_modules/object-hash/test/writeToStream.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
'use strict';
var assert = require('assert');
var stream = require('stream');
var hash = require('../index');
describe('writeToStream', function() {
it('should emit information about an object to a stream', function() {
var strm = new stream.PassThrough();
hash.writeToStream({foo: 'bar'}, strm);
var result = strm.read().toString();
assert.strictEqual(typeof result, 'string');
assert.notStrictEqual(result.indexOf('foo'), -1);
assert.notStrictEqual(result.indexOf('bar'), -1);
});
it('should leave out keys when excludeValues = true', function() {
var strm = new stream.PassThrough();
hash.writeToStream({foo: 'bar'}, {excludeValues: true}, strm);
var result = strm.read().toString();
assert.strictEqual(typeof result, 'string');
assert.notStrictEqual(result.indexOf('foo'), -1);
assert. strictEqual(result.indexOf('bar'), -1);
});
});