folder-hash
Advanced tools
Comparing version 1.0.4 to 1.0.5
48
index.js
@@ -8,3 +8,2 @@ "use strict" | ||
if (typeof Promise === 'undefined') require('when/es6-shim/Promise'); | ||
//Promise = require('when').Promise; | ||
@@ -15,5 +14,3 @@ var algo = 'sha1'; | ||
module.exports = { | ||
hashElement: createHash/** /, | ||
hashFolderPromise: hashFolderPromise, | ||
hashFilePromise: hashFilePromise/**/ | ||
hashElement: createHash | ||
} | ||
@@ -28,23 +25,5 @@ | ||
function createHash(name, directoryPath, callback) { | ||
function isString(str) { | ||
return (typeof str == 'string' || str instanceof String) | ||
} | ||
var promise; | ||
if (!isString(name)) { | ||
promise = Promise.reject(new TypeError('First argument must be a string')); | ||
} | ||
if (!isString(directoryPath)) { | ||
if (typeof directoryPath === 'function') { | ||
callback = directoryPath; | ||
} | ||
var promise = parseParameters(name, directoryPath); | ||
var callback = arguments[arguments.length-1]; | ||
directoryPath = path.dirname(name); | ||
name = path.basename(name); | ||
} | ||
promise = hashElementPromise(name, directoryPath, callback); | ||
return promise | ||
@@ -61,2 +40,15 @@ .then(function (result) { | ||
function parseParameters(name, directoryPath) { | ||
if (!isString(name)) { | ||
return Promise.reject(new TypeError('First argument must be a string')); | ||
} | ||
if (!isString(directoryPath)) { | ||
directoryPath = path.dirname(name); | ||
name = path.basename(name); | ||
} | ||
return hashElementPromise(name, directoryPath); | ||
} | ||
function hashElementPromise(name, directoryPath) { | ||
@@ -159,2 +151,3 @@ var filepath = path.join(directoryPath, name); | ||
var HashedFile = function (name, hash) { | ||
@@ -168,2 +161,7 @@ this.name = name; | ||
return padding + '{ name: \'' + this.name + '\', hash: \'' + this.hash + '\' }'; | ||
} | ||
} | ||
function isString(str) { | ||
return (typeof str == 'string' || str instanceof String) | ||
} |
{ | ||
"name": "folder-hash", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Create a hash checksum over a folder and its content - its children and their content", | ||
@@ -24,6 +24,6 @@ "main": "index.js", | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^5.2.0", | ||
"mocha": "^2.4.5", | ||
"chai-as-promised": "^6.0.0", | ||
"mocha": "^3.2.0", | ||
"rimraf": "^2.5.2" | ||
} | ||
} |
@@ -17,6 +17,12 @@ | ||
var sampleFolder = 'sample-folder'; | ||
before(helper.createTestFolderStructure(sampleFolder)); | ||
describe('Initialization', function () { | ||
it('should throw an error if no name was passed', function () { | ||
folderHash.hashElement().should.be.rejectedWith(TypeError); | ||
}); | ||
}); | ||
describe('Should generate hashes', function () { | ||
@@ -131,2 +137,2 @@ describe('when called as a promise', function () { | ||
}); | ||
}); | ||
}); |
18277
330