template-static-list
v1.1.1
Published
A library for smartly fixing template literals of lists with possibly missing values
Downloads
4
Readme
template-static-list
template-static-list
is a small template literal function that solves a problem I kept having.
Specifically, I found myself doing something like this every single time I needed to properly handle addresses for example:
let address = [
r.address,
r.city,
r.postalCode,
r.province,
r.country
].filter(Boolean).join(', ')
The above monstrosity is to get around the very real situation where not all components of the address are given by the user.
Using template-static-list
I could achieve the same result using:
const l = require('template-static-list')
let address = l`${r.address}, ${city}, ${r.postalCode}, ${r.province}, ${r.country}`
The basic idea is that when a value is missing, it'll intelligently suppress the separator before or after it automatically.
Installation
template-static-list
can be installed via the Yarn or npm clients.
Yarn
❯ yarn add template-static-list
npm
❯ npm install --save template-static-list
Contributing
This project can be found in the https://github.com/allain/template-static-list repository.