Socket
Book a DemoInstallSign in
Socket

fix-whitespace

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fix-whitespace

A tiny library that fixes whitespace in JavaScript template strings.

1.0.4
latest
Source
npmnpm
Version published
Weekly downloads
22
22.22%
Maintainers
1
Weekly downloads
 
Created
Source

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!

Keywords

template-strings

FAQs

Package last updated on 02 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.