Created
August 22, 2012 16:51
-
-
Save theskumar/3427413 to your computer and use it in GitHub Desktop.
js: chunk_split()
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
| function chunk_split (body, chunklen, end) { | |
| // http://kevin.vanzonneveld.net | |
| // + original by: Paulo Freitas | |
| // + input by: Brett Zamir (http://brett-zamir.me) | |
| // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
| // + improved by: Theriault | |
| // * 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) || 76; | |
| end = end || '\r\n'; | |
| if (chunklen < 1) { | |
| return false; | |
| } | |
| return body.match(new RegExp(".{0," + chunklen + "}", "g")).join(end); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment