intl-name-initials
v0.1.1
Published
Provide Name Initials
Downloads
51
Readme
intl-name-initials
Introduction
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:
Installation
npm install --save intl-name-initials
Usage
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
API
format(name{, options})
The function returns a string containing the Initials, if the Language of the Name does not supports Initials then it returns undefined
name
Name object, the structure expected is:
{
firstName: string,
lastName: string
}
options
At this moment no options are supported.
Examples
Example 1
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
Example 2
var IntlNameInitials = require('intl-name-initials');
var name = {lastName: '홍', firstName: '길동'};
var intlNameInitials = new IntlNameInitials();
var nameIntials = intlNameInitials.format( name );
//output: 홍
Example 3
Initials not supported.
var IntlNameInitials = require('intl-name-initials');
var name = { lastName: '李', firstName: '小龍'};
var intlNameInitials = new IntlNameInitials();
var nameIntials = intlNameInitials.format( name );
//output: undefined
Language Scripts
At this moment only specific Range of Unicode Characters are supported:
FAQ
- Is Arabic supported?
Name Initials for Arabic names are not a common practice. If you pass an Arabic name then format()
will return undefined
License
MIT © Lucas Welti