Advertisement
Guest User

Untitled

a guest
May 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. interface Entry {
  2. value: string
  3. label: string
  4. }
  5.  
  6. type Dictionary = Entry[]
  7. const dictionary: Dictionary = [
  8. { value: 'primeiro', label: '1 - Primeiro' },
  9. { value: 'segundo', label: '2 - Segundo' },
  10. { value: 'terceiro', label: '3 - Terceiro' },
  11. { value: 'quarto', label: '4 - Quarto' },
  12. { value: 'quinto', label: '5 - Quinto' },
  13. { value: 'sexto', label: '6 - Sexto' },
  14. ];
  15.  
  16.  
  17. type Data = string
  18. type DataFormated = string
  19.  
  20.  
  21. type Formatter = (_: Dictionary) => (_: Data[]) => DataFormated
  22. const formatter: Formatter = dict => data =>
  23. [[...dict]]
  24. .map( d => d
  25. .filter( e => data.join(',').includes(e.value))
  26. .map( e => e.label )
  27. .join(', ')
  28. )
  29. .map(
  30. s => s.length >= 25
  31. ? s.substring(0, 25) + '...'
  32. : s
  33. )
  34. .join('')
  35.  
  36.  
  37. const StandardFormatter = formatter(dictionary)
  38.  
  39. const r = StandardFormatter(['primeiro', 'quinto', 'sexto'])
  40.  
  41. console.log(r) // "1 - Primeiro, 5 - Quinto,..."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement