Getting Started
npm install to-line
import line from 'to-line';
import { l } from 'to-line';
line
is equal to l
Strings
line`a ${true && 'b'} c`;
Objects
line`a ${{ b: true, c: false, d: isTrue() }} e`;
Arrays
line`a ${['b', 0, false, 'c']} d`;
Resolve types
line`a ${true} ${false} ${''} ${null} ${undefined} ${0} ${NaN} b`
Trim and clear
- Remove newlines
- Convert consecutive spaces to one space
line`
a
b
${undefined}
c d
`
Mixed and nested
line`
a
${
[
1 && 'b',
{ c: false, d: null },
['e', ['f']]
]
}
g h
`;
Execute like a function
line`a b ${['c', 'd']} ${{ e: true, f: false }} ${true && 'g'}`;
line('a b', ['c', 'd'], { e: true, f: false }, true && 'g');
Related
Inspiration
- clsx - A tiny utility for constructing
className
strings conditionally