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

ne-tag-fns

v0.7.0

Published

A small template tag function library for ES6 string literals

Downloads

841

Readme

ne-tag-fns Build Status Greenkeeper badge MIT license package version

Template Tags Function Library

Overview

I am constantly finding myself rewriting variations of this code. So, in big girl fashion, I am putting out a library I can reuse and share with others who seek a similar solution.

Installation

Simply add the module to your code as a regular, peer or dev dependency as you see fit. These instructions presume you will use it as a normal dependency.

cd <your project folder>
npm install --save ne-tag-fns

Tag Functions Included

Tag functions included with the library that are directly usable are

  • dropLowest
  • dedent
  • inline
  • inlineJoin

inline Usage

The inline tag function takes the contents of a given string, even spread over several lines, and converts it to a nice single spaced output. This makes string creation in organizations where you must conform to 80 columns far easier to work with.

Inline does this by performing a few steps

  • If either the first or last line are simply whitespace, they are removed
  • Each line is trim'ed of leading and trailing whitespace
  • All remaining carriage returns and new lines will be converted to a single space.

Example

  const { inline } = require('ne-tag-fns') // or
  import { inline } from 'ne-tag-fns'      // if using ES6 with imports

  let description = inline`
    This is a nice message, and its contents
    will be all on a single line.
  `

  description === `This is a nice message, and its contents will be all on a single line` // true

inlineJoin Usage

The inlineJoin tag function takes the contents of a given string, even spread over several lines, and converts it to a nice single spaced output. This makes string creation in organizations where you must conform to 80 columns far easier to work with.

inlineJoin does this by performing a few steps

  • If either the first or last line are simply whitespace, they are removed
  • Each line is trim'ed of leading and trailing whitespace
  • All remaining carriage returns and new lines will be converted to the supplied string.
  • Optionally, all leading newlines can be trimmed
  • Optionally, all trailing newlines can be trimmed

Unlike inline, inlineJoin needs to be executed with parameters before it is used as a tag function as its execution actually returns the tag function customized in the manner desired.

Example

  const { inlineJoin } = require('ne-tag-fns') // or
  import { inlineJoin } from 'ne-tag-fns'      // if using ES6 with imports

  let description = inlineJoin('-')`
    ABC
    DEF
  ` === 'ABC-DEF' // true

  let skipLeading = inlineJoin('', true)`

    ABC
    DEF
  ` === 'ABCDEF' // true

  let skipLeadingAndTrailing = inlineJoin('-', true, true)`

    ABC
    DEF
    GHI



  ` === `ABC-DEF-GHI` // true

dropLowest Usage

In your application, wherever you may have strings that span longer than your code style allows or where you simply wish to clean up your code, import the function and use.

const { dropLowest } = require('ne-tag-fns'); // or
import { dropLowest } from 'ne-tag-fns'       // when using import

function someFunction() {
  return dropLowest`
    // A comment that has some code in it
    function contrivedFunction() {
      return 42
    }
  `;
}

// or, more simply...

const someString = dropLowest`
  Some string where all lines in the comment will
  have their common amount of shared whitespace
  removed.
    By default the lowest count, in this case 2,
    will be dropped and these two lines will also
    be flush to the left to allow for some margin
    of error.
      But this set of lines will be indented by
      the difference, so two spaces in.

  - Brie
`

dedent Usage

If you do not like that the lowest indentation count is dropped, you can use dedent to turn off this behavior

const { dedent } = require('ne-tag-fns'); // or
import { dedent } from 'ne-tag-fns'       // when using import

const someString = dedent`
  Some string where all lines in the comment will
  have their common amount of shared whitespace
  removed.
    With custom the lowest count, in this case 2,
    will not be dropped and these two lines will also
    keep their indentation
      But this set of lines will be indented as
      seen, so four spaces in.

  - Brie
`