Skip to content

Instantly share code, notes, and snippets.

@harish2704
Last active June 20, 2017 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harish2704/34d9f95bc15d2187d7b5c90f2df2f7dc to your computer and use it in GitHub Desktop.
Save harish2704/34d9f95bc15d2187d7b5c90f2df2f7dc to your computer and use it in GitHub Desktop.
multiline-to-js.js
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