jscommunity / human-format Goto Github PK
View Code? Open in Web Editor NEWConverts a number to/from a human readable string: `1337` ↔ `1.34kB`
License: ISC License
Converts a number to/from a human readable string: `1337` ↔ `1.34kB`
License: ISC License
I found some cases where human-format
breaks, it seems to have an internal rounding error somewhere and it outputs the wrong number of digits:
humanFormat(111111111, { decimals: 1 })returns:
111.09999999999998 M
expected:111.1 M
humanFormat(100000001, { decimals: 1 })returns:
99.99999999999999 M
expected:100.0 M
Hi @JsCommunity!
Awesome util, solves many tacky nuances. I am thinking to use it in plot-grid.
Though there is one thought related to this. As far as the util tries to represent values in human-oriented format, would it make sense to display exponent part as ten to the power?
E.g. 10e+20
→ 10²⁰
, or 7.2973525664e-3
→ 7.297 352 5664×10⁻³
? Wikipedia does so, and that is what I’ve been taught in school :)
Or is it better to delegate to a separate package?
Thanks!
hello ... I can not convert a json file to ARFF using your example. The result is that I have this: [ '\n', '@DaTa', '\n' ]
I can use the parse, but not the format.
thanks for help
I had to do the following custom post-processing to get the decimals to be stable (always present)
const raw = humanFormat.raw(n, { scale: frogScale, decimals: 3 });
return `${raw.value.toFixed(3)} ${raw.prefix}`;
So I'm quite glad there's a raw version, but I also wonder if most people want the behaviour of .toFixed()
when specifying decimals? (in eg. games where numbers climb rapidly, there is quite a bit of jittering when numbers jump between number of decimal places eg. 0.2
vs 0.21
Hello,
Is there an option to specify the library should always floor the rounding?
Currently 1390
gets displayed as 1.4k
, I would like for it to show 1.3k
while the input value is strictly less than 1400.
In other words, I'd like to never show a value actually higher than the input.
Just for reference, the options I'm currently using are { maxDecimals: 'auto', separator: '' }
.
Thank you.
Hi, I', trying to parse string like '100K', but it returns error:
Error: cannot parse str
const humanFormat = require('human-format')
const parsed = humanFormat.parse('100K')
Latest release of the project is 0.2.0 but bower.json says it's 0.1.1.
Branch | Build failing 🚨 |
---|---|
Dependency | standard |
Current Version | 8.5.0 |
Type | devDependency |
This version is covered by your current version range and after updating it in your project the build failed.
As standard is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.
I recommend you give this issue a high priority. I’m sure you can resolve this 💪
The new version differs by 10 commits .
3f88a12
8.6.0
b771408
changelog
4c82bc8
Remove standard-format references
938dcc3
[email protected]
21f0ca4
cross-spawn@5
451da5f
[email protected]
f27f1df
[email protected]
e542e03
[email protected]
66f1ead
Merge pull request #684 from capaj/patch-2
a0280a9
added vscode-standardjs-snippets
See the full diff.
There is a collection of frequently asked questions and of course you may always ask my humans.
Your Greenkeeper Bot 🌴
I would expect humanFormat(1)
to return 1B
, not 1000mB
... which makes no sense. The format should scale down only when values are less than 1
.
I am wondering how I can use time format ( or scale) effectively. Actually I want to output system uptime (seconds since boot) as (days) hh:mm, for example: 4 days, 22:32
I have tried the example included in the README which gives me the following:
var humanFormat = require("human-format");
var timeScale = new humanFormat.Scale({
seconds: 0,
minutes: 60,
hours: 3600,
days: 86400,
months: 2592000,
})
console.log(humanFormat(425348, { scale: timeScale }));
which gives me 4.92 days
In the readme there is example how to use custom scales
var timeScale = new humanFormat.Scale({
seconds: 1,
minutes: 60,
hours: 3600,
days: 86400,
months: 2592000,
});
humanFormat(26729235, { scale: timeScale });
which is incomplete. You can use also second way
var customScale = humanFormat.Scale.create(['a', 'b', 'c', 'd'], 1000);
humanFormat(26729235, { scale: customScale });
The other thing is if you want to use custom scale in TypeScript code there is completly missing typings for this use case. There is not defined Scale at all.
humanFormat.parse('8.3M') -> 8300000.000000001
Hey. Just curious if you guys want to include additional feature of formatting ISBN. If so, you can use beautify-isbn, which I crafted for my library software project. So the ISBN agency ranges are up-to-date all the time. :)
humanFormat(1337, {
seperator: ' - '
})
see: dictionary
Thank you for a great library!
It would be useful if the library supported higher dimensions for cases such as "m²" or "m³". An example would be:
humanFormat(1_000_000, { unit: "m²" });
//=> 1 km²
Or alternatively:
humanFormat(1_000_000_000, { unit: "m³" });
//=> 1 km³
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.