Comparing version 1.2.3 to 1.2.5
// numeral.js | ||
// version : 1.2.3 | ||
// version : 1.2.6 | ||
// author : Adam Draper | ||
// license : MIT | ||
// http://adamwdraper.github.com/Numeral-js/ | ||
(function(){function u(e){this._n=e}function a(e,t){var n=Math.pow(10,t);return(Math.round(e*n)/n).toFixed(t)}function f(e,t){var n;t.indexOf("$")>-1?n=c(e,t):t.indexOf("%")>-1?n=h(e,t):t.indexOf(":")>-1?n=p(e,t):n=v(e,t);return n}function l(e,t){if(t.indexOf(":")>-1)e._n=d(t);else{i[s].delimiters.decimal!=="."&&(t=t.replace(/\./g,"").replace(i[s].delimiters.decimal,"."));var n=new RegExp(i[s].abbreviations.thousand+"(?:\\)|\\"+i[s].currency.symbol+"?)$"),r=new RegExp(i[s].abbreviations.million+"(?:\\)|\\"+i[s].currency.symbol+"?)$");e._n=(t.match(n)?1e3:1)*(t.match(r)?1e6:1)*(t.indexOf("%")>-1?.01:1)*Number((t.indexOf("(")>-1?"-":"")+t.replace(/[^0-9\.'-]+/g,""))}return e._n}function c(e,t){t=t.replace("$","");var n=f(e,t);if(n.indexOf("(")>-1||n.indexOf("-")>-1){n=n.split("");n.splice(1,0,i[s].currency.symbol);n=n.join("")}else n=i[s].currency.symbol+n;return n}function h(e,t){t=t.replace("%","");e._n=e._n*100;var n=f(e,t);if(n.indexOf(")")>-1){n=n.split("");n.splice(-1,0,"%");n=n.join("")}else n+="%";return n}function p(e,t){var n=Math.floor(e._n/60/60),r=Math.floor((e._n-n*60*60)/60),i=Math.round(e._n-n*60*60-r*60);return n+":"+(r<10?"0"+r:r)+":"+(i<10?"0"+i:i)}function d(e){var t=e.split(":"),n=0;if(t.length===3){n+=Number(t[0])*60*60;n+=Number(t[1])*60;n+=Number(t[2])}else if(t.lenght===2){n+=Number(t[0])*60;n+=Number(t[1])}return Number(n)}function v(e,t){var n=!1,r=!1,o=!1;if(t.indexOf("(")>-1){n=!0;t=t.slice(1,-1)}if(t.indexOf("a")>-1){t=t.replace("a","");if(e._n>1e6){r=i[s].abbreviations.million;e._n=e._n/1e6}else{r=i[s].abbreviations.thousand;e._n=e._n/1e3}}if(t.indexOf("o")>-1){t=t.replace("o","");o=i[s].ordinal(e._n)}var u=e._n.toString().split(".")[0],f=t.split(".")[1],l=t.indexOf(","),c="",h=!1;if(e._n<0){u=u.slice(1);h=!0}l>-1&&(u=u.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+i[s].delimiters.thousands));t.indexOf(".")===0&&(u="");f&&(c=i[s].delimiters.decimal+a(e._n,f.length).split(".")[1]);r;return(n&&h?"(":"")+(!n&&h?"-":"")+u+c+(o?o:"")+(r?r:"")+(n&&h?")":"")}function m(e,t){i[e]=t}var e,t="1.2.3",n=Math.round,r,i={},s="en",o=typeof module!="undefined"&&module.exports;e=function(t){e.isNumeral(t)?t=t.value():Number(t)||(t=0);return new u(Number(t))};e.isNumeral=function(e){return e instanceof u};e.version=t;e.isNumeral=function(e){return e instanceof u};e.language=function(e,t){if(!e)return s;e&&!t&&(s=e);(t||!i[e])&&m(e,t);return i};e.language("en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m"},ordinal:function(e){var t=e%10;return~~(e%100/10)===1?"th":t===1?"st":t===2?"nd":t===3?"rd":"th"},currency:{symbol:"$"}});e.fn=u.prototype={clone:function(){return e(this)},format:function(t){return f(this,t?t:e.defaultFormat)},unformat:function(t){return l(this,t?t:e.defaultFormat)},value:function(){return this._n},set:function(e){this._n=Number(e);return this},add:function(e){this._n=this._n+Number(e);return this},subtract:function(e){this._n=this._n-Number(e);return this},multiply:function(e){this._n=this._n*Number(e);return this},divide:function(e){this._n=this._n/Number(e);return this},difference:function(e){var t=this._n-Number(e);t<0&&(t=-t);return t}};o&&(module.exports=e);typeof ender=="undefined"&&(this.numeral=e);typeof define=="function"&&define.amd&&define([],function(){return e})}).call(this); | ||
(function(){function u(e){this._n=e}function a(e,t,n){var r=Math.pow(10,t),i;i=(Math.round(e*r)/r).toFixed(t);if(n){var s=new RegExp("0{1,"+n+"}$");i=i.replace(s,"")}return i}function f(e,t){var n;t.indexOf("$")>-1?n=c(e,t):t.indexOf("%")>-1?n=h(e,t):t.indexOf(":")>-1?n=p(e,t):n=v(e,t);return n}function l(e,t){if(t.indexOf(":")>-1)e._n=d(t);else{i[s].delimiters.decimal!=="."&&(t=t.replace(/\./g,"").replace(i[s].delimiters.decimal,"."));var n=new RegExp(i[s].abbreviations.thousand+"(?:\\)|\\"+i[s].currency.symbol+"?)$"),r=new RegExp(i[s].abbreviations.million+"(?:\\)|\\"+i[s].currency.symbol+"?)$"),o=["KB","MB","GB","TB","PB","EB","ZB","YB"],u=!1;for(var a=0;a<=o.length;a++){u=t.indexOf(o[a])>-1?Math.pow(1024,a+1):!1;if(u)break}e._n=(u?u:1)*(t.match(n)?1e3:1)*(t.match(r)?1e6:1)*(t.indexOf("%")>-1?.01:1)*Number((t.indexOf("(")>-1?"-":"")+t.replace(/[^0-9\.'-]+/g,""));e._n=u?Math.ceil(e._n):e._n}return e._n}function c(e,t){var n=t.indexOf("$")<=1?!0:!1;t=t.replace("$","");var r=f(e,t);if(n)if(r.indexOf("(")>-1||r.indexOf("-")>-1){r=r.split("");r.splice(1,0,i[s].currency.symbol);r=r.join("")}else r=i[s].currency.symbol+r;else if(r.indexOf(")")>-1){r=r.split("");r.splice(-1,0,i[s].currency.symbol);r=r.join("")}else r+=i[s].currency.symbol;return r}function h(e,t){t=t.replace("%","");e._n=e._n*100;var n=f(e,t);if(n.indexOf(")")>-1){n=n.split("");n.splice(-1,0,"%");n=n.join("")}else n+="%";return n}function p(e,t){var n=Math.floor(e._n/60/60),r=Math.floor((e._n-n*60*60)/60),i=Math.round(e._n-n*60*60-r*60);return n+":"+(r<10?"0"+r:r)+":"+(i<10?"0"+i:i)}function d(e){var t=e.split(":"),n=0;if(t.length===3){n+=Number(t[0])*60*60;n+=Number(t[1])*60;n+=Number(t[2])}else if(t.lenght===2){n+=Number(t[0])*60;n+=Number(t[1])}return Number(n)}function v(e,t){var n=!1,r=!1,o=!1,u=!1;if(t.indexOf("(")>-1){n=!0;t=t.slice(1,-1)}if(t.indexOf("a")>-1){t=t.replace("a","");if(e._n>1e6){r=i[s].abbreviations.million;e._n=e._n/1e6}else{r=i[s].abbreviations.thousand;e._n=e._n/1e3}}if(t.indexOf("b")>-1){t=t.replace("b","");var f=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],l,c;for(var h=0;h<=f.length;h++){l=Math.pow(1024,h);c=Math.pow(1024,h+1);if(e._n>l&&e._n<c){o=f[h];l>0&&(e._n=e._n/l);break}}}if(t.indexOf("o")>-1){t=t.replace("o","");u=i[s].ordinal(e._n)}var p=e._n.toString().split(".")[0],d=t.split(".")[1],v=t.indexOf(","),m="",g=!1;if(e._n<0){p=p.slice(1);g=!0}v>-1&&(p=p.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+i[s].delimiters.thousands));t.indexOf(".")===0&&(p="");if(d){if(d.indexOf("[")>-1){d=d.replace("]","");d=d.split("[");m=a(e._n,d[0].length+d[1].length,d[1].length).split(".")[1]}else m=a(e._n,d.length).split(".")[1];m&&(m=i[s].delimiters.decimal+m)}return(n&&g?"(":"")+(!n&&g?"-":"")+p+m+(u?u:"")+(r?r:"")+(o?o:"")+(n&&g?")":"")}function m(e,t){i[e]=t}var e,t="1.2.6",n=Math.round,r,i={},s="en",o=typeof module!="undefined"&&module.exports;e=function(t){e.isNumeral(t)?t=t.value():Number(t)||(t=0);return new u(Number(t))};e.isNumeral=function(e){return e instanceof u};e.version=t;e.isNumeral=function(e){return e instanceof u};e.language=function(e,t){if(!e)return s;e&&!t&&(s=e);(t||!i[e])&&m(e,t);return i};e.language("en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m"},ordinal:function(e){var t=e%10;return~~(e%100/10)===1?"th":t===1?"st":t===2?"nd":t===3?"rd":"th"},currency:{symbol:"$"}});e.fn=u.prototype={clone:function(){return e(this)},format:function(t){return f(this,t?t:e.defaultFormat)},unformat:function(t){return l(this,t?t:e.defaultFormat)},value:function(){return this._n},set:function(e){this._n=Number(e);return this},add:function(e){this._n=this._n+Number(e);return this},subtract:function(e){this._n=this._n-Number(e);return this},multiply:function(e){this._n=this._n*Number(e);return this},divide:function(e){this._n=this._n/Number(e);return this},difference:function(e){var t=this._n-Number(e);t<0&&(t=-t);return t}};o&&(module.exports=e);typeof ender=="undefined"&&(this.numeral=e);typeof define=="function"&&define.amd&&define([],function(){return e})}).call(this); |
114
numeral.js
// numeral.js | ||
// version : 1.2.3 | ||
// version : 1.2.6 | ||
// author : Adam Draper | ||
@@ -15,3 +15,3 @@ // license : MIT | ||
var numeral, | ||
VERSION = '1.2.3', | ||
VERSION = '1.2.6', | ||
round = Math.round, i, | ||
@@ -38,10 +38,18 @@ // internal storage for language config files | ||
* | ||
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === "0.61") that present | ||
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present | ||
* problems for accounting- and finance-related software. | ||
*/ | ||
function toFixed (value, precision) { | ||
var power = Math.pow(10, precision); | ||
function toFixed (value, precision, optionals) { | ||
var power = Math.pow(10, precision), | ||
output; | ||
// Multiply up by precision, round accurately, then divide and use native toFixed(): | ||
return (Math.round(value * power) / power).toFixed(precision); | ||
output = (Math.round(value * power) / power).toFixed(precision); | ||
if (optionals) { | ||
var optionalsRegExp = new RegExp('0{1,' + optionals + '}$'); | ||
output = output.replace(optionalsRegExp, ''); | ||
} | ||
return output; | ||
} | ||
@@ -64,3 +72,3 @@ | ||
output = formatTime(n, format); | ||
} else { // plain ol' number | ||
} else { // plain ol' numbers or bytes | ||
output = formatNumber(n, format); | ||
@@ -81,5 +89,24 @@ } | ||
} | ||
// see if abbreviations are there so that we can multiply to the correct number | ||
var thousandRegExp = new RegExp(languages[currentLanguage].abbreviations.thousand + '(?:\\)|\\' + languages[currentLanguage].currency.symbol + '?)$'), | ||
millionRegExp = new RegExp(languages[currentLanguage].abbreviations.million + '(?:\\)|\\' + languages[currentLanguage].currency.symbol + '?)$'); | ||
n._n = ((string.match(thousandRegExp)) ? 1000 : 1) * ((string.match(millionRegExp)) ? 1000000 : 1) * ((string.indexOf('%') > -1) ? 0.01 : 1) * Number(((string.indexOf('(') > -1) ? '-' : '') + string.replace(/[^0-9\.'-]+/g, '')); | ||
// see if bytes are there so that we can multiply to the correct number | ||
var prefixes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
bytesMultiplier = false; | ||
for (var power = 0; power <= prefixes.length; power++) { | ||
bytesMultiplier = (string.indexOf(prefixes[power]) > -1) ? Math.pow(1024, power + 1) : false; | ||
if (bytesMultiplier) { | ||
break; | ||
} | ||
} | ||
// do some math to create our number | ||
n._n = ((bytesMultiplier) ? bytesMultiplier : 1) * ((string.match(thousandRegExp)) ? 1000 : 1) * ((string.match(millionRegExp)) ? 1000000 : 1) * ((string.indexOf('%') > -1) ? 0.01 : 1) * Number(((string.indexOf('(') > -1) ? '-' : '') + string.replace(/[^0-9\.'-]+/g, '')); | ||
// round if we are talking about bytes | ||
n._n = (bytesMultiplier) ? Math.ceil(n._n) : n._n; | ||
} | ||
@@ -90,11 +117,29 @@ return n._n; | ||
function formatCurrency (n, format) { | ||
var prependSymbol = (format.indexOf('$') <= 1) ? true : false; | ||
// remove $ for the moment | ||
format = format.replace('$', ''); | ||
// format the number | ||
var output = formatNumeral(n, format); | ||
if (output.indexOf('(') > -1 || output.indexOf('-') > -1) { | ||
output = output.split(''); | ||
output.splice(1, 0, languages[currentLanguage].currency.symbol); | ||
output = output.join(''); | ||
// position the symbol | ||
if (prependSymbol) { | ||
if (output.indexOf('(') > -1 || output.indexOf('-') > -1) { | ||
output = output.split(''); | ||
output.splice(1, 0, languages[currentLanguage].currency.symbol); | ||
output = output.join(''); | ||
} else { | ||
output = languages[currentLanguage].currency.symbol + output; | ||
} | ||
} else { | ||
output = languages[currentLanguage].currency.symbol + output; | ||
if (output.indexOf(')') > -1) { | ||
output = output.split(''); | ||
output.splice(-1, 0, languages[currentLanguage].currency.symbol); | ||
output = output.join(''); | ||
} else { | ||
output = output + languages[currentLanguage].currency.symbol; | ||
} | ||
} | ||
return output; | ||
@@ -147,2 +192,3 @@ } | ||
abbr = false, | ||
bytes = false, | ||
ord = false; | ||
@@ -169,2 +215,24 @@ | ||
// see if we are formatting bytes | ||
if (format.indexOf('b') > -1) { | ||
format = format.replace('b', ''); | ||
var prefixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | ||
min, | ||
max; | ||
for (var power = 0; power <= prefixes.length; power++) { | ||
min = Math.pow(1024, power); | ||
max = Math.pow(1024, power+1); | ||
if (n._n > min && n._n < max) { | ||
bytes = prefixes[power]; | ||
if (min > 0) { | ||
n._n = n._n / min; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
// see if ordinal is wanted | ||
@@ -198,11 +266,19 @@ if (format.indexOf('o') > -1) { | ||
if (precision) { | ||
// do to fixed | ||
d = languages[currentLanguage].delimiters.decimal + toFixed(n._n, precision.length).split('.')[1]; | ||
} | ||
if (precision.indexOf('[') > -1) { | ||
precision = precision.replace(']', ''); | ||
precision = precision.split('['); | ||
d = toFixed(n._n, (precision[0].length + precision[1].length), precision[1].length).split('.')[1]; | ||
if (abbr) { | ||
// go throg | ||
} else { | ||
// do to fixed | ||
d = toFixed(n._n, precision.length).split('.')[1]; | ||
} | ||
if (d) { | ||
d = languages[currentLanguage].delimiters.decimal + d; | ||
} | ||
} | ||
return ((negP && neg) ? '(' : '') + ((!negP && neg) ? '-' : '') + w + d + ((ord) ? ord : '') + ((abbr) ? abbr : '') + ((negP && neg) ? ')' : ''); | ||
return ((negP && neg) ? '(' : '') + ((!negP && neg) ? '-' : '') + w + d + ((ord) ? ord : '') + ((abbr) ? abbr : '') + ((bytes) ? bytes : '') + ((negP && neg) ? ')' : ''); | ||
} | ||
@@ -359,3 +435,3 @@ | ||
// add `numeral` as a global object via a string identifier, | ||
// for Closure Compiler "advanced" mode | ||
// for Closure Compiler 'advanced' mode | ||
this['numeral'] = numeral; | ||
@@ -362,0 +438,0 @@ } |
{ | ||
"name": "numeral", | ||
"version": "1.2.3", | ||
"version": "1.2.5", | ||
"description": "Format and manipulate numbers.", | ||
@@ -37,5 +37,5 @@ "homepage": "http://numeraljs.com", | ||
"ender": "./ender.js", | ||
"readme": "[Numeral.js](http://numeraljs.com)\n=======================================================\n\nA javascript library for formatting and manipulating numbers.\n\n[Website and documentation](http://adamwdraper.github.com/Numeral-js/)\n\nChangelog\n=========\n\n### 1.2.2\nChanged language definition property 'money' to 'currency'\n### 1.2.1\nBug fix: Fix unformatting non-negative abbreviations\n### 1.2.3\nBug Fix: Fix unformatting for languages that use '.' as thousands delimiter\n### 1.2.0\nAdd localization language support\n\nUpdate testing for to include languages\n### 1.1.0\nAdd Tests\n\nBug fix: Fix difference returning negative values\n### 1.0.4\nBug fix: Non negative numbers were displaying as negative when using parentheses\n### 1.0.3\nAdd ordinal formatting using 'o' in the format\n### 1.0.2\nAdd clone functionality\n### 1.0.1\n\nAdded abbreviations for thousands and millions using 'a' in the format\n\n### 1.0.0\n\nInitial release\n\nAcknowlegements\n===============\n\nNumeral.js, while less complex, was inspired by and heavily borrowed from [Moment.js](http://momentjs.com)\n\nLicense\n=======\nNumeral.js is freely distributable under the terms of the MIT license.\nCopyright (c) 2012 Adam Draper\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", | ||
"_id": "numeral@1.2.3", | ||
"readme": "[Numeral.js](http://numeraljs.com)\n=======================================================\n\nA javascript library for formatting and manipulating numbers.\n\n[Website and documentation](http://numeraljs.com)\n\nChangelog\n=========\n\n### 1.2.6\nAdd support for optional decimal places\n### 1.2.5\nAdd support for appending currency symbol\n### 1.2.4\nAdd support for humanized filesizes\n### 1.2.2\nChanged language definition property 'money' to 'currency'\n### 1.2.1\nBug fix: Fix unformatting non-negative abbreviations\n### 1.2.3\nBug Fix: Fix unformatting for languages that use '.' as thousands delimiter\n### 1.2.0\nAdd localization language support\n\nUpdate testing for to include languages\n### 1.1.0\nAdd Tests\n\nBug fix: Fix difference returning negative values\n### 1.0.4\nBug fix: Non negative numbers were displaying as negative when using parentheses\n### 1.0.3\nAdd ordinal formatting using 'o' in the format\n### 1.0.2\nAdd clone functionality\n### 1.0.1\n\nAdded abbreviations for thousands and millions using 'a' in the format\n\n### 1.0.0\n\nInitial release\n\nAcknowlegements\n===============\n\nNumeral.js, while less complex, was inspired by and heavily borrowed from [Moment.js](http://momentjs.com)\n\nLicense\n=======\nNumeral.js is freely distributable under the terms of the MIT license.\nCopyright (c) 2012 Adam Draper\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use,copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", | ||
"_id": "numeral@1.2.5", | ||
"_from": "numeral" | ||
} |
@@ -12,2 +12,14 @@ [Numeral.js](http://adamwdraper.github.com/Numeral-js/) | ||
### 1.2.6 | ||
Add support for optional decimal places | ||
### 1.2.5 | ||
Add support for appending currency symbol | ||
### 1.2.4 | ||
Add support for humanized filesizes | ||
### 1.2.3 | ||
@@ -14,0 +26,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49898
19
837
88