Last active
March 29, 2017 18:28
-
-
Save ben-ng/f1b0db0758621a24cf407c3c00b20373 to your computer and use it in GitHub Desktop.
substr shim
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
// There is no String.substr on Salesforce. This uses String.substring instead. | |
// substring's arguments are different, so this just converts substr args to | |
// their substring equivalents. | |
function substrShim (str, start, len) { | |
if (len <= 0) | |
return ''; | |
if (start < 0) | |
start = str.length + start; | |
if (len != null) | |
len = Math.min(str.length - 1, start + len); | |
return str.substring(start, len); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment