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.

35 line
712 B

  1. import getHundredName from './getHundredName'
  2. import NAMES from './names.json'
  3. import getBaseHundredUnit from './getBaseHundredUnit'
  4. interface GetThousandName {
  5. (hundreds: number, tens: number, ones: number): string,
  6. }
  7. const getThousandName: GetThousandName = (hundreds, tens, ones) => {
  8. if (hundreds === 0) {
  9. return getHundredName(tens, ones)
  10. }
  11. if (tens === 0 && ones === 0) {
  12. return getBaseHundredUnit(hundreds)
  13. }
  14. if (tens === 0) {
  15. return [
  16. getBaseHundredUnit(hundreds),
  17. NAMES.and,
  18. NAMES.base.units[ones],
  19. ]
  20. .join(' ')
  21. }
  22. return [
  23. getBaseHundredUnit(hundreds),
  24. getHundredName(tens, ones),
  25. ]
  26. .join(' ')
  27. }
  28. export default getThousandName