Skip to content

daniel-aranda/nodejs-string-multiline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UPDATE: with ECMA6 this is no longer needed. You could do this if you are using ECMA 6:

let a = `hello
multiline`;

NodeJS String Multiline

NodeJS smooth support to multiline vars. Consider that multiline string vars are commonly SQL queries, test strings, etc, this library load them from a data file, where you could put it. Also you don't mess your beauty JavaScript code with giant strings that aren't code.

##Introduction Have you every dream to have a multiline string support like Ruby and others, like this:

<<<my_var
This a very large string
>>>
<<<my_sql
SELECT
    *
FROM my_table
WHERE
    field = 'true';
>>>

And use it as:

console.log(data.my_var);
console.log(data.my_sql);

This library makes it possible.

##Installation

npm install string-multiline

###Real World example:

mkdir data
cd data
touch somedata.dat //below content of somedata.dat
cd ..
touch app.js //below content of app.js
node app.js

You should see something like this as output:

{
    my_var: '...',
    my_sql: '...'
}

####Content of somedata.dat:

<<<my_var
This is a large string
with multiline support
yeah!
>>>

<<<my_sql
SELECT
    *
FROM my_table
>>>

###Content of app.js

var stringMultiline = require('string-multiline');

stringMultiline.parseMultilineVars('./data/somedata.dat', function(result){
    console.log(result);
});

About

NodeJS support for multiline strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published