MCPcopy Create free account
hub / github.com/ampproject/amphtml / toLowerCase

Function toLowerCase

validator/js/engine/htmlparser-interface.js:6–20  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

4 * @return {string} The str in lower case format.
5 */
6const 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};
21exports.toLowerCase = toLowerCase;
22/**
23 * @param {string} str The string to upper case.

Callers 2

constructorMethod · 0.85
lowerNameMethod · 0.85

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected