tagged-table
v1.0.5
Published
A function for converting tagged template literals into an array of objects
Downloads
58
Maintainers
Readme
Tagged-Table
Tagged-Table allows you to write tables in JavaScript using ES2015 tagged templates that compile down to arrays of objects.
Install
npm i -S tagged-table
;
Usage
This:
import taggedTable from 'tagged-table';
const data = taggedTable`
id | name | value | date
${1} | first | ${false} | 1/1/1970
${2} | second | ${true} | 1/1/2000
${3} | third | ${false} | 3/5/2005
`;
Will become this:
[
{ id: 1, name: 'first', value: false, date: '1/1/1970' },
{ id: 2, name: 'second', value: true, date: '1/1/2000' },
{ id: 3, name: 'third', value: false, date: '3/5/2005' }
]
Strings don't need interpolation, but don't leave a cell empty. Use ${undefined}
instead.