├── .editorconfig ├── .eslintrc ├── .gitignore ├── .npmignore ├── .travis.yml ├── bower.json ├── lib ├── rubles.js └── rubles.min.js ├── license.md ├── package.json ├── readme.md └── test ├── mocha.opts └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | ; http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 2 9 | end_of_line = lf 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | 4 | "env": { 5 | "es6": true, 6 | "node": true, 7 | "browser": true, 8 | "mocha": true 9 | }, 10 | 11 | "rules": { 12 | "arrow-parens": 2, 13 | "arrow-spacing": [2, {"before": true, "after": true}], 14 | "brace-style": [1, "1tbs"], 15 | "callback-return": [2, ["callback", "cb", "fn", "next"]], 16 | "comma-style": [1, "last"], 17 | "computed-property-spacing": [2, "never"], 18 | "eqeqeq": 2, 19 | "indent": [2, 2, {"SwitchCase": 1}], 20 | "linebreak-style": [2, "unix"], 21 | "no-class-assign": 2, 22 | "no-console": 0, 23 | "no-const-assign": 2, 24 | "no-inner-declarations": [2, "both"], 25 | "no-useless-call": 2, 26 | "object-curly-spacing": [2, "never"], 27 | "one-var": [2, "never"], 28 | "operator-assignment": [2, "never"], 29 | "operator-linebreak": [2, "after"], 30 | "prefer-spread": 2, 31 | "quotes": [2, "single"], 32 | "semi": [2, "always"], 33 | "space-after-keywords": 1, 34 | "space-before-blocks": 1, 35 | "space-before-function-paren": [1, "never"], 36 | "space-in-parens": 1, 37 | "space-infix-ops": 1, 38 | "space-return-throw-case": 1, 39 | "wrap-iife": [2, "inside"] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *.log 3 | .DS_Store 4 | lib-cov 5 | html-report 6 | lcov.info 7 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test 2 | .editorconfig 3 | .eslintrc 4 | .travis.yml 5 | bower.json 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "0.12" 5 | - "stable" 6 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rubles", 3 | "version": "0.2.0", 4 | "author": "Alexey Simonenko ", 5 | "homepage": "http://simonenko.su/projects/rubles", 6 | "main": "./lib/rubles.min.js", 7 | "ignore": [ 8 | ".editorconfig", 9 | ".eslintrc", 10 | ".gitignore", 11 | ".npmignore", 12 | ".travis.yml", 13 | "package.json", 14 | "test" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /lib/rubles.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | 'use strict'; 3 | 4 | var words = [ 5 | [ 6 | '', 'один', 'два', 'три', 'четыре', 'пять', 'шесть', 7 | 'семь', 'восемь', 'девять', 'десять', 'одиннадцать', 8 | 'двенадцать', 'тринадцать', 'четырнадцать', 'пятнадцать', 9 | 'шестнадцать', 'семнадцать', 'восемнадцать', 'девятнадцать' 10 | ], 11 | [ 12 | '', '', 'двадцать', 'тридцать', 'сорок', 'пятьдесят', 13 | 'шестьдесят', 'семьдесят', 'восемьдесят', 'девяносто' 14 | ], 15 | [ 16 | '', 'сто', 'двести', 'триста', 'четыреста', 'пятьсот', 17 | 'шестьсот', 'семьсот', 'восемьсот', 'девятьсот' 18 | ] 19 | ]; 20 | 21 | var rusRubles = ['рубль', 'рубля', 'рублей']; 22 | 23 | var belRubles = ['белорусский рубль', 'белорусских рубля', 'белорусских рублей']; 24 | 25 | var toFloat = function(number) { 26 | return parseFloat(number); 27 | }; 28 | 29 | var plural = function(count, options) { 30 | if (options.length !== 3) { 31 | return false; 32 | } 33 | 34 | count = Math.abs(count) % 100; 35 | var rest = count % 10; 36 | 37 | if (count > 10 && count < 20) { 38 | return options[2]; 39 | } 40 | 41 | if (rest > 1 && rest < 5) { 42 | return options[1]; 43 | } 44 | 45 | if (rest === 1) { 46 | return options[0]; 47 | } 48 | 49 | return options[2]; 50 | }; 51 | 52 | var parseNumber = function(number, count, currCode) { 53 | var first; 54 | var second; 55 | var numeral = ''; 56 | 57 | if (number.length === 3) { 58 | first = number.substr(0, 1); 59 | number = number.substr(1, 3); 60 | numeral = '' + words[2][first] + ' '; 61 | } 62 | 63 | if (number < 20) { 64 | numeral = numeral + words[0][toFloat(number)] + ' '; 65 | } else { 66 | first = number.substr(0, 1); 67 | second = number.substr(1, 2); 68 | numeral = numeral + words[1][first] + ' ' + words[0][second] + ' '; 69 | } 70 | 71 | if (count === 0) { 72 | switch (currCode) { 73 | case 'BYN': { 74 | numeral = numeral + plural(number, belRubles); 75 | break; 76 | } 77 | case 'RU': 78 | default: { 79 | numeral = numeral + plural(number, rusRubles); 80 | } 81 | } 82 | } else if (count === 1) { 83 | if (numeral !== ' ') { 84 | numeral = numeral + plural(number, ['тысяча ', 'тысячи ', 'тысяч ']); 85 | numeral = numeral.replace('один ', 'одна ').replace('два ', 'две '); 86 | } 87 | } else if (count === 2) { 88 | if (numeral !== ' ') { 89 | numeral = numeral + plural(number, ['миллион ', 'миллиона ', 'миллионов ']); 90 | } 91 | } else if (count === 3) { 92 | numeral = numeral + plural(number, ['миллиард ', 'миллиарда ', 'миллиардов ']); 93 | } 94 | 95 | return numeral; 96 | }; 97 | 98 | var parseDecimals = function(number) { 99 | var text = plural(number, ['копейка', 'копейки', 'копеек']); 100 | 101 | if (number === 0) { 102 | number = '00'; 103 | } else if (number < 10) { 104 | number = '0' + number; 105 | } 106 | 107 | return ' ' + number + ' ' + text; 108 | }; 109 | 110 | var rubles = function(number, currCode) { 111 | if (!number) { 112 | return false; 113 | } 114 | 115 | var type = typeof number; 116 | if (type !== 'number' && type !== 'string') { 117 | return false; 118 | } 119 | 120 | if (type === 'string') { 121 | number = toFloat(number.replace(',', '.')); 122 | 123 | if (isNaN(number)) { 124 | return false; 125 | } 126 | } 127 | 128 | if (number <= 0) { 129 | return false; 130 | } 131 | 132 | var splt; 133 | var decimals; 134 | 135 | number = number.toFixed(2); 136 | if (number.indexOf('.') !== -1) { 137 | splt = number.split('.'); 138 | number = splt[0]; 139 | decimals = splt[1]; 140 | } 141 | 142 | var numeral = ''; 143 | var length = number.length - 1; 144 | var parts = ''; 145 | var count = 0; 146 | var digit; 147 | 148 | while (length >= 0) { 149 | digit = number.substr(length, 1); 150 | parts = digit + parts; 151 | 152 | if ((parts.length === 3 || length === 0) && !isNaN(toFloat(parts))) { 153 | numeral = parseNumber(parts, count, currCode) + numeral; 154 | parts = ''; 155 | count++; 156 | } 157 | 158 | length--; 159 | } 160 | 161 | numeral = numeral.replace(/\s+/g, ' '); 162 | 163 | if (decimals) { 164 | numeral = numeral + parseDecimals(toFloat(decimals)); 165 | } 166 | 167 | return numeral; 168 | }; 169 | 170 | var globals; 171 | 172 | if (typeof module !== 'undefined' && module !== null) { 173 | globals = exports; 174 | } else { 175 | globals = window; 176 | } 177 | 178 | globals.rubles = rubles; 179 | 180 | })(); 181 | -------------------------------------------------------------------------------- /lib/rubles.min.js: -------------------------------------------------------------------------------- 1 | !function(){"use strict";var r,e=[["","один","два","три","четыре","пять","шесть","семь","восемь","девять","десять","одиннадцать","двенадцать","тринадцать","четырнадцать","пятнадцать","шестнадцать","семнадцать","восемнадцать","девятнадцать"],["","","двадцать","тридцать","сорок","пятьдесят","шестьдесят","семьдесят","восемьдесят","девяносто"],["","сто","двести","триста","четыреста","пятьсот","шестьсот","семьсот","восемьсот","девятьсот"]],t=["рубль","рубля","рублей"],n=["белорусский рубль","белорусских рубля","белорусских рублей"],u=function(r){return parseFloat(r)},s=function(r,e){if(3!==e.length)return!1;r=Math.abs(r)%100;var t=r%10;return r>10&&r<20?e[2]:t>1&&t<5?e[1]:1===t?e[0]:e[2]},i=function(r,i,a){var f,l,o="";if(3===r.length&&(f=r.substr(0,1),r=r.substr(1,3),o=e[2][f]+" "),r<20?o=o+e[0][u(r)]+" ":(f=r.substr(0,1),l=r.substr(1,2),o=o+e[1][f]+" "+e[0][l]+" "),0===i)switch(a){case"BYN":o+=s(r,n);break;case"RU":default:o+=s(r,t)}else 1===i?" "!==o&&(o+=s(r,["тысяча ","тысячи ","тысяч "]),o=o.replace("один ","одна ").replace("два ","две ")):2===i?" "!==o&&(o+=s(r,["миллион ","миллиона ","миллионов "])):3===i&&(o+=s(r,["миллиард ","миллиарда ","миллиардов "]));return o},a=function(r){var e=s(r,["копейка","копейки","копеек"]);return 0===r?r="00":r<10&&(r="0"+r)," "+r+" "+e},f=function(r,e){if(!r)return!1;var t=typeof r;if("number"!==t&&"string"!==t)return!1;if("string"===t&&(r=u(r.replace(",",".")),isNaN(r)))return!1;if(r<=0)return!1;var n,s;r=r.toFixed(2),-1!==r.indexOf(".")&&(n=r.split("."),r=n[0],s=n[1]);for(var f,l="",o=r.length-1,c="",b=0;o>=0;)f=r.substr(o,1),c=f+c,3!==c.length&&0!==o||isNaN(u(c))||(l=i(c,b,e)+l,c="",b++),o--;return l=l.replace(/\s+/g," "),s&&(l+=a(u(s))),l};r="undefined"!=typeof module&&null!==module?exports:window,r.rubles=f}(); -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2015 Alexey Simonenko, alexey@simonenko.su, http://simonenko.su 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rubles", 3 | "version": "0.2.0", 4 | "description": "Стоимость прописью", 5 | "keywords": [ 6 | "ruble", 7 | "numeral" 8 | ], 9 | "author": "Alexey Simonenko ", 10 | "homepage": "http://simonenko.su/projects/rubles", 11 | "main": "./lib/rubles", 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/meritt/rubles.git" 15 | }, 16 | "scripts": { 17 | "build": "uglifyjs lib/rubles.js -o lib/rubles.min.js -m -c", 18 | "mocha": "mocha --reporter dot", 19 | "lint": "eslint lib/rubles.js test/test.js", 20 | "lib-cov": "istanbul instrument --output lib-cov --no-compact --variable global.__coverage__ lib", 21 | "prepush": "npm run lint", 22 | "pretest": "npm run lint && npm run build", 23 | "posttest": "npm run lib-cov && COVERAGE=1 ISTANBUL_REPORTERS=lcovonly mocha --reporter mocha-istanbul && cat lcov.info | coveralls && rm -rf lib-cov lcov.info", 24 | "test": "npm run mocha" 25 | }, 26 | "devDependencies": { 27 | "coveralls": "^2.11.4", 28 | "eslint": "^1.4.1", 29 | "husky": "^0.10.1", 30 | "istanbul": "^0.3.19", 31 | "mocha": "^2.3.2", 32 | "mocha-istanbul": "^0.2.0", 33 | "should": "^7.1.0", 34 | "uglify-js": "^2.4.24" 35 | }, 36 | "engines": { 37 | "node": "^0.12.7" 38 | }, 39 | "license": "MIT" 40 | } 41 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # rubles.js — стоимость прописью 2 | 3 | [![NPM version][npm-image]][npm-url] 4 | [![Build status][travis-image]][travis-url] 5 | [![Test coverage][coveralls-image]][coveralls-url] 6 | [![devDependency status][devdependency-image]][devdependency-url] 7 | 8 | В российском документообороте принято писать сумму прописью. Такое должно быть в договорах, актах, расписках и других подобных документах. Rubles.js призван решить эту проблему комплексно, он работает в браузере и на серверной стороне. 9 | 10 | ### На сервере 11 | 12 | #### Установить через [npm](//npmjs.org) 13 | 14 | ```bash 15 | $ npm i --save rubles 16 | ``` 17 | 18 | #### Как использовать 19 | 20 | ```js 21 | var rubles = require('rubles').rubles; 22 | 23 | var text = rubles(12.10); 24 | console.log(text); // двенадцать рублей 10 копеек 25 | 26 | var text = rubles("52151,31"); 27 | console.log(text); // пятьдесят две тысячи сто пятьдесят один рубль 31 копейка 28 | ``` 29 | 30 | ---------------- 31 | 32 | ### В браузере 33 | 34 | #### Установить через [bower](http://bower.io) 35 | 36 | ```bash 37 | $ bower install rubles --save 38 | ``` 39 | 40 | #### Подключить 41 | 42 | ```html 43 | 44 | ``` 45 | 46 | #### Использовать 47 | 48 | ```html 49 | 56 | ``` 57 | 58 | ---------------- 59 | 60 | ### Нашли ошибку? 61 | 62 | Пожалуйста, создайте тикет — https://github.com/meritt/rubles/issues 63 | 64 | ### Тестирование 65 | 66 | Для запуска тестов обновите репозиторий и запустите: 67 | 68 | ```bash 69 | $ npm test 70 | ``` 71 | 72 | ## Автор 73 | 74 | * [Алексей Симоненко](mailto:alexey@simonenko.su), [simonenko.su](http://simonenko.su) 75 | 76 | ## Лицензия 77 | 78 | Лицензия MIT, смотрите файл `license.md`. 79 | 80 | [npm-image]: https://img.shields.io/npm/v/rubles.svg?style=flat 81 | [npm-url]: https://www.npmjs.com/package/rubles 82 | [travis-image]: https://travis-ci.org/meritt/rubles.svg?branch=master 83 | [travis-url]: https://travis-ci.org/meritt/rubles 84 | [coveralls-image]: https://coveralls.io/repos/meritt/rubles/badge.svg?branch=master&service=github 85 | [coveralls-url]: https://coveralls.io/github/meritt/rubles?branch=master 86 | [devdependency-image]: https://img.shields.io/david/dev/meritt/rubles.svg?style=flat 87 | [devdependency-url]: https://david-dm.org/meritt/rubles#info=devDependencies 88 | -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | --reporter spec 2 | --require should 3 | --bail 4 | --check-leaks 5 | 6 | test/test.js 7 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var construct = function(rubles) { 4 | var text = rubles(); 5 | text.should.be.false(); 6 | 7 | var i; 8 | var poor = [undefined, false, 0, '0', '0.00', '0,00', 'test', [], [10], {}, {test: 10}]; 9 | 10 | for (i = 0; i < poor.length; i++) { 11 | text = rubles(poor[i]); 12 | text.should.be.false(); 13 | } 14 | }; 15 | 16 | var decimals = { 17 | good: function(rubles) { 18 | var text = rubles(1.00); 19 | text.should.equal('один рубль 00 копеек'); 20 | 21 | text = rubles(1.01); 22 | text.should.equal('один рубль 01 копейка'); 23 | 24 | text = rubles(2.02); 25 | text.should.equal('два рубля 02 копейки'); 26 | 27 | text = rubles(3.05); 28 | text.should.equal('три рубля 05 копеек'); 29 | 30 | text = rubles(4.12); 31 | text.should.equal('четыре рубля 12 копеек'); 32 | 33 | text = rubles(5.51); 34 | text.should.equal('пять рублей 51 копейка'); 35 | 36 | text = rubles(9.99); 37 | text.should.equal('девять рублей 99 копеек'); 38 | }, 39 | 40 | poor: function(rubles) { 41 | var text = rubles(1.156); 42 | text.should.equal('один рубль 16 копеек'); 43 | 44 | text = rubles('2,189'); 45 | text.should.equal('два рубля 19 копеек'); 46 | 47 | text = rubles(3.185); 48 | text.should.equal('три рубля 19 копеек'); 49 | 50 | text = rubles(4.0185); 51 | text.should.equal('четыре рубля 02 копейки'); 52 | 53 | text = rubles(5.134); 54 | text.should.equal('пять рублей 13 копеек'); 55 | } 56 | }; 57 | 58 | var numbers = function(rubles) { 59 | var text = rubles(12); 60 | text.should.equal('двенадцать рублей 00 копеек'); 61 | 62 | text = rubles(52); 63 | text.should.equal('пятьдесят два рубля 00 копеек'); 64 | 65 | text = rubles(100); 66 | text.should.equal('сто рублей 00 копеек'); 67 | 68 | text = rubles(112); 69 | text.should.equal('сто двенадцать рублей 00 копеек'); 70 | 71 | text = rubles(152); 72 | text.should.equal('сто пятьдесят два рубля 00 копеек'); 73 | 74 | text = rubles(512); 75 | text.should.equal('пятьсот двенадцать рублей 00 копеек'); 76 | 77 | text = rubles(552); 78 | text.should.equal('пятьсот пятьдесят два рубля 00 копеек'); 79 | 80 | text = rubles(999); 81 | text.should.equal('девятьсот девяносто девять рублей 00 копеек'); 82 | }; 83 | 84 | var thousands = function(rubles) { 85 | var text = rubles(1000); 86 | text.should.equal('одна тысяча рублей 00 копеек'); 87 | 88 | text = rubles(2000); 89 | text.should.equal('две тысячи рублей 00 копеек'); 90 | 91 | text = rubles(5000); 92 | text.should.equal('пять тысяч рублей 00 копеек'); 93 | 94 | text = rubles(1052); 95 | text.should.equal('одна тысяча пятьдесят два рубля 00 копеек'); 96 | 97 | text = rubles(52151); 98 | text.should.equal('пятьдесят две тысячи сто пятьдесят один рубль 00 копеек'); 99 | 100 | text = rubles(341000); 101 | text.should.equal('триста сорок одна тысяча рублей 00 копеек'); 102 | 103 | text = rubles(123456); 104 | text.should.equal('сто двадцать три тысячи четыреста пятьдесят шесть рублей 00 копеек'); 105 | 106 | text = rubles(999001); 107 | text.should.equal('девятьсот девяносто девять тысяч один рубль 00 копеек'); 108 | }; 109 | 110 | var millions = function(rubles) { 111 | var text = rubles(1000000); 112 | text.should.equal('один миллион рублей 00 копеек'); 113 | 114 | text = rubles(2000000); 115 | text.should.equal('два миллиона рублей 00 копеек'); 116 | 117 | text = rubles(5000000); 118 | text.should.equal('пять миллионов рублей 00 копеек'); 119 | 120 | text = rubles(1000001); 121 | text.should.equal('один миллион один рубль 00 копеек'); 122 | 123 | text = rubles(1001000); 124 | text.should.equal('один миллион одна тысяча рублей 00 копеек'); 125 | 126 | text = rubles(1001001); 127 | text.should.equal('один миллион одна тысяча один рубль 00 копеек'); 128 | 129 | text = rubles(12000000); 130 | text.should.equal('двенадцать миллионов рублей 00 копеек'); 131 | 132 | text = rubles(52000000); 133 | text.should.equal('пятьдесят два миллиона рублей 00 копеек'); 134 | 135 | text = rubles(52000122); 136 | text.should.equal('пятьдесят два миллиона сто двадцать два рубля 00 копеек'); 137 | 138 | text = rubles(123456789); 139 | text.should.equal('сто двадцать три миллиона четыреста пятьдесят шесть тысяч семьсот восемьдесят девять рублей 00 копеек'); 140 | }; 141 | 142 | var billions = function(rubles) { 143 | var text = rubles(1000000000); 144 | text.should.equal('один миллиард рублей 00 копеек'); 145 | 146 | text = rubles(2000000000); 147 | text.should.equal('два миллиарда рублей 00 копеек'); 148 | 149 | text = rubles(5000000000); 150 | text.should.equal('пять миллиардов рублей 00 копеек'); 151 | 152 | text = rubles(1000000001); 153 | text.should.equal('один миллиард один рубль 00 копеек'); 154 | 155 | text = rubles(1000000100); 156 | text.should.equal('один миллиард сто рублей 00 копеек'); 157 | 158 | text = rubles(1000001000); 159 | text.should.equal('один миллиард одна тысяча рублей 00 копеек'); 160 | 161 | text = rubles(1001000000); 162 | text.should.equal('один миллиард один миллион рублей 00 копеек'); 163 | 164 | text = rubles(1000001001); 165 | text.should.equal('один миллиард одна тысяча один рубль 00 копеек'); 166 | 167 | text = rubles(1001001001); 168 | text.should.equal('один миллиард один миллион одна тысяча один рубль 00 копеек'); 169 | 170 | text = rubles(999999999999); 171 | text.should.equal('девятьсот девяносто девять миллиардов девятьсот девяносто девять миллионов девятьсот девяносто девять тысяч девятьсот девяносто девять рублей 00 копеек'); 172 | }; 173 | 174 | var currencyCodes = function(rubles) { 175 | var text = rubles(44.20); 176 | text.should.equal('сорок четыре рубля 20 копеек'); 177 | 178 | text = rubles(44.20, 'RU'); 179 | text.should.equal('сорок четыре рубля 20 копеек'); 180 | 181 | text = rubles(44.2, 'BYN'); 182 | text.should.equal('сорок четыре белорусских рубля 20 копеек'); 183 | }; 184 | 185 | var negative = function(rubles) { 186 | var text = rubles(-100); 187 | text.should.be.false(); 188 | 189 | text = rubles(-0.01); 190 | text.should.be.false(); 191 | 192 | text = rubles('-100'); 193 | text.should.be.false(); 194 | 195 | text = rubles('-0.01'); 196 | text.should.be.false(); 197 | }; 198 | 199 | describe('Rubles in JavaScript', function() { 200 | var path = (process.env.COVERAGE) ? '../lib-cov' : '../lib'; 201 | var rubles = require(path + '/rubles.js').rubles; 202 | 203 | it('construct', function() { 204 | construct(rubles); 205 | }); 206 | 207 | it('decimals', function() { 208 | decimals.good(rubles); 209 | }); 210 | it('bad decimals', function() { 211 | decimals.poor(rubles); 212 | }); 213 | 214 | it('numbers', function() { 215 | numbers(rubles); 216 | }); 217 | it('thousands', function() { 218 | thousands(rubles); 219 | }); 220 | it('millions', function() { 221 | millions(rubles); 222 | }); 223 | it('billions', function() { 224 | billions(rubles); 225 | }); 226 | it('currencyCodes', function() { 227 | currencyCodes(rubles); 228 | }); 229 | it('negative', function() { 230 | negative(rubles); 231 | }); 232 | }); 233 | 234 | describe('Rubles in minify JavaScript', function() { 235 | var rubles = require('../lib/rubles.min.js').rubles; 236 | 237 | it('construct', function() { 238 | construct(rubles); 239 | }); 240 | 241 | it('decimals', function() { 242 | decimals.good(rubles); 243 | }); 244 | it('bad decimals', function() { 245 | decimals.poor(rubles); 246 | }); 247 | 248 | it('numbers', function() { 249 | numbers(rubles); 250 | }); 251 | it('thousands', function() { 252 | thousands(rubles); 253 | }); 254 | it('millions', function() { 255 | millions(rubles); 256 | }); 257 | it('billions', function() { 258 | billions(rubles); 259 | }); 260 | it('currencyCodes', function() { 261 | currencyCodes(rubles); 262 | }); 263 | it('negative', function() { 264 | negative(rubles); 265 | }); 266 | }); 267 | --------------------------------------------------------------------------------