| 15 | export type TokenDict = { [_: string]: Token } |
| 16 | |
| 17 | export const bar = ( |
| 18 | { length, fill = '=', head = fill, empty = ' '}: |
| 19 | { length: number, fill?: string, empty?: string, head?: string } |
| 20 | ):Token => bar => { |
| 21 | const fillLength = Math.round(length * bar.progress()) |
| 22 | return new Array(length) |
| 23 | .fill(1) |
| 24 | .map((_, idx) => { |
| 25 | if (idx < fillLength-1) { |
| 26 | return fill |
| 27 | } else if (idx === fillLength-1) { |
| 28 | return head |
| 29 | } else { |
| 30 | return empty |
| 31 | } |
| 32 | }) |
| 33 | .join("") |
| 34 | } |
| 35 | |
| 36 | export const elapsedTime = ( |
| 37 | { interval = 1, until = Date.now, ...other }: { interval?: number, until?: ()=>number } & NumberFormat = {} |