"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.biggestWordInSentence = exports.limitWidth = exports.textWithPadding = void 0; const console_utils_1 = __importDefault(require("./console-utils")); // ("How are you?",center, 20) => " How are you? " // ("How are you?",right, 20) => " How are you?" const textWithPadding = (text, alignment, columnLen) => { const curTextSize = console_utils_1.default(text); // alignments for center padding case const leftPadding = Math.floor((columnLen - curTextSize) / 2); const rightPadding = columnLen - leftPadding - curTextSize; // console.log(text, columnLen, curTextSize); switch (alignment) { case 'left': return text.concat(' '.repeat(columnLen - curTextSize)); case 'center': return ' ' .repeat(leftPadding) .concat(text) .concat(' '.repeat(rightPadding)); case 'right': default: return ' '.repeat(columnLen - curTextSize).concat(text); } }; exports.textWithPadding = textWithPadding; // ("How are you?",10) => ["How are ", "you?"] const limitWidth = (inpStr, width) => { const ret = []; const spaceSeparatedStrings = inpStr.split(' '); let now = []; let cnt = 0; spaceSeparatedStrings.forEach((strWithoutSpace) => { const consoleWidth = console_utils_1.default(strWithoutSpace); if (cnt + consoleWidth <= width) { cnt += consoleWidth + 1; // 1 for the space now.push(strWithoutSpace); } else { ret.push(now.join(' ')); now = [strWithoutSpace]; cnt = consoleWidth + 1; } }); ret.push(now.join(' ')); return ret; }; exports.limitWidth = limitWidth; // ("How are you?",10) => ["How are ", "you?"] const biggestWordInSentence = (inpStr) => inpStr.split(' ').reduce((a, b) => Math.max(a, console_utils_1.default(b)), 0); exports.biggestWordInSentence = biggestWordInSentence;