@thi.ng/args
Version:
Declarative, functional CLI argument/options parser, app framework, arg value coercions, multi/sub-commands, usage generation, error handling etc.
26 lines (25 loc) • 977 B
JavaScript
import { isPlainObject } from "@thi.ng/checks/is-plain-object";
import { lengthAnsi } from "@thi.ng/strings/ansi";
import { padRight } from "@thi.ng/strings/pad-right";
import { repeat } from "@thi.ng/strings/repeat";
import { SPLIT_ANSI, wordWrapLines } from "@thi.ng/strings/word-wrap";
import { DEFAULT_THEME } from "./api.js";
const __ansi = (x, col) => col != null ? `\x1B[${col}m${x}\x1B[0m` : x;
const __padRightAnsi = (x, width) => padRight(width)(x, lengthAnsi(x));
const __wrap = (str, width) => str ? wordWrapLines(str, {
width,
splitter: SPLIT_ANSI,
hard: false
}) : [];
const __wrapWithIndent = (body, indent, width) => {
const prefix = repeat(" ", indent);
return __wrap(body, width - indent).map((l, i) => i ? prefix + l : l).join("\n");
};
const __colorTheme = (color) => isPlainObject(color) ? { ...DEFAULT_THEME, ...color } : color !== false ? DEFAULT_THEME : {};
export {
__ansi,
__colorTheme,
__padRightAnsi,
__wrap,
__wrapWithIndent
};