diff --git a/.gitignore b/.gitignore index 9843db63..23aa3505 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ Icon # -------------------- # App Files # -------------------- -node_modules/ \ No newline at end of file +node_modules/ +.sass-cache diff --git a/Gruntfile.js b/Gruntfile.js index 4e0e1bf1..41525e26 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -21,8 +21,36 @@ module.exports = function(grunt) { }); grunt.initConfig({ - nodeunit : { - all : ['tests/**/*.js'] + mochaTest : { + all: [ + 'tests/numeral/*.js', + 'tests/languages/*.js' + ] + }, + karma: { + options: { + files: [ + 'numeral.js', + 'languages/*.js', + 'tests/numeral/*.js', + 'tests/languages/*.js' + ], + frameworks: [ + 'mocha', + 'chai' + ], + singleRun: true, + autoWatch: false + }, + local: { + browsers: [ + 'Chrome', + 'Firefox' + ] + }, + ci: { + configFile: 'karma-ci.conf.js' + } }, uglify: { my_target: { @@ -35,7 +63,7 @@ module.exports = function(grunt) { concat: { languages: { src: [ - 'languages/**/*.js' + 'languages/*.js' ], dest: 'languages.js' } @@ -44,7 +72,7 @@ module.exports = function(grunt) { all: [ 'Gruntfile.js', 'numeral.js', - 'languages/**/*.js' + 'languages/*.js' ], options: { 'node': true, @@ -64,10 +92,11 @@ module.exports = function(grunt) { } }); - grunt.loadNpmTasks('grunt-contrib-nodeunit'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-mocha-test'); + grunt.loadNpmTasks('grunt-karma'); grunt.registerTask('default', [ 'test' @@ -75,17 +104,30 @@ module.exports = function(grunt) { grunt.registerTask('test', [ 'jshint', - 'nodeunit' + 'mochaTest', + 'karma:local' + ]); + + grunt.registerTask('test:npm', [ + 'jshint', + 'mochaTest' + ]); + + grunt.registerTask('test:browser', [ + 'jshint', + 'karma:local' ]); // P grunt.registerTask('build', [ - 'jshint', - 'nodeunit', 'concat', 'uglify' ]); // Travis CI task. - grunt.registerTask('travis', ['test']); + grunt.registerTask('travis', [ + 'jshint', + 'mochaTest', + 'karma:ci' + ]); }; diff --git a/LICENSE b/LICENSE index 145e65bc..f9810c58 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012 Adam Draper +Copyright (c) 2014 Adam Draper Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/README.md b/README.md index b6c45c64..70f5c9f0 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Develop [![Build Status](https://travis-ci.org/adamwdraper/Numeral-js.svg?branch # Contributing -Please submit all pull requests to the `develop` branch. +#### Please submit all pull requests to the `develop` branch. 1. Fork the library @@ -25,13 +25,15 @@ Please submit all pull requests to the `develop` branch. 3. Run `npm install` to install dependencies -4. Add your tests to the files in `/tests` +4. Create a new branch from `develop` -5. To test your tests, run `grunt` +5. Add your tests to the files in `/tests` -6. When all your tests are passing, run `grunt build` to minify all files +6. To test your tests, run `grunt` -7. Submit a pull request to the `develop` branch. +7. When all your tests are passing, run `grunt build` to minify all files + +8. Submit a pull request to the `develop` branch. ### Languages @@ -45,6 +47,22 @@ See [the english unit tests](https://github.com/adamwdraper/Numeral-js/blob/mast # Changelog +### 1.5.4 + +Tests: Changed all tests to use Mocha and Chai + +Tests: Added browser tests for Chrome, Firefox, and IE using saucelabs + +Added reset function to reset numeral to default options + +Added nullFormat option + +Update reduce polyfill + +Added Binary bytes + +Bug fix: Fixes problem with many optional decimals + ### 1.5.3 Added currency symbol to optionally appear before negative sign / open paren diff --git a/bower.json b/bower.json index 5dcf89f5..aeb0c9e8 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "numeral", "repo": "adamwdraper/Numeral-js", - "version": "1.5.3", + "version": "1.5.4", "description": "Format and manipulate numbers.", "keywords": [ "numeral", @@ -13,4 +13,4 @@ ], "scripts": [ "numeral.js" ], "main": "numeral.js" -} \ No newline at end of file +} diff --git a/component.json b/component.json index b8239485..aeb0c9e8 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "numeral", "repo": "adamwdraper/Numeral-js", - "version": "1.5.3", + "version": "1.5.4", "description": "Format and manipulate numbers.", "keywords": [ "numeral", diff --git a/karma-ci.conf.js b/karma-ci.conf.js new file mode 100644 index 00000000..e5af43bc --- /dev/null +++ b/karma-ci.conf.js @@ -0,0 +1,41 @@ +module.exports = function(config) { + var customLaunchers = { + sl_chrome: { + base: 'SauceLabs', + browserName: 'chrome', + version: '50', + platform: 'OS X 10.11' + }, + sl_firefox: { + base: 'SauceLabs', + browserName: 'firefox', + version: '45', + platform: 'OS X 10.11' + }, + sl_ie: { + base: 'SauceLabs', + browserName: 'internet explorer', + version: '11.103', + platform: 'Windows 10' + } + }; + + process.env.SAUCE_USERNAME = 'numeraljs'; + process.env.SAUCE_ACCESS_KEY = '5506968c-cfdc-4797-ba75-294620ad475f'; + + config.set({ + reporters: [ + 'mocha', + 'saucelabs' + ], + browserDisconnectTimeout : 10000, + browserNoActivityTimeout: 120000, + browserDisconnectTolerance : 1, + browsers: Object.keys(customLaunchers), + sauceLabs: { + testName: 'Web App Unit Tests' + }, + customLaunchers: customLaunchers, + singleRun: true + }); +}; diff --git a/languages.js b/languages.js index 3aab651d..ddef04b6 100644 --- a/languages.js +++ b/languages.js @@ -243,7 +243,45 @@ this.numeral.language('en-gb', language); } }()); -/*! @preserve +/*! + * numeral.js language configuration + * language : english south africa (uk) + * author : Etienne Boshoff : etienne@zailab.com + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + var b = number % 10; + return (~~ (number % 100 / 10) === 1) ? 'th' : + (b === 1) ? 'st' : + (b === 2) ? 'nd' : + (b === 3) ? 'rd' : 'th'; + }, + currency: { + symbol: 'R' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('en-za', language); + } +}()); +/*! @preserve * numeral.js language configuration * language : spanish Spain * author : Hernan Garcia : https://github.com/hgarcia @@ -279,7 +317,7 @@ } // Browser if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('es', language); + this.numeral.language('es-ES', language); } }()); @@ -567,7 +605,7 @@ this.numeral.language('it', language); } }()); -/*! @preserve +/*! @preserve * numeral.js language configuration * language : japanese * author : teppeis : https://github.com/teppeis @@ -602,6 +640,40 @@ } }()); +/*! @preserve + * numeral.js language configuration + * language : Latvian (lv) + * author : Lauris Bukšis-Haberkorns : https://github.com/Lafriks + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: ' tūkst.', + million: ' milj.', + billion: ' mljrd.', + trillion: ' trilj.' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: '€' + } + }; + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('lv', language); + } +}()); + /*! @preserve * numeral.js language configuration * language : netherlands-dutch (nl-nl) @@ -637,6 +709,44 @@ this.numeral.language('nl-nl', language); } }()); +/*! + * numeral.js language configuration + * language : norwegian (bokmål) + * author : Ove Andersen : https://github.com/azzlack + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: 'kr' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('nb-no', language); + this.numeral.language('nn-no', language); + this.numeral.language('no', language); + this.numeral.language('nb', language); + this.numeral.language('nn', language); + } +}()); /*! @preserve * numeral.js language configuration * language : polish (pl) @@ -776,7 +886,7 @@ } }()); -/*! @preserve +/*! @preserve * numeral.js language configuration * language : russian (ru) * author : Anatoli Papirovski : https://github.com/apapirovski @@ -789,15 +899,15 @@ }, abbreviations: { thousand: 'тыс.', - million: 'млн', - billion: 'b', - trillion: 't' + million: 'млн.', + billion: 'млрд.', + trillion: 'трлн.' }, ordinal: function () { - // not ideal, but since in Russian it can taken on + // not ideal, but since in Russian it can taken on // different forms (masculine, feminine, neuter) // this is all we can do - return '.'; + return '.'; }, currency: { symbol: 'руб.' diff --git a/languages/en-za.js b/languages/en-za.js new file mode 100644 index 00000000..0a57b45c --- /dev/null +++ b/languages/en-za.js @@ -0,0 +1,38 @@ +/*! + * numeral.js language configuration + * language : english south africa (uk) + * author : Etienne Boshoff : etienne@zailab.com + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + var b = number % 10; + return (~~ (number % 100 / 10) === 1) ? 'th' : + (b === 1) ? 'st' : + (b === 2) ? 'nd' : + (b === 3) ? 'rd' : 'th'; + }, + currency: { + symbol: 'R' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('en-za', language); + } +}()); \ No newline at end of file diff --git a/languages/es-ES.js b/languages/es-ES.js index 7df615e4..f1e61bdd 100644 --- a/languages/es-ES.js +++ b/languages/es-ES.js @@ -1,4 +1,4 @@ -/*! @preserve +/*! @preserve * numeral.js language configuration * language : spanish Spain * author : Hernan Garcia : https://github.com/hgarcia @@ -34,6 +34,6 @@ } // Browser if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('es', language); + this.numeral.language('es-ES', language); } }()); diff --git a/languages/ja.js b/languages/ja.js index d7d41aa9..c1c28e09 100644 --- a/languages/ja.js +++ b/languages/ja.js @@ -1,4 +1,4 @@ -/*! @preserve +/*! @preserve * numeral.js language configuration * language : japanese * author : teppeis : https://github.com/teppeis diff --git a/languages/lv.js b/languages/lv.js new file mode 100644 index 00000000..9cbf4851 --- /dev/null +++ b/languages/lv.js @@ -0,0 +1,33 @@ +/*! @preserve + * numeral.js language configuration + * language : Latvian (lv) + * author : Lauris Bukšis-Haberkorns : https://github.com/Lafriks + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: ' tūkst.', + million: ' milj.', + billion: ' mljrd.', + trillion: ' trilj.' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: '€' + } + }; + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('lv', language); + } +}()); diff --git a/languages/no.js b/languages/no.js new file mode 100644 index 00000000..5fc36203 --- /dev/null +++ b/languages/no.js @@ -0,0 +1,38 @@ +/*! + * numeral.js language configuration + * language : norwegian (bokmål) + * author : Ove Andersen : https://github.com/azzlack + */ +(function () { + var language = { + delimiters: { + thousands: ' ', + decimal: ',' + }, + abbreviations: { + thousand: 'k', + million: 'm', + billion: 'b', + trillion: 't' + }, + ordinal: function (number) { + return '.'; + }, + currency: { + symbol: 'kr' + } + }; + + // Node + if (typeof module !== 'undefined' && module.exports) { + module.exports = language; + } + // Browser + if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { + this.numeral.language('nb-no', language); + this.numeral.language('nn-no', language); + this.numeral.language('no', language); + this.numeral.language('nb', language); + this.numeral.language('nn', language); + } +}()); \ No newline at end of file diff --git a/languages/ru.js b/languages/ru.js index 2a9ea0ec..ff22c83a 100644 --- a/languages/ru.js +++ b/languages/ru.js @@ -1,4 +1,4 @@ -/*! @preserve +/*! @preserve * numeral.js language configuration * language : russian (ru) * author : Anatoli Papirovski : https://github.com/apapirovski @@ -11,15 +11,15 @@ }, abbreviations: { thousand: 'тыс.', - million: 'млн', - billion: 'b', - trillion: 't' + million: 'млн.', + billion: 'млрд.', + trillion: 'трлн.' }, ordinal: function () { - // not ideal, but since in Russian it can taken on + // not ideal, but since in Russian it can taken on // different forms (masculine, feminine, neuter) // this is all we can do - return '.'; + return '.'; }, currency: { symbol: 'руб.' diff --git a/min/languages.min.js b/min/languages.min.js index dc2861e8..4f1fda68 100644 --- a/min/languages.min.js +++ b/min/languages.min.js @@ -3,10 +3,10 @@ * language : belgium-dutch (be-nl) * author : Dieter Luypaert : https://github.com/moeriki */ -!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:" mln",billion:" mld",trillion:" bln"},ordinal:function(a){var b=a%100;return 0!==a&&b<=1||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("be-nl",a)}(),/*! @preserve - * numeral.js language configuration - * language : simplified chinese - * author : badplum : https://github.com/badplum +!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:" mln",billion:" mld",trillion:" bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("be-nl",a)}(),/*! @preserve + * numeral.js language configuration + * language : simplified chinese + * author : badplum : https://github.com/badplum */ function(){var a={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"千",million:"百万",billion:"十亿",trillion:"兆"},ordinal:function(a){return"."},currency:{symbol:"¥"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("chs",a)}(),/*! @preserve * numeral.js language configuration @@ -33,12 +33,17 @@ function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand * language : english united kingdom (uk) * author : Dan Ristic : https://github.com/dristic */ -function(){var a={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"£"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("en-gb",a)}(),/*! @preserve +function(){var a={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"£"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("en-gb",a)}(),/*! + * numeral.js language configuration + * language : english south africa (uk) + * author : Etienne Boshoff : etienne@zailab.com + */ +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"R"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("en-za",a)}(),/*! @preserve * numeral.js language configuration * language : spanish Spain * author : Hernan Garcia : https://github.com/hgarcia */ -function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mm",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===b||3===b?"er":2===b?"do":7===b||0===b?"mo":8===b?"vo":9===b?"no":"to"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("es",a)}(),/*! @preserve +function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mm",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===b||3===b?"er":2===b?"do":7===b||0===b?"mo":8===b?"vo":9===b?"no":"to"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("es-ES",a)}(),/*! @preserve * numeral.js language configuration * language : spanish * author : Hernan Garcia : https://github.com/hgarcia @@ -81,17 +86,27 @@ function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand * language : italian Italy (it) * author : Giacomo Trombi : http://cinquepunti.it */ -function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"mila",million:"mil",billion:"b",trillion:"t"},ordinal:function(a){return"º"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("it",a)}(),/*! @preserve +function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"mila",million:"mil",billion:"b",trillion:"t"},ordinal:function(a){return"º"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("it",a)}(),/*! @preserve * numeral.js language configuration * language : japanese * author : teppeis : https://github.com/teppeis */ -function(){var a={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"千",million:"百万",billion:"十億",trillion:"兆"},ordinal:function(a){return"."},currency:{symbol:"¥"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ja",a)}(),/*! @preserve +function(){var a={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"千",million:"百万",billion:"十億",trillion:"兆"},ordinal:function(a){return"."},currency:{symbol:"¥"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ja",a)}(),/*! @preserve + * numeral.js language configuration + * language : Latvian (lv) + * author : Lauris Bukšis-Haberkorns : https://github.com/Lafriks + */ +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:" tūkst.",million:" milj.",billion:" mljrd.",trillion:" trilj."},ordinal:function(a){return"."},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("lv",a)}(),/*! @preserve * numeral.js language configuration * language : netherlands-dutch (nl-nl) * author : Dave Clayton : https://github.com/davedx */ -function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mln",billion:"mrd",trillion:"bln"},ordinal:function(a){var b=a%100;return 0!==a&&b<=1||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(),/*! @preserve +function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mln",billion:"mrd",trillion:"bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(),/*! + * numeral.js language configuration + * language : norwegian (bokmål) + * author : Ove Andersen : https://github.com/azzlack + */ +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){return"."},currency:{symbol:"kr"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&(this.numeral.language("nb-no",a),this.numeral.language("nn-no",a),this.numeral.language("no",a),this.numeral.language("nb",a),this.numeral.language("nn",a))}(),/*! @preserve * numeral.js language configuration * language : polish (pl) * author : Dominik Bulaj : https://github.com/dominikbulaj @@ -106,12 +121,12 @@ function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand * language : portuguese (pt-pt) * author : Diogo Resende : https://github.com/dresende */ -function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){return"º"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("pt-pt",a)}(),function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"тыс.",million:"млн",billion:"b",trillion:"t"},ordinal:function(){return"."},currency:{symbol:"₴"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ru-UA",a)}(),/*! @preserve +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){return"º"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("pt-pt",a)}(),function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"тыс.",million:"млн",billion:"b",trillion:"t"},ordinal:function(){return"."},currency:{symbol:"₴"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ru-UA",a)}(),/*! @preserve * numeral.js language configuration * language : russian (ru) * author : Anatoli Papirovski : https://github.com/apapirovski */ -function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"тыс.",million:"млн",billion:"b",trillion:"t"},ordinal:function(){return"."},currency:{symbol:"руб."}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ru",a)}(),/*! @preserve +function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"тыс.",million:"млн.",billion:"млрд.",trillion:"трлн."},ordinal:function(){return"."},currency:{symbol:"руб."}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ru",a)}(),/*! @preserve * numeral.js language configuration * language : slovak (sk) * author : Ahmed Al Hafoudh : http://www.freevision.sk diff --git a/min/languages/be-nl.min.js b/min/languages/be-nl.min.js index a4cb5c36..8450d92d 100644 --- a/min/languages/be-nl.min.js +++ b/min/languages/be-nl.min.js @@ -3,4 +3,4 @@ * language : belgium-dutch (be-nl) * author : Dieter Luypaert : https://github.com/moeriki */ -!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:" mln",billion:" mld",trillion:" bln"},ordinal:function(a){var b=a%100;return 0!==a&&b<=1||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("be-nl",a)}(); \ No newline at end of file +!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:" mln",billion:" mld",trillion:" bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("be-nl",a)}(); \ No newline at end of file diff --git a/min/languages/chs.min.js b/min/languages/chs.min.js index 18840388..77aa10a7 100644 --- a/min/languages/chs.min.js +++ b/min/languages/chs.min.js @@ -1,6 +1,6 @@ -/*! @preserve - * numeral.js language configuration - * language : simplified chinese - * author : badplum : https://github.com/badplum +/*! @preserve + * numeral.js language configuration + * language : simplified chinese + * author : badplum : https://github.com/badplum */ !function(){var a={delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"千",million:"百万",billion:"十亿",trillion:"兆"},ordinal:function(a){return"."},currency:{symbol:"¥"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("chs",a)}(); \ No newline at end of file diff --git a/min/languages/en-za.min.js b/min/languages/en-za.min.js new file mode 100644 index 00000000..516c0a50 --- /dev/null +++ b/min/languages/en-za.min.js @@ -0,0 +1,6 @@ +/*! + * numeral.js language configuration + * language : english south africa (uk) + * author : Etienne Boshoff : etienne@zailab.com + */ +!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"R"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("en-za",a)}(); \ No newline at end of file diff --git a/min/languages/es-ES.min.js b/min/languages/es-ES.min.js index 16b80447..16f2fd45 100644 --- a/min/languages/es-ES.min.js +++ b/min/languages/es-ES.min.js @@ -1,6 +1,6 @@ -/*! @preserve +/*! @preserve * numeral.js language configuration * language : spanish Spain * author : Hernan Garcia : https://github.com/hgarcia */ -!function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mm",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===b||3===b?"er":2===b?"do":7===b||0===b?"mo":8===b?"vo":9===b?"no":"to"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("es",a)}(); \ No newline at end of file +!function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mm",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===b||3===b?"er":2===b?"do":7===b||0===b?"mo":8===b?"vo":9===b?"no":"to"},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("es-ES",a)}(); \ No newline at end of file diff --git a/min/languages/ja.min.js b/min/languages/ja.min.js index a4a77164..908b028c 100644 --- a/min/languages/ja.min.js +++ b/min/languages/ja.min.js @@ -1,4 +1,4 @@ -/*! @preserve +/*! @preserve * numeral.js language configuration * language : japanese * author : teppeis : https://github.com/teppeis diff --git a/min/languages/lv.min.js b/min/languages/lv.min.js new file mode 100644 index 00000000..31237ccd --- /dev/null +++ b/min/languages/lv.min.js @@ -0,0 +1,6 @@ +/*! @preserve + * numeral.js language configuration + * language : Latvian (lv) + * author : Lauris Bukšis-Haberkorns : https://github.com/Lafriks + */ +!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:" tūkst.",million:" milj.",billion:" mljrd.",trillion:" trilj."},ordinal:function(a){return"."},currency:{symbol:"€"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("lv",a)}(); \ No newline at end of file diff --git a/min/languages/nl-nl.min.js b/min/languages/nl-nl.min.js index 1c22e84b..ed20694f 100644 --- a/min/languages/nl-nl.min.js +++ b/min/languages/nl-nl.min.js @@ -3,4 +3,4 @@ * language : netherlands-dutch (nl-nl) * author : Dave Clayton : https://github.com/davedx */ -!function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mln",billion:"mrd",trillion:"bln"},ordinal:function(a){var b=a%100;return 0!==a&&b<=1||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(); \ No newline at end of file +!function(){var a={delimiters:{thousands:".",decimal:","},abbreviations:{thousand:"k",million:"mln",billion:"mrd",trillion:"bln"},ordinal:function(a){var b=a%100;return 0!==a&&1>=b||8===b||b>=20?"ste":"de"},currency:{symbol:"€ "}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("nl-nl",a)}(); \ No newline at end of file diff --git a/min/languages/no.min.js b/min/languages/no.min.js new file mode 100644 index 00000000..71c8277a --- /dev/null +++ b/min/languages/no.min.js @@ -0,0 +1,6 @@ +/*! + * numeral.js language configuration + * language : norwegian (bokmål) + * author : Ove Andersen : https://github.com/azzlack + */ +!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){return"."},currency:{symbol:"kr"}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&(this.numeral.language("nb-no",a),this.numeral.language("nn-no",a),this.numeral.language("no",a),this.numeral.language("nb",a),this.numeral.language("nn",a))}(); \ No newline at end of file diff --git a/min/languages/ru.min.js b/min/languages/ru.min.js index 043efbaa..f07551a3 100644 --- a/min/languages/ru.min.js +++ b/min/languages/ru.min.js @@ -1,6 +1,6 @@ -/*! @preserve +/*! @preserve * numeral.js language configuration * language : russian (ru) * author : Anatoli Papirovski : https://github.com/apapirovski */ -!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"тыс.",million:"млн",billion:"b",trillion:"t"},ordinal:function(){return"."},currency:{symbol:"руб."}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ru",a)}(); \ No newline at end of file +!function(){var a={delimiters:{thousands:" ",decimal:","},abbreviations:{thousand:"тыс.",million:"млн.",billion:"млрд.",trillion:"трлн."},ordinal:function(){return"."},currency:{symbol:"руб."}};"undefined"!=typeof module&&module.exports&&(module.exports=a),"undefined"!=typeof window&&this.numeral&&this.numeral.language&&this.numeral.language("ru",a)}(); \ No newline at end of file diff --git a/min/numeral.min.js b/min/numeral.min.js index be8dbe7d..7dabc87e 100644 --- a/min/numeral.min.js +++ b/min/numeral.min.js @@ -1,8 +1,8 @@ /*! @preserve * numeral.js - * version : 1.5.3 + * version : 1.5.4 * author : Adam Draper * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function(){function a(a){this._value=a}function b(a,b,c,d){var e,f,g=Math.pow(10,b);return f=(c(a*g)/g).toFixed(b),d&&(e=new RegExp("0{1,"+d+"}$"),f=f.replace(e,"")),f}function c(a,b,c){var d;return d=b.indexOf("$")>-1?e(a,b,c):b.indexOf("%")>-1?f(a,b,c):b.indexOf(":")>-1?g(a,b):i(a._value,b,c)}function d(a,b){var c,d,e,f,g,i=b,j=["KB","MB","GB","TB","PB","EB","ZB","YB"],k=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===q)a._value=0;else{for("."!==o[p].delimiters.decimal&&(b=b.replace(/\./g,"").replace(o[p].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+o[p].abbreviations.thousand+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+o[p].abbreviations.million+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+o[p].abbreviations.billion+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+o[p].abbreviations.trillion+"(?:\\)|(\\"+o[p].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!(k=b.indexOf(j[g])>-1&&Math.pow(1024,g+1));g++);a._value=(k?k:1)*(i.match(c)?Math.pow(10,3):1)*(i.match(d)?Math.pow(10,6):1)*(i.match(e)?Math.pow(10,9):1)*(i.match(f)?Math.pow(10,12):1)*(b.indexOf("%")>-1?.01:1)*((b.split("-").length+Math.min(b.split("(").length-1,b.split(")").length-1))%2?1:-1)*Number(b.replace(/[^0-9\.]+/g,"")),a._value=k?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e,f=b.indexOf("$"),g=b.indexOf("("),h=b.indexOf("-"),j="";return b.indexOf(" $")>-1?(j=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(j=" ",b=b.replace("$ ","")):b=b.replace("$",""),e=i(a._value,b,c),f<=1?e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=1,(f-1?(e=e.split(""),e.splice(-1,0,j+o[p].currency.symbol),e=e.join("")):e=e+j+o[p].currency.symbol,e}function f(a,b,c){var d,e="",f=100*a._value;return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),d=i(f,b,c),d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,e+"%"),d=d.join("")):d=d+e+"%",d}function g(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*b*60)/60),d=Math.round(a._value-60*b*60-60*c);return b+":"+(c<10?"0"+c:c)+":"+(d<10?"0"+d:d)}function h(a){var b=a.split(":"),c=0;return 3===b.length?(c+=60*Number(b[0])*60,c+=60*Number(b[1]),c+=Number(b[2])):2===b.length&&(c+=60*Number(b[0]),c+=Number(b[1])),Number(c)}function i(a,c,d){var e,f,g,h,i,j,k=!1,l=!1,m=!1,n="",r=!1,s=!1,t=!1,u=!1,v=!1,w="",x="",y=Math.abs(a),z=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],A="",B=!1;if(0===a&&null!==q)return q;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(r=c.indexOf("aK")>=0,s=c.indexOf("aM")>=0,t=c.indexOf("aB")>=0,u=c.indexOf("aT")>=0,v=r||s||t||u,c.indexOf(" a")>-1?(n=" ",c=c.replace(" a","")):c=c.replace("a",""),y>=Math.pow(10,12)&&!v||u?(n+=o[p].abbreviations.trillion,a/=Math.pow(10,12)):y=Math.pow(10,9)&&!v||t?(n+=o[p].abbreviations.billion,a/=Math.pow(10,9)):y=Math.pow(10,6)&&!v||s?(n+=o[p].abbreviations.million,a/=Math.pow(10,6)):(y=Math.pow(10,3)&&!v||r)&&(n+=o[p].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(w=" ",c=c.replace(" b","")):c=c.replace("b",""),g=0;g<=z.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&a0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(x=" ",c=c.replace(" o","")):c=c.replace("o",""),x+=o[p].ordinal(a)),c.indexOf("[.]")>-1&&(m=!0,c=c.replace("[.]",".")),h=a.toString().split(".")[0],i=c.split(".")[1],j=c.indexOf(","),i?(i.indexOf("[")>-1?(i=i.replace("]",""),i=i.split("["),A=b(a,i[0].length+i[1].length,d,i[1].length)):A=b(a,i.length,d),h=A.split(".")[0],A=A.split(".")[1].length?o[p].delimiters.decimal+A.split(".")[1]:"",m&&0===Number(A.slice(1))&&(A="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),B=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+o[p].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&B?"(":"")+(!k&&B?"-":"")+(!B&&l?"+":"")+h+A+(x?x:"")+(n?n:"")+(w?w:"")+(k&&B?")":"")}function j(a,b){o[a]=b}function k(a){var b=a.toString().split(".");return b.length<2?1:Math.pow(10,b[1].length)}function l(){var a=Array.prototype.slice.call(arguments);return a.reduce(function(a,b){var c=k(a),d=k(b);return c>d?c:d},-(1/0))}var m,n="1.5.3",o={},p="en",q=null,r="0,0",s="undefined"!=typeof module&&module.exports;m=function(b){return m.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:Number(b)||(b=m.fn.unformat(b)),new a(Number(b))},m.version=n,m.isNumeral=function(b){return b instanceof a},m.language=function(a,b){if(!a)return p;if(a&&!b){if(!o[a])throw new Error("Unknown language : "+a);p=a}return!b&&o[a]||j(a,b),m},m.languageData=function(a){if(!a)return o[p];if(!o[a])throw new Error("Unknown language : "+a);return o[a]},m.language("en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"$"}}),m.zeroFormat=function(a){q="string"==typeof a?a:null},m.defaultFormat=function(a){r="string"==typeof a?a:"0.0"},"function"!=typeof Array.prototype.reduce&&(Array.prototype.reduce=function(a,b){"use strict";if(null===this||"undefined"==typeof this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof a)throw new TypeError(a+" is not a function");var c,d,e=this.length>>>0,f=!1;for(1c;++c)this.hasOwnProperty(c)&&(f?d=a(d,this[c],c,this):(d=this[c],f=!0));if(!f)throw new TypeError("Reduce of empty array with no initial value");return d}),m.fn=a.prototype={clone:function(){return m(this)},format:function(a,b){return c(this,a?a:r,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:d(this,a?a:r)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){function b(a,b,d,e){return a+c*b}var c=l.call(null,this._value,a);return this._value=[this._value,a].reduce(b,0)/c,this},subtract:function(a){function b(a,b,d,e){return a-c*b}var c=l.call(null,this._value,a);return this._value=[a].reduce(b,this._value*c)/c,this},multiply:function(a){function b(a,b,c,d){var e=l(a,b);return a*e*(b*e)/(e*e)}return this._value=[this._value,a].reduce(b,1),this},divide:function(a){function b(a,b,c,d){var e=l(a,b);return a*e/(b*e)}return this._value=[this._value,a].reduce(b),this},difference:function(a){return Math.abs(m(this._value).subtract(a).value())}},s&&(module.exports=m),"undefined"==typeof ender&&(this.numeral=m),"function"==typeof define&&define.amd&&define([],function(){return m})}).call(this); \ No newline at end of file +(function(){function a(a){this._value=a}function b(a,b,c,d){var e,f,g,h,i=a.toString().split("."),j=b-(d||0);return e=2===i.length?Math.min(Math.max(i[1].length,j),b):j,g=Math.pow(10,e),h=(c(a*g)/g).toFixed(e),d>b-e&&(f=new RegExp("\\.?0{1,"+(d-(b-e))+"}$"),h=h.replace(f,"")),h}function c(a,b,c){var d;return d=b.indexOf("$")>-1?e(a,b,c):b.indexOf("%")>-1?f(a,b,c):b.indexOf(":")>-1?g(a,b):i(a._value,b,c)}function d(a,b){var c,d,e,f,g,i=b,j=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],k=["KB","MB","GB","TB","PB","EB","ZB","YB"],l=!1;if(b.indexOf(":")>-1)a._value=h(b);else if(b===q.zeroFormat||b===q.nullFormat)a._value=0;else{for("."!==o[q.currentLanguage].delimiters.decimal&&(b=b.replace(/\./g,"").replace(o[q.currentLanguage].delimiters.decimal,".")),c=new RegExp("[^a-zA-Z]"+o[q.currentLanguage].abbreviations.thousand+"(?:\\)|(\\"+o[q.currentLanguage].currency.symbol+")?(?:\\))?)?$"),d=new RegExp("[^a-zA-Z]"+o[q.currentLanguage].abbreviations.million+"(?:\\)|(\\"+o[q.currentLanguage].currency.symbol+")?(?:\\))?)?$"),e=new RegExp("[^a-zA-Z]"+o[q.currentLanguage].abbreviations.billion+"(?:\\)|(\\"+o[q.currentLanguage].currency.symbol+")?(?:\\))?)?$"),f=new RegExp("[^a-zA-Z]"+o[q.currentLanguage].abbreviations.trillion+"(?:\\)|(\\"+o[q.currentLanguage].currency.symbol+")?(?:\\))?)?$"),g=0;g<=j.length&&!l;g++)l=b.indexOf(j[g])>-1?Math.pow(1024,g+1):b.indexOf(k[g])>-1?Math.pow(1e3,g+1):!1;a._value=(l?l:1)*(i.match(c)?Math.pow(10,3):1)*(i.match(d)?Math.pow(10,6):1)*(i.match(e)?Math.pow(10,9):1)*(i.match(f)?Math.pow(10,12):1)*(b.indexOf("%")>-1?.01:1)*((b.split("-").length+Math.min(b.split("(").length-1,b.split(")").length-1))%2?1:-1)*Number(b.replace(/[^0-9\.]+/g,"")),a._value=l?Math.ceil(a._value):a._value}return a._value}function e(a,b,c){var d,e,f=b.indexOf("$"),g=b.indexOf("("),h=b.indexOf("-"),j="";return b.indexOf(" $")>-1?(j=" ",b=b.replace(" $","")):b.indexOf("$ ")>-1?(j=" ",b=b.replace("$ ","")):b=b.replace("$",""),e=i(a._value,b,c),1>=f?e.indexOf("(")>-1||e.indexOf("-")>-1?(e=e.split(""),d=1,(g>f||h>f)&&(d=0),e.splice(d,0,o[q.currentLanguage].currency.symbol+j),e=e.join("")):e=o[q.currentLanguage].currency.symbol+j+e:e.indexOf(")")>-1?(e=e.split(""),e.splice(-1,0,j+o[q.currentLanguage].currency.symbol),e=e.join("")):e=e+j+o[q.currentLanguage].currency.symbol,e}function f(a,b,c){var d,e="",f=100*a._value;return b.indexOf(" %")>-1?(e=" ",b=b.replace(" %","")):b=b.replace("%",""),d=i(f,b,c),d.indexOf(")")>-1?(d=d.split(""),d.splice(-1,0,e+"%"),d=d.join("")):d=d+e+"%",d}function g(a){var b=Math.floor(a._value/60/60),c=Math.floor((a._value-60*b*60)/60),d=Math.round(a._value-60*b*60-60*c);return b+":"+(10>c?"0"+c:c)+":"+(10>d?"0"+d:d)}function h(a){var b=a.split(":"),c=0;return 3===b.length?(c+=60*Number(b[0])*60,c+=60*Number(b[1]),c+=Number(b[2])):2===b.length&&(c+=60*Number(b[0]),c+=Number(b[1])),Number(c)}function i(a,c,d){var e,f,g,h,i,j,k=!1,l=!1,m=!1,n="",p=!1,r=!1,s=!1,t=!1,u=!1,v="",w="",x=Math.abs(a),y=["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],z=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],A="",B=!1;if(0===a&&null!==q.zeroFormat)return q.zeroFormat;if(null===a&&null!==q.nullFormat)return q.nullFormat;if(c.indexOf("(")>-1?(k=!0,c=c.slice(1,-1)):c.indexOf("+")>-1&&(l=!0,c=c.replace(/\+/g,"")),c.indexOf("a")>-1&&(p=c.indexOf("aK")>=0,r=c.indexOf("aM")>=0,s=c.indexOf("aB")>=0,t=c.indexOf("aT")>=0,u=p||r||s||t,c.indexOf(" a")>-1&&(n=" "),c=c.replace(new RegExp(n+"a[KMBT]?"),""),x>=Math.pow(10,12)&&!u||t?(n+=o[q.currentLanguage].abbreviations.trillion,a/=Math.pow(10,12)):x=Math.pow(10,9)&&!u||s?(n+=o[q.currentLanguage].abbreviations.billion,a/=Math.pow(10,9)):x=Math.pow(10,6)&&!u||r?(n+=o[q.currentLanguage].abbreviations.million,a/=Math.pow(10,6)):(x=Math.pow(10,3)&&!u||p)&&(n+=o[q.currentLanguage].abbreviations.thousand,a/=Math.pow(10,3))),c.indexOf("b")>-1)for(c.indexOf(" b")>-1?(v=" ",c=c.replace(" b","")):c=c.replace("b",""),g=0;g<=y.length;g++)if(e=Math.pow(1024,g),f=Math.pow(1024,g+1),a>=e&&f>a){v+=y[g],e>0&&(a/=e);break}if(c.indexOf("d")>-1)for(c.indexOf(" d")>-1?(v=" ",c=c.replace(" d","")):c=c.replace("d",""),g=0;g<=z.length;g++)if(e=Math.pow(1e3,g),f=Math.pow(1e3,g+1),a>=e&&f>a){v+=z[g],e>0&&(a/=e);break}return c.indexOf("o")>-1&&(c.indexOf(" o")>-1?(w=" ",c=c.replace(" o","")):c=c.replace("o",""),w+=o[q.currentLanguage].ordinal(a)),c.indexOf("[.]")>-1&&(m=!0,c=c.replace("[.]",".")),h=a.toString().split(".")[0],i=c.split(".")[1],j=c.indexOf(","),i?(i.indexOf("[")>-1?(i=i.replace("]",""),i=i.split("["),A=b(a,i[0].length+i[1].length,d,i[1].length)):A=b(a,i.length,d),h=A.split(".")[0],A=A.indexOf(".")>-1?o[q.currentLanguage].delimiters.decimal+A.split(".")[1]:"",m&&0===Number(A.slice(1))&&(A="")):h=b(a,null,d),h.indexOf("-")>-1&&(h=h.slice(1),B=!0),j>-1&&(h=h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g,"$1"+o[q.currentLanguage].delimiters.thousands)),0===c.indexOf(".")&&(h=""),(k&&B?"(":"")+(!k&&B?"-":"")+(!B&&l?"+":"")+h+A+(w?w:"")+(n?n:"")+(v?v:"")+(k&&B?")":"")}function j(a,b){o[a]=b}function k(a){var b=a.toString().split(".");return b.length<2?1:Math.pow(10,b[1].length)}function l(){var a=Array.prototype.slice.call(arguments);return a.reduce(function(a,b){var c=k(a),d=k(b);return c>d?c:d},-(1/0))}var m,n="1.5.4",o={},p={currentLanguage:"en",zeroFormat:null,nullFormat:null,defaultFormat:"0,0"},q={currentLanguage:p.currentLanguage,zeroFormat:p.zeroFormat,nullFormat:p.nullFormat,defaultFormat:p.defaultFormat};m=function(b){return m.isNumeral(b)?b=b.value():0===b||"undefined"==typeof b?b=0:null===b?b=null:Number(b)||(b=m.fn.unformat(b)),new a(b)},m.version=n,m.isNumeral=function(b){return b instanceof a},m.language=function(a,b){if(!a)return q.currentLanguage;if(a=a.toLowerCase(),a&&!b){if(!o[a])throw new Error("Unknown language : "+a);q.currentLanguage=a}return(b||!o[a])&&j(a,b),m},m.reset=function(){for(var a in p)q[a]=p[a]},m.languageData=function(a){if(!a)return o[q.currentLanguage];if(!o[a])throw new Error("Unknown language : "+a);return o[a]},m.language("en",{delimiters:{thousands:",",decimal:"."},abbreviations:{thousand:"k",million:"m",billion:"b",trillion:"t"},ordinal:function(a){var b=a%10;return 1===~~(a%100/10)?"th":1===b?"st":2===b?"nd":3===b?"rd":"th"},currency:{symbol:"$"}}),m.zeroFormat=function(a){q.zeroFormat="string"==typeof a?a:null},m.nullFormat=function(a){q.nullFormat="string"==typeof a?a:null},m.defaultFormat=function(a){q.defaultFormat="string"==typeof a?a:"0.0"},m.validate=function(a,b){var c,d,e,f,g,h,i,j;if("string"!=typeof a&&(a+="",console.warn&&console.warn("Numeral.js: Value is not string. It has been co-erced to: ",a)),a=a.trim(),a.match(/^\d+$/))return!0;if(""===a)return!1;try{i=m.languageData(b)}catch(k){i=m.languageData(m.language())}return e=i.currency.symbol,g=i.abbreviations,c=i.delimiters.decimal,d="."===i.delimiters.thousands?"\\.":i.delimiters.thousands,j=a.match(/^[^\d]+/),null!==j&&(a=a.substr(1),j[0]!==e)?!1:(j=a.match(/[^\d]+$/),null!==j&&(a=a.slice(0,-1),j[0]!==g.thousand&&j[0]!==g.million&&j[0]!==g.billion&&j[0]!==g.trillion)?!1:(h=new RegExp(d+"{2}"),a.match(/[^\d.,]/g)?!1:(f=a.split(c),f.length>2?!1:f.length<2?!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h):1===f[0].length?!!f[0].match(/^\d+$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/):!!f[0].match(/^\d+.*\d$/)&&!f[0].match(h)&&!!f[1].match(/^\d+$/))))},Array.prototype.reduce||(Array.prototype.reduce=function(a){"use strict";if(null===this)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof a)throw new TypeError(a+" is not a function");var b,c=Object(this),d=c.length>>>0,e=0;if(2===arguments.length)b=arguments[1];else{for(;d>e&&!(e in c);)e++;if(e>=d)throw new TypeError("Reduce of empty array with no initial value");b=c[e++]}for(;d>e;e++)e in c&&(b=a(b,c[e],e,c));return b}),m.fn=a.prototype={clone:function(){return m(this)},format:function(a,b){return c(this,a?a:q.defaultFormat,void 0!==b?b:Math.round)},unformat:function(a){return"[object Number]"===Object.prototype.toString.call(a)?a:d(this,a?a:q.defaultFormat)},value:function(){return this._value},valueOf:function(){return this._value},set:function(a){return this._value=Number(a),this},add:function(a){function b(a,b,d,e){return a+c*b}var c=l.call(null,this._value,a);return this._value=[this._value,a].reduce(b,0)/c,this},subtract:function(a){function b(a,b,d,e){return a-c*b}var c=l.call(null,this._value,a);return this._value=[a].reduce(b,this._value*c)/c,this},multiply:function(a){function b(a,b,c,d){var e=l(a,b);return a*e*(b*e)/(e*e)}return this._value=[this._value,a].reduce(b,1),this},divide:function(a){function b(a,b,c,d){var e=l(a,b);return a*e/(b*e)}return this._value=[this._value,a].reduce(b),this},difference:function(a){return Math.abs(m(this._value).subtract(a).value())}},"undefined"!=typeof module&&module.exports&&(module.exports=m),"undefined"==typeof ender&&(this.numeral=m),"function"==typeof define&&define.amd&&define([],function(){return m})}).call(this); \ No newline at end of file diff --git a/numeral.js b/numeral.js index 514d56ce..cb142b0c 100644 --- a/numeral.js +++ b/numeral.js @@ -1,26 +1,33 @@ /*! @preserve * numeral.js - * version : 1.5.3 + * version : 1.5.4 * author : Adam Draper * license : MIT * http://adamwdraper.github.com/Numeral-js/ */ -(function () { +(function() { /************************************ - Constants + Variables ************************************/ var numeral, - VERSION = '1.5.3', + VERSION = '1.5.4', // internal storage for language config files languages = {}, - currentLanguage = 'en', - zeroFormat = null, - defaultFormat = '0,0', - // check for nodeJS - hasModule = (typeof module !== 'undefined' && module.exports); + defaults = { + currentLanguage: 'en', + zeroFormat: null, + nullFormat: null, + defaultFormat: '0,0' + }, + options = { + currentLanguage: defaults.currentLanguage, + zeroFormat: defaults.zeroFormat, + nullFormat: defaults.nullFormat, + defaultFormat: defaults.defaultFormat + }; /************************************ @@ -29,7 +36,7 @@ // Numeral prototype object - function Numeral (number) { + function Numeral(number) { this._value = number; } @@ -39,17 +46,29 @@ * Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present * problems for accounting- and finance-related software. */ - function toFixed (value, precision, roundingFunction, optionals) { - var power = Math.pow(10, precision), + function toFixed (value, maxDecimals, roundingFunction, optionals) { + var splitValue = value.toString().split('.'), + minDecimals = maxDecimals - (optionals || 0), + boundedPrecision, optionalsRegExp, + power, output; + // Use the smallest precision value possible to avoid errors from floating point representation + if (splitValue.length === 2) { + boundedPrecision = Math.min(Math.max(splitValue[1].length, minDecimals), maxDecimals); + } else { + boundedPrecision = minDecimals; + } + + power = Math.pow(10, boundedPrecision); + //roundingFunction = (roundingFunction !== undefined ? roundingFunction : Math.round); // Multiply up by precision, round accurately, then divide and use native toFixed(): - output = (roundingFunction(value * power) / power).toFixed(precision); + output = (roundingFunction(value * power) / power).toFixed(boundedPrecision); - if (optionals) { - optionalsRegExp = new RegExp('0{1,' + optionals + '}$'); + if (optionals > maxDecimals - boundedPrecision) { + optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecision)) + '}$'); output = output.replace(optionalsRegExp, ''); } @@ -61,7 +80,7 @@ ************************************/ // determine what type of formatting we need to do - function formatNumeral (n, format, roundingFunction) { + function formatNumeral(n, format, roundingFunction) { var output; // figure out what kind of format we are dealing with @@ -80,43 +99,42 @@ } // revert to number - function unformatNumeral (n, string) { + function unformatNumeral(n, string) { var stringOriginal = string, thousandRegExp, millionRegExp, billionRegExp, trillionRegExp, - suffixes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], + binarySuffixes = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], + decimalSuffixes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], bytesMultiplier = false, power; if (string.indexOf(':') > -1) { n._value = unformatTime(string); } else { - if (string === zeroFormat) { + if (string === options.zeroFormat || string === options.nullFormat) { n._value = 0; } else { - if (languages[currentLanguage].delimiters.decimal !== '.') { - string = string.replace(/\./g,'').replace(languages[currentLanguage].delimiters.decimal, '.'); + if (languages[options.currentLanguage].delimiters.decimal !== '.') { + string = string.replace(/\./g, '').replace(languages[options.currentLanguage].delimiters.decimal, '.'); } // 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[options.currentLanguage].abbreviations.thousand + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); + millionRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.million + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); + billionRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.billion + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); + trillionRegExp = new RegExp('[^a-zA-Z]' + languages[options.currentLanguage].abbreviations.trillion + '(?:\\)|(\\' + languages[options.currentLanguage].currency.symbol + ')?(?:\\))?)?$'); // see if bytes are there so that we can multiply to the correct number - for (power = 0; power <= suffixes.length; power++) { - bytesMultiplier = (string.indexOf(suffixes[power]) > -1) ? Math.pow(1024, power + 1) : false; - - if (bytesMultiplier) { - break; - } + for (power = 0; power <= binarySuffixes.length && !bytesMultiplier; power++) { + if (string.indexOf(binarySuffixes[power]) > -1) { bytesMultiplier = Math.pow(1024, power + 1); } + else if (string.indexOf(decimalSuffixes[power]) > -1) { bytesMultiplier = Math.pow(1000, power + 1); } + else { bytesMultiplier = false; } } // 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; @@ -125,7 +143,7 @@ return n._value; } - function formatCurrency (n, format, roundingFunction) { + function formatCurrency(n, format, roundingFunction) { var symbolIndex = format.indexOf('$'), openParenIndex = format.indexOf('('), minusSignIndex = format.indexOf('-'), @@ -152,29 +170,29 @@ if (output.indexOf('(') > -1 || output.indexOf('-') > -1) { output = output.split(''); spliceIndex = 1; - if (symbolIndex < openParenIndex || symbolIndex < minusSignIndex){ + if (symbolIndex < openParenIndex || symbolIndex < minusSignIndex) { // the symbol appears before the "(" or "-" spliceIndex = 0; } - output.splice(spliceIndex, 0, languages[currentLanguage].currency.symbol + space); + output.splice(spliceIndex, 0, languages[options.currentLanguage].currency.symbol + space); output = output.join(''); } else { - output = languages[currentLanguage].currency.symbol + space + output; + output = languages[options.currentLanguage].currency.symbol + space + output; } } else { if (output.indexOf(')') > -1) { output = output.split(''); - output.splice(-1, 0, space + languages[currentLanguage].currency.symbol); + output.splice(-1, 0, space + languages[options.currentLanguage].currency.symbol); output = output.join(''); } else { - output = output + space + languages[currentLanguage].currency.symbol; + output = output + space + languages[options.currentLanguage].currency.symbol; } } return output; } - function formatPercentage (n, format, roundingFunction) { + function formatPercentage(n, format, roundingFunction) { var space = '', output, value = n._value * 100; @@ -189,7 +207,7 @@ output = formatNumber(value, format, roundingFunction); - if (output.indexOf(')') > -1 ) { + if (output.indexOf(')') > -1) { output = output.split(''); output.splice(-1, 0, space + '%'); output = output.join(''); @@ -200,14 +218,14 @@ return output; } - function formatTime (n) { - var hours = Math.floor(n._value/60/60), - minutes = Math.floor((n._value - (hours * 60 * 60))/60), + function formatTime(n) { + 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); } - function unformatTime (string) { + function unformatTime(string) { var timeArray = string.split(':'), seconds = 0; // turn hours and minutes into seconds and add them all up @@ -227,7 +245,7 @@ return Number(seconds); } - function formatNumber (value, format, roundingFunction) { + function formatNumber(value, format, roundingFunction) { var negP = false, signed = false, optDec = false, @@ -240,7 +258,8 @@ bytes = '', ord = '', abs = Math.abs(value), - suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], + binarySuffixes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'], + decimalSuffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], min, max, power, @@ -251,8 +270,10 @@ neg = false; // check if number is zero and a custom zero format has been set - if (value === 0 && zeroFormat !== null) { - return zeroFormat; + if (value === 0 && options.zeroFormat !== null) { + return options.zeroFormat; + } else if (value === null && options.nullFormat !== null) { + return options.nullFormat; } else { // see if we should use parentheses for negative number or if we should prefix with a sign // if both are present we default to parentheses @@ -276,31 +297,30 @@ // check for space before abbreviation if (format.indexOf(' a') > -1) { abbr = ' '; - format = format.replace(' a', ''); - } else { - format = format.replace('a', ''); } + format = format.replace(new RegExp(abbr + 'a[KMBT]?'), ''); + if (abs >= Math.pow(10, 12) && !abbrForce || abbrT) { // trillion - abbr = abbr + languages[currentLanguage].abbreviations.trillion; + abbr = abbr + languages[options.currentLanguage].abbreviations.trillion; value = value / Math.pow(10, 12); } else if (abs < Math.pow(10, 12) && abs >= Math.pow(10, 9) && !abbrForce || abbrB) { // billion - abbr = abbr + languages[currentLanguage].abbreviations.billion; + abbr = abbr + languages[options.currentLanguage].abbreviations.billion; value = value / Math.pow(10, 9); } else if (abs < Math.pow(10, 9) && abs >= Math.pow(10, 6) && !abbrForce || abbrM) { // million - abbr = abbr + languages[currentLanguage].abbreviations.million; + abbr = abbr + languages[options.currentLanguage].abbreviations.million; value = value / Math.pow(10, 6); } else if (abs < Math.pow(10, 6) && abs >= Math.pow(10, 3) && !abbrForce || abbrK) { // thousand - abbr = abbr + languages[currentLanguage].abbreviations.thousand; + abbr = abbr + languages[options.currentLanguage].abbreviations.thousand; value = value / Math.pow(10, 3); } } - // see if we are formatting bytes + // see if we are formatting binary bytes if (format.indexOf('b') > -1) { // check for space before if (format.indexOf(' b') > -1) { @@ -310,12 +330,36 @@ format = format.replace('b', ''); } - for (power = 0; power <= suffixes.length; power++) { + for (power = 0; power <= binarySuffixes.length; power++) { min = Math.pow(1024, power); - max = Math.pow(1024, power+1); + max = Math.pow(1024, power + 1); + + if (value >= min && value < max) { + bytes = bytes + binarySuffixes[power]; + if (min > 0) { + value = value / min; + } + break; + } + } + } + + // see if we are formatting decimal bytes + if (format.indexOf('d') > -1) { + // check for space before + if (format.indexOf(' d') > -1) { + bytes = ' '; + format = format.replace(' d', ''); + } else { + format = format.replace('d', ''); + } + + for (power = 0; power <= decimalSuffixes.length; power++) { + min = Math.pow(1000, power); + max = Math.pow(1000, power+1); if (value >= min && value < max) { - bytes = bytes + suffixes[power]; + bytes = bytes + decimalSuffixes[power]; if (min > 0) { value = value / min; } @@ -334,7 +378,7 @@ format = format.replace('o', ''); } - ord = ord + languages[currentLanguage].ordinal(value); + ord = ord + languages[options.currentLanguage].ordinal(value); } if (format.indexOf('[.]') > -1) { @@ -357,8 +401,8 @@ w = d.split('.')[0]; - if (d.split('.')[1].length) { - d = languages[currentLanguage].delimiters.decimal + d.split('.')[1]; + if (d.indexOf('.') > -1) { + d = languages[options.currentLanguage].delimiters.decimal + d.split('.')[1]; } else { d = ''; } @@ -377,7 +421,7 @@ } 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[options.currentLanguage].delimiters.thousands); } if (format.indexOf('.') === 0) { @@ -392,39 +436,45 @@ Top Level Functions ************************************/ - numeral = function (input) { + numeral = function(input) { if (numeral.isNumeral(input)) { input = input.value(); } else if (input === 0 || typeof input === 'undefined') { input = 0; + } else if (input === null) { + input = null; } else if (!Number(input)) { input = numeral.fn.unformat(input); } - return new Numeral(Number(input)); + return new Numeral(input); }; // version number numeral.version = VERSION; // compare numeral object - numeral.isNumeral = function (obj) { + numeral.isNumeral = function(obj) { return obj instanceof Numeral; }; + // This function will load languages and then set the global language. If // no arguments are passed in, it will simply return the current global // language key. - numeral.language = function (key, values) { + numeral.language = function(key, values) { if (!key) { - return currentLanguage; + return options.currentLanguage; } + key = key.toLowerCase(); + if (key && !values) { - if(!languages[key]) { + if (!languages[key]) { throw new Error('Unknown language : ' + key); } - currentLanguage = key; + + options.currentLanguage = key; } if (values || !languages[key]) { @@ -434,12 +484,18 @@ return numeral; }; + numeral.reset = function() { + for (var property in defaults) { + options[property] = defaults[property]; + } + }; + // This function provides access to the loaded language data. If // no arguments are passed in, it will simply return the current // global language object. - numeral.languageData = function (key) { + numeral.languageData = function(key) { if (!key) { - return languages[currentLanguage]; + return languages[options.currentLanguage]; } if (!languages[key]) { @@ -460,9 +516,9 @@ billion: 'b', trillion: 't' }, - ordinal: function (number) { + ordinal: function(number) { var b = number % 10; - return (~~ (number % 100 / 10) === 1) ? 'th' : + return (~~(number % 100 / 10) === 1) ? 'th' : (b === 1) ? 'st' : (b === 2) ? 'nd' : (b === 3) ? 'rd' : 'th'; @@ -472,12 +528,106 @@ } }); - numeral.zeroFormat = function (format) { - zeroFormat = typeof(format) === 'string' ? format : null; + numeral.zeroFormat = function(format) { + options.zeroFormat = typeof(format) === 'string' ? format : null; + }; + + numeral.nullFormat = function (format) { + options.nullFormat = typeof(format) === 'string' ? format : null; }; - numeral.defaultFormat = function (format) { - defaultFormat = typeof(format) === 'string' ? format : '0.0'; + numeral.defaultFormat = function(format) { + options.defaultFormat = typeof(format) === 'string' ? format : '0.0'; + }; + + numeral.validate = function(val, culture) { + + var _decimalSep, + _thousandSep, + _currSymbol, + _valArray, + _abbrObj, + _thousandRegEx, + languageData, + temp; + + //coerce val to string + if (typeof val !== 'string') { + val += ''; + if (console.warn) { + console.warn('Numeral.js: Value is not string. It has been co-erced to: ', val); + } + } + + //trim whitespaces from either sides + val = val.trim(); + + //if val is just digits return true + if ( !! val.match(/^\d+$/)) { + return true; + } + + //if val is empty return false + if (val === '') { + return false; + } + + //get the decimal and thousands separator from numeral.languageData + try { + //check if the culture is understood by numeral. if not, default it to current language + languageData = numeral.languageData(culture); + } catch (e) { + languageData = numeral.languageData(numeral.language()); + } + + //setup the delimiters and currency symbol based on culture/language + _currSymbol = languageData.currency.symbol; + _abbrObj = languageData.abbreviations; + _decimalSep = languageData.delimiters.decimal; + if (languageData.delimiters.thousands === '.') { + _thousandSep = '\\.'; + } else { + _thousandSep = languageData.delimiters.thousands; + } + + // validating currency symbol + temp = val.match(/^[^\d]+/); + if (temp !== null) { + val = val.substr(1); + if (temp[0] !== _currSymbol) { + return false; + } + } + + //validating abbreviation symbol + 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) { + return false; + } + } + + _thousandRegEx = new RegExp(_thousandSep + '{2}'); + + if (!val.match(/[^\d.,]/g)) { + _valArray = val.split(_decimalSep); + if (_valArray.length > 2) { + return false; + } else { + if (_valArray.length < 2) { + 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+$/)); + } else { + return ( !! _valArray[0].match(/^\d+.*\d$/) && !_valArray[0].match(_thousandRegEx) && !! _valArray[1].match(/^\d+$/)); + } + } + } + } + + return false; }; /************************************ @@ -495,55 +645,43 @@ // The floating-point helper functions and implementation // borrows heavily from sinful.js: http://guipn.github.io/sinful.js/ - /** - * Array.prototype.reduce for browsers that don't support it - * 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) { + // Production steps of ECMA-262, Edition 5, 15.4.4.21 + // Reference: http://es5.github.io/#x15.4.4.21 + if (!Array.prototype.reduce) { + Array.prototype.reduce = function(callback /*, initialValue*/) { 'use strict'; - - if (null === this || 'undefined' === typeof this) { - // At the moment all modern browsers, that support strict mode, have - // native implementation of Array.prototype.reduce. For instance, IE8 - // does not support strict mode, so this check is actually useless. + if (this === null) { throw new TypeError('Array.prototype.reduce called on null or undefined'); } - if ('function' !== typeof callback) { + if (typeof callback !== 'function') { throw new TypeError(callback + ' is not a function'); } - var index, - value, - length = this.length >>> 0, - isValueSet = false; + var t = Object(this), len = t.length >>> 0, k = 0, value; - if (1 < arguments.length) { - value = opt_initialValue; - isValueSet = true; - } + if (arguments.length === 2) { + value = arguments[1]; + } else { + while (k < len && !(k in t)) { + k++; + } - for (index = 0; length > index; ++index) { - if (this.hasOwnProperty(index)) { - if (isValueSet) { - value = callback(value, this[index], index, this); - } else { - value = this[index]; - isValueSet = true; - } + if (k >= len) { + throw new TypeError('Reduce of empty array with no initial value'); } - } - if (!isValueSet) { - throw new TypeError('Reduce of empty array with no initial value'); + value = t[k++]; + } + for (; k < len; k++) { + if (k in t) { + value = callback(value, t[k], k, t); + } } - return value; }; } - /** * Computes the multiplier necessary to make x >= 1, * effectively eliminating miscalculations caused by @@ -564,10 +702,10 @@ */ function correctionFactor() { var args = Array.prototype.slice.call(arguments); - return args.reduce(function (prev, next) { + return args.reduce(function(prev, next) { var mp = multiplier(prev), mn = multiplier(next); - return mp > mn ? mp : mn; + return mp > mn ? mp : mn; }, -Infinity); } @@ -579,13 +717,13 @@ numeral.fn = Numeral.prototype = { - clone : function () { + clone: function() { return numeral(this); }, format : function (inputString, roundingFunction) { return formatNumeral(this, - inputString ? inputString : defaultFormat, + inputString ? inputString : options.defaultFormat, (roundingFunction !== undefined) ? roundingFunction : Math.round ); }, @@ -594,24 +732,25 @@ if (Object.prototype.toString.call(inputString) === '[object Number]') { return inputString; } - return unformatNumeral(this, inputString ? inputString : defaultFormat); + return unformatNumeral(this, inputString ? inputString : options.defaultFormat); }, - value : function () { + value: function() { return this._value; }, - valueOf : function () { + valueOf: function() { return this._value; }, - set : function (value) { + set: function(value) { this._value = Number(value); return this; }, - add : function (value) { + add: function(value) { var corrFactor = correctionFactor.call(null, this._value, value); + function cback(accum, curr, currI, O) { return accum + corrFactor * curr; } @@ -619,8 +758,9 @@ return this; }, - subtract : function (value) { + subtract: function(value) { var corrFactor = correctionFactor.call(null, this._value, value); + function cback(accum, curr, currI, O) { return accum - corrFactor * curr; } @@ -628,7 +768,7 @@ return this; }, - multiply : function (value) { + multiply: function(value) { function cback(accum, curr, currI, O) { var corrFactor = correctionFactor(accum, curr); return (accum * corrFactor) * (curr * corrFactor) / @@ -638,7 +778,7 @@ return this; }, - divide : function (value) { + divide: function(value) { function cback(accum, curr, currI, O) { var corrFactor = correctionFactor(accum, curr); return (accum * corrFactor) / (curr * corrFactor); @@ -647,7 +787,7 @@ return this; }, - difference : function (value) { + difference: function(value) { return Math.abs(numeral(this._value).subtract(value).value()); } @@ -658,7 +798,7 @@ ************************************/ // CommonJS module is defined - if (hasModule) { + if (typeof module !== 'undefined' && module.exports) { module.exports = numeral; } @@ -672,7 +812,7 @@ /*global define:false */ if (typeof define === 'function' && define.amd) { - define([], function () { + define([], function() { return numeral; }); } diff --git a/package.json b/package.json index ecaa7447..d422cd41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "numeral", - "version": "1.5.3", + "version": "1.5.4", "description": "Format and manipulate numbers.", "homepage": "http://numeraljs.com", "author": { @@ -27,24 +27,31 @@ "bugs": { "url": "https://github.com/adamwdraper/Numeral-js/issues" }, - "licenses": [ - { - "type": "MIT" - } - ], + "license": "MIT", "devDependencies": { - "uglify-js": "latest", + "chai": "^3.5.0", "grunt": "latest", - "grunt-contrib-uglify": "latest", + "grunt-contrib-concat": "1.0.1", "grunt-contrib-jshint": "latest", "grunt-contrib-nodeunit": "1.0.0", - "grunt-contrib-concat": "1.0.1" + "grunt-contrib-uglify": "latest", + "grunt-karma": "^2.0.0", + "grunt-mocha-test": "^0.13.2", + "grunt-saucelabs": "*", + "karma": "^1.3.0", + "karma-chai": "^0.1.0", + "karma-chrome-launcher": "^2.0.0", + "karma-firefox-launcher": "^1.0.0", + "karma-mocha": "^1.3.0", + "karma-mocha-reporter": "^2.2.1", + "karma-sauce-launcher": "^1.1.0", + "mocha": "^3.1.2", + "uglify-js": "latest" }, "scripts": { "test": "grunt" }, "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://numeraljs.com)\n\nChangelog\n=========\n\n### 1.5.2\nBug fix: Unformat should pass through if given a number\n\nAdded a mechanism to control rounding behaviour\n\nAdded languageData() for getting and setting language props at runtime### 1.5.1\nBug fix: Make sure values aren't changed during formatting### 1.5.0\nAdd defaultFormat(). numeral().format() uses the default to format if no string is provided\n\n.unformat() returns 0 when passed no string\n\nAdded languages.js that contains all languages\n\nBug fix: Fix bug while unformatting ordinals\n\nAdd format option to always show signed value\n\nAdded ability to instantiate numeral with a string value of a number\n### 1.4.9\nBug fix: Fix bug while unformatting ordinals\n### 1.4.8\nBug fix: Throw error if language is not defined\n### 1.4.7\nBug fix: Fix typo for trillion\n### 1.4.6\nBug fix: remove ' from unformatting regex that was causing an error with fr-ch.js\n### 1.4.5\nAdd zeroFormat() function that accepts a string for custom formating of zeros\n\nAdd valueOf() function\n\nChain functionality to language function\n\nMake all minified files have the same .min.js filename ending\n### 1.4.1\nBug fix: Bytes not formatting correctly\n### 1.4.0\nAdd optional format for all decimals\n### 1.3.4\nRemove AMD module id. (This is encouraged by require.js to make the module more portable, and keep it from creating a global)\n### 1.3.3\nAMD define() compatibility.\n### 1.3.2\nBug fix: Formatting some numbers results in the wrong value. Issue #21\n### 1.3.1\nBug fix: Minor fix to unformatting parser\n### 1.3.0\nAdd support for spaces before/after $, a, o, b in a format string\nBug fix: Fix unformat for languages that use '.' in ordinals\nBug fix: Fix round up floating numbers with no precision correctly.\nBug fix: Fix currency signs at the end in unformat\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.5.2", + "_id": "numeral@1.5.4", "_from": "numeral" } diff --git a/tests/languages/be-nl.js b/tests/languages/be-nl.js index 1ac29771..e9816eee 100644 --- a/tests/languages/be-nl.js +++ b/tests/languages/be-nl.js @@ -1,107 +1,102 @@ -var numeral = require('../../numeral'), - language = require('../../languages/be-nl'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/be-nl'); +} -numeral.language('be-nl', language); +describe('Language: be-nl', function() { -exports['language:be-nl'] = { - setUp: function (callback) { - numeral.language('be-nl'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(22); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2 mln'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [0,'0o','0de'], - [1,'0o','1ste'], - [2,'0o','2de'], - [8,'0o','8ste'], - [19,'0o','19de'], - [20,'0o','20ste'], - [100,'0o','100ste'], - [102,'0o','102de'], - [108,'0o','108ste'], - [109,'0o','109de'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€ 1 000,23'], - [-1000.234,'($0,0)','(€ 1 000)'], - [-1000.234,'$0.00','-€ 1000,23'], - [1230974,'($0.00a)','€ 1,23 mln'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('be-nl', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(€ 1,23 mln)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23e',23], - ['€ 10 000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('be-nl'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2 mln'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [0,'0o','0de'], + [1,'0o','1ste'], + [2,'0o','2de'], + [8,'0o','8ste'], + [19,'0o','19de'], + [20,'0o','20ste'], + [100,'0o','100ste'], + [102,'0o','102de'], + [108,'0o','108ste'], + [109,'0o','109de'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€ 1 000,23'], + [-1000.234,'($0,0)','(€ 1 000)'], + [-1000.234,'$0.00','-€ 1000,23'], + [1230974,'($0.00a)','€ 1,23 mln'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€ 1,23 mln)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23e',23], + ['€ 10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/chs.js b/tests/languages/chs.js index c9afe9f2..e5b50ff2 100644 --- a/tests/languages/chs.js +++ b/tests/languages/chs.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'); -var language = require('../../languages/chs'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/chs'); +} -numeral.language('chs', language); +describe('Language: chs', function() { -exports['language:chs'] = { - setUp: function (callback) { - numeral.language('chs'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10,000.0000'], - [10000.23,'0,0','10,000'], - [-10000,'0,0.0','-10,000.0'], - [10000.1234,'0.000','10000.123'], - [-10000,'(0,0.0000)','(10,000.0000)'], - [-0.23,'.00','-.23'], - [-0.23,'(.00)','(.23)'], - [0.23,'0.00000','0.23000'], - [1230974,'0.0a','1.2百万'], - [1460,'0a','1千'], - [-104000,'0a','-104千'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','¥1,000.23'], - [-1000.234,'($0,0)','(¥1,000)'], - [-1000.234,'$0.00','-¥1000.23'], - [1230974,'($0.00a)','¥1.23百万'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('chs', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97.488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43.000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10,000.123',10000.123], - ['(0.12345)',-0.12345], - ['(¥1.23百万)',-1230000], - ['10千',10000], - ['-10千',-10000], - ['23.',23], - ['¥10,000.00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('chs'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format number', function() { + var tests = [ + [10000,'0,0.0000','10,000.0000'], + [10000.23,'0,0','10,000'], + [-10000,'0,0.0','-10,000.0'], + [10000.1234,'0.000','10000.123'], + [-10000,'(0,0.0000)','(10,000.0000)'], + [-0.23,'.00','-.23'], + [-0.23,'(.00)','(.23)'], + [0.23,'0.00000','0.23000'], + [1230974,'0.0a','1.2百万'], + [1460,'0a','1千'], + [-104000,'0a','-104千'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','¥1,000.23'], + [-1000.234,'($0,0)','(¥1,000)'], + [-1000.234,'$0.00','-¥1000.23'], + [1230974,'($0.00a)','¥1.23百万'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97.488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43.000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10,000.123',10000.123], + ['(0.12345)',-0.12345], + ['(¥1.23百万)',-1230000], + ['10千',10000], + ['-10千',-10000], + ['23.',23], + ['¥10,000.00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/cs.js b/tests/languages/cs.js index 7be84aa1..af797538 100644 --- a/tests/languages/cs.js +++ b/tests/languages/cs.js @@ -1,102 +1,97 @@ -var numeral = require('../../numeral'), - language = require('../../languages/cs'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/cs'); +} -numeral.language('cs', language); +describe('Language: cs', function() { -exports['language:cs'] = { - setUp: function (callback) { - numeral.language('cs'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2mil.'], - [1460,'0a','1tis.'], - [-104000,'0a','-104tis.'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'0,0.00$','1 000,23Kč'], - [-1000.234,'(0,0$)','(1 000Kč)'], - [-1000.234,'0.00$','-1000,23Kč'], - [1230974,'(0.00a$)','1,23mil.Kč'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('cs', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(10); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(1,23mil.Kč)',-1230000], - ['1,23mil.Kč',1230000], - ['10tis.',10000], - ['-10tis.',-10000], - ['23.',23], - ['10 000,00Kč',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('cs'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2mil.'], + [1460,'0a','1tis.'], + [-104000,'0a','-104tis.'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'0,0.00$','1 000,23Kč'], + [-1000.234,'(0,0$)','(1 000Kč)'], + [-1000.234,'0.00$','-1000,23Kč'], + [1230974,'(0.00a$)','1,23mil.Kč'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(1,23mil.Kč)',-1230000], + ['1,23mil.Kč',1230000], + ['10tis.',10000], + ['-10tis.',-10000], + ['23.',23], + ['10 000,00Kč',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/da-dk.js b/tests/languages/da-dk.js index 2393eb1c..17f5798f 100644 --- a/tests/languages/da-dk.js +++ b/tests/languages/da-dk.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/da-dk'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/da-dk'); +} -numeral.language('da-dk', language); +describe('Language: da-dk', function() { -exports['language:da-dk'] = { - setUp: function (callback) { - numeral.language('da-dk'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10.000,0000'], - [10000.23,'0,0','10.000'], - [-10000,'0,0.0','-10.000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10.000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2mio'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','DKK1.000,23'], - [-1000.234,'($0,0)','(DKK1.000)'], - [-1000.234,'$0.00','-DKK1000,23'], - [1230974,'($0.00a)','DKK1,23mio'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('da-dk', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10.000,123',10000.123], - ['(0,12345)',-0.12345], - ['(DKK1,23mio)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23.',23], - ['DK10.000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('da-dk'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10.000,0000'], + [10000.23,'0,0','10.000'], + [-10000,'0,0.0','-10.000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10.000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2mio'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','DKK1.000,23'], + [-1000.234,'($0,0)','(DKK1.000)'], + [-1000.234,'$0.00','-DKK1000,23'], + [1230974,'($0.00a)','DKK1,23mio'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['(DKK1,23mio)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23.',23], + ['DK10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/de-ch.js b/tests/languages/de-ch.js index bb989359..9cae4b1d 100644 --- a/tests/languages/de-ch.js +++ b/tests/languages/de-ch.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/de-ch'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/de-ch'); +} -numeral.language('de-ch', language); +describe('Language: de-ch', function() { -exports['language:de-ch'] = { - setUp: function (callback) { - numeral.language('de-ch'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2m'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','CHF1 000,23'], - [-1000.234,'($0,0)','(CHF1 000)'], - [-1000.234,'$0.00','-CHF1000,23'], - [1230974,'($0.00a)','CHF1,23m'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('de-ch', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [.974878234,'0.000%','97,488%'], - [-.43,'0%','-43%'], - [.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-.12345], - ['(CHF1,23m)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23.',23], - ['CHF10 000,00',10000], - ['-76%',-.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('de-ch'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2m'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','CHF1 000,23'], + [-1000.234,'($0,0)','(CHF1 000)'], + [-1000.234,'$0.00','-CHF1000,23'], + [1230974,'($0.00a)','CHF1,23m'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(CHF1,23m)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23.',23], + ['CHF10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/de.js b/tests/languages/de.js index 3860d66a..8daae61a 100644 --- a/tests/languages/de.js +++ b/tests/languages/de.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/de'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/de'); +} -numeral.language('de', language); +describe('Language: de', function() { -exports['language:de'] = { - setUp: function (callback) { - numeral.language('de'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2m'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€1 000,23'], - [-1000.234,'($0,0)','(€1 000)'], - [-1000.234,'$0.00','-€1000,23'], - [1230974,'($0.00a)','€1,23m'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('de', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(€1,23m)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23.',23], - ['€10 000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('de'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2m'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€1 000,23'], + [-1000.234,'($0,0)','(€1 000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23m'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€1,23m)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23.',23], + ['€10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/en-gb.js b/tests/languages/en-gb.js index 45fb975b..cd4d05f7 100644 --- a/tests/languages/en-gb.js +++ b/tests/languages/en-gb.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/en-gb'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/en-gb'); +} -numeral.language('en-gb', language); +describe('Language: en-gb', function() { -exports['language:en-gb'] = { - setUp: function (callback) { - numeral.language('en-gb'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10,000.0000'], - [10000.23,'0,0','10,000'], - [-10000,'0,0.0','-10,000.0'], - [10000.1234,'0.000','10000.123'], - [-10000,'(0,0.0000)','(10,000.0000)'], - [-0.23,'.00','-.23'], - [-0.23,'(.00)','(.23)'], - [0.23,'0.00000','0.23000'], - [1230974,'0.0a','1.2m'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1st'], - [52,'0o','52nd'], - [23,'0o','23rd'], - [100,'0o','100th'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','£1,000.23'], - [-1000.234,'($0,0)','(£1,000)'], - [-1000.234,'$0.00','-£1000.23'], - [1230974,'($0.00a)','£1.23m'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('en-gb', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97.488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43.000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10,000.123',10000.123], - ['(0.12345)',-0.12345], - ['(£1.23m)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23rd',23], - ['£10,000.00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('en-gb'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10,000.0000'], + [10000.23,'0,0','10,000'], + [-10000,'0,0.0','-10,000.0'], + [10000.1234,'0.000','10000.123'], + [-10000,'(0,0.0000)','(10,000.0000)'], + [-0.23,'.00','-.23'], + [-0.23,'(.00)','(.23)'], + [0.23,'0.00000','0.23000'], + [1230974,'0.0a','1.2m'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1st'], + [52,'0o','52nd'], + [23,'0o','23rd'], + [100,'0o','100th'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','£1,000.23'], + [-1000.234,'($0,0)','(£1,000)'], + [-1000.234,'$0.00','-£1000.23'], + [1230974,'($0.00a)','£1.23m'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97.488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43.000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10,000.123',10000.123], + ['(0.12345)',-0.12345], + ['(£1.23m)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23rd',23], + ['£10,000.00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/en-za.js b/tests/languages/en-za.js new file mode 100644 index 00000000..93baadf4 --- /dev/null +++ b/tests/languages/en-za.js @@ -0,0 +1,96 @@ +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/en-za'); +} + +describe('Language: en-za', function() { + + before(function() { + numeral.language('en-za', language); + + numeral.language('en-za'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2m'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1st'], + [52,'0o','52nd'], + [23,'0o','23rd'], + [100,'0o','100th'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','R1 000,23'], + [-1000.234,'($0,0)','(R1 000)'], + [-1000.234,'$0.00','-R1000,23'], + [1230974,'($0.00a)','R1,23m'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(R1,23m)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23rd',23], + ['R10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/en.js b/tests/languages/en.js index 48a34f37..97e76650 100644 --- a/tests/languages/en.js +++ b/tests/languages/en.js @@ -1,98 +1,85 @@ -var numeral = require('../../numeral'); - -exports['language:en'] = { - setUp: function (callback) { - numeral.language('en'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10,000.0000'], - [10000.23,'0,0','10,000'], - [-10000,'0,0.0','-10,000.0'], - [10000.1234,'0.000','10000.123'], - [-10000,'(0,0.0000)','(10,000.0000)'], - [-0.23,'.00','-.23'], - [-0.23,'(.00)','(.23)'], - [0.23,'0.00000','0.23000'], - [1230974,'0.0a','1.2m'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1st'], - [52,'0o','52nd'], - [23,'0o','23rd'], - [100,'0o','100th'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','$1,000.23'], - [-1000.234,'($0,0)','($1,000)'], - [-1000.234,'$0.00','-$1000.23'], - [1230974,'($0.00a)','$1.23m'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97.488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43.000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10,000.123',10000.123], - ['(0.12345)',-0.12345], - ['($1.23m)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23rd',23], - ['$10,000.00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; +} + +describe('Language: en', function() { + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10,000.0000'], + [10000.23,'0,0','10,000'], + [-10000,'0,0.0','-10,000.0'], + [10000.1234,'0.000','10000.123'], + [-10000,'(0,0.0000)','(10,000.0000)'], + [-0.23,'.00','-.23'], + [-0.23,'(.00)','(.23)'], + [0.23,'0.00000','0.23000'], + [1230974,'0.0a','1.2m'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1st'], + [52,'0o','52nd'], + [23,'0o','23rd'], + [100,'0o','100th'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','$1,000.23'], + [-1000.234,'($0,0)','($1,000)'], + [-1000.234,'$0.00','-$1000.23'], + [1230974,'($0.00a)','$1.23m'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97.488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43.000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10,000.123',10000.123], + ['(0.12345)',-0.12345], + ['($1.23m)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23rd',23], + ['$10,000.00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/es-ES.js b/tests/languages/es-ES.js index a0db5368..08311618 100644 --- a/tests/languages/es-ES.js +++ b/tests/languages/es-ES.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/es-ES'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/es-ES'); +} -numeral.language('es-ES', language); +describe('Language: es-ES', function() { -exports['language:es-ES'] = { - setUp: function (callback) { - numeral.language('es-ES'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10.000,0000'], - [10000.23,'0,0','10.000'], - [-10000,'0,0.0','-10.000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10.000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2mm'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1er'], - [52,'0o','52do'], - [23,'0o','23er'], - [100,'0o','100mo'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€1.000,23'], - [-1000.234,'($0,0)','(€1.000)'], - [-1000.234,'$0.00','-€1000,23'], - [1230974,'($0.00a)','€1,23mm'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('es-ES', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10.000,123',10000.123], - ['(0,12345)',-0.12345], - ['($1,23mm)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23er',23], - ['$10.000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('es-ES'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10.000,0000'], + [10000.23,'0,0','10.000'], + [-10000,'0,0.0','-10.000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10.000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2mm'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1er'], + [52,'0o','52do'], + [23,'0o','23er'], + [100,'0o','100mo'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€1.000,23'], + [-1000.234,'($0,0)','(€1.000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23mm'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['($1,23mm)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23er',23], + ['$10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/es.js b/tests/languages/es.js index 06843184..04a2b271 100644 --- a/tests/languages/es.js +++ b/tests/languages/es.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/es'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/es'); +} -numeral.language('es', language); +describe('Language: es', function() { -exports['language:es'] = { - setUp: function (callback) { - numeral.language('es'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10.000,0000'], - [10000.23,'0,0','10.000'], - [-10000,'0,0.0','-10.000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10.000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2mm'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1er'], - [52,'0o','52do'], - [23,'0o','23er'], - [100,'0o','100mo'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','$1.000,23'], - [-1000.234,'($0,0)','($1.000)'], - [-1000.234,'$0.00','-$1000,23'], - [1230974,'($0.00a)','$1,23mm'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('es', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10.000,123',10000.123], - ['(0,12345)',-0.12345], - ['($1,23mm)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23er',23], - ['$10.000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('es'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10.000,0000'], + [10000.23,'0,0','10.000'], + [-10000,'0,0.0','-10.000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10.000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2mm'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1er'], + [52,'0o','52do'], + [23,'0o','23er'], + [100,'0o','100mo'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','$1.000,23'], + [-1000.234,'($0,0)','($1.000)'], + [-1000.234,'$0.00','-$1000,23'], + [1230974,'($0.00a)','$1,23mm'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['($1,23mm)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23er',23], + ['$10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/et.js b/tests/languages/et.js index 1f1e54a3..3ec74a4c 100644 --- a/tests/languages/et.js +++ b/tests/languages/et.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/et'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/et'); +} -numeral.language('et', language); +describe('Language: et', function() { -exports['language:et'] = { - setUp: function (callback) { - numeral.language('et'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2 mln'], - [1460,'0a','1 tuh'], - [-104000,'0a','-104 tuh'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€1 000,23'], - [-1000.234,'($0,0)','(€1 000)'], - [-1000.234,'$0.00','-€1000,23'], - [1230974,'($0.00a)','€1,23 mln'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('et', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10.000,123',10000.123], - ['(0,12345)',-0.12345], - ['(€1,23 mln)',-1230000], - ['10 tuh',10000], - ['-10 tuh',-10000], - ['23.',23], - ['€10.000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('et'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2 mln'], + [1460,'0a','1 tuh'], + [-104000,'0a','-104 tuh'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€1 000,23'], + [-1000.234,'($0,0)','(€1 000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23 mln'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€1,23 mln)',-1230000], + ['10 tuh',10000], + ['-10 tuh',-10000], + ['23.',23], + ['€10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/fi.js b/tests/languages/fi.js index 2637f074..dfd22a1d 100644 --- a/tests/languages/fi.js +++ b/tests/languages/fi.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/fi'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/fi'); +} -numeral.language('fi', language); +describe('Language: fi', function() { -exports['language:fi'] = { - setUp: function (callback) { - numeral.language('fi'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2M'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€1 000,23'], - [-1000.234,'($0,0)','(€1 000)'], - [-1000.234,'$0.00','-€1000,23'], - [1230974,'($0.00a)','€1,23M'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('fi', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10.000,123',10000.123], - ['(0,12345)',-0.12345], - ['(€1,23M)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23.',23], - ['€10.000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('fi'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2M'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€1 000,23'], + [-1000.234,'($0,0)','(€1 000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23M'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€1,23M)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23.',23], + ['€10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/fr-CA.js b/tests/languages/fr-CA.js index 8ad94bc3..24da89c5 100644 --- a/tests/languages/fr-CA.js +++ b/tests/languages/fr-CA.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/fr-CA'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/fr-CA'); +} -numeral.language('fr-CA', language); +describe('Language: fr-CA', function() { -exports['language:fr'] = { - setUp: function (callback) { - numeral.language('fr-CA'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0 a','1,2 M'], - [1460,'0 a','1 k'], - [-104000,'0 a','-104 k'], - [1,'0o','1er'], - [52,'0o','52e'], - [23,'0o','23e'], - [100,'0o','100e'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'0,0.00 $','1 000,23 $'], - [-1000.234,'(0,0 $)','(1 000 $)'], - [-1000.234,'0.00 $','-1000,23 $'], - [1230974,'(0.00 a$)','1,23 M$'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('fr-CA', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0 %','100 %'], - [0.974878234,'0.000 %','97,488 %'], - [-0.43,'0 %','-43 %'], - [0.43,'(0.000 %)','43,000 %'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(1,23 M$)',-1230000], - ['10 k',10000], - ['-10 k',-10000], - ['23e',23], - ['10 000,00 $',10000], - ['-76 %',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('fr-CA'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0 a','1,2 M'], + [1460,'0 a','1 k'], + [-104000,'0 a','-104 k'], + [1,'0o','1er'], + [52,'0o','52e'], + [23,'0o','23e'], + [100,'0o','100e'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'0,0.00 $','1 000,23 $'], + [-1000.234,'(0,0 $)','(1 000 $)'], + [-1000.234,'0.00 $','-1000,23 $'], + [1230974,'(0.00 a$)','1,23 M$'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0 %','100 %'], + [0.974878234,'0.000 %','97,488 %'], + [-0.43,'0 %','-43 %'], + [0.43,'(0.000 %)','43,000 %'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(1,23 M$)',-1230000], + ['10 k',10000], + ['-10 k',-10000], + ['23e',23], + ['10 000,00 $',10000], + ['-76 %',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/fr-ch.js b/tests/languages/fr-ch.js index 14a9a22d..aeb96800 100644 --- a/tests/languages/fr-ch.js +++ b/tests/languages/fr-ch.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/fr-ch'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/fr-ch'); +} -numeral.language('fr-ch', language); +describe('Language: fr-ch', function() { -exports['language:fr-ch'] = { - setUp: function (callback) { - numeral.language('fr-ch'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10\'000.0000'], - [10000.23,'0,0','10\'000'], - [-10000,'0,0.0','-10\'000.0'], - [10000.1234,'0.000','10000.123'], - [-10000,'(0,0.0000)','(10\'000.0000)'], - [-0.23,'.00','-.23'], - [-0.23,'(.00)','(.23)'], - [0.23,'0.00000','0.23000'], - [1230974,'0.0a','1.2m'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1er'], - [52,'0o','52e'], - [23,'0o','23e'], - [100,'0o','100e'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','CHF1\'000.23'], - [-1000.234,'($0,0)','(CHF1\'000)'], - [-1000.234,'$0.00','-CHF1000.23'], - [1230974,'($0.00a)','CHF1.23m'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('fr-ch', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97.488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43.000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10\'000.123',10000.123], - ['(0.12345)',-0.12345], - ['(CHF1.23m)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23e',23], - ['CHF10\'000.00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('fr-ch'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10\'000.0000'], + [10000.23,'0,0','10\'000'], + [-10000,'0,0.0','-10\'000.0'], + [10000.1234,'0.000','10000.123'], + [-10000,'(0,0.0000)','(10\'000.0000)'], + [-0.23,'.00','-.23'], + [-0.23,'(.00)','(.23)'], + [0.23,'0.00000','0.23000'], + [1230974,'0.0a','1.2m'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1er'], + [52,'0o','52e'], + [23,'0o','23e'], + [100,'0o','100e'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','CHF1\'000.23'], + [-1000.234,'($0,0)','(CHF1\'000)'], + [-1000.234,'$0.00','-CHF1000.23'], + [1230974,'($0.00a)','CHF1.23m'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97.488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43.000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10\'000.123',10000.123], + ['(0.12345)',-0.12345], + ['(CHF1.23m)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23e',23], + ['CHF10\'000.00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/fr.js b/tests/languages/fr.js index 3a461538..b03627eb 100644 --- a/tests/languages/fr.js +++ b/tests/languages/fr.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/fr'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/fr'); +} -numeral.language('fr', language); +describe('Language: fr', function() { -exports['language:fr'] = { - setUp: function (callback) { - numeral.language('fr'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2m'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1er'], - [52,'0o','52e'], - [23,'0o','23e'], - [100,'0o','100e'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€1 000,23'], - [-1000.234,'($0,0)','(€1 000)'], - [-1000.234,'$0.00','-€1000,23'], - [1230974,'($0.00a)','€1,23m'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('fr', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(€1,23m)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23e',23], - ['€10 000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('fr'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2m'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1er'], + [52,'0o','52e'], + [23,'0o','23e'], + [100,'0o','100e'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€1 000,23'], + [-1000.234,'($0,0)','(€1 000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23m'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€1,23m)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23e',23], + ['€10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/hu.js b/tests/languages/hu.js index 407baaae..6a50ef8a 100644 --- a/tests/languages/hu.js +++ b/tests/languages/hu.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/hu'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/hu'); +} -numeral.language('hu', language); +describe('Language: hu', function() { -exports['language:hu'] = { - setUp: function (callback) { - numeral.language('hu'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2M'], - [1460,'0a','1E'], - [-104000,'0a','-104E'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'0,0.00$','1 000,23 Ft'], - [-1000.234,'(0,0$)','(1 000 Ft)'], - [-1000.234,'0.00$','-1000,23 Ft'], - [1230974,'(0.00a$)','1,23M Ft'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('hu', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(1,23M Ft)',-1230000], - ['10E',10000], - ['-10E',-10000], - ['23.',23], - ['10 000,00 Ft',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('hu'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2M'], + [1460,'0a','1E'], + [-104000,'0a','-104E'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'0,0.00$','1 000,23 Ft'], + [-1000.234,'(0,0$)','(1 000 Ft)'], + [-1000.234,'0.00$','-1000,23 Ft'], + [1230974,'(0.00a$)','1,23M Ft'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(1,23M Ft)',-1230000], + ['10E',10000], + ['-10E',-10000], + ['23.',23], + ['10 000,00 Ft',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/it.js b/tests/languages/it.js index 0d610793..7e7b3dc3 100644 --- a/tests/languages/it.js +++ b/tests/languages/it.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/it'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/it'); +} -numeral.language('it', language); +describe('Language: it', function() { -exports['language:it'] = { - setUp: function (callback) { - numeral.language('it'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10.000,0000'], - [10000.23,'0,0','10.000'], - [-10000,'0,0.0','-10.000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10.000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2mil'], - [1460,'0a','1mila'], - [-104000,'0a','-104mila'], - [1,'0o','1º'], - [52,'0o','52º'], - [23,'0o','23º'], - [100,'0o','100º'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€1.000,23'], - [-1000.234,'($0,0)','(€1.000)'], - [-1000.234,'$0.00','-€1000,23'], - [1230974,'($0.00a)','€1,23mil'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('it', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10.000,123',10000.123], - ['(0,12345)',-0.12345], - ['(€1,23mil)',-1230000], - ['10mila',10000], - ['-10mila',-10000], - ['23º',23], - ['€10.000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('it'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10.000,0000'], + [10000.23,'0,0','10.000'], + [-10000,'0,0.0','-10.000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10.000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2mil'], + [1460,'0a','1mila'], + [-104000,'0a','-104mila'], + [1,'0o','1º'], + [52,'0o','52º'], + [23,'0o','23º'], + [100,'0o','100º'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€1.000,23'], + [-1000.234,'($0,0)','(€1.000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23mil'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€1,23mil)',-1230000], + ['10mila',10000], + ['-10mila',-10000], + ['23º',23], + ['€10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/ja.js b/tests/languages/ja.js index 6e58bd82..26d89627 100644 --- a/tests/languages/ja.js +++ b/tests/languages/ja.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/ja'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/ja'); +} -numeral.language('ja', language); +describe('Language: ja', function() { -exports['language:ja'] = { - setUp: function (callback) { - numeral.language('ja'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10,000.0000'], - [10000.23,'0,0','10,000'], - [-10000,'0,0.0','-10,000.0'], - [10000.1234,'0.000','10000.123'], - [-10000,'(0,0.0000)','(10,000.0000)'], - [-0.23,'.00','-.23'], - [-0.23,'(.00)','(.23)'], - [0.23,'0.00000','0.23000'], - [1230974,'0.0a','1.2百万'], - [1460,'0a','1千'], - [-104000,'0a','-104千'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','¥1,000.23'], - [-1000.234,'($0,0)','(¥1,000)'], - [-1000.234,'$0.00','-¥1000.23'], - [1230974,'($0.00a)','¥1.23百万'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('ja', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97.488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43.000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10,000.123',10000.123], - ['(0.12345)',-0.12345], - ['(¥1.23百万)',-1230000], - ['10千',10000], - ['-10千',-10000], - ['23.',23], - ['¥10,000.00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('ja'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10,000.0000'], + [10000.23,'0,0','10,000'], + [-10000,'0,0.0','-10,000.0'], + [10000.1234,'0.000','10000.123'], + [-10000,'(0,0.0000)','(10,000.0000)'], + [-0.23,'.00','-.23'], + [-0.23,'(.00)','(.23)'], + [0.23,'0.00000','0.23000'], + [1230974,'0.0a','1.2百万'], + [1460,'0a','1千'], + [-104000,'0a','-104千'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','¥1,000.23'], + [-1000.234,'($0,0)','(¥1,000)'], + [-1000.234,'$0.00','-¥1000.23'], + [1230974,'($0.00a)','¥1.23百万'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97.488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43.000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10,000.123',10000.123], + ['(0.12345)',-0.12345], + ['(¥1.23百万)',-1230000], + ['10千',10000], + ['-10千',-10000], + ['23.',23], + ['¥10,000.00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/lv.js b/tests/languages/lv.js new file mode 100644 index 00000000..e6581d8c --- /dev/null +++ b/tests/languages/lv.js @@ -0,0 +1,96 @@ +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/lv'); +} + +describe('Language: lv', function() { + + before(function() { + numeral.language('lv', language); + + numeral.language('lv'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2 milj.'], + [1460,'0a','1 tūkst.'], + [-104000,'0a','-104 tūkst.'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€1 000,23'], + [-1000.234,'($0,0)','(€1 000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23 milj.'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€1,23 milj.)',-1230000], + ['10 tūkst.',10000], + ['-10 tūkst.',-10000], + ['23.',23], + ['€10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/nl-nl.js b/tests/languages/nl-nl.js index ce49b07e..32c93085 100644 --- a/tests/languages/nl-nl.js +++ b/tests/languages/nl-nl.js @@ -1,109 +1,104 @@ -var numeral = require('../../numeral'), - language = require('../../languages/nl-nl'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/nl-nl'); +} -numeral.language('nl-nl', language); +describe('Language: nl-nl', function() { -exports['language:nl-nl'] = { - setUp: function (callback) { - numeral.language('nl-nl'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(24); - - var tests = [ - [10000,'0,0.0000','10.000,0000'], - [10000.23,'0,0','10.000'], - [-10000,'0,0.0','-10.000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10.000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2mln'], - [1430974124,'0.0a','1,4mrd'], - [9123456789234,'0.0a','9,1bln'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [0,'0o','0de'], - [1,'0o','1ste'], - [2,'0o','2de'], - [8,'0o','8ste'], - [19,'0o','19de'], - [20,'0o','20ste'], - [100,'0o','100ste'], - [102,'0o','102de'], - [108,'0o','108ste'], - [109,'0o','109de'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€ 1.000,23'], - [-1000.234,'($0,0)','(€ 1.000)'], - [-1000.234,'$0.00','-€ 1000,23'], - [1230974,'($0.00a)','€ 1,23mln'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('nl-nl', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10.000,123',10000.123], - ['(0,12345)',-0.12345], - ['(€ 1,23 mln)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23e',23], - ['€ 10.000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('nl-nl'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10.000,0000'], + [10000.23,'0,0','10.000'], + [-10000,'0,0.0','-10.000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10.000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2mln'], + [1430974124,'0.0a','1,4mrd'], + [9123456789234,'0.0a','9,1bln'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [0,'0o','0de'], + [1,'0o','1ste'], + [2,'0o','2de'], + [8,'0o','8ste'], + [19,'0o','19de'], + [20,'0o','20ste'], + [100,'0o','100ste'], + [102,'0o','102de'], + [108,'0o','108ste'], + [109,'0o','109de'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€ 1.000,23'], + [-1000.234,'($0,0)','(€ 1.000)'], + [-1000.234,'$0.00','-€ 1000,23'], + [1230974,'($0.00a)','€ 1,23mln'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€ 1,23 mln)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23e',23], + ['€ 10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/no.js b/tests/languages/no.js new file mode 100644 index 00000000..a77804eb --- /dev/null +++ b/tests/languages/no.js @@ -0,0 +1,96 @@ +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/no'); +} + +describe('Language: no', function() { + + before(function() { + numeral.language('no', language); + + numeral.language('no'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2m'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','kr1 000,23'], + [-1000.234,'($0,0)','(kr1 000)'], + [-1000.234,'$0.00','-kr1000,23'], + [1230974,'($0.00a)','kr1,23m'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(kr1,23m)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23.',23], + ['kr10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/pl.js b/tests/languages/pl.js index 51e5e2d4..a7c086bc 100644 --- a/tests/languages/pl.js +++ b/tests/languages/pl.js @@ -1,102 +1,97 @@ -var numeral = require('../../numeral'), - language = require('../../languages/pl'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/pl'); +} -numeral.language('pl', language); +describe('Language: pl', function() { -exports['language:pl'] = { - setUp: function (callback) { - numeral.language('pl'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2mln'], - [1460,'0a','1tys.'], - [-104000,'0a','-104tys.'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'0,0.00$','1 000,23PLN'], - [-1000.234,'(0,0$)','(1 000PLN)'], - [-1000.234,'0.00$','-1000,23PLN'], - [1230974,'(0.00a$)','1,23mlnPLN'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('pl', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(10); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(1,23mlnPLN)',-1230000], - ['1,23mlnPLN',1230000], - ['10tys.',10000], - ['-10tys.',-10000], - ['23.',23], - ['10 000,00PLN',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('pl'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2mln'], + [1460,'0a','1tys.'], + [-104000,'0a','-104tys.'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'0,0.00$','1 000,23PLN'], + [-1000.234,'(0,0$)','(1 000PLN)'], + [-1000.234,'0.00$','-1000,23PLN'], + [1230974,'(0.00a$)','1,23mlnPLN'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(1,23mlnPLN)',-1230000], + ['1,23mlnPLN',1230000], + ['10tys.',10000], + ['-10tys.',-10000], + ['23.',23], + ['10 000,00PLN',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/pt-br.js b/tests/languages/pt-br.js index 965965a1..99d95b15 100644 --- a/tests/languages/pt-br.js +++ b/tests/languages/pt-br.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/pt-br'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/pt-br'); +} -numeral.language('pt-br', language); +describe('Language: pt-br', function() { -exports['language:pt-br'] = { - setUp: function (callback) { - numeral.language('pt-br'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10.000,0000'], - [10000.23,'0,0','10.000'], - [-10000,'0,0.0','-10.000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10.000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2milhões'], - [1460,'0a','1mil'], - [-104000,'0a','-104mil'], - [1,'0o','1º'], - [52,'0o','52º'], - [23,'0o','23º'], - [100,'0o','100º'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','R$1.000,23'], - [-1000.234,'($0,0)','(R$1.000)'], - [-1000.234,'$0.00','-R$1000,23'], - [1230974,'($0.00a)','R$1,23milhões'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('pt-br', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10.000,123',10000.123], - ['(0,12345)',-0.12345], - ['(R$1,23milhões)',-1230000], - ['10mil',10000], - ['-10mil',-10000], - ['23º',23], - ['R$10.000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('pt-br'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10.000,0000'], + [10000.23,'0,0','10.000'], + [-10000,'0,0.0','-10.000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10.000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2milhões'], + [1460,'0a','1mil'], + [-104000,'0a','-104mil'], + [1,'0o','1º'], + [52,'0o','52º'], + [23,'0o','23º'], + [100,'0o','100º'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','R$1.000,23'], + [-1000.234,'($0,0)','(R$1.000)'], + [-1000.234,'$0.00','-R$1000,23'], + [1230974,'($0.00a)','R$1,23milhões'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['(R$1,23milhões)',-1230000], + ['10mil',10000], + ['-10mil',-10000], + ['23º',23], + ['R$10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/pt-pt.js b/tests/languages/pt-pt.js index d6d1221e..7cf49103 100644 --- a/tests/languages/pt-pt.js +++ b/tests/languages/pt-pt.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/pt-pt'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/pt-pt'); +} -numeral.language('pt-pt', language); +describe('Language: pt-pt', function() { -exports['language:pt-pt'] = { - setUp: function (callback) { - numeral.language('pt-pt'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2m'], - [1460,'0a','1k'], - [-104000,'0a','-104k'], - [1,'0o','1º'], - [52,'0o','52º'], - [23,'0o','23º'], - [100,'0o','100º'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€1 000,23'], - [-1000.234,'($0,0)','(€1 000)'], - [-1000.234,'$0.00','-€1000,23'], - [1230974,'($0.00a)','€1,23m'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('pt-pt', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(€1,23m)',-1230000], - ['10k',10000], - ['-10k',-10000], - ['23º',23], - ['€10 000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('pt-pt'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2m'], + [1460,'0a','1k'], + [-104000,'0a','-104k'], + [1,'0o','1º'], + [52,'0o','52º'], + [23,'0o','23º'], + [100,'0o','100º'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€1 000,23'], + [-1000.234,'($0,0)','(€1 000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23m'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€1,23m)',-1230000], + ['10k',10000], + ['-10k',-10000], + ['23º',23], + ['€10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/ru-UA.js b/tests/languages/ru-UA.js index 36651dce..f533cc48 100644 --- a/tests/languages/ru-UA.js +++ b/tests/languages/ru-UA.js @@ -1,102 +1,97 @@ -var numeral = require('../../numeral'), - language = require('../../languages/ru-UA'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/ru-UA'); +} -numeral.language('ru-UA', language); +describe('Language: ru-UA', function() { -exports['language:ru-UA'] = { - setUp: function (callback) { - numeral.language('ru-UA'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2млн'], - [1460,'0a','1тыс.'], - [-104000,'0a','-104тыс.'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'0,0.00$','1 000,23₴'], - [-1000.234,'(0,0$)','(1 000₴)'], - [-1000.234,'0.00$','-1000,23₴'], - [1230974,'(0.00a$)','1,23млн₴'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('ru-UA', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(10); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(1,23млн₴)',-1230000], - ['1,23млн₴',1230000], - ['10тыс.',10000], - ['-10тыс.',-10000], - ['23.',23], - ['10 000,00₴',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('ru-UA'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2млн'], + [1460,'0a','1тыс.'], + [-104000,'0a','-104тыс.'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'0,0.00$','1 000,23₴'], + [-1000.234,'(0,0$)','(1 000₴)'], + [-1000.234,'0.00$','-1000,23₴'], + [1230974,'(0.00a$)','1,23млн₴'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(1,23млн₴)',-1230000], + ['1,23млн₴',1230000], + ['10тыс.',10000], + ['-10тыс.',-10000], + ['23.',23], + ['10 000,00₴',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/ru.js b/tests/languages/ru.js index 90ec7723..52b00a69 100644 --- a/tests/languages/ru.js +++ b/tests/languages/ru.js @@ -1,102 +1,97 @@ -var numeral = require('../../numeral'), - language = require('../../languages/ru'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/ru'); +} -numeral.language('ru', language); +describe('Language: ru', function() { -exports['language:ru'] = { - setUp: function (callback) { - numeral.language('ru'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2млн'], - [1460,'0a','1тыс.'], - [-104000,'0a','-104тыс.'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'0,0.00$','1 000,23руб.'], - [-1000.234,'(0,0$)','(1 000руб.)'], - [-1000.234,'0.00$','-1000,23руб.'], - [1230974,'(0.00a$)','1,23млнруб.'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('ru', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(10); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(1,23млнруб.)',-1230000], - ['1,23млнруб.',1230000], - ['10тыс.',10000], - ['-10тыс.',-10000], - ['23.',23], - ['10 000,00руб.',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('ru'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2млн.'], + [1460,'0a','1тыс.'], + [-104000,'0a','-104тыс.'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'0,0.00$','1 000,23руб.'], + [-1000.234,'(0,0$)','(1 000руб.)'], + [-1000.234,'0.00$','-1000,23руб.'], + [1230974,'(0.00a$)','1,23млн.руб.'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(1,23млн.руб.)',-1230000], + ['1,23млн.руб.',1230000], + ['10тыс.',10000], + ['-10тыс.',-10000], + ['23.',23], + ['10 000,00руб.',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/sk.js b/tests/languages/sk.js index 6e40ba0f..28a63713 100644 --- a/tests/languages/sk.js +++ b/tests/languages/sk.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/sk'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/sk'); +} -numeral.language('sk', language); +describe('Language: sk', function() { -exports['language:sk'] = { - setUp: function (callback) { - numeral.language('sk'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2mil.'], - [1460,'0a','1tis.'], - [-104000,'0a','-104tis.'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','€1 000,23'], - [-1000.234,'($0,0)','(€1 000)'], - [-1000.234,'$0.00','-€1000,23'], - [1230974,'($0.00a)','€1,23mil.'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('sk', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(€1,23mil.)',-1230000], - ['10tis.',10000], - ['-10tis.',-10000], - ['23e',23], - ['€10 000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('sk'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2mil.'], + [1460,'0a','1tis.'], + [-104000,'0a','-104tis.'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','€1 000,23'], + [-1000.234,'($0,0)','(€1 000)'], + [-1000.234,'$0.00','-€1000,23'], + [1230974,'($0.00a)','€1,23mil.'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(€1,23mil.)',-1230000], + ['10tis.',10000], + ['-10tis.',-10000], + ['23e',23], + ['€10 000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/th.js b/tests/languages/th.js index e0209aa6..31538981 100644 --- a/tests/languages/th.js +++ b/tests/languages/th.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/th'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/th'); +} -numeral.language('th', language); +describe('Language: th', function() { -exports['language:th'] = { - setUp: function (callback) { - numeral.language('th'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10,000.0000'], - [10000.23,'0,0','10,000'], - [-10000,'0,0.0','-10,000.0'], - [10000.1234,'0.000','10000.123'], - [-10000,'(0,0.0000)','(10,000.0000)'], - [-0.23,'.00','-.23'], - [-0.23,'(.00)','(.23)'], - [0.23,'0.00000','0.23000'], - [1230974,'0.0a','1.2ล้าน'], - [1460,'0a','1พัน'], - [-104000,'0a','-104พัน'], - [1,'0o','1.'], - [52,'0o','52.'], - [23,'0o','23.'], - [100,'0o','100.'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','฿1,000.23'], - [-1000.234,'($0,0)','(฿1,000)'], - [-1000.234,'$0.00','-฿1000.23'], - [1230974,'($0.00a)','฿1.23ล้าน'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('th', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97.488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43.000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10,000.123',10000.123], - ['(0.12345)',-0.12345], - ['(฿1.23ล้าน)',-1230000], - ['10พัน',10000], - ['-10พัน',-10000], - ['23.',23], - ['฿10,000.00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; + numeral.language('th'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10,000.0000'], + [10000.23,'0,0','10,000'], + [-10000,'0,0.0','-10,000.0'], + [10000.1234,'0.000','10000.123'], + [-10000,'(0,0.0000)','(10,000.0000)'], + [-0.23,'.00','-.23'], + [-0.23,'(.00)','(.23)'], + [0.23,'0.00000','0.23000'], + [1230974,'0.0a','1.2ล้าน'], + [1460,'0a','1พัน'], + [-104000,'0a','-104พัน'], + [1,'0o','1.'], + [52,'0o','52.'], + [23,'0o','23.'], + [100,'0o','100.'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','฿1,000.23'], + [-1000.234,'($0,0)','(฿1,000)'], + [-1000.234,'$0.00','-฿1000.23'], + [1230974,'($0.00a)','฿1.23ล้าน'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97.488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43.000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10,000.123',10000.123], + ['(0.12345)',-0.12345], + ['(฿1.23ล้าน)',-1230000], + ['10พัน',10000], + ['-10พัน',-10000], + ['23.',23], + ['฿10,000.00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/tr.js b/tests/languages/tr.js index 3a34d348..30dffe9a 100644 --- a/tests/languages/tr.js +++ b/tests/languages/tr.js @@ -1,101 +1,96 @@ -var numeral = require('../../numeral'), - language = require('../../languages/tr'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/tr'); +} -numeral.language('tr', language); +describe('Language: tr', function() { -exports['language:tr'] = { - setUp: function (callback) { - numeral.language('tr'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10.000,0000'], - [10000.23,'0,0','10.000'], - [-10000,'0,0.0','-10.000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10.000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2milyon'], - [1460,'0a','1bin'], - [-104000,'0a','-104bin'], - [1,'0o','1\'inci'], - [52,'0o','52\'nci'], - [23,'0o','23\'üncü'], - [100,'0o','100\'üncü'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'$0,0.00','\u20BA1.000,23'], - [-1000.234,'($0,0)','(\u20BA1.000)'], - [-1000.234,'$0.00','-\u20BA1000,23'], - [1230974,'($0.00a)','\u20BA1,23milyon'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('tr', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(9); - - var tests = [ - ['10.000,123',10000.123], - ['(0,12345)',-0.12345], - ['(\u20BA1,23milyon)',-1230000], - ['10bin',10000], - ['-10bin',-10000], - ['23üncü',23], - ['\u20BA10.000,00',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('tr'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10.000,0000'], + [10000.23,'0,0','10.000'], + [-10000,'0,0.0','-10.000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10.000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2milyon'], + [1460,'0a','1bin'], + [-104000,'0a','-104bin'], + [1,'0o','1\'inci'], + [52,'0o','52\'nci'], + [23,'0o','23\'üncü'], + [100,'0o','100\'üncü'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'$0,0.00','\u20BA1.000,23'], + [-1000.234,'($0,0)','(\u20BA1.000)'], + [-1000.234,'$0.00','-\u20BA1000,23'], + [1230974,'($0.00a)','\u20BA1,23milyon'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10.000,123',10000.123], + ['(0,12345)',-0.12345], + ['(\u20BA1,23milyon)',-1230000], + ['10bin',10000], + ['-10bin',-10000], + ['23üncü',23], + ['\u20BA10.000,00',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/languages/uk-UA.js b/tests/languages/uk-UA.js index 38e0e0b0..ed8ce934 100644 --- a/tests/languages/uk-UA.js +++ b/tests/languages/uk-UA.js @@ -1,102 +1,97 @@ -var numeral = require('../../numeral'), - language = require('../../languages/uk-UA'); +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; + var language = require('../../languages/uk-UA'); +} -numeral.language('uk-UA', language); +describe('Language: uk-UA', function() { -exports['language:uk-UA'] = { - setUp: function (callback) { - numeral.language('uk-UA'); - callback(); - }, - - tearDown: function (callback) { - numeral.language('en'); - callback(); - }, - - format: function (test) { - test.expect(16); - - var tests = [ - [10000,'0,0.0000','10 000,0000'], - [10000.23,'0,0','10 000'], - [-10000,'0,0.0','-10 000,0'], - [10000.1234,'0.000','10000,123'], - [-10000,'(0,0.0000)','(10 000,0000)'], - [-0.23,'.00','-,23'], - [-0.23,'(.00)','(,23)'], - [0.23,'0.00000','0,23000'], - [1230974,'0.0a','1,2млн'], - [1460,'0a','1тис.'], - [-104000,'0a','-104тис.'], - [1,'0o','1'], - [52,'0o','52'], - [23,'0o','23'], - [100,'0o','100'], - [1,'0[.]0','1'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - test.expect(4); - - var tests = [ - [1000.234,'0,0.00$','1 000,23₴'], - [-1000.234,'(0,0$)','(1 000₴)'], - [-1000.234,'0.00$','-1000,23₴'], - [1230974,'(0.00a$)','1,23млн₴'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } + before(function() { + numeral.language('uk-UA', language); - test.done(); - }, - - percentages: function (test) { - test.expect(4); - - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97,488%'], - [-0.43,'0%','-43%'], - [0.43,'(0.000%)','43,000%'] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - unformat: function (test) { - test.expect(10); - - var tests = [ - ['10 000,123',10000.123], - ['(0,12345)',-0.12345], - ['(1,23млн₴)',-1230000], - ['1,23млн₴',1230000], - ['10тис.',10000], - ['-10тис.',-10000], - ['23.',23], - ['10 000,00₴',10000], - ['-76%',-0.76], - ['2:23:57',8637] - ]; - - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + numeral.language('uk-UA'); + }); + + after(function() { + numeral.reset(); + }); + + describe('Number', function() { + it('should format a number', function() { + var tests = [ + [10000,'0,0.0000','10 000,0000'], + [10000.23,'0,0','10 000'], + [-10000,'0,0.0','-10 000,0'], + [10000.1234,'0.000','10000,123'], + [-10000,'(0,0.0000)','(10 000,0000)'], + [-0.23,'.00','-,23'], + [-0.23,'(.00)','(,23)'], + [0.23,'0.00000','0,23000'], + [1230974,'0.0a','1,2млн'], + [1460,'0a','1тис.'], + [-104000,'0a','-104тис.'], + [1,'0o','1'], + [52,'0o','52'], + [23,'0o','23'], + [100,'0o','100'], + [1,'0[.]0','1'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format a currency', function() { + var tests = [ + [1000.234,'0,0.00$','1 000,23₴'], + [-1000.234,'(0,0$)','(1 000₴)'], + [-1000.234,'0.00$','-1000,23₴'], + [1230974,'(0.00a$)','1,23млн₴'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format a percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97,488%'], + [-0.43,'0%','-43%'], + [0.43,'(0.000%)','43,000%'] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Unformat', function() { + it('should unformat', function() { + var tests = [ + ['10 000,123',10000.123], + ['(0,12345)',-0.12345], + ['(1,23млн₴)',-1230000], + ['1,23млн₴',1230000], + ['10тис.',10000], + ['-10тис.',-10000], + ['23.',23], + ['10 000,00₴',10000], + ['-76%',-0.76], + ['2:23:57',8637] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/numeral/format.js b/tests/numeral/format.js index 53427ad4..76f19ac4 100644 --- a/tests/numeral/format.js +++ b/tests/numeral/format.js @@ -1,204 +1,208 @@ -var numeral = require('../../numeral'); -exports.format = { - default: function (test) { - test.expect(1); - - numeral.defaultFormat('0,0'); - - test.strictEqual(numeral(10000).format(), '10,000', '0.0'); - - test.done(); - }, - value: function (test) { - var tests = [ - '0,0.00', - '$0,0.00', - '0b', - '0,0%', - '00:00:00' - ], - value = 12345.6, - n = numeral(value), - format, - i; - - test.expect(test.length); - - for (i = 0; i < tests.length; i++) { - format = n.format(test[i]); - test.strictEqual(n.value(), value, 'value unchanged after format' + test[i]); - } - - test.done(); - }, - numbers: function (test) { - var tests = [ - [10000,'0,0.0000','10,000.0000'], - [10000.23,'0,0','10,000'], - [-10000,'0,0.0','-10,000.0'], - [10000.1234,'0.000','10000.123'], - [10000,'0[.]00','10000'], - [10000.1,'0[.]00','10000.10'], - [10000.123,'0[.]00','10000.12'], - [10000.456,'0[.]00','10000.46'], - [10000.001,'0[.]00','10000'], - [10000.45,'0[.]00[0]','10000.45'], - [10000.456,'0[.]00[0]','10000.456'], - [-10000,'(0,0.0000)','(10,000.0000)'], - [-12300,'+0,0.0000','-12,300.0000'], - [1230,'+0,0','+1,230'], - [100.78, '0', '101'], - [100.28, '0', '100'], - [1.932,'0.0','1.9'], - [1.9687,'0','2'], - [1.9687,'0.0','2.0'], - [-0.23,'.00','-.23'], - [-0.23,'(.00)','(.23)'], - [0.23,'0.00000','0.23000'], - [0.67,'0.0[0000]','0.67'], - [2000000000,'0.0a','2.0b'], - [1230974,'0.0a','1.2m'], - [1460,'0a','1k'], - [-104000,'0 a','-104 k'], - [1,'0o','1st'], - [52,'0 o','52 nd'], - [23,'0o','23rd'], - [100,'0o','100th'], - - // specified abbreviations - [-5444333222111, '0,0 aK', '-5,444,333,222 k'], - [-5444333222111, '0,0 aM', '-5,444,333 m'], - [-5444333222111, '0,0 aB', '-5,444 b'], - [-5444333222111, '0,0 aT', '-5 t'] - ], - i; - - test.expect(tests.length); - - for (i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - currency: function (test) { - var tests = [ - [1000.234,'$0,0.00','$1,000.23'], - [1001,'$ 0,0.[00]','$ 1,001'], - [1000.234,'0,0.00 $','1,000.23 $'], - [-1000.234,'($0,0)','($1,000)'], - [-1000.234,'(0,0$)','(1,000$)'], - [-1000.234,'$0.00','-$1000.23'], - [1230974,'($0.00 a)','$1.23 m'], - - // test symbol position before negative sign / open parens - [-1000.234,'$ (0,0)','$ (1,000)'], - [-1000.234,'$(0,0)','$(1,000)'], - [-1000.234,'$ (0,0.00)','$ (1,000.23)'], - [-1000.234,'$(0,0.00)','$(1,000.23)'], - [-1000.238,'$(0,0.00)','$(1,000.24)'], - [-1000.234,'$-0,0','$-1,000'], - [-1000.234,'$ -0,0','$ -1,000'], - - [1000.234,'$ (0,0)','$ 1,000'], - [1000.234,'$(0,0)','$1,000'], - [1000.234,'$ (0,0.00)','$ 1,000.23'], - [1000.234,'$(0,0.00)','$1,000.23'], - [1000.238,'$(0,0.00)','$1,000.24'], - [1000.234,'$-0,0)','$1,000'], - [1000.234,'$ -0,0','$ 1,000'] - ], - i; - - test.expect(tests.length); - - for (i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - bytes: function (test) { - var tests = [ - [100,'0b','100B'], - [1024*2,'0 b','2 KB'], - [1024*1024*5,'0b','5MB'], - [1024*1024*1024*7.343,'0.[0] b','7.3 GB'], - [1024*1024*1024*1024*3.1536544,'0.000b','3.154TB'], - [1024*1024*1024*1024*1024*2.953454534534,'0b','3PB'] +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; +} + +describe('Format', function() { + after(function() { + numeral.reset(); + }); + + describe('Default', function() { + it('should set a default format', function() { + numeral.defaultFormat('0,0'); + + expect(numeral(10000).format()).to.equal('10,000'); + }); + }); + + describe('Value', function() { + it('should return a value', function() { + var tests = [ + '0,0.00', + '$0,0.00', + '0b', + '0,0%', + '00:00:00' + ], + value = 12345.6, + n = numeral(value), + format, + test; + + for (i = 0; i < tests.length; i++) { + format = n.format(tests[i]); + + expect(n.value()).to.equal(value); + } + }); + }); + + describe('Numbers', function() { + it('should format to a number', function() { + var tests = [ + [10000,'0,0.0000','10,000.0000'], + [10000.23,'0,0','10,000'], + [-10000,'0,0.0','-10,000.0'], + [10000.1234,'0.000','10000.123'], + [10000,'0[.]00','10000'], + [10000.1,'0[.]00','10000.10'], + [10000.123,'0[.]00','10000.12'], + [10000.456,'0[.]00','10000.46'], + [10000.001,'0[.]00','10000'], + [10000.45,'0[.]00[0]','10000.45'], + [10000.456,'0[.]00[0]','10000.456'], + [-10000,'(0,0.0000)','(10,000.0000)'], + [-12300,'+0,0.0000','-12,300.0000'], + [1230,'+0,0','+1,230'], + [100.78, '0', '101'], + [100.28, '0', '100'], + [1.932,'0.0','1.9'], + [1.9687,'0','2'], + [1.9687,'0.0','2.0'], + [-0.23,'.00','-.23'], + [-0.23,'(.00)','(.23)'], + [0.23,'0.00000','0.23000'], + [0.67,'0.0[0000]','0.67'], + [3162.63,'0.0[00000000000000]','3162.63'], + [1.99,'0.[0]','2'], + [1.0501,'0.00[0]','1.05'], + [2000000000,'0.0a','2.0b'], + [1230974,'0.0a','1.2m'], + [1460,'0a','1k'], + [-104000,'0 a','-104 k'], + [1,'0o','1st'], + [52,'0 o','52 nd'], + [23,'0o','23rd'], + [100,'0o','100th'], + + // specified abbreviations + [-5444333222111, '0,0 aK', '-5,444,333,222 k'], + [-5444333222111, '0,0 aM', '-5,444,333 m'], + [-5444333222111, '0,0 aB', '-5,444 b'], + [-5444333222111, '0,0 aT', '-5 t'], + [123456, '0.0[0] aK', '123.46 k'] + ], + i; + + for (i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Currency', function() { + it('should format to currency', function() { + var tests = [ + [1000.234,'$0,0.00','$1,000.23'], + [1001,'$ 0,0.[00]','$ 1,001'], + [1000.234,'0,0.00 $','1,000.23 $'], + [-1000.234,'($0,0)','($1,000)'], + [-1000.234,'(0,0$)','(1,000$)'], + [-1000.234,'$0.00','-$1000.23'], + [1230974,'($0.00 a)','$1.23 m'], + + // test symbol position before negative sign / open parens + [-1000.234,'$ (0,0)','$ (1,000)'], + [-1000.234,'$(0,0)','$(1,000)'], + [-1000.234,'$ (0,0.00)','$ (1,000.23)'], + [-1000.234,'$(0,0.00)','$(1,000.23)'], + [-1000.238,'$(0,0.00)','$(1,000.24)'], + [-1000.234,'$-0,0','$-1,000'], + [-1000.234,'$ -0,0','$ -1,000'], + + [1000.234,'$ (0,0)','$ 1,000'], + [1000.234,'$(0,0)','$1,000'], + [1000.234,'$ (0,0.00)','$ 1,000.23'], + [1000.234,'$(0,0.00)','$1,000.23'], + [1000.238,'$(0,0.00)','$1,000.24'], + [1000.234,'$-0,0)','$1,000'], + [1000.234,'$ -0,0','$ 1,000'] + ], + i; + + for (i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Bytes', function() { + it('should format to bytes', function() { + var tests = [ + [100,'0b','100B'], + [1024*2,'0 b','2 KiB'], + [1024*1024*5,'0b','5MiB'], + [1024*1024*1024*7.343,'0.[0] b','7.3 GiB'], + [1024*1024*1024*1024*3.1536544,'0.000b','3.154TiB'], + [1024*1024*1024*1024*1024*2.953454534534,'0b','3PiB'], + [1000*2,'0 d','2 KB'], + [1000*1000*5,'0d','5MB'], + [1000*1000*1000*7.343,'0.[0] d','7.3 GB'], + [1000*1000*1000*1000*3.1536544,'0.000d','3.154TB'], + [1000*1000*1000*1000*1000*2.953454534534,'0d','3PB'] + ], + i; + + for (i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Percentages', function() { + it('should format to percentages', function() { + var tests = [ + [1,'0%','100%'], + [0.974878234,'0.000%','97.488%'], + [-0.43,'0 %','-43 %'], + [0.43,'(0.00[0]%)','43.00%'] + ], + i; + + for (i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); + + describe('Times', function() { + it('should format to times', function() { + var tests = [ + [25,'00:00:00','0:00:25'], + [238,'00:00:00','0:03:58'], + [63846,'00:00:00','17:44:06'] + ], + i; + + for (i = 0; i < tests.length; i++) { + expect(numeral(tests[i][0]).format(tests[i][1])).to.equal(tests[i][2]); + } + + }); + }); + + describe('Rounding', function() { + it('should format with rounding', function() { + var tests = [ + // value, format string, expected w/ floor, expected w/ ceil + [2280002, '0.00a', '2.28m', '2.29m'], + [10000.23,'0,0','10,000', '10,001'], + [1000.234,'$0,0.00','$1,000.23', '$1,000.24'], + [0.974878234,'0.000%','97.487%','97.488%'], + [-0.433,'0 %','-44 %', '-43 %'] ], i; - test.expect(tests.length); - - for (i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - percentages: function (test) { - var tests = [ - [1,'0%','100%'], - [0.974878234,'0.000%','97.488%'], - [-0.43,'0 %','-43 %'], - [0.43,'(0.00[0]%)','43.00%'] - ], - i; - - test.expect(tests.length); - - for (i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - times: function (test) { - var tests = [ - [25,'00:00:00','0:00:25'], - [238,'00:00:00','0:03:58'], - [63846,'00:00:00','17:44:06'] - ], - i; + for (i = 0; i < tests.length; i++) { + // floor + expect(numeral(tests[i][0]).format(tests[i][1], Math.floor)).to.equal(tests[i][2]); - test.expect(tests.length); - - for (i = 0; i < tests.length; i++) { - test.strictEqual(numeral(tests[i][0]).format(tests[i][1]), tests[i][2], tests[i][1]); - } - - test.done(); - }, - - rounding: function (test) { - var tests = [ - // value, format string, expected w/ floor, expected w/ ceil - [2280002, '0.00a', '2.28m', '2.29m'], - [10000.23,'0,0','10,000', '10,001'], - [1000.234,'$0,0.00','$1,000.23', '$1,000.24'], - [0.974878234,'0.000%','97.487%','97.488%'], - [-0.433,'0 %','-44 %', '-43 %'] - ], - i; - - test.expect(tests.length * 2); - - for (i = 0; i < tests.length; i++) { - // floor - test.strictEqual(numeral(tests[i][0]).format(tests[i][1], Math.floor), tests[i][2], tests[i][1] + ", floor"); - - // ceil - test.strictEqual(numeral(tests[i][0]).format(tests[i][1], Math.ceil), tests[i][3], tests[i][1] + ", ceil"); - - } - - test.done(); - - }, -}; + // ceil + expect(numeral(tests[i][0]).format(tests[i][1], Math.ceil)).to.equal(tests[i][3]); + } + }); + }); +}); diff --git a/tests/numeral/manipulate.js b/tests/numeral/manipulate.js index bddd52e8..da0c522a 100644 --- a/tests/numeral/manipulate.js +++ b/tests/numeral/manipulate.js @@ -1,91 +1,104 @@ -var numeral = require('../../numeral'); - -exports.manipulate = { - - add: function (test) { - test.expect(4); - - var tests = [ - [1000,10,1010], - [0.5,3,3.5], - [-100,200,100], - [0.1,0.2,0.3] - ], - num; - - for (var i = 0; i < tests.length; i++) { - num = numeral(tests[i][0]); - num.add(tests[i][1]); - test.strictEqual(num.value(), tests[i][2], tests[i][0] + ' + ' + tests[i][1]); - } - - test.done(); - }, - - subtract: function (test) { - test.expect(4); - - var tests = [ - [1000,10,990], - [0.5,3,-2.5], - [-100,200,-300], - [0.3,0.1,0.2] - ], - num; - - for (var i = 0; i < tests.length; i++) { - num = numeral(tests[i][0]); - num.subtract(tests[i][1]); - test.strictEqual(num.value(), tests[i][2], tests[i][0] + ' - ' + tests[i][1]); - } - - test.done(); - }, - - multiply: function (test) { - test.expect(4); - - var tests = [ - [1000,10,10000], - [0.5,3,1.5], - [-100,200,-20000], - [0.1,0.2,0.02] - ], - num; - - for (var i = 0; i < tests.length; i++) { - num = numeral(tests[i][0]); - num.multiply(tests[i][1]); - test.strictEqual(num.value(), tests[i][2], tests[i][0] + ' * ' + tests[i][1]); - } - - test.done(); - }, - - divide: function (test) { - test.expect(4); - - var tests = [ - [1000,10,100], - [0.5,3,0.16666666666666666], - [-100,200,-0.5], - [5.3,0.1,53] - ], - num; - - for (var i = 0; i < tests.length; i++) { - num = numeral(tests[i][0]); - num.divide(tests[i][1]); - test.strictEqual(num.value(), tests[i][2], tests[i][0] + ' / ' + tests[i][1]); - } - - test.done(); - }, - - difference: function (test) { - test.expect(4); - - var tests = [ +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; +} + +describe('Manipulate', function() { + after(function() { + numeral.reset(); + }); + + describe('Add', function() { + it('should add', function() { + var tests = [ + [1000,10,1010], + [0.5,3,3.5], + [-100,200,100], + [0.1,0.2,0.3] + ], + num; + + for (var i = 0; i < tests.length; i++) { + num = numeral(tests[i][0]); + + num.add(tests[i][1]); + + expect(num.value()).to.equal(tests[i][2]); + } + }); + }); + + describe('Subtract', function() { + it('should subtract', function() { + var tests = [ + [1000,10,990], + [0.5,3,-2.5], + [-100,200,-300], + [0.3,0.1,0.2] + ], + num; + + for (var i = 0; i < tests.length; i++) { + num = numeral(tests[i][0]); + + num.subtract(tests[i][1]); + + expect(num.value()).to.equal(tests[i][2]); + } + }); + }); + + + describe('Add', function() { + it('should add', function() { + }); + }); + + + describe('Multiply', function() { + it('should multiply', function() { + var tests = [ + [1000,10,10000], + [0.5,3,1.5], + [-100,200,-20000], + [0.1,0.2,0.02] + ], + num; + + for (var i = 0; i < tests.length; i++) { + num = numeral(tests[i][0]); + + num.multiply(tests[i][1]); + + expect(num.value()).to.equal(tests[i][2]); + } + }); + }); + + describe('Divide', function() { + it('should divide', function() { + var tests = [ + [1000,10,100], + [0.5,3,0.16666666666666666], + [-100,200,-0.5], + [5.3,0.1,53] + ], + num; + + for (var i = 0; i < tests.length; i++) { + num = numeral(tests[i][0]); + + num.divide(tests[i][1]); + + expect(num.value()).to.equal(tests[i][2]); + } + }); + }); + + describe('Difference', function() { + it('should find a difference', function() { + var tests = [ [1000,10,990], [0.5,3,2.5], [-100,200,300], @@ -93,12 +106,11 @@ exports.manipulate = { ], num; - for (var i = 0; i < tests.length; i++) { - num = numeral(tests[i][0]); - test.strictEqual(num.difference(tests[i][1]), tests[i][2], 'Difference between ' + tests[i][0] + ' and ' + tests[i][1]); - } - - test.done(); - } + for (var i = 0; i < tests.length; i++) { + num = numeral(tests[i][0]); -}; \ No newline at end of file + expect(num.difference(tests[i][1])).to.equal(tests[i][2]); + } + }); + }); +}); diff --git a/tests/numeral/misc.js b/tests/numeral/misc.js index 0a07a482..a7ceaf37 100644 --- a/tests/numeral/misc.js +++ b/tests/numeral/misc.js @@ -1,65 +1,82 @@ -var numeral = require('../../numeral'); - -exports.misc = { - - value: function (test) { - test.expect(5); - - var tests = [ +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; +} + +describe('Misc', function() { + after(function() { + numeral.reset(); + }); + + describe('Add', function() { + it('should return a value', function() { + var tests = [ [1000, 1000], [0.5, 0.5], - [, 0], + [null, null], ['1,000', 1000], ['not a number', 0] ], num; - for (var i = 0; i < tests.length; i++) { - num = numeral(tests[i][0]); - test.strictEqual(num.value(), tests[i][1], tests[i][1]); - } + for (var i = 0; i < tests.length; i++) { + num = numeral(tests[i][0]); - test.done(); - }, + expect(num.value()).to.equal(tests[i][1]); + } + }); + }); - set: function (test) { - test.expect(2); - - var tests = [ + describe('Set', function() { + it('should set a value', function() { + var tests = [ [1000,1000], [-0.25,-0.25] ], num; - for (var i = 0; i < tests.length; i++) { - num = numeral().set(tests[i][0]); - test.strictEqual(num.value(), tests[i][1], tests[i][0]); - } - - test.done(); - }, + for (var i = 0; i < tests.length; i++) { + num = numeral().set(tests[i][0]); - customZero: function (test) { - test.expect(3); + expect(num.value()).to.equal(tests[i][1]); + } + }); + }); - var tests = [ - [0,null,'0'], + describe('Custom Zero', function() { + it('should change zero value', function() { + var tests = [ [0,'N/A','N/A'], [0,'',''] ]; - for (var i = 0; i < tests.length; i++) { - numeral.zeroFormat(tests[i][1]); - test.strictEqual(numeral(tests[i][0]).format('0'), tests[i][2], tests[i][1]); - } + for (var i = 0; i < tests.length; i++) { + numeral.zeroFormat(tests[i][1]); - test.done(); - }, + expect(numeral(tests[i][0]).format('0')).to.equal(tests[i][2]); + } + }); + }); - clone: function (test) { - test.expect(4); + describe('Custom Null', function() { + it('should change null value', function() { + var tests = [ + [null,'N/A','N/A'], + [null,'',''] + ]; + + for (var i = 0; i < tests.length; i++) { + numeral.nullFormat(tests[i][1]); + + expect(numeral(tests[i][0]).format('0')).to.equal(tests[i][2]); + } + }); + }); - var a = numeral(1000), + describe('Clone', function() { + it('should clone', function() { + var a = numeral(1000), b = numeral(a), c = a.clone(), aVal = a.value(), @@ -67,57 +84,54 @@ exports.misc = { bVal = b.value(), cVal = c.add(10).value(); - test.strictEqual(aVal, 1000, 'Parent starting value'); - test.strictEqual(aSet, 2000, 'Parent set to 2000'); - test.strictEqual(bVal, 1000, 'Implicit clone unmanipulated'); - test.strictEqual(cVal, 1010, 'Explicit clone + 10'); - - test.done(); - }, - - isNumeral: function (test) { - test.expect(2); + expect(aVal).to.equal(1000); + expect(aSet).to.equal(2000); + expect(bVal).to.equal(1000); + expect(cVal).to.equal(1010); + }); + }); - var tests = [ + describe('isNumeral', function() { + it('should return boolean', function() { + var tests = [ [numeral(),true], [1,false] ]; - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral.isNumeral(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - }, - - languageData: function(test) { - test.expect(10); - - var cOld = '$', - cNew = '!', - formatTestVal = function() { return numeral('100').format('$0,0') }, - oldCurrencyVal = cOld + '100', - newCurrencyVal = cNew + '100'; - - test.strictEqual(numeral.languageData().currency.symbol, cOld, 'Current language currency is ' + cOld); - test.strictEqual(numeral.languageData('en').currency.symbol, cOld, 'English language currency is ' + cOld); - - numeral.languageData().currency.symbol = cNew; - test.strictEqual(numeral.languageData().currency.symbol, cNew, 'Current language currency is changed to ' + cNew); - test.strictEqual(formatTestVal(), newCurrencyVal, 'Format uses new currency'); - - numeral.languageData().currency.symbol = cOld; - test.strictEqual(numeral.languageData().currency.symbol, '$', 'Current language currency is reset to ' + cOld); - test.strictEqual(formatTestVal(), oldCurrencyVal, 'Format uses old currency'); - - numeral.languageData('en').currency.symbol = cNew; - test.strictEqual(numeral.languageData().currency.symbol, cNew, 'English language currency is changed to ' + cNew); - test.strictEqual(formatTestVal(), newCurrencyVal, 'Format uses new currency'); - - numeral.languageData('en').currency.symbol = cOld; - test.strictEqual(numeral.languageData().currency.symbol, cOld, 'English language currency is reset to ' + cOld); - test.strictEqual(formatTestVal(), oldCurrencyVal, 'Format uses old currency'); - - test.done(); - } -}; \ No newline at end of file + for (var i = 0; i < tests.length; i++) { + expect(numeral.isNumeral(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); + + describe('Language Data', function() { + it('should use custom language data', function() { + var cOld = '$', + cNew = '!', + formatTestVal = function() { + return numeral('100').format('$0,0'); + }, + oldCurrencyVal = cOld + '100', + newCurrencyVal = cNew + '100'; + + expect(numeral.languageData().currency.symbol).to.equal(cOld); + expect(numeral.languageData('en').currency.symbol).to.equal(cOld); + + numeral.languageData().currency.symbol = cNew; + expect(numeral.languageData().currency.symbol).to.equal(cNew); + expect(formatTestVal()).to.equal(newCurrencyVal); + + numeral.languageData().currency.symbol = cOld; + expect(numeral.languageData().currency.symbol).to.equal('$'); + expect(formatTestVal()).to.equal(oldCurrencyVal); + + numeral.languageData('en').currency.symbol = cNew; + expect(numeral.languageData().currency.symbol).to.equal(cNew); + expect(formatTestVal()).to.equal(newCurrencyVal); + + numeral.languageData('en').currency.symbol = cOld; + expect(numeral.languageData().currency.symbol).to.equal(cOld); + expect(formatTestVal()).to.equal(oldCurrencyVal); + }); + }); +}); diff --git a/tests/numeral/unformat.js b/tests/numeral/unformat.js index f0b059b9..232dc96f 100644 --- a/tests/numeral/unformat.js +++ b/tests/numeral/unformat.js @@ -1,15 +1,23 @@ -var numeral = require('../../numeral'); - -exports.unformat = { - setUp: function (callback) { +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; +} + +describe('Unformat', function() { + beforeEach(function() { numeral.zeroFormat('N/A'); - callback(); - }, - numbers: function (test) { - test.expect(15); + numeral.nullFormat('N/A'); + }); + + after(function() { + numeral.reset(); + }); - var tests = [ + describe('Numbers', function() { + it('should unformat a number', function() { + var tests = [ ['10,000.123', 10000.123], ['(0.12345)', -0.12345], ['((--0.12345))', 0.12345], @@ -17,9 +25,8 @@ exports.unformat = { ['31st', 31], ['1.23t', 1230000000000], ['N/A', 0], - [, 0], + [null, 0], ['', 0], - // Pass Through for Numbers [0, 0], [1, 1], @@ -29,68 +36,60 @@ exports.unformat = { [-1.1, -1.1] ]; - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); - test.done(); - }, - - currency: function (test) { - test.expect(2); - - var tests = [ + describe('Currency', function() { + it('should unformat currency', function() { + var tests = [ ['($1.23m)', -1230000], ['$ 10,000.00', 10000] ]; - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - }, + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); - bytes: function (test) { - test.expect(2); - - var tests = [ + describe('Bytes', function() { + it('should unformat bytes', function() { + var tests = [ ['100B', 100], - ['3.154 TB', 3467859674006] + ['3.154 TiB', 3467859674006], + ['3.154 TB', 3154000000000] ]; - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - }, - - percentages: function (test) { - test.expect(1); + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); - var tests = [ + describe('Percentages', function() { + it('should unformat percentages', function() { + var tests = [ ['-76%', -0.76] ]; - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); - test.done(); - }, - - time: function (test) { - test.expect(1); - - var tests = [ + describe('Time', function() { + it('should unformat time', function() { + var tests = [ ['2:23:57', 8637] ]; - for (var i = 0; i < tests.length; i++) { - test.strictEqual(numeral().unformat(tests[i][0]), tests[i][1], tests[i][0]); - } - - test.done(); - } -}; \ No newline at end of file + for (var i = 0; i < tests.length; i++) { + expect(numeral().unformat(tests[i][0])).to.equal(tests[i][1]); + } + }); + }); +}); diff --git a/tests/numeral/validate.js b/tests/numeral/validate.js new file mode 100644 index 00000000..9a16bb6d --- /dev/null +++ b/tests/numeral/validate.js @@ -0,0 +1,80 @@ +// Node +if (typeof module !== 'undefined' && module.exports) { + var numeral = require('../../numeral'); + var expect = require('chai').expect; +} + +describe('Validate', function() { + var language = 'en'; + + after(function() { + numeral.reset(); + }); + + describe('Numbers', function() { + it('should validate numbers', function() { + var tests = [ + ['1000', true], + ['1,000', true], + ['10,0,0', true], + ['10.123', true], + ['1,000.123', true], + ['1000,123.123', true], + ['1000 ', true], + [' 1000 ', true], + [' 1000', true], + [' 1000,100.123', true], + ['1.0,00', false], + ['1.0.00', false], + ['1 000', false], + ['1.000,123', false], + ['1000.', false], + ['1000,', false], + ['10..00', false], + ['10,,00', false], + ['10, 00', false] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral.validate(tests[i][0], language)).to.equal(tests[i][1]); + } + }); + }); + describe('Currency', function() { + it('should validate currency', function() { + var tests = [ + ['$1000', true], + ['$1,000', true], + ['$10,0,0', true], + ['$10.123', true], + ['$1,000.123', true], + ['$1000 ', true], + [' $1000 ', true], + [' $1000', true], + [' $1000,100.123', true], + ['$100.123k', true], + ['$100.123m', true], + ['$100.123b', true], + ['$100.123t', true], + ['100,456.123k', true], + [' 100,456.123t ', true], + ['$1,00.123k', true], + ['%100', false], + [' %1.0.00', false], + [' ^1 000 ', false], + ['^1.000 ', false], + ['$ 1000.', false], + ['%1000', false], + ['100,456.123z', false], + ['$100$', false], + ['$100,213.456l', false], + ['aa100,213.456l', false], + ['$100,213.456kk', false] + ]; + + for (var i = 0; i < tests.length; i++) { + expect(numeral.validate(tests[i][0], language)).to.equal(tests[i][1]); + } + }); + }); +});