This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

to-line
TypeScript icon, indicating that this package has built-in type declarations

1.5.5 • Public • Published

Conditionally assign and trim strings into one line ~250B

NPM Version NPM Version NPM package ( download / month ) Follow @mastercorg Github release actions


Getting Started

npm install to-line
import line from 'to-line';
// or
import { l } from 'to-line';

line is equal to l

Strings

line`a ${true && 'b'} c`;
// 'a b c'

Objects

line`a ${{ b: true, c: false, d: isTrue() }} e`;
// 'a b d e'

Arrays

line`a ${['b', 0, false, 'c']} d`;
// 'a b c d'

Resolve types

line`a ${true} ${false} ${''} ${null} ${undefined} ${0} ${NaN} b`
// 'a b'

Trim and clear

  • Remove newlines
  • Convert consecutive spaces to one space
line`
    a
    b
    ${undefined}
    c    d
`
// 'a b c d'

Mixed and nested

line`
    a
    ${
        [
            1 && 'b',
            { c: false, d: null },
            ['e', ['f']]
        ]
    }
    g    h
`;
// 'a b e f g h'

Execute like a function

line`a b ${['c', 'd']} ${{ e: true, f: false }} ${true && 'g'}`;
// or
line('a b', ['c', 'd'], { e: true, f: false }, true && 'g');

// 'a b c d e g'

Related

Inspiration

  • clsx - A tiny utility for constructing className strings conditionally

Package Sidebar

Install

npm i to-line

Homepage

aron.tw

Weekly Downloads

0

Version

1.5.5

License

MIT

Unpacked Size

7.3 kB

Total Files

5

Last publish

Collaborators

  • 1aron