Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ryu1kn/multiline-string

Repository files navigation

Build Status Coverage Status

multiline-string

Remove leading space characters to let you nicely indent your multiline strings in your code.

Prerequisite

  • Node v4+

Usage

By default, multiline detects indentation by looking at the first non-empty line. Notice that the first empty line is dropped from the output to let you to start the first line with the indentation level you like.

const multiline = require('multiline-string')()
const s = multiline(`
 1. xxx
 a. yyy
 2. zzz
 `)
console.log(s)
// => "1. xxx\n a. yyy\n2. zzz"

If you want to start your string with an empty line, you can do:

const s = multiline(`

 Line 1
 Line 2
 `)
// => "\nLine 1\nLine 2\n"

You can also give marginMark to identify the start of each line to include indentation in the resulting text.

const multiline = require('multiline-string')({ marginMark: '|' })
const s = multiline(`
 | Usage: my-command file
 |
 | -v, --version Show version
 | -h, --help Show help information
 |`)
console.log(s)
// => " Usage: ...\n\n -v, --version ..."

About

Nicer look multiline string in your JavaScript

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

AltStyle によって変換されたページ (->オリジナル) /