displayName.js
Make correct first name/last name combination among differerent languages
Motivation
Chinese differs from English in combining first name and last name (family name), where last name is put in front of first name in Chinese. This small utility function helps eliminating the difference by making the correct combination. It is done by using a regular expression to detect the unicode range of first name and last name. Moreover, Japanese and Korean is treated identically with Chinese as well (i.e. CJK characters).
The regular expression to detect CJK characters is generated from Unicode range RegExp generator.
Constraints
displayName.js
does not deal with middle names,
so feel free to modify the code to fit your needs.
Installation
For Node.js:
npm install display-name
For frontend:
Usage and Examples
// In node.js/AMD/CommonJSvar displayName = ; // In browservar displayName = windowdisplayName; var redComet = first: 'Char' last: 'Aznable'; redCometfull = ;// redComet.full = 'Char Aznable' var uruz7 = first: 'そうすけ' last: 'さがら'; uruz7full = ;// uruz7.full = 'さがらそうすけ' var author = familyName: '曾' name: '台綸'; authorfull = ;// author.full = '曾台綸'
Build
npm install
npm run build