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

Date Number #31

Closed
Chriz74 opened this issue Feb 17, 2022 · 12 comments
Closed

Date Number #31

Chriz74 opened this issue Feb 17, 2022 · 12 comments
Labels
enhancement New feature or request

Comments

@Chriz74
Copy link

Chriz74 commented Feb 17, 2022

Is it possible to remove the '.' on thousands?
I try to count to a year e.g. 2020. It displays then 2.021

'separator = false' seems to work only for decimals ...

@rzlnhd
Copy link
Contributor

rzlnhd commented Feb 22, 2022

@Chriz74 in what scenario you need to counter date as an object? And why didn't you convert that date to number? For example, you can use .getFullYear() to get the year as number.

Or you can give me your piece of code from jsfiddle or pastebin, so I can test it.

@Chriz74
Copy link
Author

Chriz74 commented Feb 22, 2022

Here is a simple basic setup:
https://jsfiddle.net/cmuschiol/uj07dska/7/

What i want to achieve is the number "2005" and not "2.005" ... so no '.' in it.

@rzlnhd
Copy link
Contributor

rzlnhd commented Feb 22, 2022

@Chriz74 Let me see... This code works well on my browser. But I think this can be happen because we use .toLocaleString(undefined, ...) to format number to string. And we just detect comma(s) as separator in here new RegExp(/,/gi, 'gi').

Maybe this issue will appear on some locales that doesn't use comma(s) to separate thousands number.

image

@Chriz74
Copy link
Author

Chriz74 commented Feb 22, 2022

i am testing with german browser (de_DE) ...
Edit-fiddle-JSFiddle-Code-Playground

@srexi
Copy link
Owner

srexi commented Feb 22, 2022

@Chriz74 can you share a screenshot of the result you're getting please

@Chriz74
Copy link
Author

Chriz74 commented Feb 22, 2022

edited my reply with screenshot :)

@rzlnhd
Copy link
Contributor

rzlnhd commented Feb 22, 2022

@Chriz74 well, accoding to MDN, de_DE use dot(s) (or whatever it name) as thausands separator.
image

@srexi
Copy link
Owner

srexi commented Mar 4, 2022

@Chriz74 well, accoding to MDN, de_DE use dot(s) (or whatever it name) as thausands separator. image

Right but there might be situations where formatting would want to be turned off.
Forexample if you want to represent counting through a series of years. Then thousand seperators doesn't make much sense.

Imo. we need a setting to remove formatting:
formatter=false ideally we'd also accept closures just so users can really customize how they want it presented.

Possible values: boolean [off], closure, string='locale' (default - because that's what we currently do)

@srexi srexi added the enhancement New feature or request label Mar 17, 2022
rzlnhd added a commit to rzlnhd/purecounterjs that referenced this issue Mar 20, 2022
feat: Add "formater" config (Date Number srexi#31)
rzlnhd added a commit to rzlnhd/purecounterjs that referenced this issue Mar 20, 2022
@rzlnhd
Copy link
Contributor

rzlnhd commented Mar 21, 2022

@Chriz74 I'm just create PR #32 for this issue. You can check out my repository and test it to your project...
For the JS file, you can use this link https://rzlnhd.github.io/purecounterjs/dist/purecounter_vanilla.js or https://rzlnhd.github.io/purecounterjs/dist/purecounter.js.

You can specify formater configuration on HTML element, or when you declare new PureCounter(). The formater accept string for locale (by default is "en-US"), or you can turn it off by set the value to false. More detail just check my PR Submission

@Chriz74
Copy link
Author

Chriz74 commented Mar 21, 2022

Works like a charm :)
Thank you!!!!

@srexi
Copy link
Owner

srexi commented Mar 21, 2022

I'll be merging this in tonight (in about 12 hours from now)

@srexi
Copy link
Owner

srexi commented Mar 22, 2022

This feature is live in version 1.5.0+ thanks for the suggestion @Chriz74

@srexi srexi closed this as completed Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants