Skip to content

Commit

Permalink
fix: ignore empty lines from command output
Browse files Browse the repository at this point in the history
fix #23
  • Loading branch information
Alex-D committed May 21, 2023
1 parent ec6c34a commit e7247ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ function checkDiskSpace(directoryPath: string, dependencies: Dependencies = {
mapping: Record<string, number>,
coefficient: number,
): DiskSpace {
const parsed = stdout.trim().split('\n').slice(1).map(line => {
return line.trim().split(/\s+(?=[\d/])/)
})
const parsed = stdout
.split('\n') // Split lines
.map(line => line.trim()) // Trim all lines
.filter(line => line.length !== 0) // Remove empty lines
.slice(1) // Remove header
.map(line => line.split(/\s+(?=[\d/])/)) // Split on spaces to get columns

const filtered = parsed.filter(filter)

Expand Down
19 changes: 19 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ const platformFixtures = {
Caption FreeSpace Size
C: 159345410048 171204145152
D: 0 4001759232
`,
result: {
diskPath: 'C:',
free: 159345410048,
size: 171204145152,
},
},
{
title: 'Windows 11: With strange Powershell settings #23',
release: '11.12.0',
path: 'C:/User/toto',
execOutput: `
Caption FreeSpace Size
C: 159345410048 171204145152
D: 0 4001759232
`,
result: {
diskPath: 'C:',
Expand Down

0 comments on commit e7247ef

Please sign in to comment.