generated from EdJoPaTo/typescript-node-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
1d8e735
commit 169b8c3
Showing
11 changed files
with
109 additions
and
128 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @type {import('prettier').Options} | ||
*/ | ||
export default { | ||
printWidth: 80, | ||
tabWidth: 2, | ||
useTabs: false, | ||
semi: false, | ||
singleQuote: false, | ||
trailingComma: "none", | ||
bracketSpacing: true, | ||
bracketSameLine: true, | ||
}; |
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 was deleted.
Oops, something went wrong.
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,8 +1,62 @@ | ||
export function moduleName(input: string | undefined): string { | ||
if (typeof input !== 'string' && input !== undefined) { | ||
throw new TypeError(`Expected a string, got ${typeof input}`); | ||
} | ||
/** | ||
* Represents a console progress bar that tracks the progress of a task. | ||
*/ | ||
export class ConsoleProgressBar { | ||
current: number | ||
startTime: number | ||
updateInterval: number | ||
lastUpdate: number | ||
|
||
const sanetized = input?.trim() ?? 'Glitter'; | ||
return sanetized + ' & rainbows'; | ||
/** | ||
* Creates a new instance of ConsoleProgressBar. | ||
* @param total The total number of units to be processed. | ||
* @param updateInterval The interval at which the progress bar should be updated, in milliseconds. Default is 2000ms. | ||
*/ | ||
constructor( | ||
public total: number, | ||
updateInterval = 2000 | ||
) { | ||
this.current = 0 | ||
this.startTime = performance.now() | ||
this.updateInterval = updateInterval | ||
this.lastUpdate = 0 | ||
} | ||
|
||
/** | ||
* Updates the progress bar with the current value. | ||
* @param currentValue The current value of the progress. | ||
*/ | ||
update(currentValue: number) { | ||
const now = performance.now() | ||
if (now - this.lastUpdate < this.updateInterval) { | ||
return | ||
} | ||
|
||
this.current = currentValue | ||
const percentage = (this.current / this.total) * 100 | ||
const elapsedTime = now - this.startTime | ||
const estimatedTotalTime = (elapsedTime / this.current) * this.total | ||
const eta = (estimatedTotalTime - elapsedTime) / 1000 // Seconds | ||
|
||
console.clear() | ||
console.log( | ||
`Progress: [${this.renderBar( | ||
percentage | ||
)}] ${percentage}% ETA: ${eta.toFixed(2)}s` | ||
) | ||
|
||
this.lastUpdate = now | ||
} | ||
|
||
/** | ||
* Renders the progress bar based on the given percentage. | ||
* @param percentage The percentage of progress completed. | ||
* @returns The rendered progress bar. | ||
*/ | ||
private renderBar(percentage: number) { | ||
const barLength = 20 | ||
const filledLength = Math.round((barLength * percentage) / 100) | ||
const bar = "█".repeat(filledLength) + "░".repeat(barLength - filledLength) | ||
return bar | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,11 +1,9 @@ | ||
{ | ||
"extends": "@sindresorhus/tsconfig/tsconfig.json", | ||
"include": [ | ||
"source" | ||
], | ||
"compilerOptions": { | ||
"lib": ["ES2020"], | ||
"target": "ES2020", // Node.js 14 | ||
"outDir": "dist" | ||
} | ||
"extends": "@sindresorhus/tsconfig/tsconfig.json", | ||
"include": ["source"], | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"outDir": "dist" | ||
} | ||
} |