[Proposal] ignoreCase method
Isiah Meadows
isiahmeadows at gmail.com
Wed Jun 27 12:56:50 UTC 2018
BTW, have you tried `string.localeCompare(other, null, {sensitivity:
"base"})` or `sensitivity: "accent"`?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
-----
Isiah Meadows
me at isiahmeadows.com
www.isiahmeadows.com
On Wed, Jun 27, 2018 at 7:35 AM, Michael Luder-Rosefield <
rosyatrandom at gmail.com> wrote:
> Would it not be simpler to simply change the signature from
> `function(value, arrayOfStrings)` to `function(...values)`?
>
> I'd also suggest that a better, more general purpose formulation of
> comparing a string against multiple values might be to use #match.
> Something like:
>
> ```
> const checkString = (str, { ignoreCase, startsWith, endsWith, equals }={}
> ) => {
> const start = startsWith || equals ? '^' : '';
> const end = endsWith || equals ? '$' : '';
> const rx = v => new RegExp(`${start}${v}${end}`,ignoreCase && 'i');
>
> return { against: (...values) => values.some(value =>
> str.match(rx(value))) };
> }
> ```
>
>
> On Wed, 27 Jun 2018 at 11:50 Robert Wozniak <wozniakj.robert at gmail.com>
> wrote:
>
>> 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 at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180627/c44aec8e/attachment-0001.html>
More information about the es-discuss
mailing list