Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

folder-hash

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

folder-hash - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

examples/readme-with-callbacks.js

14

package.json
{
"name": "folder-hash",
"version": "1.1.1",
"version": "1.1.2",
"description": "Create a hash checksum over a folder and its content - its children and their content",

@@ -10,3 +10,3 @@ "main": "index.js",

"cover": "node node_modules/istanbul/lib/cli.js cover --dir test_coverage node_modules/mocha/bin/_mocha test",
"doc": "./node_modules/.bin/jsdoc index.js"
"doc": "./node_modules/.bin/jsdoc index.js -R README.md -d doc"
},

@@ -23,9 +23,9 @@ "author": {

"dependencies": {
"graceful-fs": "^4.1.11",
"minimatch": "^3.0.3",
"when": "^3.7.7"
"graceful-fs": "~4.1.11",
"minimatch": "~3.0.4",
"when": "~3.7.8"
},
"devDependencies": {
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"chai": "^4.0.2",
"chai-as-promised": "^7.1.1",
"istanbul": "^0.4.5",

@@ -32,0 +32,0 @@ "jsdoc": "^3.4.3",

@@ -1,5 +0,2 @@

# folderHash
## Description
Create a hash checksum over a folder or a file.
Create a hash checksum over a folder or a file.
The hashes are propagated upwards, the hash that is returned for a folder is generated over all the hashes of its children.

@@ -10,13 +7,15 @@ The hashes are generated with the _sha1_ algorithm and returned in _base64_ encoding.

{ name: 'test',
hash: 'qmUXLCsTQGOEF6p0w9V78MC7sJI=',
children: [
{ name: 'helper',
hash: 'x1CX3yVH3UuLTw7zcSitSs/PbGE=',
children: [
{ name: 'helper.js', hash: 'pHYwd8k/oZV01oABTz9MC8KovkU=' }
] },
{ name: 'test.js', hash: 'L/vqpdQhxmD5w62k24m4TuZJ1PM=' }
]
}
```js
{ name: 'test',
hash: 'qmUXLCsTQGOEF6p0w9V78MC7sJI=',
children: [
{ name: 'helper',
hash: 'x1CX3yVH3UuLTw7zcSitSs/PbGE=',
children: [
{ name: 'helper.js', hash: 'pHYwd8k/oZV01oABTz9MC8KovkU=' }
] },
{ name: 'test.js', hash: 'L/vqpdQhxmD5w62k24m4TuZJ1PM=' }
]
}
```

@@ -26,50 +25,54 @@ Each file returns a name and a hash, and each folder returns additionally an array of children (file or folder elements).

## Usage
First, install the dependencies by executing `npm install`.
First, install folder-hash with `npm install --save folder-hash`.
### With promises
var hasher = require('folder-hash');
// pass element name and folder path separately
hasher.hashElement('node_modules', __dirname).then(function (hash) {
console.log('Result for folder "node_modules" in directory "' + __dirname + '":');
console.log(hash.toString());
});
// pass element path directly
hasher.hashElement(__dirname).then(function (hash) {
console.log('Result for folder "' + __dirname + '":');
console.log(hash.toString());
});
// pass options (example: exclude dotFiles)
var options = { excludes: ['.*'], match: { basename: true, path: false } };
hasher.hashElement(__dirname, options, function (error, hash)) {
if (error) return console.error('hashing failed:', error);
console.log('Result for folder "' + __dirname + '":');
console.log(hash.toString());
});
```js
var hasher = require('folder-hash');
// pass element name and folder path separately
hasher.hashElement('node_modules', __dirname).then(function (hash) {
console.log('Result for folder "node_modules" in directory "' + __dirname + '":');
console.log(hash.toString());
});
// pass element path directly
hasher.hashElement(__dirname).then(function (hash) {
console.log('Result for folder "' + __dirname + '":');
console.log(hash.toString());
});
// pass options (example: exclude dotFiles)
var options = { excludes: ['.*'], match: { basename: true, path: false } };
hasher.hashElement(__dirname, options)
.then(function (hash) {
console.log('Result for folder "' + __dirname + '":');
console.log(hash.toString());
})
.catch(function (error) {
return console.error('hashing failed:', error);
});
```
### With callbacks
var hasher = require('folder-hash');
// pass element name and folder path separately
hasher.hashElement('node_modules', __dirname, function (error, hash)) {
if (error) return console.error('hashing failed:', error);
console.log('Result for folder "node_modules" in directory "' + __dirname + '":');
console.log(hash.toString());
});
// pass element path directly
hasher.hashElement(__dirname, function (error, hash)) {
if (error) return console.error('hashing failed:', error);
console.log('Result for folder "' + __dirname + '":');
console.log(hash.toString());
});
// pass options (example: exclude dotFiles)
var options = { excludes: ['**/.*'], match: { basename: false, path: true } };
hasher.hashElement(__dirname, options, function (error, hash)) {
if (error) return console.error('hashing failed:', error);
console.log('Result for folder "' + __dirname + '":');
console.log(hash.toString());
});
```js
var hasher = require('folder-hash');
// pass element name and folder path separately
hasher.hashElement('node_modules', __dirname, function (error, hash) {
if (error) return console.error('hashing failed:', error);
console.log('Result for folder "node_modules" in directory "' + __dirname + '":');
console.log(hash.toString());
});
// pass element path directly
hasher.hashElement(__dirname, function (error, hash) {
if (error) return console.error('hashing failed:', error);
console.log('Result for folder "' + __dirname + '":');
console.log(hash.toString());
});
// pass options (example: exclude dotFiles)
var options = { excludes: ['**/.*'], match: { basename: false, path: true } };
hasher.hashElement(__dirname, options, function (error, hash) {
console.log('Result for folder "' + __dirname + '":');
console.log(hash.toString());
});
```
### Parameters for the hashElement function

@@ -228,3 +231,3 @@

### Creating hashes over folders
Content means in this case a folders children - both the files and the subfolders with their children.
Content means in this case a folder's children - both the files and the subfolders with their children.

@@ -243,2 +246,2 @@ **The hashes are the same if:**

## License
MIT, see LICENSE.txt
MIT, see LICENSE.txt
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc