0.1.2 • Published 9 months ago

@karmaniverous/tagged-templates v0.1.2

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
9 months ago

tagged-templates

Here are some handy tagged template functions to make your ES6 template literals work better!

Installation

npm install @karmaniverous/tagged-templates

Usage

import { def, n2e, sn2e, sn2u } from '@karmaniverous/tagged-templates';

// Replicate default template literal functionality. Just FYI!
console.log(def`a${'b'}c`); // 'abc'
console.log(def`a${undefined}c`); // 'aundefinedc'

// Replace any nil expression (i.e. null or undefined) with an empty string.
console.log(n2e`a${undefined}c`); // 'ac'

// Return an empty string if any expression is nil.
console.log(sn2e`a${undefined}c`); // ''

// Return null if any expression is nil.
console.log(sn2n`a${undefined}c`); // null

// Return undefined if any expression is nil.
console.log(sn2u`a${undefined}c`); // undefined

API Documentation

taggedTemplates

taggedTemplates.normstr ⇒ string

Normalize a string by converting diacriticals to base characters, removing non-word characters, and converting to lower case.

Kind: static constant of taggedTemplates
Returns: string - The normalized string or undefined if not a string.

ParamTypeDescription
strstringThe string to normalize.

taggedTemplates.def ⇒ string

Replicates standard string template behavior.

Kind: static constant of taggedTemplates
Returns: string - The output string.

ParamTypeDescription
stringsArray.<string>The string literals.
...expanyThe expressions.

taggedTemplates.n2e ⇒ string

Nil to Empty: replaces nil expressions with empty strings.

Kind: static constant of taggedTemplates
Returns: string - The output string.

ParamTypeDescription
stringsArray.<string>The string literals.
...expanyThe expressions.

taggedTemplates.sn2e ⇒ string

Some Nil to Empty: returns empty string when any expression nil.

Kind: static constant of taggedTemplates
Returns: string - The output string.

ParamTypeDescription
stringsArray.<string>The string literals.
...expanyThe expressions.

taggedTemplates.sn2n ⇒ string

Some Nil to Null: returns null when any expression nil.

Kind: static constant of taggedTemplates
Returns: string - The output string.

ParamTypeDescription
stringsArray.<string>The string literals.
...expanyThe expressions.

taggedTemplates.sn2u ⇒ string

Some Nil to Undefined: returns undefined when any expression nil.

Kind: static constant of taggedTemplates
Returns: string - The output string.

ParamTypeDescription
stringsArray.<string>The string literals.
...expanyThe expressions.

See more great templates and other tools on my GitHub Profile!

0.1.2

9 months ago

0.1.0

1 year ago

0.1.1

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago