folder-hash
Advanced tools
Comparing version 3.0.0 to 3.1.0
10
index.js
@@ -14,2 +14,3 @@ const crypto = require('crypto'), | ||
matchPath: false, | ||
ignoreBasename: false, | ||
ignoreRootName: false | ||
@@ -22,2 +23,3 @@ }, | ||
matchPath: false, | ||
ignoreBasename: false, | ||
ignoreRootName: false | ||
@@ -139,3 +141,5 @@ } | ||
const hash = crypto.createHash(options.algo); | ||
if (isRootElement && options.files.ignoreRootName) { | ||
if (options.files.ignoreBasename || | ||
(isRootElement && options.files.ignoreRootName)) | ||
{ | ||
log.match(`omitted name of ${filePath} from hash`) | ||
@@ -189,3 +193,5 @@ } else { | ||
const hash = crypto.createHash(options.algo); | ||
if (isRootElement && options.folders.ignoreRootName) { | ||
if (options.folders.ignoreBasename || | ||
(isRootElement && options.folders.ignoreRootName)) | ||
{ | ||
log.match(`omitted name of folder ${name} from hash`) | ||
@@ -192,0 +198,0 @@ } else { |
{ | ||
"name": "folder-hash", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Create a hash checksum over a folder and its content - its children and their content", | ||
@@ -36,3 +36,3 @@ "main": "index.js", | ||
"chai-as-promised": "^7.1.1", | ||
"jsdoc": "^3.4.3", | ||
"jsdoc": "3.5.5", | ||
"memfs": "^2.8.0", | ||
@@ -39,0 +39,0 @@ "mocha": "^6.0.2", |
189
README.md
@@ -11,5 +11,6 @@ Create a hash checksum over a folder or a file. | ||
### Simple example | ||
See file *./examples/readme-example1.js*. | ||
This example excludes all files and folders starting with a dot, (e.g. *.git/* and *.gitignore*), the *node_modules* folder. | ||
To see differences to the last version of this package, I would create hashes over all *.js* and *.json* files. But ignore everything inside folders starting wiht a dot, and also from the folders *node_modules*, *test_coverage*. The structure of the options object is documented <a href="#options">on this page.</a> | ||
This example is also stored in [./examples/readme-example1.js](/examples/readme-example1.js). | ||
```js | ||
@@ -54,6 +55,6 @@ const { hashElement } = require('folder-hash'); | ||
``` | ||
And the structure may be traversed to e.g. create incremental backups. | ||
It is also possible to only match the full path and not the basename. The same configuration could look like this: | ||
_But unfortunately *nix and Windows behave differently, so please use caution._ | ||
_You should be aware that *nix and Windows behave differently, so please use caution._ | ||
```js | ||
@@ -74,77 +75,2 @@ const options = { | ||
### Other examples using promises | ||
See file *./examples/readme-with-promises.js* | ||
```js | ||
const path = require('path'); | ||
const { hashElement } = require('folder-hash'); | ||
// pass element name and folder path separately | ||
hashElement('test', path.join(__dirname, '..')) | ||
.then(hash => { | ||
console.log('Result for folder "../test":', hash.toString(), '\n'); | ||
}) | ||
.catch(error => { | ||
return console.error('hashing failed:', error); | ||
}); | ||
// pass element path directly | ||
hashElement(__dirname) | ||
.then(hash => { | ||
console.log(`Result for folder "${__dirname}":`); | ||
console.log(hash.toString(), '\n'); | ||
}) | ||
.catch(error => { | ||
return console.error('hashing failed:', error); | ||
}); | ||
// pass options (example: exclude dotFolders) | ||
const options = { encoding: 'hex', folders: { exclude: ['.*'] } }; | ||
hashElement(__dirname, options) | ||
.then(hash => { | ||
console.log('Result for folder "' + __dirname + '" (with options):'); | ||
console.log(hash.toString(), '\n'); | ||
}) | ||
.catch(error => { | ||
return console.error('hashing failed:', error); | ||
}); | ||
``` | ||
### Other examples using error-first callbacks | ||
See *./examples/readme-with-callbacks.js* | ||
```js | ||
const path = require('path'); | ||
const { hashElement } = require('folder-hash'); | ||
// pass element name and folder path separately | ||
hashElement('test', path.join(__dirname, '..'), (error, hash) => { | ||
if (error) { | ||
return console.error('hashing failed:', error); | ||
} else { | ||
console.log('Result for folder "../test":', hash.toString(), '\n'); | ||
} | ||
}); | ||
// pass element path directly | ||
hashElement(__dirname, (error, hash) => { | ||
if (error) { | ||
return console.error('hashing failed:', error); | ||
} else { | ||
console.log('Result for folder "' + __dirname + '":'); | ||
console.log(hash.toString(), '\n'); | ||
} | ||
}); | ||
// pass options (example: exclude dotFiles) | ||
const options = { algo: 'md5', files: { exclude: ['.*'], matchBasename: true } }; | ||
hashElement(__dirname, options, (error, hash) => { | ||
if (error) { | ||
return console.error('hashing failed:', error); | ||
} else { | ||
console.log('Result for folder "' + __dirname + '":'); | ||
console.log(hash.toString()); | ||
} | ||
}); | ||
``` | ||
### Parameters for the hashElement function | ||
@@ -190,3 +116,3 @@ | ||
<td> | ||
Options object (see below) | ||
<a href="#options">Options object (see below)</a> | ||
</td> | ||
@@ -207,4 +133,4 @@ </tr> | ||
#### Options object properties | ||
##### Default values | ||
## Options | ||
### Default values | ||
```js | ||
@@ -219,2 +145,3 @@ { | ||
matchPath: false, | ||
ignoreBasename: false, | ||
ignoreRootName: false | ||
@@ -278,3 +205,3 @@ }, | ||
<td colspan="2"> | ||
Rules object (see below) | ||
<a href="#rules-object-properties">Rules object (see below)</a> | ||
</td> | ||
@@ -291,3 +218,3 @@ </tr> | ||
<td colspan="2"> | ||
Rules object (see below) | ||
<a href="#rules-object-properties">Rules object (see below)</a> | ||
</td> | ||
@@ -363,2 +290,15 @@ </tr> | ||
<tr> | ||
<td>ignoreBasename</td> | ||
<td> | ||
<span>bool</span> | ||
</td> | ||
<td> | ||
<optional><br> | ||
</td> | ||
<td> | ||
false | ||
</td> | ||
<td>Set to true to calculate the hash without the basename element</td> | ||
</tr> | ||
<tr> | ||
<td>ignoreRootName</td> | ||
@@ -380,2 +320,79 @@ <td> | ||
## Examples | ||
### Other examples using promises | ||
See file *./examples/readme-with-promises.js* | ||
```js | ||
const path = require('path'); | ||
const { hashElement } = require('folder-hash'); | ||
// pass element name and folder path separately | ||
hashElement('test', path.join(__dirname, '..')) | ||
.then(hash => { | ||
console.log('Result for folder "../test":', hash.toString(), '\n'); | ||
}) | ||
.catch(error => { | ||
return console.error('hashing failed:', error); | ||
}); | ||
// pass element path directly | ||
hashElement(__dirname) | ||
.then(hash => { | ||
console.log(`Result for folder "${__dirname}":`); | ||
console.log(hash.toString(), '\n'); | ||
}) | ||
.catch(error => { | ||
return console.error('hashing failed:', error); | ||
}); | ||
// pass options (example: exclude dotFolders) | ||
const options = { encoding: 'hex', folders: { exclude: ['.*'] } }; | ||
hashElement(__dirname, options) | ||
.then(hash => { | ||
console.log('Result for folder "' + __dirname + '" (with options):'); | ||
console.log(hash.toString(), '\n'); | ||
}) | ||
.catch(error => { | ||
return console.error('hashing failed:', error); | ||
}); | ||
``` | ||
### Other examples using error-first callbacks | ||
See *./examples/readme-with-callbacks.js* | ||
```js | ||
const path = require('path'); | ||
const { hashElement } = require('folder-hash'); | ||
// pass element name and folder path separately | ||
hashElement('test', path.join(__dirname, '..'), (error, hash) => { | ||
if (error) { | ||
return console.error('hashing failed:', error); | ||
} else { | ||
console.log('Result for folder "../test":', hash.toString(), '\n'); | ||
} | ||
}); | ||
// pass element path directly | ||
hashElement(__dirname, (error, hash) => { | ||
if (error) { | ||
return console.error('hashing failed:', error); | ||
} else { | ||
console.log('Result for folder "' + __dirname + '":'); | ||
console.log(hash.toString(), '\n'); | ||
} | ||
}); | ||
// pass options (example: exclude dotFiles) | ||
const options = { algo: 'md5', files: { exclude: ['.*'], matchBasename: true } }; | ||
hashElement(__dirname, options, (error, hash) => { | ||
if (error) { | ||
return console.error('hashing failed:', error); | ||
} else { | ||
console.log('Result for folder "' + __dirname + '":'); | ||
console.log(hash.toString()); | ||
} | ||
}); | ||
``` | ||
## Behavior | ||
@@ -386,3 +403,3 @@ The behavior is documented and verified in the unit tests. Execute `npm test` or `mocha test`, and have a look at the _test_ subfolder. | ||
### Creating hashes over files | ||
### Creating hashes over files (with default options) | ||
**The hashes are the same if:** | ||
@@ -399,3 +416,3 @@ | ||
### Creating hashes over folders | ||
### Creating hashes over folders (with default options) | ||
Content means in this case a folder's children - both the files and the subfolders with their children. | ||
@@ -402,0 +419,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80595
29
944
421