Skip to content

Commit

Permalink
fix(lib): [format] empty string handling
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Dec 16, 2022
1 parent 4263bf9 commit 5f0de54
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const config = {
}
},
{
files: ['./src/lib/resolve.ts'],
files: ['./src/lib/format.ts', './src/lib/resolve.ts'],
rules: {
'@typescript-eslint/prefer-nullish-coalescing': 0
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/__tests__/format.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('unit:lib/format', () => {
[{ ext: '.png', name: 'x' }],
[{ ext: '.html', name: 'index' }],
[{ ext: '.html', name: 'index', root: '/' }],
[{ dir: 'some/dir', ext: '.html', name: 'index' }]
[{ dir: 'some/dir', ext: '.html', name: 'index' }],
[{ base: '', dir: 'lib', ext: '.mjs', name: 'index', root: '' }]
]

// Act + Expect
Expand Down
4 changes: 2 additions & 2 deletions src/lib/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ const format = (pathObject: FormatInputPathObject): string => {
* @const {string} base
*/
const base: string =
pathObject.base ?? `${pathObject.name ?? ''}${formatExt(pathObject.ext)}`
pathObject.base || `${pathObject.name ?? ''}${formatExt(pathObject.ext)}`

/**
* Directory name or full path.
*
* @const {string | undefined} dir
*/
const dir: string | undefined = pathObject.dir ?? pathObject.root
const dir: string | undefined = pathObject.dir || pathObject.root

return !dir
? base
Expand Down

0 comments on commit 5f0de54

Please sign in to comment.