Skip to content

Commit

Permalink
refactor(utils): qa
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Dec 14, 2022
1 parent f61889c commit fda2454
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/utils/add-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import formatExt from './format-ext'
const addExt = (path: string, ext?: Nullable<string>): string => {
validateString(path, 'path')

// exit early if extension isn't provided or validate ext
// exit early if extension isn't provided
if (ext === null || ext === undefined) return path
// validate file extension
else validateString(ext, 'ext')

// exit early if extension is empty string or path already ends with extension
Expand Down
8 changes: 6 additions & 2 deletions src/utils/change-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ import formatExt from './format-ext'
const changeExt = (path: string, ext?: Nullable<string>): string => {
validateString(path, 'path')

// exit early if extension isn't provided or validate ext
// exit early if extension isn't provided
if (ext === null || ext === undefined) return path
// validate file extension
else validateString(ext, 'ext')

// exit early if extension is empty string
if (!ext.trim()) return path

// ensure path does not end with dot character
path = path.replace(/\.$/, '')

/**
* File extension of {@linkcode path}.
*
* @const {EmptyString | Ext} extension
*/
const extension: EmptyString | Ext = extname((path = path.replace(/\.$/, '')))
const extension: EmptyString | Ext = extname(path)

return extension
? path.replace(new RegExp(`\\${extension}$`), formatExt(ext))
Expand Down
8 changes: 6 additions & 2 deletions src/utils/default-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ const defaultExt = (
): string => {
validateString(path, 'path')

// exit early if extension isn't provided or validate ext
// exit early if extension isn't provided
if (ext === null || ext === undefined) return path
// validate file extension
else validateString(ext, 'ext')

// exit early if extension is empty string
Expand All @@ -62,12 +63,15 @@ const defaultExt = (
.filter(ignorable => ignorable.trim().length > 0)
: []

// ensure path does not end with dot character
path = path.replace(/\.$/, '')

/**
* File extension of {@linkcode path}.
*
* @const {EmptyString | Ext} extension
*/
const extension: EmptyString | Ext = extname((path = path.replace(/\.$/, '')))
const extension: EmptyString | Ext = extname(path)

return extension && !ignore.includes(extension) ? path : addExt(path, ext)
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/remove-ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import formatExt from './format-ext'
const removeExt = (path: string, ext?: Nullable<string>): string => {
validateString(path, 'path')

// exit early if extension isn't provided or validate ext
// exit early if extension isn't provided
if (ext === null || ext === undefined) return path
// validate file extension
else validateString(ext, 'ext')

// exit early if extension is empty string
Expand Down

0 comments on commit fda2454

Please sign in to comment.