Created
January 30, 2020 05:58
-
-
Save lucymtc/276f882720d3b1dc0bad150148ace556 to your computer and use it in GitHub Desktop.
Javascript rtrim, ltrim, trim helpers
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
export const ltrim = (str, char) => { | |
let message = str; | |
if (typeof message !== 'undefined') { | |
while (message[0] === char) { | |
message = message.substring(1); | |
} | |
} | |
return message; | |
}; | |
export const rtrim = (str, char) => { | |
let message = str; | |
if (typeof message !== 'undefined') { | |
while (message[message.length - 1] === char) { | |
message = message.substring(0, message.length - 1); | |
} | |
} | |
return message; | |
}; | |
export const trim = (str, char) => { | |
return ltrim(rtrim(str, char), char); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment