@knutkirkhorn/free-space
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -12,3 +12,3 @@ { | ||
"parserOptions": { | ||
"ecmaVersion": 10, | ||
"ecmaVersion": 2021, | ||
"sourceType": "module" | ||
@@ -31,19 +31,19 @@ }, | ||
"linebreak-style": "off", | ||
"no-console": "off", | ||
"object-curly-spacing": "off", | ||
"eol-last": "off", | ||
"comma-dangle": "off", | ||
"arrow-parens": "off", | ||
"arrow-parens": [ | ||
"error", | ||
"as-needed" | ||
], | ||
"object-curly-spacing": [ | ||
"error", | ||
"never" | ||
], | ||
"comma-dangle": [ | ||
"error", | ||
"never" | ||
], | ||
"max-len": "off", | ||
"no-plusplus": "off", | ||
"strict": "off", | ||
"arrow-body-style": "off", | ||
"consistent-return": "off", | ||
"no-loop-func": "off", | ||
"no-shadow": "off", | ||
"import/newline-after-import": "off", | ||
"no-await-in-loop": "off", | ||
"no-constant-condition": "off", | ||
"operator-linebreak": "off" | ||
"import/extensions": ["error", "always"] | ||
} | ||
} | ||
} |
@@ -29,2 +29,2 @@ 'use strict'; | ||
return unix(disk); | ||
}; | ||
}; |
@@ -5,35 +5,33 @@ 'use strict'; | ||
module.exports = disk => { | ||
return new Promise((resolve, reject) => { | ||
// Output of command: "Filesystem | 1K-blocks | Used | Available | Use% | Mounted on" | ||
exec('df -k', (err, stdout, stderr) => { | ||
if (stderr) { | ||
reject(new Error('Something wrong happened')); | ||
return; | ||
} | ||
module.exports = disk => new Promise((resolve, reject) => { | ||
// Output of command: "Filesystem | 1K-blocks | Used | Available | Use% | Mounted on" | ||
exec('df -k', (err, stdout, stderr) => { | ||
if (stderr) { | ||
reject(new Error('Something wrong happened')); | ||
return; | ||
} | ||
if (stdout.length === 0 || err) { | ||
reject(new Error(`Could not find disk: ${disk}`)); | ||
return; | ||
} | ||
if (stdout.length === 0 || err) { | ||
reject(new Error(`Could not find disk: ${disk}`)); | ||
return; | ||
} | ||
// Get every line from output and remove whitespace between data in each line | ||
const freeDiskSpaces = stdout.split('\n').slice(1).map(currentDisk => { | ||
const diskProperties = currentDisk.split(' '); | ||
// Get every line from output and remove whitespace between data in each line | ||
const freeDiskSpaces = stdout.split('\n').slice(1).map(currentDisk => { | ||
const diskProperties = currentDisk.split(' '); | ||
return diskProperties.filter(element => element !== ''); | ||
}); | ||
return diskProperties.filter(element => element !== ''); | ||
}); | ||
const selectedDisk = freeDiskSpaces.find(currentDisk => currentDisk[0] === disk); | ||
const selectedDisk = freeDiskSpaces.find(currentDisk => currentDisk[0] === disk); | ||
if (!selectedDisk) { | ||
reject(new Error(`Could not find disk: ${disk}`)); | ||
return; | ||
} | ||
if (!selectedDisk) { | ||
reject(new Error(`Could not find disk: ${disk}`)); | ||
return; | ||
} | ||
const availableDiskSpace = selectedDisk[3]; | ||
const availableDiskSpace = selectedDisk[3]; | ||
resolve(parseInt(availableDiskSpace, 10) * 1024); | ||
}); | ||
resolve(parseInt(availableDiskSpace, 10) * 1024); | ||
}); | ||
}; | ||
}); |
@@ -26,2 +26,2 @@ 'use strict'; | ||
}); | ||
}; | ||
}; |
{ | ||
"name": "@knutkirkhorn/free-space", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Get the amount of free space for a drive", | ||
@@ -12,3 +12,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/Knutakir/free-space.git" | ||
"url": "git+https://github.com/knutkirkhorn/free-space.git" | ||
}, | ||
@@ -24,11 +24,11 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/Knutakir/free-space/issues" | ||
"url": "https://github.com/knutkirkhorn/free-space/issues" | ||
}, | ||
"homepage": "https://github.com/Knutakir/free-space#readme", | ||
"homepage": "https://github.com/knutkirkhorn/free-space#readme", | ||
"devDependencies": { | ||
"ava": "^3.11.1", | ||
"eslint": "^7.7.0", | ||
"eslint-config-airbnb-base": "^14.2.0", | ||
"eslint-plugin-ava": "^11.0.0", | ||
"eslint-plugin-import": "^2.22.0" | ||
"ava": "^3.15.0", | ||
"eslint": "^7.24.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-plugin-ava": "^12.0.0", | ||
"eslint-plugin-import": "^2.22.1" | ||
}, | ||
@@ -35,0 +35,0 @@ "dependencies": { |
@@ -1,2 +0,2 @@ | ||
# free-space [![Build Status](https://travis-ci.org/Knutakir/free-space.svg?branch=master)](https://travis-ci.org/Knutakir/free-space) | ||
# free-space | ||
> Get the amount of free space for a drive | ||
@@ -33,6 +33,6 @@ | ||
## Related | ||
- [system-disk](https://github.com/Knutakir/system-disk) - Get the system disk of the computer (e.g. `C:` or `/dev/sda`) | ||
- [@knutkirkhorn/free-space-cli](https://github.com/Knutakir/free-space-cli) - CLI for this module | ||
- [system-disk](https://github.com/knutkirkhorn/system-disk) - Get the system disk of the computer (e.g. `C:` or `/dev/sda`) | ||
- [@knutkirkhorn/free-space-cli](https://github.com/knutkirkhorn/free-space-cli) - CLI for this module | ||
## License | ||
MIT © [Knut Kirkhorn](LICENSE) |
@@ -27,2 +27,2 @@ const test = require('ava'); | ||
t.is(error.message, 'Input disk should be of type `string`'); | ||
}); | ||
}); |
7857
143