Last active
March 6, 2016 15:30
-
-
Save marshall007/7274532 to your computer and use it in GitHub Desktop.
AngularJS filter for displaying acronyms.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work on me, could you provide a JS version of it ?