# core/formatters/journal.formatter.ts

> 37 lines of code and 9 definitions.

Tree: Bane's Lab Deploy
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/deploy#file-deploy-core-formatters-journal-formatter-ts
Source text: https://banes-lab.com/source/deploy/core/formatters/journal.formatter.ts.txt

Listed in [core/formatters](https://banes-lab.com/api/source/deploy/core/formatters.md).

## Definitions

- `transferLineOf` (lexical_declaration, line 22, exported)
- `barOf` (lexical_declaration, line 17)
- `percentOf` (lexical_declaration, line 12, exported)
- `ratio` (lexical_declaration, line 13, exported)
- `filled` (lexical_declaration, line 18)
- `percent` (lexical_declaration, line 23, exported)
- `seconds` (lexical_declaration, line 24, exported)
- `rate` (lexical_declaration, line 25, exported)
- `remaining` (lexical_declaration, line 26, exported)

## Contained in

- [core/formatters](https://banes-lab.com/anatomy/deploy/folder-deploy-core-formatters.md)

## Uses

- [configuration/strings/deployment.strings.ts](https://banes-lab.com/source/deploy/configuration/strings/deployment.strings.ts.md)
- [core/converters/text.converter.ts](https://banes-lab.com/source/deploy/core/converters/text.converter.ts.md)

## Used by

- [core/reporters/journal.reporter.ts](https://banes-lab.com/source/deploy/core/reporters/journal.reporter.ts.md)

## Linked from

- [configuration/strings](https://banes-lab.com/anatomy/deploy/folder-deploy-configuration-strings.md)
- [core/converters](https://banes-lab.com/anatomy/deploy/folder-deploy-core-converters.md)
- [core/formatters](https://banes-lab.com/anatomy/deploy/folder-deploy-core-formatters.md)
- [core/reporters](https://banes-lab.com/anatomy/deploy/folder-deploy-core-reporters.md)

## Source

```typescript
import {
    BAR_EMPTY,
    BAR_FILLED,
    MS_PER_SECOND,
    PERCENT,
    PROGRESS_BAR_WIDTH,
} from "#configuration/constants/deployment.constants";
import { TIME_UNKNOWN, transferLine } from "#configuration/strings/deployment.strings";
import { formatBytes, formatClock } from "#core/converters/text.converter";
import type { TransferState } from "#types/deployment.types";

export const percentOf = function percentOf(state: TransferState): number {
    const ratio = state.size > 0 ? state.transferred / state.size : state.done / Math.max(state.total, 1);
    return Math.min(PERCENT, Math.floor(ratio * PERCENT));
};

const barOf = function barOf(percent: number): string {
    const filled = Math.round((percent / PERCENT) * PROGRESS_BAR_WIDTH);
    return BAR_FILLED.repeat(filled) + BAR_EMPTY.repeat(PROGRESS_BAR_WIDTH - filled);
};

export const transferLineOf = function transferLineOf(state: TransferState, now: number): string {
    const percent = percentOf(state);
    const seconds = Math.max((now - state.startedAt) / MS_PER_SECOND, 0);
    const rate = seconds > 0 ? state.transferred / seconds : 0;
    const remaining = Math.max(state.size - state.transferred, 0);
    return transferLine({
        bar: barOf(percent),
        done: state.done.toLocaleString(),
        failed: String(state.failed),
        label: state.label,
        left: rate > 0 ? formatClock(remaining / rate) : TIME_UNKNOWN,
        moved: formatBytes(state.transferred),
        percent: String(percent),
        rate: formatBytes(rate),
        size: formatBytes(state.size),
        total: state.total.toLocaleString(),
        unit: state.unit,
    });
};
```
