Skip to content

Instantly share code, notes, and snippets.

@gaoxiaoliangz
Last active April 28, 2019 04:54
Show Gist options
  • Save gaoxiaoliangz/28a02da850413a51ff95f0c9b92fab89 to your computer and use it in GitHub Desktop.
Save gaoxiaoliangz/28a02da850413a51ff95f0c9b92fab89 to your computer and use it in GitHub Desktop.
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