Last active
April 28, 2019 04:54
-
-
Save gaoxiaoliangz/28a02da850413a51ff95f0c9b92fab89 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 toVSCodeSnippetBody = string => | |
string | |
.split('\n') | |
.map(line => { | |
const chars = Array.from(line) | |
if (chars.length === 0) { | |
return '"",' | |
} | |
let newChars = [] | |
chars.forEach((char, idx) => { | |
if (idx === 0) { | |
newChars.push('"') | |
} | |
if (char === '"') { | |
newChars.push('\\') | |
} | |
newChars.push(char) | |
if (chars.length - 1 === idx) { | |
newChars.push('"') | |
newChars.push(',') | |
} | |
}) | |
return newChars.join('') | |
}) | |
.join('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment