New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

literaljs

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

literaljs

Lightweight components using template literals, strings, or arrays and objects.

  • 1.1.7
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-63.16%
Maintainers
1
Weekly downloads
 
Created
Source

LiteralJS

Is a simple view library for creating components with Template Literals, Strings, or Arrays and Objects.

Usage without NPM

<!DOCTYPE html>
<html>
 <head>
   <title>Literal JS Test</title>
   <script src="http://unpkg.com/literaljs"></script>
 </head>
 <body>
   <div id="app"></div>
   <script>
     var firstComponent = Literal.Component(
       `<div>
         This should render.
         <p>Isn't this lovely?</p>
         ${secondComponent}
       </div>`
     );

     var secondComponent = Literal.Component(
       `<div>
         Oh yeah!
       </div>`
     );

     Literal.Render(firstComponent, 'app');
   </script>
 </body>
</html>

Example

Component([string, array])

With template literals, strings:

Literal.Component(
  `<p class="corn">
    <div>
      This is a div!
    </div>
  </p>`
);

You can also use an array with multiple objects. Besides the example below, objects should accept any attributes and generate proper markup:

Literal.Component([
  {
    element: 'div',
    class: 'layout',
    children: [
      {
        element: 'h1',
        id: 'child',
        innerHTML: 'This is a child of layout',
        'data-example': 'data-works'
      },
      {
        element: 'p',
        class: 'content',
        innerHTML: 'Amazing!',
        events: [
          {
            type: 'click',
            action: function() {
              console.log('This event listener is working!');
            }
          }
        ]
      }
    ]
  },
  {
    element: 'div',
    id: 'notchild',
    innerHTML: 'This is not a child of layout.',
    events: {
      type: 'click',
      action: function() {
        console.log('This also works!');
      }
    }
  }
]);

Components just accept Template Literals, Strings, or an Array of Objects and generate markup. You can combine template literal components with ${ }, or just call another component directly inside of the component object:

var firstComponent = Literal.Component(
  `<div>
    This should render like React.
    <p>Isn't this lovely?</p>
    ${secondComponent}
  </div>`
);

var secondComponent = Literal.Component(
  `<div>
    Oh yeah!
  </div>`
  );

It is recommended to use either template literals, strings, or object arrays and not mix them within the same Render call.

Render
Literal.Render(RootComponent, 'app');

The Render method takes the main parent component of your app and id of the DOM node you want to attach the markup to.

FAQs

Package last updated on 01 Feb 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc