Gets the name of a number, even if it's stupidly big. Supersedes TheoryOfNekomata/number-name.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!DOCTYPE html>
  2. <html lang="en-PH">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>@modal-sh/numerica-core</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <style>
  8. .main-form {
  9. position: fixed;
  10. top: 0;
  11. left: 0;
  12. width: 100%;
  13. height: 100%;
  14. display: flex;
  15. flex-direction: column;
  16. align-items: stretch;
  17. }
  18. .main-form > fieldset {
  19. display: contents;
  20. }
  21. .main-form > fieldset > div {
  22. padding: 1rem;
  23. box-sizing: border-box;
  24. display: flex;
  25. gap: 1rem;
  26. }
  27. .main-form > fieldset > legend {
  28. position: absolute;
  29. left: -999999px;
  30. }
  31. .main-form > div {
  32. flex-direction: column;
  33. display: flex;
  34. flex: auto;
  35. }
  36. .main-form > div > textarea {
  37. flex: auto;
  38. width: 100%;
  39. height: 0;
  40. font-size: 2rem;
  41. padding: 1rem;
  42. border: 0;
  43. outline: 0;
  44. resize: none;
  45. box-sizing: border-box;
  46. }
  47. .checkbox > input {
  48. position: absolute;
  49. left: -999999px;
  50. }
  51. .checkbox > input + span {
  52. display: inline-flex;
  53. align-items: center;
  54. justify-content: center;
  55. height: 3rem;
  56. padding: 0 1rem;
  57. border: 1px solid #ccc;
  58. border-radius: 0.25rem;
  59. cursor: pointer;
  60. }
  61. .checkbox > input:checked + span {
  62. border-color: #000;
  63. background-color: #000;
  64. color: #fff;
  65. }
  66. @media (min-width: 1080px) {
  67. .main-form > div {
  68. flex-direction: row;
  69. }
  70. .main-form > div > textarea {
  71. width: 0;
  72. height: 100%;
  73. }
  74. }
  75. </style>
  76. </head>
  77. <body>
  78. <form id="mainForm" class="main-form">
  79. <fieldset>
  80. <legend>
  81. Options
  82. </legend>
  83. <div>
  84. <label class="checkbox">
  85. <input type="checkbox" name="shortenMillia">
  86. <span>Shorten millia</span>
  87. </label><label class="checkbox">
  88. <input type="checkbox" name="addTensDashes" checked>
  89. <span>Add dashes to tens</span>
  90. </label>
  91. </div>
  92. </fieldset>
  93. <div>
  94. <textarea aria-label="Number" name="number" placeholder="123"></textarea>
  95. <textarea aria-label="Name" name="name" placeholder="one hundred twenty three"></textarea>
  96. </div>
  97. </form>
  98. <script type="module">
  99. import { stringify, parse } from './numerica.js';
  100. function MainForm(el) {
  101. const numberInput = el.querySelector('[name="number"]');
  102. const nameInput = el.querySelector('[name="name"]');
  103. const addTensDashesCheckbox = el.querySelector('[name="addTensDashes"]');
  104. const shortenMilliaCheckbox = el.querySelector('[name="shortenMillia"]');
  105. const options = {
  106. stringify: {
  107. makeGroupOptions: {
  108. shortenMillia: false,
  109. addTensDashes: true,
  110. },
  111. },
  112. parse: {
  113. type: 'bigint',
  114. }
  115. };
  116. numberInput.addEventListener('input', (e) => {
  117. nameInput.value = '';
  118. if (e.currentTarget.value.trim() === '') {
  119. return;
  120. }
  121. nameInput.value = stringify(e.currentTarget.value, options.stringify);
  122. });
  123. nameInput.addEventListener('input', (e) => {
  124. numberInput.value = '';
  125. if (e.currentTarget.value.trim() === '') {
  126. return;
  127. }
  128. numberInput.value = parse(e.currentTarget.value, options.parse).toString();
  129. });
  130. addTensDashesCheckbox.addEventListener('change', (e) => {
  131. options.stringify.makeGroupOptions.addTensDashes = e.currentTarget.checked;
  132. numberInput.dispatchEvent(new Event('input'));
  133. });
  134. shortenMilliaCheckbox.addEventListener('change', (e) => {
  135. options.stringify.makeGroupOptions.shortenMillia = e.currentTarget.checked;
  136. numberInput.dispatchEvent(new Event('input'));
  137. });
  138. }
  139. const mainForm = window.document.getElementById('mainForm');
  140. new MainForm(mainForm);
  141. </script>
  142. </body>
  143. </html>