faker-js / faker

Generate massive amounts of fake data in the browser and node.js
https://fakerjs.dev
Other
12.71k stars 913 forks source link

Don't allow faker.location.buildingNumber() to start with a 0 #2031

Closed matthewmayer closed 1 year ago

matthewmayer commented 1 year ago

Clear and concise description of the problem

Building numbers that start with a zero lead to addresses like '013 Schultz Circles' which look incorrect.

faker.helpers.multiple(faker.location.buildingNumber, {count:100}).filter(x=>x.startsWith("0"))
[
  '050',   '01460', '07806',
  '001',   '05217', '0670',
  '07971', '076',   '03212',
  '034',   '062',   '005',
  '08119'
]

Suggested solution

Change the patterns. As this uses replaceSymbolWithNumber we only have the choice of # (0-9) or ! (2-9) as special chars.

We can use a pattern like ['1##', '!##', '1###', '!###', '1####', '!####'] to ensure the numbers can start with any of 1-9, but not 0. This causes a slight side-effect that numbers starting with 1 will be more common. However Benford's law means thats not unrealistic anyway.

Alternative

No response

Additional context

No response

ST-DDT commented 1 year ago

IMO instead of doing this strange pattern duplication stuff we should rather change the implementation to not use replacewithnumber and instead use a simple regex replace with numeric without leading zero or something.

ST-DDT commented 1 year ago

See also

matthewmayer commented 1 year ago

Note if you change the implementation it needs to handle a bunch of different localization patterns beyond simple numbers, i see the following unique patterns. Note the ones with slashes in, which have two numbers.

[
  ' #',      ' ##',     ' ###',  ' ####',
  ' s/n.',   '#',       '# bis', '##',
  '## bis',  '###',     '### I', '### II',
  '### III', '### bis', '####',  '#####',
  '###/#',   '###/2',   '###a',  '###b',
  '###c',    '##/#',    '##a',   '##b',
  '##c',     '#/#',     "'א#",   "'א##",
  "'ב#",     "'ב##",    ', #',   ', ##',
  'Bloc ##'
]
ST-DDT commented 1 year ago

Team Decision