(str)
| 4 | * @return {string} The str in lower case format. |
| 5 | */ |
| 6 | const toLowerCase = function(str) { |
| 7 | // htmlparser heavily relies on the length of the strings, and |
| 8 | // unfortunately some characters change their length when |
| 9 | // lowercased; for instance, the Turkish İ has a length of 1, but |
| 10 | // when lower-cased, it has a length of 2. So, as a workaround we |
| 11 | // check that the length be the same as before lower-casing, and if |
| 12 | // not, we only lower-case the letters A-Z. |
| 13 | const lowerCased = str.toLowerCase(); |
| 14 | if (lowerCased.length == str.length) { |
| 15 | return lowerCased; |
| 16 | } |
| 17 | return str.replace(/[A-Z]/g, function(ch) { |
| 18 | return String.fromCharCode(ch.charCodeAt(0) | 32); |
| 19 | }); |
| 20 | }; |
| 21 | exports.toLowerCase = toLowerCase; |
| 22 | /** |
| 23 | * @param {string} str The string to upper case. |
no test coverage detected