Get the name of a number, even if it's stupidly big.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

31 rivejä
627 B

  1. import NAMES from './names.json'
  2. interface GetBaseTenUnit {
  3. (tens: number): string
  4. }
  5. const getBaseTenUnit: GetBaseTenUnit = (tens) => {
  6. let tenUnit = NAMES.base.units[tens]
  7. const tenSuffix = NAMES.ten
  8. const unitLastCharacter = tenUnit.slice(-1)
  9. switch (unitLastCharacter) {
  10. case 't':
  11. case 'm':
  12. return tenUnit + 'na' + tenSuffix
  13. case 'o':
  14. tenUnit = tenUnit.slice(0, -1) + 'u'
  15. break
  16. case 'a':
  17. if (tenUnit.startsWith('i')) {
  18. tenUnit = tenUnit.slice(1)
  19. }
  20. break
  21. default:
  22. break
  23. }
  24. return tenUnit + 'm' + tenSuffix
  25. }
  26. export default getBaseTenUnit