Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eldoy/htmlview

HTML view template string function
https://github.com/eldoy/htmlview

Last synced: 6 days ago
JSON representation

HTML view template string function

Awesome Lists containing this project

README

        

# HTML View

HTML view template string function.

This is a convenience function for creating HTML with Javascript.

### Install

In the browser, grab one of the files from the `dist` folder in this repository.

```
npm i htmlview
```

### Usage

```js
// For usage with NodeJS only
const h = require('htmlview')

// HTML string, just like normal template string
const html = h`

hello
`
//
hello

// HTML string with variables, like normal
const html = h`

hello ${5}
`
//
hello 5

// Automatically joins array variables
const html = h`

hello ${[ '1', '2', '3']}
`
//
hello 123

// Avoid automatically joining array variables
const html = h`

hello ${[ '1', '2', '3'].join(',')}
`
//
hello 1,2,3

// Automatically calls functions
const html = h`

hello ${() => 'bye'}
`
//
hello bye

// Returns empty string by default, not 'undefined'
const html = h`

hello${() => {
if (project.done) return 'bye'
}}
`
//
hello

```

MIT Licensed. Enjoy!