# @master/literal

> Conditionally construct class names and strings with template literals.

Latest version **1.0.11** (published 2022-09-17) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @master/literal
pnpm add @master/literal
yarn add @master/literal
bun add @master/literal
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2022-09-17 |
| First published | 2022-07-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Aoyue Design LLC. |
| Maintainers | 1aron, aoyue |
| Keywords | class, trim, strings, sentence, classnames, oneline, templateliterals |

## Links

- npm: https://www.npmjs.com/package/@master/literal
- Repository: https://github.com/master-co/literal
- Homepage: https://github.com/master-co/literal#readme
- Issues: https://github.com/master-co/literal/issues
- Funding: https://opencollective.com/master-co
- npm.io page: https://npm.io/package/@master/literal

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.11 (latest) — 2022-09-17
- 1.0.10 — 2022-07-16
- 1.0.9 — 2022-07-16
- 1.0.8 — 2022-07-16
- 1.0.7 — 2022-07-16
- 1.0.6 — 2022-07-15
- 1.0.5 — 2022-07-15
- 1.0.4 — 2022-07-15
- 1.0.3 — 2022-07-15
- 1.0.2 — 2022-07-15
- 1.0.1 — 2022-07-15
- 1.0.0 — 2022-07-15

## README

<br><br>
<div align="center">

<p align="center">
    <img src="https://raw.githubusercontent.com/master-co/package/document/images/logo-and-text.svg" alt="logo" width="142">
</p>
<p align="center">
    <b><!-- name -->literal<!----></b>
</p>
<p align="center"><!-- package.description -->Conditionally construct class names and strings with template literals.<!----></p>
<p align="center">
<!-- badges.map((badge) => `\n[![${badge.alt}](${badge.src})](${badge.href})`).join('&nbsp;')-->

[![MIT License](https://flat.badgen.net/github/license/master-co/literal?color=yellow)](https://github.com/master-co/css/blob/main/LICENSE)
[![Latest Release](https://flat.badgen.net/npm/v/@master/literal?icon=npm&label&color=yellow)](https://www.npmjs.com/package/@master/literal)
[![Bundle Size](https://flat.badgen.net/bundlephobia/minzip/@master/literal?icon=packagephobia&label&color=yellow)](https://bundlephobia.com/package/@master/literal 'gzip bundle size (including dependencies)')
[![Package Size](https://flat.badgen.net/badgesize/brotli/https://cdn.jsdelivr.net/npm/@master/literal?icon=jsdelivr&label&color=yellow)](https://unpkg.com/@master/literal 'brotli package size (without dependencies)')
[![Github](https://flat.badgen.net/badge/icon/master-co%2Fliteral?icon=github&label&color=yellow)](https://github.com/master-co/literal)
[![CI](https://flat.badgen.net/github/status/master-co/literal/main/ci/circleci?icon=circleci)](https://circleci.com/gh/master-co/workflows/literal/tree/main)
<!-- -->
</p>
</div>

###### On this page
- [Install](#install)
- [Import](#import)
- [Usage and behavior](#usage-and-behavior)
  - [Strings](#strings)
  - [Objects](#objects)
  - [Arrays](#arrays)
  - [Resolve types](#resolve-types)
  - [Trim and clear](#trim-and-clear)
  - [Mixed and nested](#mixed-and-nested)
  - [Execute like a function](#execute-like-a-function)
- [Related](#related)
- [Inspiration](#inspiration)

# Install
```sh
npm install @master/literal
```

# Import
```js
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
```js
$`a ${true && 'b'} c`;
// 'a b c'
```

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

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

## Resolve types
```js
$`a ${true} ${false} ${''} ${null} ${undefined} ${0} ${NaN} b`
// 'a b'
```

## Trim and clear
- Remove newlines
- Convert consecutive spaces to one space
```js
$`
    a
    b
    ${undefined}
    c    d
`
// 'a b c d'
```

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

## Execute like a function
```js
$`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
- [@master/style-element.react](https://github.com/master-co/style-element.react) - Quickly create styled React elements with conditional class names.
- [@master/css](https://github.com/master-co/css) - A Virtual CSS language with enhanced syntax. ~13KB

# Inspiration
- [clsx](https://github.com/lukeed/clsx) - A tiny utility for constructing `className` strings conditionally.

---
_Source: https://npm.io/package/@master/literal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
