Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(utils): clean up semicolons and improve ternary operations #1602

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/utils/src/console/formatMs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Format millisecond
*/
export const formatMs = (ms: number): string => {

Check failure on line 4 in packages/utils/src/console/formatMs.ts

View workflow job for this annotation

GitHub Actions / check (macos-latest, 18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 4 in packages/utils/src/console/formatMs.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 20)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 4 in packages/utils/src/console/formatMs.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 4 in packages/utils/src/console/formatMs.ts

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest, 22)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 4 in packages/utils/src/console/formatMs.ts

View workflow job for this annotation

GitHub Actions / check (macos-latest, 22)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 4 in packages/utils/src/console/formatMs.ts

View workflow job for this annotation

GitHub Actions / check (macos-latest, 20)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 4 in packages/utils/src/console/formatMs.ts

View workflow job for this annotation

GitHub Actions / check (windows-latest, 20)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 4 in packages/utils/src/console/formatMs.ts

View workflow job for this annotation

GitHub Actions / check (windows-latest, 18)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check failure on line 4 in packages/utils/src/console/formatMs.ts

View workflow job for this annotation

GitHub Actions / check (windows-latest, 22)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
if (ms < 1000) return `${ms}ms`
return `${(ms / 1000).toFixed(2)}s`
return (ms < 1000) ? `${ms}ms` : `${(ms / 1000).toFixed(2)}s`;
}
18 changes: 10 additions & 8 deletions packages/utils/src/console/withSpinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ export const withSpinner =
(msg: string) =>
async <T>(target: (spinner?: Ora) => Promise<T>): Promise<T> => {
if (process.env.DEBUG) {
return target()
return target();
}

const start = Date.now()
const spinner = ora()
const start = Date.now();
const spinner = ora();
try {
spinner.start(msg)
const result = await target(spinner)
spinner.succeed(`${msg} - done in ${formatMs(Date.now() - start)}`)
return result
spinner.start(msg);
const result = await target(spinner);
const after = Date.now();
spinner.succeed(`${msg} - done in ${formatMs(after - start)}`);
return result;
} catch (e) {
spinner.fail(`${msg} - failed in ${formatMs(Date.now() - start)}`)
const after = Date.now();
spinner.fail(`${msg} - failed in ${formatMs(after - start)}`);
throw e
}
}
10 changes: 5 additions & 5 deletions packages/utils/src/module/isChildPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import path from 'upath'
* they are the same path
*/
export const isChildPath = (child: string, parent: string): boolean => {
const childPath = path.normalize(child)
const parentPath = path.normalize(parent)
const childPath = path.normalize(child);
const parentPath = path.normalize(parent);
// path.win32.isAbsolute could check both win32 and posix absolute path correctly
if (!path.win32.isAbsolute(childPath) || !path.win32.isAbsolute(parentPath)) {
return false
return false;
}
const relativePath = path.relative(parentPath, childPath)
return relativePath === '' || !relativePath.startsWith('..')
const relativePath = path.relative(parentPath, childPath);
return relativePath === '' || !relativePath.startsWith('..');
}
10 changes: 6 additions & 4 deletions packages/utils/src/ssr/renderHead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export const renderHead = ([
attrs,
innerHTML = '',
]: HeadConfig): string => {
const openTag = `<${tag}${renderHeadAttrs(attrs)}>`
if (tag === 'link' || tag === 'meta' || tag === 'base') {
return openTag
const openTag = `<${tag}${renderHeadAttrs(attrs)}>`;
const tagsWithNoInnerHtml = ['link', 'meta', 'base'];

if (tagsWithNoInnerHtml.includes(tag)) {
return openTag;
}
return `${openTag}${innerHTML}</${tag}>`
return `${openTag}${innerHTML}</${tag}>`;
}
Loading