word-wrap icon indicating copy to clipboard operation
word-wrap copied to clipboard

feature request: able specify different indent for the first line

Open jonathon-love opened this issue 8 years ago • 1 comments

hey, it would be super handy if a different indent could be specified for the first line, i.e.

  Lorem ipsum dolor sit amet, consectetur adipiscing
      elit, sed do eiusmod tempor incididunt ut labore
      et dolore magna aliqua. Ut enim ad minim veniam,
      quis nostrud exercitation ullamco laboris nisi ut
      aliquip ex ea commodo consequat.

thanks, and keep up the good work!

jonathon-love avatar Jan 11 '17 00:01 jonathon-love

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()}`);

Whobeu avatar Jan 08 '21 12:01 Whobeu