-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnumer.min.js
7 lines (7 loc) · 928 Bytes
/
numer.min.js
1
2
3
4
5
6
7
/* @license
numer.js
v0.1.0
https://github.com/bunlong/numer.js
License: MIT
*/
!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&"undefined"!=typeof exports?module.exports=e():t.Numer=e()}(this,function(){"use strict";function t(t){this._input=t}return t.prototype={format:function(t){var e,r,n,o=t;switch(this._input.style){case"comma":return o.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");case"abbreviation":return function(t){var e=t;if(1e3<=t){for(var r=Math.floor((""+t).length/3),n="",o=2;1<=o;o--)if(((n=parseFloat((0!==r?t/Math.pow(1e3,r):t).toPrecision(o)))+"").replace(/[^a-zA-Z 0-9]+/g,"").length<=2)break;n%1!=0&&(n=n.toFixed(1)),e=n+["","K","M","B","T"][r]}return e}(o);case"ordinal":return n=(e=o)%100,1!=(r=e%10)||11==n?2!=r||12==n?3!=r||13==n?e+"th":e+"rd":e+"nd":e+"st";default:throw new Error("The formatting style to use: comma, abbreviation and ordinal.")}}},t});