https://github.com/eldoy/htmlview
HTML view template string function
https://github.com/eldoy/htmlview
Last synced: about 1 month ago
JSON representation
HTML view template string function
- Host: GitHub
- URL: https://github.com/eldoy/htmlview
- Owner: eldoy
- License: mit
- Created: 2022-02-23T08:20:41.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-19T11:10:04.000Z (about 3 years ago)
- Last Synced: 2025-10-22T09:06:09.458Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 769 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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!