Giter VIP home page Giter VIP logo

create-html's Introduction

create-html

Create the content of an html file with one function call.

npm travis standard conduct

Install

npm install --save create-html

Usage

createHTML(options)

options

  • title
  • script
  • scriptAsync
  • css
  • cssAsync
  • lang
  • dir
  • head
  • body
  • favicon

Examples

Simple example that create an html file with the title example:

var html = createHTML({
  title: 'example'
})

Example using all options:

var html = createHTML({
  title: 'example',
  script: 'example.js',
  scriptAsync: true,
  css: 'example.css',
  lang: 'en',
  dir: 'rtl',
  head: '<meta name="description" content="example">',
  body: '<p>example</p>',
  favicon: 'favicon.png'
})

Create a file with the html contents using the fs module:

var fs = require('fs')
var createHTML = require('create-html')

var html = createHTML({
  title: 'example'
})

fs.writeFile('index.html', html, function (err) {
  if (err) console.log(err)
})

Create a stream by pairing this module with from2-string:

var fromString = require('from2-string')
var createHTML = require('create-html')

var html = createHTML({
  title: 'example'
})

var stream = fromString(html)
stream.pipe(process.stdout)

Pipe content into the html that this module generates by using from2-string and hyperstream

var fs = require('fs')
var fromString = require('from2-string')
var hyperstream = require('hyperstream')
var createHTML = require('./index')

var html = createHTML({
  title: 'example'
})

var hs = hyperstream({
  'body': fs.createReadStream('some.html')
})

var stream = fromString(html)
stream.pipe(hs).pipe(process.stdout)

CLI

This module comes with a simple command-line tool for creating html files.

Install it globally with npm i -g create-html

Usage:

Usage:
  create-html [options]

Options:
  --title, -t        Page title
  --script, -s       JavaScript filename, optional
  --script-async, -a Add async attribute to script tag
  --css, -c          CSS filename, optional
  --favicon, -f      Site favicon
  --lang, -l         Language of content
  --dir, -d          Direction of content
  --head, -H         Content to insert into <head> tag
  --body, -b         Content to insert into <body> tag
  --output, -o       File name. optional. default: stdout
  --help, -h         Show this help message

Example:

create-html --title "an example html file"

See also

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.