You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actions minLength and maxLength use String.prototype.length, which is not very reliable as it relies on the number of character codes. This approach is not ideal for checking the number of characters the way humans perceive it, especially with emojis. For example, most emojis have a length of 2 (like 🙃), but some have a length of 7 (like 🧑🏻💻).
I suggest adding new actions like minGraphemeCount or maxGraphemeCount, which would use the Intl.Segmenter API instead of String.prototype.length. This would be particularly useful when dealing with user-generated content. As of April 2024, the API is supported in all major browsers.
The code would look something like this:
import*asvfrom'valibot';constPostSchema=v.object({title: v.pipe(v.string(),v.maxGraphemeCount(300,/* optional language parameter */'en')),});
The text was updated successfully, but these errors were encountered:
Thank you for your contribution. We have already discussed this in PR #666 (comment). Feel free to create a PR and copy the source code of length, notLength, minLength and maxLength and implement graphemes, notGraphemes, minGraphemes and minGraphemes based on it.
Actions
minLength
andmaxLength
useString.prototype.length
, which is not very reliable as it relies on the number of character codes. This approach is not ideal for checking the number of characters the way humans perceive it, especially with emojis. For example, most emojis have a length of 2 (like 🙃), but some have a length of 7 (like 🧑🏻💻).I suggest adding new actions like
minGraphemeCount
ormaxGraphemeCount
, which would use theIntl.Segmenter
API instead ofString.prototype.length
. This would be particularly useful when dealing with user-generated content. As of April 2024, the API is supported in all major browsers.The code would look something like this:
The text was updated successfully, but these errors were encountered: