Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dist/object_hash.js

This file was deleted.

4,763 changes: 0 additions & 4,763 deletions dist/object_hash_test.js

This file was deleted.

99 changes: 69 additions & 30 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
'use strict';

var gulp = require('gulp');
var browserify = require('gulp-browserify');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var coveralls = require('gulp-coveralls');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');
import browserify from 'browserify';
import gulp from 'gulp';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import uglify from 'gulp-uglify';
import rename from 'gulp-rename';
import replace from 'gulp-replace';
import coveralls from 'gulp-coveralls';
import istanbul from 'gulp-istanbul';
import mocha from 'gulp-mocha';
import sourcemaps from 'gulp-sourcemaps';
import log from 'gulplog';

var paths = {
index: './index.js',
tests: './test/**/*.js'
};

console.info(mocha);

function preTest(src) {
return gulp.src(src)
.pipe(istanbul())
Expand All @@ -37,30 +43,63 @@ function testKarma(done){
}, done).start();
}

gulp.task('dist', function(){
return Promise.all([
gulp.src([paths.index])
.pipe(browserify({
insertGlobals : true,
debug: true,
standalone: 'objectHash'
}))
// Hack: See https://github.com/puleos/object-hash/issues/71.
// It's probably better to replace gulp-browserify altogether instead.
.pipe(replace(/_global.crypto/g, 'false'))
.pipe(rename('object_hash.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist')),
gulp.src([paths.tests])
// Hack: browserify seems to not support async-await.
// It's probably better to replace gulp-browserify altogether instead.
.pipe(replace(/async function/g, 'function'))
.pipe(browserify())
.pipe(rename('object_hash_test.js'))
.pipe(gulp.dest('./dist'))
]);
gulp.task('dist', function() {
var b = browserify({
entries: paths.index,
basedir: './',
debug: false,
standalone: 'objectHash',
insertGlobals : false,
bundleExternal: false,
bare: true,
});
b.external('crypto');
b.require('crypto');
// b.external('buffer');
// b.exclude('buffer');
// b.ignore('buffer');

return b.bundle()
.pipe(source('object_hash.js'))
.pipe(buffer())
// .pipe(sourcemaps.init({loadMaps: true}))
.on('error', log.error)
// .pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'))
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest('./dist'))
});


// function() {
// // gulp expects tasks to return a stream, so we create one here.
// var bundledStream = through();

// bundledStream
// .pipe(source('object_hash_test.js'))
// .pipe(buffer())
// // .pipe(sourcemaps.init({loadMaps: true}))
// // .pipe(uglify())
// .on('error', log.error)
// // .pipe(sourcemaps.write('./'))
// .pipe(gulp.dest('./dist'));

// globby([paths.tests]).then(function(entries) {
// var b = browserify({
// entries: entries,
// basedir: './tests',
// debug: false,
// });

// b.bundle().pipe(bundledStream);
// });

// return bundledStream;
// },
// ], cb);
// });

gulp.task('pre-test', function() {
return preTest([paths.index]);
});
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function applyDefaults(object, sourceOptions){
options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true; // default to true
options.replacer = sourceOptions.replacer || undefined;
options.excludeKeys = sourceOptions.excludeKeys || undefined;
options.exclude = sourceOptions.exclude || undefined;

if(typeof object === 'undefined') {
throw new Error('Object argument required.');
Expand Down Expand Up @@ -175,6 +176,7 @@ function typeHasher(options, writeTo, context){
};

return {
level: -1,
dispatch: function(value){
if (options.replacer) {
value = options.replacer(value);
Expand All @@ -187,7 +189,10 @@ function typeHasher(options, writeTo, context){

//console.log("[DEBUG] Dispatch: ", value, "->", type, " -> ", "_" + type);

return this['_' + type](value);
++this.level;
var result = this['_' + type](value);
--this.level;
return result;
},
_object: function(object) {
var pattern = (/\[object (.*)\]/i);
Expand Down Expand Up @@ -242,6 +247,11 @@ function typeHasher(options, writeTo, context){
keys = keys.filter(function(key) { return !options.excludeKeys(key); });
}

if (options.exclude) {
var level = this.level;
keys = keys.filter(function(key) { return !options.exclude(key, object[key], level); });
}

write('object:' + keys.length + ':');
var self = this;
return keys.forEach(function(key){
Expand Down
Loading