Giter VIP home page Giter VIP logo

numeral-js's Introduction

numeral.js

Build Status

A javascript library for formatting and manipulating numbers. Forked from https://github.com/adamwdraper/Numeral-js

Acknowlegements

Numeral.js, while less complex, was inspired by and heavily borrowed from Moment.js

License

Numeral.js is freely distributable under the terms of the MIT license. See the LICENSE file.

numeral-js's People

Contributors

adamwdraper avatar apapirovski avatar baer avatar clayzermk1 avatar daclayton avatar donvince avatar dresende avatar ecmel avatar hgarcia avatar jojosati avatar kennynaoh avatar koesbong avatar lafriks avatar marcus-old avatar moeriki avatar nreese avatar pickypg avatar piefel avatar ragulka avatar samitheberber avatar sinky avatar spalger avatar streamich avatar teppeis avatar ticking-clock avatar tsullivan avatar w33ble avatar wylieconlon avatar zeke avatar zeusdeux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

numeral-js's Issues

Support for fractional durations / time notation with milliseconds

numeral-js supports formatting a number of seconds in HH:MM:SS format (by typing 00:00:00). Unfortunately it seems that 00:00:00.[000] does not produce a format with milliseconds. When times are short (or can vary from few seconds to minutes), this could be nice to have.

I think it'd be rather simple to implement in the same style as the existing code - it just checks for the existence of : to determine whether to format as time - so there could just be a switch for . (possibly count zeros after for precision) to determine whether to format fractional seconds.

Incorrect formatting on very small numbers

I found this repo while searching for a fork that fixed the Numeral JS bug "NaN returned if value < 1e-6"
I see that this fork fixes that issue somewhat; it doesn't return NaN anymore, but the formatting of the output string has problems.

If I use format 0,0 on a number like 4.8439166267322474e-8, the formatted string looks like this:

4.8,439,166,267,322,474e-8

Note there are commas in the mantissa after the decimal point. I'd expect an output of 0 here, actually.

Format 0,0.00 returns the same string as above, where I'd expect 0.00 or 4.84e-8 or something.

Here's a codepen that shows the strangeness:
https://codepen.io/foundryspatial-duncan/pen/YzqWxgK

Problem dealing with large exponential numbers

Discovered with version 2.2.1.

We currently facing a issue in kibana when show some float type fields.

In some cases, one float type number value is like some exponential number like -1e+35. And I found kibana then threw some error saying it cannot read length of undefined. In particular, this happens when exporting to CSV.

The issue seems to be on line 374 and 49. It is trying to read the digit from a toFixed return value., and toFixed doesn't return a proper digit number with a '.', then it throws an error.

I think the fix might be something like changing the toFixed function to toPrecision. But it may need more investigation there.

This may be an upstream issue too, I'm still investigating.

Update bytes formatter, support bits formatting

I've just found these bug reports/feature requests for Kibana, and want to make sure we're tracking them here.

elastic/kibana#7892
elastic/kibana#7543

For bytes, the actionable thing is to display KiB and MiB, etc suffixes when using the b formatter, instead of KB and MB. This diverges from the choice that was made in the core numeral-js library here, where the author chose to make two changes (one breaking) instead of one change: adamwdraper#388

Proposal:

  • Fix the bug in the b formatter by replacing suffixes
  • Introduce another formatter for base-1000 bytes (KB, MB, etc) which has a different name than the numeral formatter. Proposal: bd for "bytes decimal"
  • Create a github-pages documentation website for our fork to distinguish the formatters.

Problem with languages build on Windows OS

I have a problem building project output on Windows PC,
This probably should fix issue:

diff --git a/Gruntfile.js b/Gruntfile.js
index 93e8d77..9fab86c 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -1,6 +1,7 @@
 const fs = require('fs');
 const path = require('path');
 const prettier = require('prettier');
+const endOfLine = require('os').EOL;

 module.exports = function(grunt) {

@@ -51,7 +52,7 @@ module.exports = function(grunt) {
           const content = fs.readFileSync(path.resolve(__dirname, 'languages', filename), 'utf8');
           const name = content.match(/(?:\*|\/\/)\s*language\s*:\s*(.+)$/m)[1]

-          const lines = content.split('\n');
+          const lines = content.split(endOfLine);
           const start = lines.findIndex(line => line.match(/^\s{4}var\s+language\s+=\s+\{/))
           const end = lines.findIndex(line => line.match(/^\s{4}\};/))
           if (start === -1) {

Let me know if you're accepting PRs

TypeError when formatting numbers <= 1e-7

Hi thanks for forking and developing numeral-js. Using this module b/c the original numeral-js has been abandoned by its maintainer.

Just ran into this:

const numeral = require('@elastic/numeral');
console.log(numeral('0.0000001').format('0,0.00'));

Error:

node_modules/@elastic/numeral/numeral.js:378
                if (d.split('.')[1].length) {
                                   ^

TypeError: Cannot read property 'length' of undefined
    at formatNumber (node_modules/@elastic/numeral/numeral.js:378:36)
...

Same thing happens when formatting 1e-7 or smaller.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.