Gets the name of a number, even if it's stupidly big. Supersedes TheoryOfNekomata/number-name.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.html 3.5 KiB

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