CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-common-tags

A set of well-tested template literal tag functions for ES2015+ that solve common string manipulation and formatting problems.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

string-processing.mddocs/

String Processing

Core template tags for manipulating string formatting, indentation, and line structure. These tags are essential for code generation, template rendering, and text processing workflows.

Capabilities

Strip Indent

Strips the initial indentation from the beginning of each line while preserving relative indentation structure.

/**
 * Strips initial indentation from each line while preserving relative indentation
 * @param strings - Template strings array
 * @param expressions - Template substitution values
 * @returns String with initial indentation removed
 */
function stripIndent(strings, ...expressions): string;

Usage Examples:

import { stripIndent } from "common-tags";

// Basic indentation stripping
const code = stripIndent`
  function hello() {
    console.log("Hello World");
      return true;
  }
`;
// Result:
// function hello() {
//   console.log("Hello World");
//     return true;
// }

// With substitutions
const functionName = "greet";
const message = "Hello";
const func = stripIndent`
  function ${functionName}() {
    console.log("${message}");
  }
`;

Strip Indents

Strips all indentation from the beginning of each line, flattening the entire text structure.

/**
 * Strips all indentation from each line
 * @param strings - Template strings array  
 * @param expressions - Template substitution values
 * @returns String with all indentation removed
 */
function stripIndents(strings, ...expressions): string;

Usage Examples:

import { stripIndents } from "common-tags";

const code = stripIndents`
  function hello() {
    console.log("Hello World");
      return true;
  }
`;
// Result:
// function hello() {
// console.log("Hello World");
// return true;
// }

One Line

Converts multiline strings to a single line, replacing line breaks with spaces while preserving word separation.

/**
 * Converts multiline strings to single line with space separation
 * @param strings - Template strings array
 * @param expressions - Template substitution values
 * @returns Single-line string with spaces between former lines
 */
function oneLine(strings, ...expressions): string;

Usage Examples:

import { oneLine } from "common-tags";

// Basic multiline to single line
const description = oneLine`
  This is a very long description
  that spans multiple lines
  but should be on one line
`;
// Result: "This is a very long description that spans multiple lines but should be on one line"

// With substitutions
const name = "John";
const age = 30;
const intro = oneLine`
  Hello, my name is ${name}
  and I am ${age} years old.
`;
// Result: "Hello, my name is John and I am 30 years old."

One Line Trim

Converts multiline strings to a single line by removing newlines entirely and trims leading and trailing whitespace.

/**
 * Converts multiline strings to single line by removing newlines and trims surrounding whitespace
 * @param strings - Template strings array
 * @param expressions - Template substitution values
 * @returns Trimmed single-line string
 */
function oneLineTrim(strings, ...expressions): string;

Usage Examples:

import { oneLineTrim } from "common-tags";

// URL building with clean result
const url = oneLineTrim`
  https://api.example.com/v1/users
  ?search=active
  &limit=10
`;
// Result: "https://api.example.com/v1/users ?search=active &limit=10"

// Clean up formatted text
const cleanText = oneLineTrim`
  
  This text has extra whitespace
  at the beginning and end
  
`;
// Result: "This text has extra whitespace at the beginning and end"

Combination Tags

One Line Inline Lists

Combines oneLine functionality with inlineLists array processing.

/**
 * Converts to single line and renders arrays as space-separated lists
 * @param strings - Template strings array
 * @param expressions - Template substitution values
 * @returns Single-line string with inline array formatting
 */
function oneLineInlineLists(strings, ...expressions): string;

Usage Examples:

import { oneLineInlineLists } from "common-tags";

const fruits = ['apple', 'banana', 'cherry'];
const message = oneLineInlineLists`
  I really like these fruits:
  ${fruits}
  They are delicious!
`;
// Result: "I really like these fruits: apple banana cherry They are delicious!"

Implementation Notes

  • stripIndent uses the shortest common indentation as the baseline to remove
  • stripIndents removes all leading whitespace characters from each line
  • oneLine replaces \n characters with spaces and normalizes whitespace
  • oneLineTrim removes newlines entirely (unlike oneLine which replaces with spaces) and trims leading/trailing whitespace
  • All string processing tags support both template literal and function call usage
  • Substitution values are processed after string transformations are applied

docs

custom-tags.md

html-templates.md

index.md

list-formatting.md

string-processing.md

tile.json