Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

number-to-word

v0.86.0arrow_drop_down
v0.86.0
v0.85.0
v0.84.0
STATUS
Passing
DOWNLOADS
19,877
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
9 months ago
SIZE
678 B
Return the number word for numbers 1-16
1 contributor
Use number-to-word in your project ?
Copied
npm i @bit/semantic-org.semantic-ui-react.utils.number-to-word
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Files
numberToWord.js
34 Lines(25 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export const numberToWordMap = {
  1: 'one',
  2: 'two',
  3: 'three',
  4: 'four',
  5: 'five',
  6: 'six',
  7: 'seven',
  8: 'eight',
  9: 'nine',
  10: 'ten',
  11: 'eleven',
  12: 'twelve',
  13: 'thirteen',
  14: 'fourteen',
  15: 'fifteen',
  16: 'sixteen',
}

/**
 * Return the number word for numbers 1-16.
 * Returns strings or numbers as is if there is no corresponding word.
 * Returns an empty string if value is not a string or number.
 * @param {string|number} value The value to convert to a word.
 * @returns {string}
 */
export function numberToWord(value) {
  const type = typeof value
  if (type === 'string' || type === 'number') {
    return numberToWordMap[value] || value
  }

  return ''
}