UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

24 lines (23 loc) 912 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.truncateString = truncateString; const picocolors_1 = __importDefault(require("@brillout/picocolors")); const assert_js_1 = require("./assert.js"); function truncateString(str, lenMax) { const lenMaxReal = lenMax - 3; (0, assert_js_1.assert)(lenMaxReal >= 1); // Show at least one character before the ellipsis if (str.length < lenMax) { return str; } else { // Breaks ANSI codes. // - So far, the `str` we pass to truncateString(str) is always expected to not contain any ANSI code str = str.substring(0, lenMaxReal); const ellipsis = picocolors_1.default.dim('...'); str = str + ellipsis; return str; } }