Socket
Socket
Sign inDemoInstall

@sindresorhus/df

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sindresorhus/df - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

75

index.js
'use strict';
var childProcess = require('child_process');
const execa = require('execa');
function run(args, cb) {
childProcess.execFile('df', args, function (err, stdout) {
if (err) {
cb(err);
return;
}
const run = args => execa('df', args).then(res =>
res.stdout.trim().split('\n').slice(1).map(x => {
const cl = x.split(/\s+(?=[\d\/])/);
cb(null, stdout.trim().split('\n').slice(1).map(function (el) {
var cl = el.split(/\s+(?=[\d\/])/);
return {
filesystem: cl[0],
size: parseInt(cl[1], 10) * 1024,
used: parseInt(cl[2], 10) * 1024,
available: parseInt(cl[3], 10) * 1024,
capacity: parseInt(cl[4], 10) / 100,
mountpoint: cl[5]
};
})
);
return {
filesystem: cl[0],
size: parseInt(cl[1], 10) * 1024,
used: parseInt(cl[2], 10) * 1024,
available: parseInt(cl[3], 10) * 1024,
capacity: parseInt(cl[4], 10) / 100,
mountpoint: cl[5]
};
}));
});
};
const df = module.exports = () => run(['-kP']);
var df = module.exports = function (cb) {
run(['-kP'], cb);
};
df.fs = function (name, cb) {
df.fs = name => {
if (typeof name !== 'string') {
throw new Error('name required');
return Promise.reject(new Error('name required'));
}
run(['-kP'], function (err, data) {
if (err) {
cb(err);
return;
return run(['-kP']).then(data => {
for (const x of data) {
if (x.filesystem === name) {
return x;
}
}
var ret;
data.forEach(function (el) {
if (el.filesystem === name) {
ret = el;
}
});
cb(null, ret);
});
};
df.file = function (file, cb) {
df.file = file => {
if (typeof file !== 'string') {
throw new Error('file required');
return Promise.reject(new Error('file required'));
}
run(['-kP', file], function (err, data) {
if (err) {
cb(err);
return;
}
cb(null, data[0]);
});
return run(['-kP', file]).then(data => data[0]);
};
{
"name": "@sindresorhus/df",
"version": "1.0.1",
"version": "2.0.0",
"description": "Get free disk space info from `df -kP`",

@@ -13,7 +13,10 @@ "license": "MIT",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "node test.js"
"test": "xo && ava"
},
"publishConfig": {
"access": "public"
},
"files": [

@@ -39,5 +42,12 @@ "index.js"

],
"dependencies": {
"execa": "^0.2.2"
},
"devDependencies": {
"ava": "0.0.4"
"ava": "*",
"xo": "*"
},
"xo": {
"esnext": true
}
}

@@ -20,5 +20,5 @@ # df [![Build Status](https://travis-ci.org/sindresorhus/df.svg?branch=master)](https://travis-ci.org/sindresorhus/df)

```js
var df = require('@sindresorhus/df');
const df = require('@sindresorhus/df');
df(function (err, list) {
df().then(list => {
console.log(list);

@@ -33,7 +33,7 @@ /*

mountpoint: '/'
}, ...]
*/
}, ...]
*/
});
df.fs('/dev/disk1', function (err, data) {
df.fs('/dev/disk1').then(data => {
console.log(data);

@@ -44,7 +44,7 @@ /*

...
}
*/
}
*/
});
df.file(__dirname, function (err, data) {
df.file(__dirname).then(data => {
console.log(data);

@@ -55,4 +55,4 @@ /*

...
}
*/
}
*/
});

@@ -64,35 +64,10 @@ ```

### df(callback)
### df()
#### callback(error, list)
Returns a promise for an array of filesystems with space info.
*Required*
Type: `function`
### df.fs(filesystem)
##### list
Returns a promise for an object with the space info for the specified filesystem.
Type: `array`
List of `data` objects.
### df.fs(filesystem, callback)
Get space info for a specific filesystem.
#### filesystem
*Required*
Type: `string`
#### callback(error, data)
*Required*
Type: `function`
##### data
Type: `object`
Data for the specified filesystem:
- `filesystem` - The name of the filesystem.

@@ -105,19 +80,13 @@ - `size` - Total size in bytes.

### df.file(file, callback)
#### filesystem
Get space info for the filesystem the supplied file is part of.
#### file
*Required*
Type: `string`
#### callback(error, data)
### df.file(file)
*Required*
Type: `function`
Returns a promise for an object with the space info for the filesystem the supplied file is part of.
##### data
#### file
Same as `df.fs()`.
Type: `string`

@@ -127,2 +96,2 @@

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
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