UNPKG
string-to-js
Version:
latest (0.0.1)
0.0.1
Make plain text (HTML, CSS, JSON, etc) require()-able
string-to-js
/
index.js
16 lines
(14 loc)
•
268 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/** * Convert `str` to a module.exports string. * *
@param
{
String
}
str
*
@return
{
String
} *
@api
public
*/
module
.
exports
=
function
(
str
){
return
"module.exports = '"
+ str .
replace
(
/'/g
,
"\\'"
) .
replace
(
/\r\n|\r|\n/g
,
"\\n"
) +
"';"
; };