1.0.11 • Published 2 years ago

@master/literal v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

MIT License Latest Release Bundle Size Package Size Github CI

On this page

Install

npm install @master/literal

Import

import $ from '@master/literal';
// or
import { literal } from '@master/literal';

$ is equal to literal

Usage and behavior

Try it online at https://stackblitz.com/edit/js-5jtq81

Strings

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

Objects

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

Arrays

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

Resolve types

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

Trim and clear

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

Mixed and nested

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

Execute like a function

$`a b ${['c', 'd']} ${{ e: true, f: false }} ${true && 'g'}`;
// or
$('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.
1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago