fix-whitespace

1.0.4 • Public • Published

fix-whitespace

A tiny library that fixes whitespace in JavaScript template strings.

const items = [1, 2, 3]

const generateSitePage = (head, content) => fixWhitespace`
  <!DOCTYPE html>
  <html>
    <head>
      (Begin head..)${head}(..End head)
      <meta charset='utf-8'>
    </head>
    <body>
      <div id='content'>
        ${"Early insert!"} (Begin content x1..)${content}(..end content; begin content x2..)${content}(..end content!)
        ${"And back down."}
      </div>
    </body>
  </html>
`

console.log(generateSitePage(
  fixWhitespace`
    <title>Hello, world!</title>
  `,

  fixWhitespace`
    <ul>${items.map(x => `<li>${x}</li>`).join('\n')}</ul>
  `
))
<!DOCTYPE html>
<html>
  <head>
    (Begin head..)<title>Hello, world!</title>(..End head)
    <meta charset='utf-8'>
  </head>
  <body>
    <div id='content'>
      Early insert! (Begin content x1..)<ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
      </ul>
        <!-- Further indent at end! -->(..end content; begin content x2..)<ul>
          <li>1</li>
          <li>2</li>
          <li>3</li>
        </ul>
          <!-- Further indent at end! -->(..end content!)
      And back down.
    </div>
  </body>
</html>

Documentation

Read the code!

Package Sidebar

Install

npm i fix-whitespace

Weekly Downloads

19

Version

1.0.4

License

MIT

Unpacked Size

9.61 kB

Total Files

4

Last publish

Collaborators

  • towerofnix