Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including tsmlj with all npm packages installed. Try it out:

var tsmlj = require("tsmlj")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

tsmlj v1.0.0

ES6 template string tag for joining multi-line blocks of text with a single space.

tsmlj

ES6 template string tag for joining multi-line blocks of text with a single space.

This template string tag allows you to break long, multi-word strings (in other words: sentences) into multiple lines. Any whitespace characters will be replaced by a single space (tabs, newlines, etc) and the result trimmed.

For example, by default, this...

var text = `
  This is a really long sentence 
  that doesn't fit neatly on a 
  single line!
`;

...yields...


  This is a really long sentence 
  that doesn't fit neatly on a 
  single line!

...when you may have wanted...

This is a really long sentence that doesn't fit neatly on a single line!

...but you didn't want to write...

let text = `This is a really long sentence that doesn't fit neatly on a single line!`;

This is what tsmlj provides: the desired result above while maintaining the more readable code in the first block!

const tsmlj = require('tsmlj');

var text = tsmlj`
  This is a really long sentence 
  that doesn't fit neatly on a 
  single line!
`;

Compatibility

Support for template strings exists in Node as of 4.0.0, but this module is not tied to that engine in package.json because Babel users should be able to use it on many other platforms (including the browser).

Inspiration

If you didn't guess from the name, this module is inspired by Rod Vagg's tsml, which is similar except it takes a multi-line template string and returns a single line string. It's also very useful!

License

tsmlj is Copyright (c) 2015 Pat O'Neill and licensed under the MIT license.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free