Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: able specify different indent for the first line #17

Open
jonathon-love opened this issue Jan 11, 2017 · 1 comment
Open

Comments

@jonathon-love
Copy link

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!

@Whobeu
Copy link

Whobeu commented Jan 8, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants