Skip to content

Instantly share code, notes, and snippets.

@theskumar
Created August 22, 2012 17:22
Show Gist options
  • Save theskumar/3427715 to your computer and use it in GitHub Desktop.
Save theskumar/3427715 to your computer and use it in GitHub Desktop.
js: split_to_array()
function split_to_array (body, chunklen) {
// * example 1: chunk_split('Hello world!', 1);
// * returns 1: 'H*e*l*l*o* *w*o*r*l*d*!*'
// * example 2: chunk_split('Hello world!', 10, '*');
// * returns 2: '["Hello worl","d!"]'
chunklen = parseInt(chunklen, 10) || body.length;
if (chunklen < 1) {
return false;
}
return body.match(new RegExp(".{1," + chunklen + "}", "g"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment