Skip to content

Instantly share code, notes, and snippets.

@marshall007
Last active March 6, 2016 15:30
Show Gist options
  • Save marshall007/7274532 to your computer and use it in GitHub Desktop.
Save marshall007/7274532 to your computer and use it in GitHub Desktop.
AngularJS filter for displaying acronyms.
## Examples
#
# "Turn Around Low" | acronym -> "TAL"
# "turn_around.low" | acronym -> "TAL"
# "list_price" | acronym -> "LP"
# "name" | acronym -> "N"
# "name" | acronym:2 -> "NA"
module.filter 'acronym', ->
first = (word) -> word?[0] or ''
(input, min_length = 2) ->
words = input.split /[^A-Za-z]+/
if words.length is 1
words = words[0].slice(0, min_length).split('')
return words.map(first).join('').toUpperCase()
## or use underscore.js
# return words.map(_.first).join('').toUpperCase()
@tucq88
Copy link

tucq88 commented Mar 6, 2016

Doesn't work on me, could you provide a JS version of it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment