faker icon indicating copy to clipboard operation
faker copied to clipboard

Random identity card number

Open Shinigami92 opened this issue 3 years ago • 10 comments

Clear and concise description of the problem

I would like to have a function to generate a random identity card number

In germany the implementation would follow this pattern: https://de.wikipedia.org/wiki/Ausweisnummer

Not sure right now how patterns in other country looks like, but in the long run I would need these also.

The sequence should be seed-based

Suggested solution

Implement a function that returns an identity card number that is seed-based and related to the current selected locale

Alternative

No response

Additional context

No response

Shinigami92 avatar Feb 04 '22 08:02 Shinigami92

What about locales that do not have a "national identity card"? The US doesn't have anything like that, would this function generate a Social Security number? Passport number?

ejcheng avatar Feb 04 '22 12:02 ejcheng

How about designing it more generic. We could use a Record<string, algorithm config> to define these things and the user has to know or lookup which generators are available for generateId(type: string). The you can have one pattern for driving licences, for personal identity card numbers.

Or even more generically, a method that just takes the generation config and will build it for you. You want a credit card with name, number, expiration date...? You get will get it. You want an array of x-y foobars? You will get it. You want a single identity card number that is generated based on a specific pattern? You will get it. You just have to describe the thing you want. Something like fake() and mustache() but for generic objects/arrays/elements.

ST-DDT avatar Feb 04 '22 12:02 ST-DDT

How about designing it more generic. We could use a Record<string, algorithm config> to define these things and the user has to know or lookup which generators are available for generateId(type: string). The you can have one pattern for driving licences, for personal identity card numbers.

Or even more generically, a method that just takes the generation config and will build it for you. You want a credit card with name, number, expiration date...? You get will get it. You want an array of x-y foobars? You will get it. You want a single identity card number that is generated based on a specific pattern? You will get it. You just have to describe the thing you want. Something like fake() and mustache() but for generic objects/arrays/elements.

Yes, that would be nice in the long run, but I don't want to pass an algorithm or pattern as developer to faker, in that case I could just write it myself. I would like to have it very basic and easy to use for now. And if a locale doesn't have such thing, I'm satisfied with undefined for now.

Shinigami92 avatar Feb 04 '22 13:02 Shinigami92

Algorithimically generated ID numbers like the Ausweisnummer seem like a pretty heavy lift. Seems like these should have their own defined functions, perhaps as part of a locale. US Social Security numbers are easier, as they aren't algorithimically validated. You can get a US SSN using the existing faker.helpers.regexpStyleStringParse`, e.g.:

faker.helpers.regexpStyleStringParse('[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]')

What might be cool is if this method could repeat string patterns as well as single characters, so that might condense down to:

faker.helpers.regexpStyleStringParse('[0-9](3)-[0-9](2)-[0-9](4)')l

Or perhaps with common format identifiers, e.g.:

faker.helpers.regexpStyleStringParse('us-ssn');

There are likely multiple "National ID"s for any given country. The US has SSN, passport number, driver's license number (which varies by state), PASSID/KTN, license plates (again varying by state), etc.

bryancross avatar Aug 14 '22 00:08 bryancross

Since this varies greatly in both available ids and their implementation we have two choices:

  • Move implementation to the locales (The list of available generator varies by country and there would be no real ts support).
  • Implement it as a new (plugin-)module (per country)

I don't see this in v7 and even v8.

ST-DDT avatar Aug 15 '22 13:08 ST-DDT

If you are interested in this feature, please upvote this issue.

ST-DDT avatar Mar 16 '23 16:03 ST-DDT

Maybe this will help create some random number SSN-like value:

faker.phone.number('###-##-####')
// Example Results:
// 771-00-9483
// 315-74-5571

For a "valid" Honduras ID number:

faker.phone.number('####-####-#####')

It creates something that may work, but may create some invalid values, for Honduras ID, the first 2 digits is the Department, the next two digits is the municipality, next 4 is year issued, next 5 are indeed random. The year is easy to generate, but the first 4 requires more development.

I like this idea:

Implement it as a new (plugin-)module (per country)

guitartsword avatar Apr 28 '23 23:04 guitartsword

Thank you for your feature proposal.

We marked it as "waiting for user interest" for now to gather some feedback from our community:

  • If you would like to see this feature be implemented, please react to the description with an up-vote (:+1:).
  • If you have a suggestion or want to point out some special cases that need to be considered, please leave a comment, so we are aware about them.

We would also like to hear about other community members' use cases for the feature to give us a better understanding of their potential implicit or explicit requirements.

We will start the implementation based on:

  • the number of votes (:+1:) and comments
  • the relevance for the ecosystem
  • availability of alternatives and workarounds
  • and the complexity of the requested feature

We do this because:

  • There are plenty of languages/countries out there and we would like to ensure that every method can cover all or almost all of them.
  • Every feature we add to faker has "costs" associated to it:
    • initial costs: design, implementation, reviews, documentation
    • running costs: awareness of the feature itself, more complex module structure, increased bundle size, more work during refactors

View more issues which are waiting for user interest

github-actions[bot] avatar May 05 '23 07:05 github-actions[bot]