generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
270 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
export function renderMarkdownTable( | ||
rows: string[][], | ||
headers: string[] = [] | ||
rows: string[][], | ||
headers: string[] = [] | ||
): string { | ||
if (!rows.length) { | ||
return '' | ||
} | ||
const align = [':---', ':---:', ':---:', ':---:'].slice(0, rows[0].length) | ||
const lines = [headers, align, ...rows].filter(Boolean) | ||
return lines.map(columns => `| ${columns.join(' | ')} |`).join('\n') | ||
if (!rows.length) { | ||
return '' | ||
} | ||
const align = [':---', ':---:', ':---:', ':---:'].slice(0, rows[0].length) | ||
const lines = [headers, align, ...rows].filter(Boolean) | ||
return lines.map((columns) => `| ${columns.join(' | ')} |`).join('\n') | ||
} | ||
|
||
export function formatDuration(milliseconds: number): string { | ||
const SECOND = 1000 | ||
const MINUTE = 60 * SECOND | ||
const HOUR = 60 * MINUTE | ||
const DAY = 24 * HOUR | ||
const SECOND = 1000 | ||
const MINUTE = 60 * SECOND | ||
const HOUR = 60 * MINUTE | ||
const DAY = 24 * HOUR | ||
|
||
let remaining = milliseconds | ||
let remaining = milliseconds | ||
|
||
const days = Math.floor(remaining / DAY) | ||
remaining %= DAY | ||
const days = Math.floor(remaining / DAY) | ||
remaining %= DAY | ||
|
||
const hours = Math.floor(remaining / HOUR) | ||
remaining %= HOUR | ||
const hours = Math.floor(remaining / HOUR) | ||
remaining %= HOUR | ||
|
||
const minutes = Math.floor(remaining / MINUTE) | ||
remaining %= MINUTE | ||
const minutes = Math.floor(remaining / MINUTE) | ||
remaining %= MINUTE | ||
|
||
const seconds = +(remaining / SECOND).toFixed(1) | ||
const seconds = +(remaining / SECOND).toFixed(1) | ||
|
||
return [ | ||
days && `${days} ${n('day', days)}`, | ||
hours && `${hours} ${n('hour', hours)}`, | ||
minutes && `${minutes} ${n('minute', minutes)}`, | ||
seconds && `${seconds} ${n('second', seconds)}` | ||
] | ||
.filter(Boolean) | ||
.join(', ') | ||
return [ | ||
days && `${days} ${n('day', days)}`, | ||
hours && `${hours} ${n('hour', hours)}`, | ||
minutes && `${minutes} ${n('minute', minutes)}`, | ||
seconds && `${seconds} ${n('second', seconds)}` | ||
] | ||
.filter(Boolean) | ||
.join(', ') | ||
} | ||
|
||
export function upperCaseFirst(str: string): string { | ||
return str.charAt(0).toUpperCase() + str.slice(1) | ||
return str.charAt(0).toUpperCase() + str.slice(1) | ||
} | ||
|
||
export function n(str: string, count: number): string { | ||
return count === 1 ? str : `${str}s` | ||
return count === 1 ? str : `${str}s` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import fs from 'fs/promises' | ||
|
||
export async function fileExists(filename: string): Promise<boolean> { | ||
try { | ||
await fs.access(filename, fs.constants.F_OK) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
try { | ||
await fs.access(filename, fs.constants.F_OK) | ||
return true | ||
} catch (e) { | ||
return false | ||
} | ||
} | ||
|
||
export async function readFile(path: string): Promise<string> { | ||
return await fs.readFile(path, { encoding: 'utf8' }) | ||
return await fs.readFile(path, { encoding: 'utf8' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.