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

Simplify address.direction #1228

Closed
pkuczynski opened this issue Aug 3, 2022 · 9 comments
Closed

Simplify address.direction #1228

pkuczynski opened this issue Aug 3, 2022 · 9 comments
Assignees
Labels
c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs m: location Something is referring to the location module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug

Comments

@pkuczynski
Copy link
Member

Clear and concise description of the problem

There are 3 separate functions now direction, cardinalDirection and ordinalDirection, which is not convenience to use. Also they depend on specific order of localisation, which is hard to verify when reviewing PR.

Suggested solution

Should we change the definition to look more like:

interface Directions {
  cardinal: string[]
  ordinal: string[] // or intercardinal ?
  secondaryIntercardinal?: string[]
}

type DirectionType = keyof Directions

And then both directions and directions_abbr should use this type?

Additionally, I think it makes sense to simplify the usage and change direction signature to:

direction ({ abbr: boolean, type: DirectionType, types: DirectionType[]})

// @examples
faker.address.direction() // 'north'
faker.address.direction({ abbr: true }) // 'N'
faker.address.direction({ type: 'ordinal' }) // 'north west'
faker.address.direction({ abbr: true, type: 'ordinal' }) // 'NW'
faker.address.direction({ abbr: true, types: ['ordinal', 'secondaryIntercardinal']  }) // 'NNW'

And then deprecate the other methods?

Alternative

We might also skip secondaryIntercardinal...

Additional context

No response

@Shinigami92
Copy link
Member

The proposed signature confuses me a bit:
e.g. what will happen if you call faker.address.direction({ abbr: true, type: 'cardinal', types: ['ordinal'] })
I as a user calling this or reading this code would be totally confused what it could return

@pkuczynski
Copy link
Member Author

pkuczynski commented Aug 4, 2022

Yeah, good point! How about direction ({ abbr: boolean, types: DirectionType[] }) or direction ({ abbr?: boolean, type?: DirectionType, except?: DirectionType[]})

@Shinigami92
Copy link
Member

Both are better, lets discuss more on team meeting
But second proposed is also dangerous as you can call direction ({ type: ['ordinal'], except: ['ordinal'] }) and we would need to throw an error

@pkuczynski
Copy link
Member Author

pkuczynski commented Aug 4, 2022

That's correct. But I guess more predictable. And unlikely someone would do it anyway. So we have the following proposals on the table, just to summarise:

direction ({ abbr?: boolean, type?: DirectionType | DirectionType[] })
direction ({ abbr?: boolean, types?: DirectionType[] })
direction ({ abbr?: boolean, type?: DirectionType, except?: DirectionType[]})

I think I like the first most.

@import-brain import-brain added c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs m: location Something is referring to the location module and removed s: pending triage Pending Triage labels Aug 4, 2022
@ST-DDT
Copy link
Member

ST-DDT commented Aug 4, 2022

Team decision

Refactor our locales to match these:

interface Directions {
  cardinal: string[]
  ordinal: string[]
}

Merge the directions functions into a single method:

direction ({ abbr?: boolean = false, type?: DirectionType | DirectionType[] = ['cardinal', 'ordinal'] })

Throw if type is an empty array.

@ST-DDT ST-DDT added the s: accepted Accepted feature / Confirmed bug label Aug 4, 2022
@wael-fadlallah
Copy link
Contributor

Hello, I can take care of this one, please assign it to me

@pkuczynski
Copy link
Member Author

We already discussed this with @hankucz and she will look at it. Thank you @wael-fadlallah

@hankucz
Copy link
Contributor

hankucz commented Aug 5, 2022

Yeah, I'm already looking into it

@xDivisionByZerox
Copy link
Member

I'm closing this as #2476 provides the suggested change. If you think this is a mistake, please reopen the issue or create a new one with additional, related information.

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 m: location Something is referring to the location module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

No branches or pull requests

7 participants