display-name

0.1.0 • Public • Published

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:

<script type="text/javascript" src="displayName.min.js"></script>

Usage and Examples

 
// In node.js/AMD/CommonJS
var displayName = require('display-name');
 
// In browser
var displayName = window.displayName;
 
var redComet = {
    first: 'Char',
    last: 'Aznable'
};
 
redComet.full = displayName(redComet.first, redComet.last);
// redComet.full = 'Char Aznable'
 
var uruz7 = {
    first: 'そうすけ',
    last: 'さがら'
};
 
uruz7.full = displayName(uruz7.first, uruz7.last);
// uruz7.full = 'さがらそうすけ'
 
var author = {
    familyName: '',
    name: '台綸'
};
 
author.full = displayName(author.name, author.familyName);
// author.full = '曾台綸'
 

Build

npm install
npm run build

License

MIT License

Readme

Keywords

none

Package Sidebar

Install

npm i display-name

Weekly Downloads

724

Version

0.1.0

License

MIT

Last publish

Collaborators

  • teaualune