Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface Entry {
- value: string
- label: string
- }
- type Dictionary = Entry[]
- const dictionary: Dictionary = [
- { value: 'primeiro', label: '1 - Primeiro' },
- { value: 'segundo', label: '2 - Segundo' },
- { value: 'terceiro', label: '3 - Terceiro' },
- { value: 'quarto', label: '4 - Quarto' },
- { value: 'quinto', label: '5 - Quinto' },
- { value: 'sexto', label: '6 - Sexto' },
- ];
- type Data = string
- type DataFormated = string
- type Formatter = (_: Dictionary) => (_: Data[]) => DataFormated
- const formatter: Formatter = dict => data =>
- [[...dict]]
- .map( d => d
- .filter( e => data.join(',').includes(e.value))
- .map( e => e.label )
- .join(', ')
- )
- .map(
- s => s.length >= 25
- ? s.substring(0, 25) + '...'
- : s
- )
- .join('')
- const StandardFormatter = formatter(dictionary)
- const r = StandardFormatter(['primeiro', 'quinto', 'sexto'])
- console.log(r) // "1 - Primeiro, 5 - Quinto,..."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement