koblas / stdnum-js

A JavaScript library to provide functions to handle, parse and validate standard numbers.
MIT License
38 stars 26 forks source link

Enhance each stdnum type with an example property #108

Open ChrisWooldridge opened 9 months ago

ChrisWooldridge commented 9 months ago

It would be useful if each number type had an additional property 'example' that gives a compact form of the number. For example BR.cpf would have the property "39053344705" and AU.tfn would have '123456782' The example property for each type should validate (the data is already in each test case). My use case is to generate a UI prompt. My AU.tfn prompt might be: "Enter your TFN (e.g., 123 456 782) An alternative use would be to generate an input mask. The BR.cpf example, above, would be formatted 390.533.447-05 which could then be used to create a mask:

.###.###-

(The creation of the mask is an exercise left to the user.)

koblas commented 9 months ago

That's a pretty cool idea.

Some numbers have multiple formats or variations, so would require a list of formats, does that make sense to you?

I would probably borrow from the IBAN registry:

n = digits [0-9] a = alphabetic [a-z] c = character [a-z0-9]

That would make the brazil CPF have the format of: nnn.nnn.nnn-nn

ChrisWooldridge commented 9 months ago

Your idea is better than my suggestion.