A lightweight JavaScript library for converting plain text to JS string variable.
npm install text2jsvartext2jsvar
==========
  
text2jsvar is a lightweight JavaScript library for converting plain text to JS string variable.
It can easily transfer the following JavaScript function text into a JavaScript string variable.
Convert:
``javascript
`
var sayHello = function() {
alert("Hello World");
}
`
To:
javascript
`
var result = "var sayHello = function() {\n alert(\"Hello World\");\n}"
`
Online demo: Text to JS variable converter.
Install
`
npm install text2jsvar
`
Usage in Node.js
javascript
`
var text2jsvar = require('text2jsvar');
text2jsvar.convert('a\nb'); // return 'a\\nb'
~/node_modules/text2jsvar/min/text2jsvar.min.js
Usage in browsers
You can find the minified JS file for browsers at . Copy this file to your web project and include it using
``
| Parameter | Type | Description |
|---|---|---|
| source | String | The source string to be converted. |
| double | Boolean | Default: false. If double is set to true, the source string will be converted twice. |
| Parameter | Type | Description |
|---|---|---|
| convertedText | String | The converted text to be reverted back. |
| double | Boolean | Default: false. Set double to true if the text was converted twice. |