@sindresorhus/df
Advanced tools
Comparing version 3.1.0 to 3.1.1
44
index.js
'use strict'; | ||
const execa = require('execa'); | ||
const run = async args => { | ||
const {stdout} = await execa('df', args); | ||
const getColumnBoundaries = async header => { | ||
// Regex captures each individual column | ||
// ^\S+\s+ -> First column | ||
// \s*\S+\s*\S+$ -> Last column (combined) | ||
// \s*\S+ -> Regular columns | ||
const regex = /^\S+\s+|\s*\S+\s*\S+$|\s*\S+/g; | ||
const boundaries = []; | ||
let match; | ||
return stdout.trim().split('\n').slice(1).map(line => { | ||
const cl = line.split(/\s+(?=[\d/])/); | ||
while ((match = regex.exec(header))) { | ||
boundaries.push(match[0].length); | ||
} | ||
// Extend last column boundary | ||
boundaries[boundaries.length - 1] = -1; | ||
return boundaries; | ||
}; | ||
const parseOutput = async output => { | ||
const lines = output.trim().split('\n'); | ||
const boundaries = await getColumnBoundaries(lines[0]); | ||
return lines.slice(1).map(line => { | ||
const cl = boundaries.map(boundary => { | ||
// Handle extra-long last column | ||
const column = boundary > 0 ? line.slice(0, boundary) : line; | ||
line = line.slice(boundary); | ||
return column.trim(); | ||
}); | ||
return { | ||
@@ -21,2 +46,7 @@ filesystem: cl[0], | ||
const run = async args => { | ||
const {stdout} = await execa('df', args); | ||
return parseOutput(stdout); | ||
}; | ||
const df = async () => run(['-kP']); | ||
@@ -49,3 +79,3 @@ | ||
} catch (error) { | ||
if (/No such file or directory/.test(error.message)) { | ||
if (/No such file or directory/.test(error.stderr)) { | ||
throw new Error(`The specified file \`${file}\` doesn't exist`); | ||
@@ -63,1 +93,5 @@ } | ||
module.exports.default = df; | ||
if (process.env.NODE_ENV === 'test') { | ||
module.exports._parseOutput = parseOutput; | ||
} |
{ | ||
"name": "@sindresorhus/df", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Get free disk space info from `df -kP`", | ||
@@ -40,6 +40,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"execa": "^1.0.0" | ||
"execa": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"ava": "^2.1.0", | ||
"tsd": "^0.7.1", | ||
@@ -46,0 +46,0 @@ "xo": "^0.24.0" |
@@ -89,6 +89,1 @@ # df [![Build Status](https://travis-ci.org/sindresorhus/df.svg?branch=master)](https://travis-ci.org/sindresorhus/df) | ||
Path to a file on the filesystem to get the space info for. | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
6919
124
89
2
+ Addedcross-spawn@7.0.3(transitive)
+ Addedexeca@2.1.0(transitive)
+ Addedget-stream@5.2.0(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addednpm-run-path@3.1.0(transitive)
+ Addedonetime@5.1.2(transitive)
+ Addedp-finally@2.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedstrip-final-newline@2.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
- Removedcross-spawn@6.0.5(transitive)
- Removedexeca@1.0.0(transitive)
- Removedget-stream@4.1.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednice-try@1.0.5(transitive)
- Removednpm-run-path@2.0.2(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedpath-key@2.0.1(transitive)
- Removedsemver@5.7.2(transitive)
- Removedshebang-command@1.2.0(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedstrip-eof@1.0.0(transitive)
- Removedwhich@1.3.1(transitive)
Updatedexeca@^2.0.1