Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 66 lines (46 sloc) 1.677 kb
b1c1dd5 @tj Initial commit
authored
1
20ed7aa @tj rename to string-to-js
authored
2 # string-to-js
b1c1dd5 @tj Initial commit
authored
3
20ed7aa @tj rename to string-to-js
authored
4 Make plain text (HTML, CSS, JSON, etc) require()-able.
334047b @tj add example in docs
authored
5
6 ## Installation
7
20ed7aa @tj rename to string-to-js
authored
8 $ npm install string-to-js
334047b @tj add example in docs
authored
9
10 ## Example
11
12 tip.html:
13
14 ```html
15 <div class="tip">
16 <div class="tip-message"></div>
17 </div>
18 ```
19
20 js:
21
22 ```js
23
24 /**
25 * Module dependencies.
26 */
27
28 var fs = require('fs')
20ed7aa @tj rename to string-to-js
authored
29 , str2js = require('string-to-js')
334047b @tj add example in docs
authored
30 , read = fs.readFileSync;
31
9d18697 @tj docs
authored
32 var html = read('tip.html', 'utf8');
20ed7aa @tj rename to string-to-js
authored
33 var js = str2js(html);
334047b @tj add example in docs
authored
34 console.log(js);
35 ```
36
37 output js string:
38
39 ```js
40 module.exports = '<div class="tip">\n <div class="tip-message">\'Message here\'</div>\n</div>';
41 ```
b1c1dd5 @tj Initial commit
authored
42
43 ## License
44
45 (The MIT License)
46
47 Copyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
48
49 Permission is hereby granted, free of charge, to any person obtaining
50 a copy of this software and associated documentation files (the
51 'Software'), to deal in the Software without restriction, including
52 without limitation the rights to use, copy, modify, merge, publish,
53 distribute, sublicense, and/or sell copies of the Software, and to
54 permit persons to whom the Software is furnished to do so, subject to
55 the following conditions:
56
57 The above copyright notice and this permission notice shall be
58 included in all copies or substantial portions of the Software.
59
60 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
61 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
63 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
64 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
66 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.