Hi everyone, ignoreCase - JavaScript proposal
It's a proposal to implement a new function to compare two strings but without case sensitivity. The proposal is bringing an important function, which is being used in Java. Many times in my career I had to compare two strings but ignore case sensitivity. I had to convert it first and then I could compare. I'd like developers to be able to use the function and compare two strings without worrying about case sensitivity. <https://github.com/robertjwozniak/ignoreCase#1-syntax>1. Syntax String.prototype.ignoreCase = function(value, arrayOfStrings) { var secondOption = value.toLowerCase() || arrayOfStrings.join(',').toLowerCase().split(','); var firstOption = this.valueOf().toLowerCase(); if(typeof secondOption === 'object') { for(var i = 0, l = arrayOfStrings.length; i < l; i++) { if(firstOption === secondOption[i]) { return true; break; } } } else { if(firstOption === secondOption) { return true; } else { return false; } } }; Above code presents *ignoreCase* function and what's happening inside. The function takes two parameters: (value, arrayOfStrings) <https://github.com/robertjwozniak/ignoreCase#11-value-parameter>1.1 "value" parameter The value parameter is the string which is going to be compared with the parent string chosen by the developer, for example: const stringOne = "Matheus";stringOne.ignoreCase("matheus"); // true; <https://github.com/robertjwozniak/ignoreCase#12-arrayofstrings-paramenter>1.2 "arrayOfStrings" parameter The "arrayOfStrings" parameter is an array of strings, which are going to be compared with the parent string chosen by the developer. Once the parent string equals one of the strings in an array, it will return true and stops iterating through. Example: const stringOne = "Matheus";const manyStrings = ['robert', 'lucas', 'matheus'];stringOne.ignoreCase('', manyStrings) // true; <https://github.com/robertjwozniak/ignoreCase#2-response>2. Response The function is going to return true or false. The result depends on equality between chosen strings. <https://github.com/robertjwozniak/ignoreCase#3-how-it-works>3. How does it work? The function converts all of the strings, which the developer chose to the lower case. After performing the previous operation, it compares all of them. If at least one, equals the provided parent string, then the function returns true. You can the proposal on my GitHub: https://github.com/robertjwozniak/ignoreCase -- Regards, Robert Wozniak
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss