0.0.6 • Published 7 years ago

string-dom v0.0.6

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

string-dom

string-dom on NPM Standard JavaScript Style

Create HTML strings using JSX (or functions).

Install

$ npm i string-dom --save

About

string-dom is a function that creates an HTML string. It is meant to work with JSX, but does not create DOM (regular or virtual). It effectively turns JSX into an HTML templating language that can be used separately of React.

Usage

import sd from 'string-dom'

/** @jsx sd */

// with JSX
// note the comment above, and see the link below
// https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx#custom
document.body.innerHTML += (
  <div class="wrapper">
    <h1 class="heading" data-heading="data-heading">Heading Text</h1>
    <p class="heading-sub" data-subheading="data-subheading">Subheading Text</p>
    <p>An element without attributes.</p>
  </div>
)

// without JSX
document.body.innerHTML += (
  sd('div', { class: 'wrapper' },
    sd('h1', { class: 'heading', 'data-heading': 'data-heading' }, 'Heading Text'),
    sd('p', { class: 'heading-sub', 'data-subheading': 'data-subheading' }, 'Subheading Text'),
    sd('p', 'An element without attributes.')
  )
)

Both the above generate the following HTML (as a string), then add it to the body:

<div class="wrapper">
  <h1 class="heading" data-heading="data-heading">Heading Text</h1>
  <p class="heading-sub" data-subheading="data-subheading">Subheading Text</p>
  <p>An element without attributes.</p>
</div>

Prior Art

Linting

JS Standard Style

License

MIT. © 2017 Michael Cavalea

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago