Closed strdr4605 closed 5 years ago
@strdr4605 Do you mind if I take this on?
@cukejianya, you can work on this. Let me know if you need some help!
@cukejianya, Wanted to ask your opinion about RexExp flags.
For every letter in the string is needed to check
letter.match(new RegExp(options.upper, 'g'))
i
flag should be added along with g
flag and then the regex will ignore case, so
new RegExp('a', 'gi')
will match for both a
and A
.
@cukejianya, As I discussed with some people, requirements for this issue will be probably changed! :blush:
Idea: upper/lower should behave like String.prototype.replace
after default convert
I will think again and change them in the next days. If you have some opinion, please write.
@strdr4605 When you say upper/lower should behave like String.prototype.replace
, do you mean that mockingcase("Hello World", upper:"worl")
should return "Hello WORLd"
instead of "heLLO WORld"
@cukejianya, The new idea is: step1: default convert "hElLo wOrLd" step2: "hElLo wOrLd".replace(new RegExp(upper, 'gi'), toUpperCase) Use case
mockingcase("Hello World", { upper: "worl" });
// step1: "hElLo wOrLd"
// step2: "hElLo WORLd"
mockingcase("Hello World", { upper: /worl/ });
// step1: "hElLo wOrLd"
// step2: "hElLo WORLd"
mockingcase("Hello World", { upper: "[worl]" });
// step1: "hElLo wOrLd"
// step2: "hELLO WORLd"
mockingcase("Hello World", { upper: /[worl]/ });
// step1: "hElLo wOrLd"
// step2: "hELLO WORLd"
If other options are present the order should be:
P.S. Let me know if you understand new requirements! You can also add comments. If everything is ok I will update the description of the issue!! 😊
P.S.1 Also
if (typeof upper !== "string" || !(upper instanceof RegExp)) {
throw TypeError(`options.upper: Expected string or RegExp but got "${typeof upper}"`);
}
Gotcha. So that means that I should ignore:
If only upper is present, then convert other letters that don't much the regex to lower case
If only lower is present, then convert other letters that don't much the regex to upper case
I should only convert letters that match regex. And for those that do not match, default to convert(input, (str, i) => i % 2 === 1)
(Unless other options are passed). Am I correct?
Yes, but I would suggest to first convert default or random
or firstUpper
and after go with lower
/upper
!
Option object should have these fields:
upper
should be of typestring
or instanceofRegExp
lower
should be of typestring
or instanceofRegExp
elseThe RegExp will be created as:
Possible solution:
Step 1: Convert the input with default behavior (even prostion: lowerCase; odd position: upperCase) or if any option is present that do it first:
onlyLetters
firstUpper
random
Step 2:
upper
has a higher priority so convert letters that much that regex after conversion oflower
Expected:
TO DO:
Status:
@cukejianya is working on this!