numbers_hi.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.NUMBERS = void 0;
  4. const grammar_js_1 = require("../../rule_engine/grammar.js");
  5. const messages_js_1 = require("../messages.js");
  6. function hundredsToWords_(num) {
  7. let n = num % 1000;
  8. let str = '';
  9. str += exports.NUMBERS.ones[Math.floor(n / 100)]
  10. ? exports.NUMBERS.ones[Math.floor(n / 100)] +
  11. exports.NUMBERS.numSep +
  12. exports.NUMBERS.special.hundred
  13. : '';
  14. n = n % 100;
  15. if (n) {
  16. str += str ? exports.NUMBERS.numSep : '';
  17. str += exports.NUMBERS.ones[n];
  18. }
  19. return str;
  20. }
  21. function numberToWords(num) {
  22. if (num === 0) {
  23. return exports.NUMBERS.zero;
  24. }
  25. if (num >= Math.pow(10, 32)) {
  26. return num.toString();
  27. }
  28. let pos = 0;
  29. let str = '';
  30. const hundreds = num % 1000;
  31. const hundredsWords = hundredsToWords_(hundreds);
  32. num = Math.floor(num / 1000);
  33. if (!num) {
  34. return hundredsWords;
  35. }
  36. while (num > 0) {
  37. const thousands = num % 100;
  38. if (thousands) {
  39. str =
  40. exports.NUMBERS.ones[thousands] +
  41. exports.NUMBERS.numSep +
  42. exports.NUMBERS.large[pos] +
  43. (str ? exports.NUMBERS.numSep + str : '');
  44. }
  45. num = Math.floor(num / 100);
  46. pos++;
  47. }
  48. return hundredsWords ? str + exports.NUMBERS.numSep + hundredsWords : str;
  49. }
  50. function numberToOrdinal(num, _plural) {
  51. if (num <= 10) {
  52. return exports.NUMBERS.special.smallDenominators[num];
  53. }
  54. return wordOrdinal(num) + ' अंश';
  55. }
  56. function wordOrdinal(num) {
  57. const gender = grammar_js_1.Grammar.getInstance().getParameter('gender');
  58. if (num <= 0) {
  59. return num.toString();
  60. }
  61. if (num < 10) {
  62. return gender === 'f'
  63. ? exports.NUMBERS.special.ordinalsFeminine[num]
  64. : exports.NUMBERS.special.ordinalsMasculine[num];
  65. }
  66. const ordinal = numberToWords(num);
  67. return ordinal + (gender === 'f' ? 'वीं' : 'वाँ');
  68. }
  69. function numericOrdinal(num) {
  70. const gender = grammar_js_1.Grammar.getInstance().getParameter('gender');
  71. if (num > 0 && num < 10) {
  72. return gender === 'f'
  73. ? exports.NUMBERS.special.simpleSmallOrdinalsFeminine[num]
  74. : exports.NUMBERS.special.simpleSmallOrdinalsMasculine[num];
  75. }
  76. const ordinal = num
  77. .toString()
  78. .split('')
  79. .map(function (x) {
  80. const num = parseInt(x, 10);
  81. return isNaN(num) ? '' : exports.NUMBERS.special.simpleNumbers[num];
  82. })
  83. .join('');
  84. return ordinal + (gender === 'f' ? 'वीं' : 'वाँ');
  85. }
  86. exports.NUMBERS = (0, messages_js_1.NUMBERS)({
  87. wordOrdinal: wordOrdinal,
  88. numericOrdinal: numericOrdinal,
  89. numberToWords: numberToWords,
  90. numberToOrdinal: numberToOrdinal
  91. });