Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate helpers.replaceSymbolWithNumber #1994

Closed
ST-DDT opened this issue Mar 29, 2023 · 11 comments · Fixed by #2557
Closed

Deprecate helpers.replaceSymbolWithNumber #1994

ST-DDT opened this issue Mar 29, 2023 · 11 comments · Fixed by #2557
Assignees
Labels
c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs deprecation A deprecation was made in the PR good first issue Good for newcomers m: helpers Something is referring to the helpers module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Milestone

Comments

@ST-DDT
Copy link
Member

ST-DDT commented Mar 29, 2023

Clear and concise description of the problem

The method helpers.replaceSymbolWithNumber is mostly a black box that does some arbritary char -> digit transformations.

The implementation contains unexpected branches.

Suggested solution

  1. Replace all usages in our code base with a
string.replace(/char+/g, (m) => faker.string.numeric(m.length));

Deprecate helpers.replaceSymbolWithNumber

Alternative

Keep the method as is

Additional context

No response

@ST-DDT ST-DDT added p: 1-normal Nothing urgent c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs m: helpers Something is referring to the helpers module deprecation A deprecation was made in the PR labels Mar 29, 2023
@ST-DDT
Copy link
Member Author

ST-DDT commented Mar 29, 2023

@ST-DDT ST-DDT moved this to Todo in Faker Roadmap Mar 29, 2023
@ST-DDT ST-DDT added s: on hold Blocked by something or frozen to avoid conflicts s: needs decision Needs team/maintainer decision labels Mar 29, 2023
@ST-DDT ST-DDT added s: accepted Accepted feature / Confirmed bug and removed s: needs decision Needs team/maintainer decision labels Mar 30, 2023
@ST-DDT
Copy link
Member Author

ST-DDT commented Mar 30, 2023

Team Decision

We want this.

@ST-DDT ST-DDT removed the s: on hold Blocked by something or frozen to avoid conflicts label Apr 9, 2023
@xDivisionByZerox xDivisionByZerox added the good first issue Good for newcomers label Jul 14, 2023
@suyashgulati
Copy link
Contributor

suyashgulati commented Aug 9, 2023

@ST-DDT Can you assign this one to me

I am gonna use String.replaceAll instead of String.replace for this issue

Q1. Can you confirm one thing, as we are deprecating this function what would be the change required at this line phone_number.ts#L13

Q2. What will be the @see jsdoc for the deprecated function. replaceSymbols?

Q3. With deprecation, will there be any change in the tests? Should we remove tests or not?

@ST-DDT
Copy link
Member Author

ST-DDT commented Aug 9, 2023

Q1. Can you confirm one thing, as we are deprecating this function what would be the change required at this line phone_number.ts#L13

It should list the supported replacements.

Q2. What will be the @see jsdoc for the deprecated function. replaceSymbols?

I dont think that we need one. The deprecation message can cover the string replace. Maybe we can refer to the new helpers regex method.

Q3. With deprecation, will there be any change in the tests? Should we remove tests or not?

Tests shouldn't be removed. We might have to change some of them slightly (test snapshots etc).

@suyashgulati
Copy link
Contributor

Thanks for the prompt replies

Q2. What will be the @see jsdoc for the deprecated function. replaceSymbols?

I dont think that we need one. The deprecation message can cover the string replace. Maybe we can refer to the new helpers regex method.

One thing I need help on, I might not be aware of new helpers regex method
Can you point me to that?

@ST-DDT
Copy link
Member Author

ST-DDT commented Aug 10, 2023

@matthewmayer
Copy link
Contributor

The main reason for the existence of this method seems to be handling North American phone numbers which need the "no 0 or 1 in this position" symbol !. So maybe if we come up for a smarter way to deal with those in #2303 this method would no longer be needed.

@ST-DDT
Copy link
Member Author

ST-DDT commented Aug 10, 2023

faker.helpers.fake would probably work.

@matthewmayer
Copy link
Contributor

Maybe it would be best to keep the current implementation but only as an internal helper for phone number patterns? No longer expose it in helpers module after deprecation.

@ST-DDT
Copy link
Member Author

ST-DDT commented Nov 14, 2023

@suyashgulati Are you still interested in this?
We would like to wrap up v8 this week/shortly. Are you able to create a PR for the issue this week?

ToDos:

  • Deprecate helpers.replaceSymbolWithNumber
  • Move the current implemenation to an internal function similar to helpers.regexpStyleStringParse
  • Replace all current usages of replaceSymbolWithNumber with the internal function
  • Suggested replacements (for the deprecation message): string.replace(/#+/g, (m) => faker.string.numeric(m.length));

@suyashgulati
Copy link
Contributor

@ST-DDT Yes I am still up for it. Thanks for the detailed todos. I wasn't clear about the expectation after the open ended discussion.
I will get into this shortly. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs deprecation A deprecation was made in the PR good first issue Good for newcomers m: helpers Something is referring to the helpers module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
No open projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

4 participants