A set of well-tested template literal tag functions for ES2015+ that solve common string manipulation and formatting problems.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Core template tags for manipulating string formatting, indentation, and line structure. These tags are essential for code generation, template rendering, and text processing workflows.
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}");
}
`;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;
// }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."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"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!"stripIndent uses the shortest common indentation as the baseline to removestripIndents removes all leading whitespace characters from each lineoneLine replaces \n characters with spaces and normalizes whitespaceoneLineTrim removes newlines entirely (unlike oneLine which replaces with spaces) and trims leading/trailing whitespace