Skip to content
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

Ability to disable non-unicode patterns in format function #3735

Open
patorjk opened this issue Mar 15, 2024 · 1 comment
Open

Ability to disable non-unicode patterns in format function #3735

patorjk opened this issue Mar 15, 2024 · 1 comment

Comments

@patorjk
Copy link

patorjk commented Mar 15, 2024

Let's say I have an app that let's a user enter a date format and preview it: https://codesandbox.io/p/sandbox/date-fns-test-mlfc2n

And that format might be used by another app that uses Unicode Technical Standard 35. It would be nice if the format function had an option to disable the format additions listed in Note 7. I can do it by hand, but that wouldn't protect against any options that get added in the future.

@fturmel
Copy link
Member

fturmel commented Mar 31, 2024

Interesting use case, and I think it could be done fairly simply.

Could be worth having the same mirror option to the parse function too.

Adding an option to FormatOptions (like useStandardUnicodeTokensOnly or disableNonStandardTokens), add an alternate formattingTokensRegExp for standard tokens only, and not matching the longFormattingTokensRegExp might be all we need?

const formattingTokensRegExp =
/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
// This RegExp catches symbols escaped by quotes, and also
// sequences of symbols P, p, and the combinations like `PPPPPPPppppp`
const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants