New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

text2jsvar

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

text2jsvar

A lightweight JavaScript library for converting plain text to JS string variable.

latest
Source
npmnpm
Version
1.2.1
Version published
Weekly downloads
46
1050%
Maintainers
1
Weekly downloads
 
Created
Source

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

ParameterTypeDescription
sourceStringThe source string to be converted.
doubleBooleanDefault: false. If double is set to true, the source string will be converted twice.

Return value

The converted text.

text2jsvar.revert(convertedText, double)

Description: Revert the converted text to the source string.

Arguments

ParameterTypeDescription
convertedTextStringThe converted text to be reverted back.
doubleBooleanDefault: false. Set double to true if the text was converted twice.

Return value

The source string of the converted text.

FAQs

Package last updated on 24 Feb 2017

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