Socket
Socket
Sign inDemoInstall

jarg

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jarg

JavaScript template engine powered by arrays


Version published
Weekly downloads
0
Maintainers
1
Install size
5.58 kB
Created
Weekly downloads
 

Readme

Source

jarg

JavaScript template engine powered by arrays, inspired by Clojure.

Target languages

HTML

Using
const html = require('jarg').html 

const template =
  ['tagName', { optionalObjectWithAttributes },
    anotherTagsOrJustText]

html(template) // => HTML string
Examples
['div', { class: 'messages' },
  ['p', 'Some message'],
  ['p', 'Other message'],
  'Just text']

will rendered into

<div class="messages">
  <p>Some message</p>
  <p>Other message</p>
  Just text
</div>

With jarg.html conditional rendering becomes a trivial thing:

const greetingComponent = name =>
  ['div',
    'Hello ', name || 'stranger', '!']

html(greetingComponent('jarg')) // => <div>Hello jarg!</div>

And you can use some components inside others, by dividing your application into many independent parts:

const todos = ['Program something', 'Eat', 'Kill spiders']

const todoList = todos =>
  ['ul',
    ...todos.map(todo => ['li', todo])]

const todoApp =
  ['div',
    ['h3', 'TODO'],
    todoList(todos),
    ['form', { action: 'someUrl' },
      ['label', 'What needs to be done?'],
      ['input'],
      ['button', 'Add']]]

html(todoApp)
Comments and restrictions

Each template should have only one root tag.

Keywords

FAQs

Last updated on 03 Jun 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc