srexi / purecounterjs

A simple yet configurable native javascript counter which you can count on.
MIT License
125 stars 47 forks source link

Date Number #31

Closed Chriz74 closed 2 years ago

Chriz74 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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

srexi commented 2 years ago

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

Chriz74 commented 2 years ago

edited my reply with screenshot :)

rzlnhd commented 2 years ago

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

srexi commented 2 years ago

@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)

rzlnhd commented 2 years ago

@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 commented 2 years ago

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

srexi commented 2 years ago

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

srexi commented 2 years ago

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