-
Notifications
You must be signed in to change notification settings - Fork 2
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
Difference to text-mask? #1
Comments
While the mentioned "text-mask" is an excellent library, there is a fundamental difference compared to this project. This explanation is worth adding to the README, but for now I'll keep it here. When using a library for formatting the user input, you have to tell the library how it should format it. The basic difference is how you tell it. Almost all libraries that I know of use a mask. Masks are a great idea and one that is very simple to use.... but not for all cases. Say that we expect the user to enter 16-digits bank card number and we want to put a space between each digit group (so that
Or in case of the mentioned {
mask: [
/\d/, /\d/, /\d/, /\d/, ' ',
/\d/, /\d/, /\d/, /\d/, ' ',
/\d/, /\d/, /\d/, /\d/, ' ',
/\d/, /\d/, /\d/, /\d/,
],
} It's quite simple. It's the case for which a mask is a great choice. But let's say that we want the user to enter a number of an arbitrary length and we want to do the digit grouping How do you describe it with a mask? I think it's quite hard. Surely some kind of mask-regex syntax can be invented, but this would just add complexity to the problem. But at the same time... if we just ask ourselves, "how hard can it be to go from function formatNumber(string = '') {
return string
.split('').reverse().map((char, i) => {
if (i && i % 3 === 0) {
return `${char},`;
}
return char;
})
.reverse().join('');
} So I thought, wouldn't it be great if we just give the library a function which describes what kind of output we wish to get given a certain input and the library would just take care of the cursor position? It would have lots of benefits, the major one being that we don't even care how that function formatNumber(string = '') {
return new Intl.NumberFormat('en-US').format(string);
} This is how easy it can potentially be to use a standard So this is why I believe functions to be superior to masks and why I decided to create this library. But thanks to this issue, I checked out this |
Hey @everdimension thanks for your long explanation 👍 I totally agree there is a great value of moving cursor position into a library like yours and often multiple solutions to the same problem lead to better results in the end. When I saw your project I was just trying to make sure you know textmask and can reuse some of the ideas or contribute to their project :) If I remember correctly text mask offers two configurations:
|
Hi - what are the differences to https://github.com/text-mask/text-mask ?
The text was updated successfully, but these errors were encountered: