Open jonathon-love opened 7 years ago
This is something I was looking for too and it was rather trivial to add to the module and option called "trimstart" after the "options.trim" check:
if (options.trimstart === true) {
result = result.replace(/^\s*/, '');
}
With the new option added to my code:
const wrapped = wrap(text, { indent: ' ', width: 60, trimstart: true });
console.log(`Text: ${wrapped}`);
The output is:
Text: Sit cillum sunt id ullamco esse aliquip ullamco fugiat
cillum irure aute. Eiusmod voluptate ea adipisicing aliquip
minim irure commodo adipisicing voluptate. Magna Lorem est
ea incididunt nisi et aute eiusmod excepteur et irure
pariatur non. Pariatur ut labore non mollit est adipisicing
fugiat dolore minim. Dolor est veniam ullamco est.
Of course I could skip modifying the word-wrap module and apply the regex (or newer trimStart() method) to the resultant "wrapped" string instead:
console.log(`Text: ${wrapped.replace(/^\s*/, '')}`);
console.log(`Text: ${wrapped.trimStart()}`);
hey, it would be super handy if a different indent could be specified for the first line, i.e.
thanks, and keep up the good work!