locutus
Version:
Locutus other languages' standard libraries to JavaScript for fun and educational purposes
12 lines (11 loc) • 471 B
JavaScript
export function strip(str) {
// parity verified: Ruby 3.3
// discuss at: https://locutus.io/ruby/String/strip/
// original by: Kevin van Zonneveld (https://kvz.io)
// note 1: Returns a copy of str with leading and trailing whitespace removed.
// example 1: strip(' hello ')
// returns 1: 'hello'
// example 2: strip('\t\ngoodbye\r\n')
// returns 2: 'goodbye'
return (str + '').trim();
}