Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

to-line

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-line

Conditionally assign and trim strings into one line ~250B

  • 1.5.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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'

Inspiration

  • clsx - A tiny utility for constructing className strings conditionally

Keywords

FAQs

Package last updated on 27 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc