1.2.1 • Published 7 years ago

text2jsvar v1.2.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

text2jsvar

NPM version NPM downloads MIT License

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:

var sayHello = function() {
    alert("Hello World");
}

To:

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

var text2jsvar = require('text2jsvar');
text2jsvar.convert('a\nb'); // return 'a\\nb'

Usage in browsers

You can find the minified JS file for browsers at ~/node_modules/text2jsvar/min/text2jsvar.min.js. Copy this file to your web project and include it using <script> tag, it will declare a global variable: text2jsvar.

<script src="text2jsvar.min.js"></script>
<script>
    text2jsvar.convert('a\nb'); // return 'a\\nb'
</script>

text2jsvar.convert(source, double)

Description: Convert text to JavaScript string variable.

Arguments

Return value

The converted text.

text2jsvar.revert(convertedText, double)

Description: Revert the converted text to the source string.

Arguments

Return value

The source string of the converted text.

1.2.1

7 years ago

1.2.0

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago