Last active
June 20, 2017 06:08
-
-
Save harish2704/34d9f95bc15d2187d7b5c90f2df2f7dc to your computer and use it in GitHub Desktop.
multiline-to-js.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getStdin = require('get-stdin'); | |
/* Usage */ | |
/* | |
>> cat file.html | node multiline-to-js.js | |
*/ | |
/* Input */ | |
/* | |
<div class="tab-pane active" > | |
<div class="card-box"> | |
<div class="form-group m-b-20"> | |
<label>From address<span class="text-danger">*</span></label> | |
*/ | |
/* Output */ | |
/* | |
'<div class="tab-pane active" >' + | |
'<div class="card-box">' + | |
'' + | |
'<div class="form-group m-b-20">' + | |
'<label>From address<span class="text-danger">*</span></label>' | |
*/ | |
getStdin(function(txt){ | |
txt = txt | |
.split('\n') | |
.map(function(line){ | |
const match = line.trimRight().match(/(\ *)(.*)/); | |
if( !match ){ | |
return `'${line}'`; | |
} | |
return `${ match[ 1 ] }'${match[ 2 ]}'`; | |
}) | |
.join(' +\n'); | |
console.log( txt ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment