UNPKG

aws-sdk-js-codemod

Version:

Collection of codemod scripts that help update AWS SDK for JavaScript APIs

39 lines (38 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTransformDescription = void 0; const getWrappedBlocks = (sentence, blockLength) => { const words = sentence.split(" "); const blocks = []; let currentBlock = ""; // iterate over the words and add them to blocks for (const word of words) { // if the current block plus the next word is longer than the block length, // add the current block to the list of blocks and start a new block if (currentBlock.length + word.length > blockLength) { blocks.push(currentBlock); currentBlock = ""; } // add the word to the current block currentBlock += `${word} `; } // add the final block to the list of blocks blocks.push(currentBlock); return blocks; }; const getTransformDescription = (transform) => { const descriptionArr = []; const columnLength = 15; const borderLength = 2; descriptionArr[0] = " ".repeat(columnLength - borderLength - transform.name.length) + transform.name + " ".repeat(borderLength); const wrappedBlocks = getWrappedBlocks(transform.description, 80); descriptionArr[0] += wrappedBlocks[0]; for (let i = 1; i < wrappedBlocks.length; i++) { descriptionArr.push(" ".repeat(columnLength) + wrappedBlocks[i]); } return descriptionArr; }; exports.getTransformDescription = getTransformDescription;