Socket
Socket
Sign inDemoInstall

@sindresorhus/df

Package Overview
Dependencies
Maintainers
1
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 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;
}

6

package.json
{
"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)
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