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

html2js

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html2js

html2js

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
421
decreased by-16.14%
Maintainers
1
Weekly downloads
 
Created
Source

html2js

RT. html2js. 解决require tpl无法跨域的问题

简单使用示例:

test.html:

<div id="i-am-a-id">
  <div class="i-am-a-class">
    i am test
  </div>
</div>

js:

var fs = require('fs');
var html2js = require('../html2js');

var filename = 'test.html';

var html = fs.readFileSync(filename, 'utf8');

var modes = ['format', 'default', 'compress'];

var output = modes.map(
    function (mode) {
        return ''
            + '// '
            + mode
            + '\n'
            + html2js(html, {
                mode: mode,
                wrap: true
            });
    }
).join('\n');

console.log(output);
fs.writeFile( filename + '.js', output );

output:

// format
define(function () {
    return ''
        + '<div id="i-am-a-id">'
        +   '<div class="i-am-a-class">'
        +     'i am test'
        +   '</div>'
        + '</div>';
});
// default
define(function () {return '<div id="i-am-a-id">\n  <div class="i-am-a-class">\n    i am test\n  </div>\n</div>';});
// compress
define(function () {return '<div id="i-am-a-id"><div class="i-am-a-class">i am test</div></div>';});

FAQs

Package last updated on 28 May 2014

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