Provide the Name Initials if this is supported by the Language (Script) of the name.
This is handy if you need to build an interface where you don't have the Profile Image and can display the Initials of the user:
npm install --save intl-name-initials
var IntlNameInitials = require('intl-name-initials');
var name = { firstName: 'Juan', lastName: 'Perez'};
var intlNameInitials = new IntlNameInitials();
var nameIntials = intlNameInitials.format( name );
console.log(nameInitials);
// > JP
The function returns a string containing the Initials, if the Language of the Name does not supports Initials then it returns undefined
Name object, the structure expected is:
{
firstName: string,
lastName: string
}
At this moment no options are supported.
Example 1: Juan Pérez
var IntlNameInitials = require('intl-name-initials');
var name = { firstName: 'Juan', lastName: 'Pérez'};
var intlNameInitials = new IntlNameInitials();
var nameIntials = intlNameInitials.format( name );
//output: JP
var IntlNameInitials = require('intl-name-initials');
var name = {lastName: '홍', firstName: '길동'};
var intlNameInitials = new IntlNameInitials();
var nameIntials = intlNameInitials.format( name );
//output: 홍
Initials not supported.
var IntlNameInitials = require('intl-name-initials');
var name = { lastName: '李', firstName: '小龍'};
var intlNameInitials = new IntlNameInitials();
var nameIntials = intlNameInitials.format( name );
//output: undefined
At this moment only specific Range of Unicode Characters are supported:
- Is Arabic supported?
Name Initials for Arabic names are not a common practice. If you pass an Arabic name then format()
will return undefined
MIT © Lucas Welti