Last active
September 2, 2019 10:07
-
-
Save guillaumegarcia13/21e050f40f55d2dec80f5f940f4254ed to your computer and use it in GitHub Desktop.
Split long string into concatenated assignment (eg. base64 images)
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 CHUNK_SIZE = 80; // put whatever size is relevant here | |
const CONCAT_OPERATOR = '+'; // put string concatenation operator here | |
const text = `Very long text would like to be splitted to fit any clumsy editor at there that does only support fixed number of characters per line`; | |
const regexp = new RegExp('.{1,'+ CHUNK_SIZE+'}', 'g'); | |
const result = '`' + text.match(regexp).join('` ' + CONCAT_OPERATOR + ' \n`') + '`'; | |
// Result with (CHUNK_SIZE=40 and CONCAT_OPERATOR='&&') is: | |
// | |
// `Very long text would like to be splitted` && | |
// ` to fit any clumsy editor at there that ` && | |
// `does only support fixed number of charac` && | |
// `ters per line` | |
// Pre-defined scenarios | |
'`' + text.match(/.{1,80}/g).join('` &&\n`') + '`'; // ABAP Version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment