| | |
| | | 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; |
| | | function applyDefaults(object, sourceOptions){ |
| | | sourceOptions = sourceOptions || {}; |
| | | |
| | | // create a copy rather than mutating |
| | | var options = {}; |
| | | options.algorithm = sourceOptions.algorithm || 'sha1'; |
| | | options.encoding = sourceOptions.encoding || 'hex'; |
| | | options.excludeValues = sourceOptions.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; |
| | | options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true; // default to false |
| | | options.respectType = sourceOptions.respectType === false ? false : true; // default to true |
| | | options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true; |
| | | options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true; |
| | | options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true; // default to false |
| | | options.unorderedSets = sourceOptions.unorderedSets === false ? false : true; // default to false |
| | | options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true; // default to true |
| | | options.replacer = sourceOptions.replacer || undefined; |
| | | options.excludeKeys = sourceOptions.excludeKeys || undefined; |
| | | |
| | | if(typeof object === 'undefined') { |
| | | throw new Error('Object argument required.'); |
| | |
| | | |
| | | var hasher = typeHasher(options, hashingStream); |
| | | hasher.dispatch(object); |
| | | if (!hashingStream.update) |
| | | hashingStream.end('') |
| | | if (!hashingStream.update) { |
| | | hashingStream.end(''); |
| | | } |
| | | |
| | | if (hashingStream.digest) { |
| | | return hashingStream.digest(options.encoding === 'buffer' ? undefined : options.encoding); |
| | |
| | | function typeHasher(options, writeTo, context){ |
| | | context = context || []; |
| | | var write = function(str) { |
| | | if (writeTo.update) |
| | | if (writeTo.update) { |
| | | return writeTo.update(str, 'utf8'); |
| | | else |
| | | } else { |
| | | return writeTo.write(str, 'utf8'); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | return { |
| | | dispatch: function(value){ |
| | |
| | | return write(object); |
| | | } |
| | | |
| | | if(objType !== 'object' && objType !== 'function') { |
| | | if(objType !== 'object' && objType !== 'function' && objType !== 'asyncfunction') { |
| | | if(this['_' + objType]) { |
| | | this['_' + objType](object); |
| | | } else if (options.ignoreUnknown) { |
| | |
| | | var arr = Array.from(set); |
| | | return this._array(arr, options.unorderedSets !== false); |
| | | }, |
| | | _file: function(file) { |
| | | write('file:'); |
| | | return this.dispatch([file.name, file.size, file.type, file.lastModfied]); |
| | | }, |
| | | _blob: function() { |
| | | if (options.ignoreUnknown) { |
| | | return write('[blob]'); |
| | |
| | | 'Use "options.replacer" or "options.ignoreUnknown"\n'); |
| | | }, |
| | | _domwindow: function() { return write('domwindow'); }, |
| | | _bigint: function(number){ |
| | | return write('bigint:' + number.toString()); |
| | | }, |
| | | /* Node.js standard native objects */ |
| | | _process: function() { return write('process'); }, |
| | | _timer: function() { return write('timer'); }, |
| | |
| | | _dataview: function() { return write('dataview'); }, |
| | | _signal: function() { return write('signal'); }, |
| | | _fsevent: function() { return write('fsevent'); }, |
| | | _tlswrap: function() { return write('tlswrap'); } |
| | | _tlswrap: function() { return write('tlswrap'); }, |
| | | }; |
| | | } |
| | | |