diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 00000000..a8f838c5 --- /dev/null +++ b/.jshintignore @@ -0,0 +1,3 @@ +node_modules/ +dist/ +*.min.* diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 00000000..22a12500 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,78 @@ +{ + + // == Enforcing Options =============================================== + // + // These options tell JSHint to be more strict towards your code. + + "bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.). + "camelcase" : true, // Force all variable names to use either camelCase style or UPPER_CASE with underscores. + "curly" : true, // Require {} for every new block or scope. + "eqeqeq" : true, // Require triple equals i.e. `===`. + "es3" : false, // Adhere to ECMAScript 3 specification for legacy browsers like Internet Explorer 6/7/8. + "forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`. + "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` + "indent" : 4, // Specify indentation spacing + "latedef" : true, // Prohibit variable use before definition. + "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. + "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`. + "noempty" : true, // Prohibit use of empty blocks. + "nonew" : true, // Prohibit use of constructors for side-effects. + "plusplus" : false, // Prohibit use of `++` & `--`. + "quotmark" : "single", // Forces single quotes for strings + "undef" : true, // Require all non-global variables be declared before they are used. + "unused" : true, // Prevent declaring unused functions and variables. + "strict" : true, // Require `use strict` pragma in every file. + "maxparams" : 4, // Set the max number of formal parameters allowed per function + "maxlen" : 120, // Set the maximum line length + + // == Relaxing Options ================================================ + // + // These options allow you to suppress certain types of warnings. Use + // them only if you are absolutely positive that you know what you are + // doing. + + "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons). + "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. + "debug" : false, // Allow debugger statements e.g. browser breakpoints. + "eqnull" : false, // Tolerate use of `== null`. + "esnext" : false, // Allow ES.next specific features such as `const` and `let`. + "evil" : false, // Tolerate use of `eval`. + "expr" : false, // Tolerate `ExpressionStatement` as Programs. + "funcscope" : false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside. + "globalstrict" : false, // Allow global "use strict" (also enables 'strict'). + "iterator" : false, // Allow usage of __iterator__ property. + "lastsemic" : false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block. + "laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. + "laxcomma" : false, // Suppress warnings about comma-first coding style. + "loopfunc" : false, // Allow functions to be defined within loops. + "moz" : false, // Use Mozilla JavaScript extensions. Unless you develop specifically for the Firefox web browser you don't need this option. + "multistr" : false, // Tolerate multi-line strings. + "proto" : false, // Tolerate __proto__ property. This property is deprecated. + "scripturl" : false, // Tolerate script-targeted URLs. + "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`. + "sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. + "supernew" : false, // Tolerate `new function () { ... };` and `new Object;`. + "validthis" : false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function. + + // == Environments ==================================================== + // + // These options pre-define global variables that are exposed by + // popular JavaScript libraries and runtime environments—such as + // browser or node.js. + + "browser" : true, // Standard browser globals e.g. `window`, `document`. + "couch" : false, // Enable globals exposed by CouchDB. + "devel" : false, // Allow development statements e.g. `console.log();`. + "jquery" : false, // Enable globals exposed by jQuery JavaScript library. + "node" : true, // Enable globals available when code is running inside of the NodeJS runtime environment. + "nonstandard" : false, // Define non-standard but widely adopted globals such as escape and unescape. + "wsh" : false, // Enable globals available when your code is running as a script for the Windows Script Host. + + // == Global Variables ================================================ + // + // These will be ignored by jsHint and will not throw warning caused by the + // debug or undef options + + "globals": { + } +} diff --git a/Gruntfile.js b/Gruntfile.js index 39616767..104f4055 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,6 +2,7 @@ var fs = require('fs'); var path = require('path'); module.exports = function(grunt) { + 'use strict'; grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), @@ -15,7 +16,7 @@ module.exports = function(grunt) { }, }, uglify: { - my_target: { + target: { files: [ { src: [ 'dist/languages.js' ], dest: 'dist/min/languages.min.js', }, { src: [ 'numbro.js' ], dest: 'dist/min/numbro.min.js', }, @@ -44,7 +45,8 @@ module.exports = function(grunt) { createTag: false, push: false, globalReplace: true, - regExp: new RegExp('([\'|\"]?version[\'|\"]?[ ]*[:=][ ]*[\'|\"]?)(\\d+\\.\\d+\\.\\d+(-\\.\\d+)?(-\\d+)?)[\\d||A-a|.|-]*([\'|\"]?)') + regExp: new RegExp('([\'|\"]?version[\'|\"]?[ ]*[:=][ ]*[\'|\"]?)'+ + '(\\d+\\.\\d+\\.\\d+(-\\.\\d+)?(-\\d+)?)[\\d||A-a|.|-]*([\'|\"]?)') }, }, confirm: { @@ -69,26 +71,14 @@ module.exports = function(grunt) { all: ['tests/**/*.js'], }, jshint: { + options: { + jshintrc : '.jshintrc' + }, all: [ 'Gruntfile.js', 'numbro.js', 'languages/**/*.js' - ], - options: { - 'node': true, - 'browser': true, - 'curly': true, - 'devel': false, - 'eqeqeq': true, - 'eqnull': true, - 'newcap': true, - 'noarg': true, - 'onevar': true, - 'undef': true, - 'sub': true, - 'strict': false, - 'quotmark': 'single' - } + ] } }); diff --git a/languages/cs-CZ.js b/languages/cs-CZ.js index d6bc175e..028f2484 100644 --- a/languages/cs-CZ.js +++ b/languages/cs-CZ.js @@ -4,6 +4,8 @@ * author : Anatoli Papirovski : https://github.com/apapirovski */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/da-DK.js b/languages/da-DK.js index 2365c941..f143c351 100644 --- a/languages/da-DK.js +++ b/languages/da-DK.js @@ -4,6 +4,8 @@ * author : Michael Storgaard : https://github.com/mstorgaard */ (function () { + 'use strict'; + var language = { delimiters: { thousands: '.', @@ -15,7 +17,7 @@ billion: 'mia', trillion: 'b' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/de-DE.js b/languages/de-DE.js index eca5ffaf..3c045eed 100644 --- a/languages/de-DE.js +++ b/languages/de-DE.js @@ -4,6 +4,8 @@ * author : Marco Krage : https://github.com/sinky */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', @@ -15,7 +17,7 @@ billion: 'b', trillion: 't' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/de-ch.js b/languages/de-ch.js index 6e1c3d7d..0f4018f9 100644 --- a/languages/de-ch.js +++ b/languages/de-ch.js @@ -4,6 +4,8 @@ * author : Michael Piefel : https://github.com/piefel (based on work from Marco Krage : https://github.com/sinky) */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', @@ -15,7 +17,7 @@ billion: 'b', trillion: 't' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/en-GB.js b/languages/en-GB.js index 5401c3c7..2ef7d840 100644 --- a/languages/en-GB.js +++ b/languages/en-GB.js @@ -4,6 +4,8 @@ * author : Dan Ristic : https://github.com/dristic */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ',', diff --git a/languages/es-AR.js b/languages/es-AR.js index 7e7525c8..381239ed 100644 --- a/languages/es-AR.js +++ b/languages/es-AR.js @@ -4,6 +4,8 @@ * author : Hernan Garcia : https://github.com/hgarcia */ (function () { + 'use strict'; + var language = { delimiters: { thousands: '.', diff --git a/languages/es-ES.js b/languages/es-ES.js index 58b0b0be..ad5379ec 100644 --- a/languages/es-ES.js +++ b/languages/es-ES.js @@ -4,6 +4,8 @@ * author : Hernan Garcia : https://github.com/hgarcia */ (function () { + 'use strict'; + var language = { delimiters: { thousands: '.', diff --git a/languages/et-EE.js b/languages/et-EE.js index 8df069a0..c309cefc 100644 --- a/languages/et-EE.js +++ b/languages/et-EE.js @@ -7,6 +7,8 @@ * from numbers with a space */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', @@ -18,7 +20,7 @@ billion: ' mld', trillion: ' trl' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/fa-IR.js b/languages/fa-IR.js index 5fef3768..a6a38e53 100644 --- a/languages/fa-IR.js +++ b/languages/fa-IR.js @@ -4,6 +4,8 @@ * author : neo13 : https://github.com/neo13 */ (function () { + 'use strict'; + var language = { delimiters: { thousands: '،', @@ -15,7 +17,7 @@ billion: 'میلیارد', trillion: 'تریلیون' }, - ordinal: function (number) { + ordinal: function () { return 'ام'; }, currency: { diff --git a/languages/fi-FI.js b/languages/fi-FI.js index 704e6999..20d7ced0 100644 --- a/languages/fi-FI.js +++ b/languages/fi-FI.js @@ -4,6 +4,8 @@ * author : Sami Saada : https://github.com/samitheberber */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', @@ -15,7 +17,7 @@ billion: 'G', trillion: 'T' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/fil-PH.js b/languages/fil-PH.js index 6471ac62..897118dd 100644 --- a/languages/fil-PH.js +++ b/languages/fil-PH.js @@ -4,6 +4,8 @@ * author : Michael Abadilla : https://github.com/mjmaix */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ',', diff --git a/languages/fr-CA.js b/languages/fr-CA.js index a22f2881..a23c9a28 100644 --- a/languages/fr-CA.js +++ b/languages/fr-CA.js @@ -4,6 +4,8 @@ * author : Léo Renaud-Allaire : https://github.com/renaudleo */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/fr-CH.js b/languages/fr-CH.js index 8cba24a8..c547d5ff 100644 --- a/languages/fr-CH.js +++ b/languages/fr-CH.js @@ -4,6 +4,8 @@ * author : Adam Draper : https://github.com/adamwdraper */ (function () { + 'use strict'; + var language = { delimiters: { thousands: '\'', diff --git a/languages/fr-FR.js b/languages/fr-FR.js index 1708ff48..deafcbbc 100644 --- a/languages/fr-FR.js +++ b/languages/fr-FR.js @@ -4,6 +4,8 @@ * author : Adam Draper : https://github.com/adamwdraper */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/hu-HU.js b/languages/hu-HU.js index 1fc162ba..1799ab00 100644 --- a/languages/hu-HU.js +++ b/languages/hu-HU.js @@ -4,6 +4,8 @@ * author : Peter Bakondy : https://github.com/pbakondy */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', @@ -15,7 +17,7 @@ billion: 'Mrd', // milliárd trillion: 'T' // trillió }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/it-IT.js b/languages/it-IT.js index c2158433..908df088 100644 --- a/languages/it-IT.js +++ b/languages/it-IT.js @@ -4,6 +4,8 @@ * author : Giacomo Trombi : http://cinquepunti.it */ (function () { + 'use strict'; + var language = { delimiters: { thousands: '.', @@ -15,7 +17,7 @@ billion: 'b', trillion: 't' }, - ordinal: function (number) { + ordinal: function () { return 'º'; }, currency: { diff --git a/languages/ja-JP.js b/languages/ja-JP.js index 2f6aa462..20c8e1c1 100644 --- a/languages/ja-JP.js +++ b/languages/ja-JP.js @@ -4,6 +4,8 @@ * author : teppeis : https://github.com/teppeis */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ',', @@ -15,7 +17,7 @@ billion: '十億', trillion: '兆' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/lv-LV.js b/languages/lv-LV.js index 5bf75561..6ed3d4fc 100644 --- a/languages/lv-LV.js +++ b/languages/lv-LV.js @@ -4,6 +4,8 @@ * author : Lauris Bukšis-Haberkorns : https://github.com/Lafriks */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', @@ -15,7 +17,7 @@ billion: ' mljrd.', trillion: ' trilj.' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/nb-NO.js b/languages/nb-NO.js index a4a96a34..748a9503 100644 --- a/languages/nb-NO.js +++ b/languages/nb-NO.js @@ -4,6 +4,8 @@ * author : Benjamin Van Ryseghem */ (function() { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/nl-BE.js b/languages/nl-BE.js index 262bf4ee..2a5ef345 100644 --- a/languages/nl-BE.js +++ b/languages/nl-BE.js @@ -4,6 +4,8 @@ * author : Dieter Luypaert : https://github.com/moeriki */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/nl-NL.js b/languages/nl-NL.js index feaf9e9f..42d8be95 100644 --- a/languages/nl-NL.js +++ b/languages/nl-NL.js @@ -4,6 +4,8 @@ * author : Dave Clayton : https://github.com/davedx */ (function () { + 'use strict'; + var language = { delimiters: { thousands: '.', diff --git a/languages/pl-PL.js b/languages/pl-PL.js index 875f1b6e..8b6073e9 100644 --- a/languages/pl-PL.js +++ b/languages/pl-PL.js @@ -4,6 +4,8 @@ * author : Dominik Bulaj : https://github.com/dominikbulaj */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', @@ -15,7 +17,7 @@ billion: 'mld', trillion: 'bln' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/pt-BR.js b/languages/pt-BR.js index 4a639a2c..64e275e2 100644 --- a/languages/pt-BR.js +++ b/languages/pt-BR.js @@ -4,6 +4,8 @@ * author : Ramiro Varandas Jr : https://github.com/ramirovjr */ (function () { + 'use strict'; + var language = { delimiters: { thousands: '.', @@ -15,7 +17,7 @@ billion: 'b', trillion: 't' }, - ordinal: function (number) { + ordinal: function () { return 'º'; }, currency: { diff --git a/languages/pt-PT.js b/languages/pt-PT.js index fce0c10f..094b2687 100644 --- a/languages/pt-PT.js +++ b/languages/pt-PT.js @@ -4,6 +4,8 @@ * author : Diogo Resende : https://github.com/dresende */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', @@ -15,7 +17,7 @@ billion: 'b', trillion: 't' }, - ordinal : function (number) { + ordinal : function () { return 'º'; }, currency: { diff --git a/languages/ru-RU.js b/languages/ru-RU.js index fb2dbeea..cf81642d 100644 --- a/languages/ru-RU.js +++ b/languages/ru-RU.js @@ -4,6 +4,8 @@ * author : Anatoli Papirovski : https://github.com/apapirovski */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/ru-UA.js b/languages/ru-UA.js index 89ec7666..d1491d22 100644 --- a/languages/ru-UA.js +++ b/languages/ru-UA.js @@ -2,6 +2,8 @@ // language : Russian for the Ukraine (ru-UA) // author : Anatoli Papirovski : https://github.com/apapirovski (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/sk-SK.js b/languages/sk-SK.js index c34a386b..387378c2 100644 --- a/languages/sk-SK.js +++ b/languages/sk-SK.js @@ -4,6 +4,8 @@ * author : Ahmed Al Hafoudh : http://www.freevision.sk */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/sv-SE.js b/languages/sv-SE.js index c62e82a8..4a5de87f 100644 --- a/languages/sv-SE.js +++ b/languages/sv-SE.js @@ -4,6 +4,8 @@ * author : Benjamin Van Ryseghem (benjamin.vanryseghem.com) */ (function() { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/th-TH.js b/languages/th-TH.js index b5b3bf0b..6b1c844a 100644 --- a/languages/th-TH.js +++ b/languages/th-TH.js @@ -4,6 +4,8 @@ * author : Sathit Jittanupat : https://github.com/jojosati */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ',', @@ -15,7 +17,7 @@ billion: 'พันล้าน', trillion: 'ล้านล้าน' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/languages/tr-TR.js b/languages/tr-TR.js index 2bf39c04..7325b796 100644 --- a/languages/tr-TR.js +++ b/languages/tr-TR.js @@ -1,9 +1,13 @@ /*! * numbro.js language configuration * language : turkish (tr) - * author : Ecmel Ercan : https://github.com/ecmel, Erhan Gundogan : https://github.com/erhangundogan, Burak Yiğit Kaya: https://github.com/BYK + * author : Ecmel Ercan : https://github.com/ecmel, + * Erhan Gundogan : https://github.com/erhangundogan, + * Burak Yiğit Kaya: https://github.com/BYK */ (function() { + 'use strict'; + var suffixes = { 1: '\'inci', 5: '\'inci', diff --git a/languages/uk-UA.js b/languages/uk-UA.js index 594c0e55..fd633616 100644 --- a/languages/uk-UA.js +++ b/languages/uk-UA.js @@ -2,6 +2,8 @@ // language : Ukrainian for the Ukraine (uk-UA) // author : Michael Piefel : https://github.com/piefel (with help from Tetyana Kuzmenko) (function () { + 'use strict'; + var language = { delimiters: { thousands: ' ', diff --git a/languages/zh-CN.js b/languages/zh-CN.js index 6b3e0058..57328f48 100644 --- a/languages/zh-CN.js +++ b/languages/zh-CN.js @@ -4,6 +4,8 @@ * author : badplum : https://github.com/badplum */ (function () { + 'use strict'; + var language = { delimiters: { thousands: ',', @@ -15,7 +17,7 @@ billion: '十亿', trillion: '兆' }, - ordinal: function (number) { + ordinal: function () { return '.'; }, currency: { diff --git a/numbro.js b/numbro.js index 8fcc9573..259d08de 100644 --- a/numbro.js +++ b/numbro.js @@ -6,7 +6,8 @@ * http://www.foretagsplatsen.se */ -(function() { +(function () { + 'use strict'; /************************************ Constants @@ -103,10 +104,14 @@ } // see if abbreviations are there so that we can multiply to the correct number - thousandRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.thousand + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); - millionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.million + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); - billionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.billion + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); - trillionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.trillion + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); + thousandRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.thousand + + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); + millionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.million + + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); + billionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.billion + + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); + trillionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.trillion + + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); // see if bytes are there so that we can multiply to the correct number for (power = 0; power <= binarySuffixes.length && !bytesMultiplier; power++) { @@ -118,7 +123,15 @@ } // do some math to create our number - n._value = ((bytesMultiplier) ? bytesMultiplier : 1) * ((stringOriginal.match(thousandRegExp)) ? Math.pow(10, 3) : 1) * ((stringOriginal.match(millionRegExp)) ? Math.pow(10, 6) : 1) * ((stringOriginal.match(billionRegExp)) ? Math.pow(10, 9) : 1) * ((stringOriginal.match(trillionRegExp)) ? Math.pow(10, 12) : 1) * ((string.indexOf('%') > -1) ? 0.01 : 1) * (((string.split('-').length + Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2) ? 1 : -1) * Number(string.replace(/[^0-9\.]+/g, '')); + n._value = ((bytesMultiplier) ? bytesMultiplier : 1) * + ((stringOriginal.match(thousandRegExp)) ? Math.pow(10, 3) : 1) * + ((stringOriginal.match(millionRegExp)) ? Math.pow(10, 6) : 1) * + ((stringOriginal.match(billionRegExp)) ? Math.pow(10, 9) : 1) * + ((stringOriginal.match(trillionRegExp)) ? Math.pow(10, 12) : 1) * + ((string.indexOf('%') > -1) ? 0.01 : 1) * + (((string.split('-').length + + Math.min(string.split('(').length - 1, string.split(')').length - 1)) % 2) ? 1 : -1) * + Number(string.replace(/[^0-9\.]+/g, '')); // round if we are talking about bytes n._value = (bytesMultiplier) ? Math.ceil(n._value) : n._value; @@ -249,7 +262,9 @@ var hours = Math.floor(n._value / 60 / 60), minutes = Math.floor((n._value - (hours * 60 * 60)) / 60), seconds = Math.round(n._value - (hours * 60 * 60) - (minutes * 60)); - return hours + ':' + ((minutes < 10) ? '0' + minutes : minutes) + ':' + ((seconds < 10) ? '0' + seconds : seconds); + return hours + ':' + + ((minutes < 10) ? '0' + minutes : minutes) + ':' + + ((seconds < 10) ? '0' + seconds : seconds); } function unformatTime(string) { @@ -466,7 +481,8 @@ if (precision.indexOf('[') > -1) { precision = precision.replace(']', ''); precision = precision.split('['); - d = toFixed(value, (precision[0].length + precision[1].length), roundingFunction, precision[1].length); + d = toFixed(value, (precision[0].length + precision[1].length), roundingFunction, + precision[1].length); } else { d = toFixed(value, precision.length, roundingFunction); } @@ -494,7 +510,8 @@ } if (thousands > -1) { - w = w.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + languages[currentLanguage].delimiters.thousands); + w = w.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + + languages[currentLanguage].delimiters.thousands); } if (format.indexOf('.') === 0) { @@ -511,7 +528,12 @@ } - return paren + ((!neg && signed) ? '+' : '') + w + d + ((ord) ? ord : '') + ((abbr && !sep) ? abbr : '') + ((bytes) ? bytes : '') + ((negP && neg) ? ')' : ''); + return paren + ((!neg && signed) ? '+' : '') + + w + d + + ((ord) ? ord : '') + + ((abbr && !sep) ? abbr : '') + + ((bytes) ? bytes : '') + + ((negP && neg) ? ')' : ''); } } @@ -712,7 +734,8 @@ temp = val.match(/[^\d]+$/); if (temp !== null) { val = val.slice(0, -1); - if (temp[0] !== _abbrObj.thousand && temp[0] !== _abbrObj.million && temp[0] !== _abbrObj.billion && temp[0] !== _abbrObj.trillion) { + if (temp[0] !== _abbrObj.thousand && temp[0] !== _abbrObj.million && + temp[0] !== _abbrObj.billion && temp[0] !== _abbrObj.trillion) { return false; } } @@ -728,9 +751,13 @@ return ( !! _valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx)); } else { if (_valArray[0].length === 1) { - return ( !! _valArray[0].match(/^\d+$/) && !_valArray[0].match(_thousandRegEx) && !! _valArray[1].match(/^\d+$/)); + return ( !! _valArray[0].match(/^\d+$/) && + !_valArray[0].match(_thousandRegEx) && + !! _valArray[1].match(/^\d+$/)); } else { - return ( !! _valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx) && !! _valArray[1].match(/^\d+$/)); + return ( !! _valArray[0].match(/^\d+.*\d$/) && + !_valArray[0].match(_thousandRegEx) && + !! _valArray[1].match(/^\d+$/)); } } } @@ -759,8 +786,7 @@ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Compatibility */ if ('function' !== typeof Array.prototype.reduce) { - Array.prototype.reduce = function(callback, opt_initialValue) { - 'use strict'; + Array.prototype.reduce = function(callback, optInitialValue) { if (null === this || 'undefined' === typeof this) { // At the moment all modern browsers, that support strict mode, have @@ -779,7 +805,7 @@ isValueSet = false; if (1 < arguments.length) { - value = opt_initialValue; + value = optInitialValue; isValueSet = true; } @@ -844,7 +870,8 @@ format: function(inputString, roundingFunction) { return formatNumbro(this, - inputString ? inputString : defaultFormat, (roundingFunction !== undefined) ? roundingFunction : Math.round + inputString ? inputString : defaultFormat, + (roundingFunction !== undefined) ? roundingFunction : Math.round ); }, @@ -878,7 +905,7 @@ add: function(value) { var corrFactor = correctionFactor.call(null, this._value, value); - function cback(accum, curr, currI, O) { + function cback(accum, curr) { return accum + corrFactor * curr; } this._value = [this._value, value].reduce(cback, 0) / corrFactor; @@ -888,7 +915,7 @@ subtract: function(value) { var corrFactor = correctionFactor.call(null, this._value, value); - function cback(accum, curr, currI, O) { + function cback(accum, curr) { return accum - corrFactor * curr; } this._value = [value].reduce(cback, this._value * corrFactor) / corrFactor; @@ -896,7 +923,7 @@ }, multiply: function(value) { - function cback(accum, curr, currI, O) { + function cback(accum, curr) { var corrFactor = correctionFactor(accum, curr); return (accum * corrFactor) * (curr * corrFactor) / (corrFactor * corrFactor); @@ -906,7 +933,7 @@ }, divide: function(value) { - function cback(accum, curr, currI, O) { + function cback(accum, curr) { var corrFactor = correctionFactor(accum, curr); return (accum * corrFactor) / (curr * corrFactor); } @@ -934,7 +961,7 @@ // here, `this` means `window` in the browser, or `global` on the server // add `numbro` as a global object via a string identifier, // for Closure Compiler 'advanced' mode - this['numbro'] = numbro; + this.numbro = numbro; } /*global define:false */ diff --git a/tests/.jshintrc b/tests/.jshintrc new file mode 100644 index 00000000..f44e7914 --- /dev/null +++ b/tests/.jshintrc @@ -0,0 +1,19 @@ +{ + "extends": "../.jshintrc", + + // == Relaxing Options ================================================ + // + // These options allow you to suppress certain types of warnings. Use + // them only if you are absolutely positive that you know what you are + // doing. + + "globalstrict" : true, // Allow global "use strict" (also enables 'strict'). + + // == Environments ==================================================== + // + // These options pre-define global variables that are exposed by + // popular JavaScript libraries and runtime environments—such as + // browser or node.js. + + "node" : true // Enable globals available when code is running inside of the NodeJS runtime environment. +} diff --git a/tests/languages/be-nl.js b/tests/languages/be-nl.js index 9f5076a5..3fd050ed 100644 --- a/tests/languages/be-nl.js +++ b/tests/languages/be-nl.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/nl-BE'); diff --git a/tests/languages/chs.js b/tests/languages/chs.js index dd59a599..09af53d2 100644 --- a/tests/languages/chs.js +++ b/tests/languages/chs.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'); var language = require('../../languages/zh-CN'); diff --git a/tests/languages/cs.js b/tests/languages/cs.js index 8ff1160c..6dee0a62 100644 --- a/tests/languages/cs.js +++ b/tests/languages/cs.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/cs-CZ'); diff --git a/tests/languages/da-dk.js b/tests/languages/da-dk.js index ec2385c4..4949313f 100644 --- a/tests/languages/da-dk.js +++ b/tests/languages/da-dk.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/da-DK'); diff --git a/tests/languages/de-ch.js b/tests/languages/de-ch.js index 04bbe066..72301ce6 100644 --- a/tests/languages/de-ch.js +++ b/tests/languages/de-ch.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/de-ch'); @@ -65,9 +67,9 @@ exports['language:de-ch'] = { var tests = [ [1,'0%','100%'], - [.974878234,'0.000%','97,488%'], - [-.43,'0%','-43%'], - [.43,'(0.000%)','43,000%'] + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] ]; for (var i = 0; i < tests.length; i++) { @@ -82,13 +84,13 @@ exports['language:de-ch'] = { var tests = [ ['10 000,123',10000.123], - ['(0,12345)',-.12345], + ['(0,12345)',-0.12345], ['(CHF1,23m)',-1230000], ['10k',10000], ['-10k',-10000], ['23.',23], ['CHF10 000,00',10000], - ['-76%',-.76], + ['-76%',-0.76], ['2:23:57',8637] ]; diff --git a/tests/languages/de.js b/tests/languages/de.js index a929b70b..2994c8b4 100644 --- a/tests/languages/de.js +++ b/tests/languages/de.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/de-DE'); diff --git a/tests/languages/en-gb.js b/tests/languages/en-gb.js index 6ffb9569..78b9f238 100644 --- a/tests/languages/en-gb.js +++ b/tests/languages/en-gb.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/en-GB'); diff --git a/tests/languages/en.js b/tests/languages/en.js index b9911d8d..ec3a9e47 100644 --- a/tests/languages/en.js +++ b/tests/languages/en.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'); exports['language:en'] = { diff --git a/tests/languages/es-ES.js b/tests/languages/es-ES.js index 079907ef..bbb3b6df 100644 --- a/tests/languages/es-ES.js +++ b/tests/languages/es-ES.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/es-ES'); diff --git a/tests/languages/es.js b/tests/languages/es.js index e48591f3..21459eea 100644 --- a/tests/languages/es.js +++ b/tests/languages/es.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/es-AR'); diff --git a/tests/languages/et.js b/tests/languages/et.js index b4d67d1a..5efdb522 100644 --- a/tests/languages/et.js +++ b/tests/languages/et.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/et-EE'); diff --git a/tests/languages/fa-IR.js b/tests/languages/fa-IR.js index 07fc5fdc..ffdc5151 100644 --- a/tests/languages/fa-IR.js +++ b/tests/languages/fa-IR.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/fa-IR'); diff --git a/tests/languages/fi.js b/tests/languages/fi.js index eb571e96..0e440689 100644 --- a/tests/languages/fi.js +++ b/tests/languages/fi.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/fi-FI'); diff --git a/tests/languages/fil-PH.js b/tests/languages/fil-PH.js index 063282b2..cbb79efb 100644 --- a/tests/languages/fil-PH.js +++ b/tests/languages/fil-PH.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/fil-PH'); diff --git a/tests/languages/fr-CA.js b/tests/languages/fr-CA.js index 6e27cddd..11d1928b 100644 --- a/tests/languages/fr-CA.js +++ b/tests/languages/fr-CA.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/fr-CA'); diff --git a/tests/languages/fr-ch.js b/tests/languages/fr-ch.js index 76d386cc..9a60be07 100644 --- a/tests/languages/fr-ch.js +++ b/tests/languages/fr-ch.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/fr-CH'); diff --git a/tests/languages/fr.js b/tests/languages/fr.js index b9155611..f67ae86f 100644 --- a/tests/languages/fr.js +++ b/tests/languages/fr.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/fr-FR'); diff --git a/tests/languages/hu.js b/tests/languages/hu.js index 9fa3f792..02fa0b13 100644 --- a/tests/languages/hu.js +++ b/tests/languages/hu.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/hu-HU'); diff --git a/tests/languages/it.js b/tests/languages/it.js index fe257e84..0adac1bd 100644 --- a/tests/languages/it.js +++ b/tests/languages/it.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/it-IT'); diff --git a/tests/languages/ja.js b/tests/languages/ja.js index 476d1cff..9465e03b 100644 --- a/tests/languages/ja.js +++ b/tests/languages/ja.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/ja-JP'); diff --git a/tests/languages/lv.js b/tests/languages/lv.js index fb84c699..61523a1e 100644 --- a/tests/languages/lv.js +++ b/tests/languages/lv.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/lv-LV'); diff --git a/tests/languages/nl-nl.js b/tests/languages/nl-nl.js index 59683cfb..1088c244 100644 --- a/tests/languages/nl-nl.js +++ b/tests/languages/nl-nl.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/nl-NL'); diff --git a/tests/languages/pl.js b/tests/languages/pl.js index 78c19d40..dad89c11 100644 --- a/tests/languages/pl.js +++ b/tests/languages/pl.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/pl-PL'); diff --git a/tests/languages/pt-br.js b/tests/languages/pt-br.js index 0b9e9156..6138427f 100644 --- a/tests/languages/pt-br.js +++ b/tests/languages/pt-br.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/pt-BR'); diff --git a/tests/languages/pt-pt.js b/tests/languages/pt-pt.js index 560f3e97..e61a6494 100644 --- a/tests/languages/pt-pt.js +++ b/tests/languages/pt-pt.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/pt-PT'); diff --git a/tests/languages/ru-UA.js b/tests/languages/ru-UA.js index d5e1116f..a4f87bee 100644 --- a/tests/languages/ru-UA.js +++ b/tests/languages/ru-UA.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/ru-UA'); diff --git a/tests/languages/ru.js b/tests/languages/ru.js index 252f51d0..17f2ef94 100644 --- a/tests/languages/ru.js +++ b/tests/languages/ru.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/ru-RU'); diff --git a/tests/languages/sk.js b/tests/languages/sk.js index 12747aac..42bb928b 100644 --- a/tests/languages/sk.js +++ b/tests/languages/sk.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/sk-SK'); diff --git a/tests/languages/sv-SE.js b/tests/languages/sv-SE.js index 0f227bad..0d6c7241 100644 --- a/tests/languages/sv-SE.js +++ b/tests/languages/sv-SE.js @@ -1,3 +1,5 @@ +'use strict'; + /*! * numbro.js language configuration * language : swedish - Sweden diff --git a/tests/languages/th.js b/tests/languages/th.js index b0c7b5e1..cb3dc014 100644 --- a/tests/languages/th.js +++ b/tests/languages/th.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/th-TH'); diff --git a/tests/languages/tr.js b/tests/languages/tr.js index 9bd43b1f..bb44abc5 100644 --- a/tests/languages/tr.js +++ b/tests/languages/tr.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/tr-TR'); diff --git a/tests/languages/uk-UA.js b/tests/languages/uk-UA.js index d0a62664..eab91620 100644 --- a/tests/languages/uk-UA.js +++ b/tests/languages/uk-UA.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = require('../../languages/uk-UA'); diff --git a/tests/numbro/format.js b/tests/numbro/format.js index 307b987f..457969db 100644 --- a/tests/numbro/format.js +++ b/tests/numbro/format.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'); exports.format = { @@ -493,10 +495,10 @@ exports.format = { for (i = 0; i < tests.length; i++) { // floor - test.strictEqual(numbro(tests[i][0]).format(tests[i][1], Math.floor), tests[i][2], tests[i][1] + ", floor"); + test.strictEqual(numbro(tests[i][0]).format(tests[i][1], Math.floor), tests[i][2], tests[i][1] + ', floor'); // ceil - test.strictEqual(numbro(tests[i][0]).format(tests[i][1], Math.ceil), tests[i][3], tests[i][1] + ", ceil"); + test.strictEqual(numbro(tests[i][0]).format(tests[i][1], Math.ceil), tests[i][3], tests[i][1] + ', ceil'); } diff --git a/tests/numbro/manipulate.js b/tests/numbro/manipulate.js index 4a178e44..50bedda3 100644 --- a/tests/numbro/manipulate.js +++ b/tests/numbro/manipulate.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'); exports.manipulate = { @@ -95,7 +97,8 @@ exports.manipulate = { for (var i = 0; i < tests.length; i++) { num = numbro(tests[i][0]); - test.strictEqual(num.difference(tests[i][1]), tests[i][2], 'Difference between ' + tests[i][0] + ' and ' + tests[i][1]); + test.strictEqual(num.difference(tests[i][1]), tests[i][2], + 'Difference between ' + tests[i][0] + ' and ' + tests[i][1]); } test.done(); diff --git a/tests/numbro/misc.js b/tests/numbro/misc.js index 6372818c..500c67aa 100644 --- a/tests/numbro/misc.js +++ b/tests/numbro/misc.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'); exports.misc = { @@ -8,7 +10,7 @@ exports.misc = { var tests = [ [1000, 1000], [0.5, 0.5], - [, 0], + [undefined, 0], ['1,000', 1000], ['not a number', 0] ], @@ -95,7 +97,7 @@ exports.misc = { var cOld = '$', cNew = '!', - formatTestVal = function() { return numbro('100').format('$0,0') }, + formatTestVal = function() { return numbro('100').format('$0,0'); }, oldCurrencyVal = cOld + '100', newCurrencyVal = cNew + '100'; @@ -103,7 +105,8 @@ exports.misc = { test.strictEqual(numbro.languageData('en-US').currency.symbol, cOld, 'English language currency is ' + cOld); numbro.languageData().currency.symbol = cNew; - test.strictEqual(numbro.languageData().currency.symbol, cNew, 'Current language currency is changed to ' + cNew); + test.strictEqual(numbro.languageData().currency.symbol, cNew, + 'Current language currency is changed to ' + cNew); test.strictEqual(formatTestVal(), newCurrencyVal, 'Format uses new currency'); numbro.languageData().currency.symbol = cOld; @@ -111,11 +114,13 @@ exports.misc = { test.strictEqual(formatTestVal(), oldCurrencyVal, 'Format uses old currency'); numbro.languageData('en-US').currency.symbol = cNew; - test.strictEqual(numbro.languageData().currency.symbol, cNew, 'English language currency is changed to ' + cNew); + test.strictEqual(numbro.languageData().currency.symbol, cNew, + 'English language currency is changed to ' + cNew); test.strictEqual(formatTestVal(), newCurrencyVal, 'Format uses new currency'); numbro.languageData('en-US').currency.symbol = cOld; - test.strictEqual(numbro.languageData().currency.symbol, cOld, 'English language currency is reset to ' + cOld); + test.strictEqual(numbro.languageData().currency.symbol, cOld, + 'English language currency is reset to ' + cOld); test.strictEqual(formatTestVal(), oldCurrencyVal, 'Format uses old currency'); test.done(); diff --git a/tests/numbro/unformat.js b/tests/numbro/unformat.js index aaf77ade..a34c6784 100644 --- a/tests/numbro/unformat.js +++ b/tests/numbro/unformat.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'); exports.unformat = { @@ -17,7 +19,7 @@ exports.unformat = { ['31st', 31], ['1.23t', 1230000000000], ['N/A', 0], - [, 0], + [undefined, 0], ['', 0], // Pass Through for Numbers diff --git a/tests/numbro/validate.js b/tests/numbro/validate.js index 95bb7687..47e920e8 100644 --- a/tests/numbro/validate.js +++ b/tests/numbro/validate.js @@ -1,3 +1,5 @@ +'use strict'; + var numbro = require('../../numbro'), language = 'en-US'; @@ -27,7 +29,8 @@ exports.validate = { ]; test.expect(tests.length); for(var i=0; i