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

tiny-dedent

v1.0.2

Published

A Tiny module for stripping indentation from multi-line strings

Downloads

225

Readme

tiny-dedent

Node NPM Travis David Coverage Status NPM

A Tiny module for stripping indentation from multi-line strings.

  • It's tiny! 150 bytes (gzipped)
  • No dependencies!
  • It's Fast!

Installation

Yarn

yarn add tiny-dedent

NPM

npm install tiny-dedent

CDN

If you don't use a package manager, you can access tiny-dedent via unpkg (CDN), download the source, or point your package manager to the url.

  • https://unpkg.com/tiny-dedent/

Usage

import S from "tiny-dedent";

function usageExample() {
  const first = S(`A string that gets so long you need to break it over
                       multiple lines. Luckily tiny-dedent is here to keep it
                       readable without lots of spaces ending up in the string
                       itself.`);
A string that gets so long you need to break it over
multiple lines. Luckily tiny-dedent is here to keep it
readable without lots of spaces ending up in the string
itself.
const second = S(`
    Leading and trailing lines will be trimmed, so you can write something like
    this and have it work as you expect:

      * how convenient it is
      * that I can use an indented list
         - and still have it do the right thing

    That's all.
  `);
Leading and trailing lines will be trimmed, so you can write something like
this and have it work as you expect:

  * how convenient it is
  * that I can use an indented list
    - and still have it do the right thing

That's all.

Wait! I lied. Dedent can also be used as a function.

Motivation

I've been writting this replace regex over and over at the end of every template literal string, then I found there's a pretty popular package called dedent, which does exactly that. But I didn't feel like adding a dependency to do something that should be a macro, so I wrote this as a simple function.

This library is meant to be kept really really simple. It does not try to handle any edge cases, if you need something something more sophisticated take a look at the dedent package, it is around ~50 lines.

Why not a tagged function?

A tagged function has to manually make the interpolations, instead of running it natively. Passing the string it as regular function parameter leaves the hard work for the javascript engine instead of doing it in userland, in theory it should be faster, and you need ship less code.

Suggestions / Questions

File a issue on this repository

License

MIT