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 2.1.0 to 3.0.0

index.d.ts

58

index.js
'use strict';
const execa = require('execa');
const run = args => execa('df', args).then(res =>
res.stdout.trim().split('\n').slice(1).map(x => {
const cl = x.split(/\s+(?=[\d\/])/);
const run = async args => {
const {stdout} = await execa('df', args);
return stdout.trim().split('\n').slice(1).map(line => {
const cl = line.split(/\s+(?=[\d/])/);
return {

@@ -16,37 +18,43 @@ filesystem: cl[0],

};
})
);
});
};
const df = module.exports = () => run(['-kP']);
const df = async () => run(['-kP']);
df.fs = name => {
df.fs = async name => {
if (typeof name !== 'string') {
return Promise.reject(new Error('name required'));
throw new TypeError('The `name` parameter required');
}
return run(['-kP']).then(data => {
for (const x of data) {
if (x.filesystem === name) {
return x;
}
const data = await run(['-kP']);
for (const item of data) {
if (item.filesystem === name) {
return item;
}
}
throw new Error(`The specified filesystem \`${name}\` doesn't exist`);
});
throw new Error(`The specified filesystem \`${name}\` doesn't exist`);
};
df.file = file => {
df.file = async file => {
if (typeof file !== 'string') {
return Promise.reject(new Error('file required'));
throw new TypeError('The `file` parameter is required');
}
return run(['-kP', file])
.then(data => data[0])
.catch(err => {
if (/No such file or directory/.test(err.message)) {
err = new Error(`The specified file \`${file}\` doesn't exist`);
}
let data;
try {
data = await run(['-kP', file]);
} catch (error) {
if (/No such file or directory/.test(error.message)) {
throw new Error(`The specified file \`${file}\` doesn't exist`);
}
throw err;
});
throw error;
}
return data[0];
};
module.exports = df;
module.exports.default = df;
{
"name": "@sindresorhus/df",
"version": "2.1.0",
"description": "Get free disk space info from `df -kP`",
"license": "MIT",
"repository": "sindresorhus/df",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"publishConfig": {
"access": "public"
},
"files": [
"index.js"
],
"keywords": [
"df",
"dfkp",
"df-kp",
"disk",
"space",
"free",
"info",
"data",
"fs",
"filesystem",
"file-system",
"drive",
"mount",
"size",
"capacity"
],
"dependencies": {
"execa": "^0.2.2"
},
"devDependencies": {
"ava": "*",
"xo": "*"
},
"xo": {
"esnext": true
}
"name": "@sindresorhus/df",
"version": "3.0.0",
"description": "Get free disk space info from `df -kP`",
"license": "MIT",
"repository": "sindresorhus/df",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"df",
"dfkp",
"df-kp",
"disk",
"space",
"free",
"info",
"data",
"fs",
"filesystem",
"file-system",
"drive",
"mount",
"size",
"capacity"
],
"dependencies": {
"execa": "^1.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"tsd-check": "^0.3.0",
"xo": "^0.24.0"
}
}
# df [![Build Status](https://travis-ci.org/sindresorhus/df.svg?branch=master)](https://travis-ci.org/sindresorhus/df)
> Get free disk space info from [`df -kP`](http://en.wikipedia.org/wiki/Df_\(Unix\))
> Get free disk space info from [`df -kP`](https://en.wikipedia.org/wiki/Df_\(Unix\))
Works on any Unix based system like macOS and Linux.
Works on any Unix-based system like macOS and Linux.

@@ -13,3 +13,3 @@ *Created because all the other `df` wrappers are terrible. This one uses simple and explicit parsing. Uses `execFile` rather than `exec`. Ensures better platform portability by using the `-P` flag. Returns sizes in bytes instead of kilobytes and the capacity as a float.*

```
$ npm install --save @sindresorhus/df
$ npm install @sindresorhus/df
```

@@ -23,35 +23,34 @@

df().then(list => {
console.log(list);
(async () => {
console.log(await df());
/*
[{
filesystem: '/dev/disk1',
size: 499046809600,
used: 443222245376,
available: 55562420224,
capacity: 0.89,
mountpoint: '/'
}, ...]
[
{
filesystem: '/dev/disk1',
size: 499046809600,
used: 443222245376,
available: 55562420224,
capacity: 0.89,
mountpoint: '/'
},
]
*/
});
df.fs('/dev/disk1').then(data => {
console.log(data);
console.log(await df.fs('/dev/disk1'));
/*
{
filesystem: '/dev/disk1',
...
}
*/
});
df.file(__dirname).then(data => {
console.log(data);
console.log(await df.file(__dirname));
/*
{
filesystem: '/dev/disk1',
...
}
*/
});
})();
```

@@ -64,9 +63,9 @@

Returns a promise for an array of filesystems with space info.
Returns a `Promise<Object[]>` with a list of space info objects for each filesystem.
### df.fs(filesystem)
### df.fs(path)
Returns a promise for an object with the space info for the specified filesystem.
Returns a `Promise<Object>` with the space info for the given filesystem path.
- `filesystem` - The name of the filesystem.
- `filesystem` - Name of the filesystem.
- `size` - Total size in bytes.

@@ -78,17 +77,21 @@ - `used` - Used size in bytes.

#### filesystem
#### path
Type: `string`
### df.file(file)
Path to a [filesystem device file](https://en.wikipedia.org/wiki/Device_file). Example: `'/dev/disk1'`.
Returns a promise for an object with the space info for the filesystem the supplied file is part of.
### df.file(path)
#### file
Returns a `Promise<Object>` with the space info for the filesystem the given file is part of.
#### path
Type: `string`
Path to a file on the filesystem to get the space info for.
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

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