npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

doc-chomp

v1.1.0

Published

Doc Chomp chomps on your document literals

Downloads

1,180

Readme

🍴 Doc Chomp

npm doc-chomp Build Status codecov

Doc Chomp chomps on your document literals

Usage

Doc Chomp is useful for keeping nice indentation outside ES6 template literals, while making them internally clean and consistent.

Automatic

The simplest way to use Doc Chomp is to tag a string!

const DocChomp = require('doc-chomp');

let chompedString = DocChomp`
  This string will be trimmed such that all indentation matches this line

  * Extra indentation is supported just fine
    * No problem! 👌🏼

  The line after the DocChomp call shouldn't be used, or Doc Chomp will complain!
  `

function compareStrings() {
  if (chompedString) {
    return chompedString === DocChomp`
      This string will be trimmed such that all indentation matches this line

      * Extra indentation is supported just fine
        * No problem! 👌🏼

      The line after the DocChomp call shouldn't be used, or Doc Chomp will complain!
      `;
  }
}

compareStrings(); // true!

In this example, chompedString will have two space characters trimmed from each line, and the other one will have six removed from each line.

With this usage, the first blank line (adjacent to DocChomp) is removed, and no text may be added on that line as DocChomp. If text was accepted here, Doc Chomp couldn't make a good choice about spacing! If you need to put text on that line, you can use the manual modes below!

Manual

In both of these modes, note that if the line DocChomp is on is blank, it will be omitted from the output, and line numbers begin at the next line.

Indentation line

If passed a number, Doc Chomp will detect the indentation from that line of the input.

function mcGuffin() {
  if (this.glazed) {
    return chompedString === DocChomp(2)`This string will have six space characters removed from the start of each line

      * Because this line is defined as line 2, and used for indentation detection
        * 👌🏼
      `;
  } else {
    return chompedString === DocChomp(2)`
      This is the "first" line (line 0), according to Doc Chomp, because the above line is blank.

      * Which means this is line 2, and used for indentation detection
        * No problem! 👌🏼
      `;
  }
}

Indentation string

If passed a string, Doc Chomp will remove exactly that indentation from each line.

function mcGuffin() {
  if (this.glazed) {
    return chompedString === DocChomp('      ')`This string will have six space characters removed from the start of each line

      * Extra indentation is supported just fine
        * No problem! 👌🏼
      `;
  } else {
    return chompedString === DocChomp('\t\t\t')`This string will have three tab characters removed from the start of each line

			* Extra indentation is supported just fine
				* No problem! 👌🏼
			`;
  }
}