uttesh / ngletteravatar

directive for the letter avatar for the given string like gmail, first letter of the given data will be the avatar .
http://uttesh.github.io/ngletteravatar/
MIT License
136 stars 36 forks source link

Additional naming cases #17

Closed akougblenou closed 8 years ago

akougblenou commented 8 years ago

Hi I think your directive is really helpful. However, I had some requirements in terms of how it would behave for example I wanted different display for different naming type:

function determineCharacterNumbers(isMultiple, avatarData, charCount){
            var words = [],
                valReturn = null;
            if(!isMultiple){
                valReturn = avatarData.substr(0, charCount).toUpperCase();
            }
            else{
                words = avatarData.split(" ");
                for (var i = 0; i < words.length; i++) {
                    if(words.length >= 2){
                        // we pop particle names "De", "Of", "The", "Van" etc...
                        if((i != 0) && ( words[i].length === 2 || words[i].length === 3)){
                            if(i != words.length - 1){
                                words.splice(i,1);
                            }
                        }
                        words[i] = words[i].substr(0,1).toUpperCase();
                    }
                };
                // we add something like ['A', 'V'] that becomes AV
                valReturn = words.join('').substr(0, charCount).toUpperCase();
            }
            return valReturn;
        }

// and in the link function
var c = determineCharacterNumbers(params.multiWord, params.data, params.charCount);

The code might not be the most efficient but it does the job, if you are okay with it I was wondering if it could be added to your directive?