-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgetTransformDescription.ts
46 lines (35 loc) · 1.33 KB
/
getTransformDescription.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { AwsSdkJsCodemodTransform } from "../transforms";
const getWrappedBlocks = (sentence: string, blockLength: number): string[] => {
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;
};
export const getTransformDescription = (transform: AwsSdkJsCodemodTransform): string[] => {
const descriptionArr: string[] = [];
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;
};