# core/converters/route.converter.ts

> 48 lines of code and 13 definitions.

Tree: Project Scripts
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/scripts#file-scripts-core-converters-route-converter-ts
Source text: https://banes-lab.com/source/scripts/core/converters/route.converter.ts.txt

Listed in [core/converters](https://banes-lab.com/api/source/scripts/core/converters.md), after [core/converters/rate.converter.ts](https://banes-lab.com/source/scripts/core/converters/rate.converter.ts.md) and before [core/converters/snapshot.converter.ts](https://banes-lab.com/source/scripts/core/converters/snapshot.converter.ts.md).

## Definitions

- `PNG_SUFFIX` (lexical_declaration, line 10)
- `LOG_SUFFIX` (lexical_declaration, line 11)
- `HOME_STEM` (lexical_declaration, line 12)
- `ROUTE_SEPARATOR` (lexical_declaration, line 13)
- `STEM_SEPARATOR` (lexical_declaration, line 14)
- `readCaptureOptions` (lexical_declaration, line 16, exported)
- `routes` (lexical_declaration, line 17, exported)
- `outDir` (lexical_declaration, line 18, exported)
- `rooted` (lexical_declaration, line 19, exported)
- `artifactStem` (lexical_declaration, line 32, exported)
- `words` (lexical_declaration, line 33, exported)
- `snapshotFor` (lexical_declaration, line 37, exported)
- `stem` (lexical_declaration, line 38, exported)

## Contained in

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

## Source

```typescript
import { flagValue, flagValues, hasFlag, numberFlag } from "@govlab/argv";
import { join, resolve } from "node:path";
import type { CaptureOptions } from "#types/route.types";
import { LOCAL_ORIGIN } from "#configuration/configs/route.config";
import type { ParsedArgv } from "@govlab/argv";
import { SNAPSHOT_DEFAULTS } from "#configuration/configs/snapshot.config";
import type { SnapshotOptions } from "#types/snapshot.types";
import { portOf } from "@ssot/secrets";

const PNG_SUFFIX = ".png";
const LOG_SUFFIX = ".log";
const HOME_STEM = "index";
const ROUTE_SEPARATOR = "/";
const STEM_SEPARATOR = "-";

export const readCaptureOptions = function readCaptureOptions(argv: ParsedArgv): CaptureOptions | null {
    const routes = flagValues(argv, "--route");
    const outDir = flagValue(argv, "--out-dir");
    const rooted = routes.every((route) => route.startsWith(ROUTE_SEPARATOR));
    if (routes.length === 0 || !rooted || outDir === undefined) {
        return null;
    }
    return {
        browser: flagValue(argv, "--browser") ?? null,
        outDir: resolve(outDir),
        routes,
        settleMs: numberFlag(argv, "--settle", SNAPSHOT_DEFAULTS.settleMs),
        software: !hasFlag(argv, "--gpu"),
    };
};

export const artifactStem = function artifactStem(route: string): string {
    const words = route.split(ROUTE_SEPARATOR).filter((word) => word.length > 0);
    return words.length === 0 ? HOME_STEM : words.join(STEM_SEPARATOR);
};

export const snapshotFor = function snapshotFor(options: CaptureOptions, route: string): SnapshotOptions {
    const stem = join(options.outDir, artifactStem(route));
    return {
        browser: options.browser,
        clickAfterMs: SNAPSHOT_DEFAULTS.clickAfterMs,
        clickAt: null,
        height: SNAPSHOT_DEFAULTS.height,
        log: stem + LOG_SUFFIX,
        out: stem + PNG_SUFFIX,
        settleMs: options.settleMs,
        software: options.software,
        timeoutMs: SNAPSHOT_DEFAULTS.timeoutMs,
        url: LOCAL_ORIGIN + String(portOf("SITE_DEV_PORT")) + route,
        width: SNAPSHOT_DEFAULTS.width,
    };
};
```
