Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@builder/html-generator

Package Overview
Dependencies
Maintainers
5
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@builder/html-generator

Generate HTML.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

@builder/html-generator

Install

$ npm install @builder/html-generator --save-dev

Usage

Base

import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="root">Weclome Home</div></body></html>';

const $ = new Generator(tmpl);

console.log('HTML is ', $.html());

Config root element

import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="container">Weclome Home</div></body></html>';

const $ = new Generator(tmpl, { rootId: 'container' });

Modify root element content

import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="container">Weclome Home</div></body></html>';

const $ = new Generator(tmpl, { rootId: 'container' });

$.root.innerHTML = 'New content.';

Get root element content

import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="container">Weclome Home</div></body></html>';

const $ = new Generator(tmpl, { rootId: 'container' });

console.log('Root element content is ', $.root.innerHTML);

Modify title content

import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="container">Weclome Home</div></body></html>';

const $ = new Generator(tmpl, { rootId: 'container' });

$.title..innerHTML = 'New title';

Modify body attributes

import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="container">Weclome Home</div></body></html>';

const $ = new Generator(tmpl, { rootId: 'container' });

$.body.attributes += ' data-index="example"';
import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="container">Weclome Home</div></body></html>';

const $ = new Generator(tmpl, { rootId: 'container' });

// Arrays are also supported
$.insertLink('<link rel="stylesheet" type="text/css" href="//g.alicdn.com">');

Insert meta

import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="container">Weclome Home</div></body></html>';

const $ = new Generator(tmpl, { rootId: 'container' });

// Arrays are also supported
$.insertMeta('<meta name="viewport" content="width=device-width, initial-scale=1.0">');

Insert script

import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="container">Weclome Home</div></body></html>';

const $ = new Generator(tmpl, { rootId: 'container' });

// Arrays are also supported
$.insertScript('<script src="//g.alicdn.com/index.js"></script>');

Get inserted elements

import Generator from '@builder/html-generator';

const tmpl = '<html><head><title>Rax App</title></head><body><div class="home" id="container">Weclome Home</div></body></html>';

const $ = new Generator(tmpl, { rootId: 'container' });

$.insertScript('<script src="//g.alicdn.com/index.js"></script>');

console.log('Inserted scripts: ', $.getInsertedScripts);

FAQs

Package last updated on 17 Mar 2021

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