You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
4.0 KiB
98 lines
4.0 KiB
/**
|
|
* 傳入姓名,返回首字,複姓返回兩個字,英文返回大寫
|
|
* @param {*} fullname
|
|
* @param {*} lang
|
|
* @returns
|
|
*/
|
|
export function getFirstName(fullname,lang) {
|
|
let hyphenated = ['欧阳', '太史', '端木', '上官', '司马', '东方', '独孤', '南宫', '万俟', '闻人',
|
|
'夏侯', '诸葛', '尉迟', '公羊', '赫连', '澹台', '皇甫', '宗政', '濮阳', '公冶',
|
|
'太叔', '申屠', '公孙', '慕容', '仲孙', '钟离', '长孙', '宇文', '城池', '司徒',
|
|
'鲜于', '司空', '汝嫣', '闾丘', '子车', '亓官', '司寇', '巫马', '公西', '颛孙',
|
|
'壤驷', '公良', '漆雕', '乐正', '宰父', '谷梁', '拓跋', '夹谷', '轩辕', '令狐',
|
|
'段干', '百里', '呼延', '东郭', '南门', '羊舌', '微生', '公户', '公玉', '公仪',
|
|
'梁丘', '公仲', '公上', '公门', '公山', '公坚', '左丘', '公伯', '西门', '公祖',
|
|
'第五', '公乘', '贯丘', '公皙', '南荣', '东里', '东宫', '仲长', '子书', '子桑',
|
|
'即墨', '达奚', '褚师'];
|
|
if(lang=='zh-TW'){
|
|
hyphenated = ['歐陽', '太史', '端木', '上官', '司馬', '東方', '獨孤', '南宮', '萬俟', '聞人',
|
|
'夏侯', '諸葛', '尉遲', '公羊', '赫連', '淡臺', '皇甫', '宗政', '濮陽', '公冶',
|
|
'太叔', '申屠', '公孫', '慕容', '仲孫', '鐘離', '長孫', '宇文', '城池', '司徒',
|
|
'鮮於', '司空', '汝嫣', '閭丘', '子車', '亓官', '司寇', '巫馬', '公西', '顓孫',
|
|
'壤駟', '公良', '漆雕', '樂正', '宰父', '谷梁', '拓跋', '夾谷', '軒轅', '令狐',
|
|
'段幹', '百裏', '呼延', '東郭', '南門', '羊舌', '微生', '公戶', '公玉', '公儀',
|
|
'梁丘', '公仲', '公上', '公門', '公山', '公堅', '左丘', '公伯', '西門', '公祖',
|
|
'第五', '公乘', '貫丘', '公皙', '南榮', '東裏', '東宮', '仲長', '子書', '子桑',
|
|
'即墨', '達奚', '褚師'];
|
|
}
|
|
if(fullname == undefined || fullname == null || fullname == ''){
|
|
return ["",true];
|
|
}
|
|
var re = /[A-Za-z]+/;
|
|
var result = fullname.search(re);
|
|
if(result>=0){
|
|
return [fullname.substr(0, 1).toUpperCase(),false];
|
|
}
|
|
let hyset = new Set(hyphenated);
|
|
let vLength = fullname.length;
|
|
// 前為姓,后為名
|
|
let lastname = '', firstname = '';
|
|
if (vLength > 2){
|
|
var preTwoWords = fullname.substr(0, 2);
|
|
// 取名字的前兩個字,看是否在複姓庫中
|
|
if (hyset.has(preTwoWords)){
|
|
firstname = preTwoWords;
|
|
// lastname = fullname.substr(2);
|
|
}else{
|
|
firstname = fullname.substr(0, 1);
|
|
// lastname = fullname.substr(1);
|
|
}
|
|
}else if (vLength === 2){
|
|
// 全名只有兩個字時,前一個為姓,後一個為名
|
|
firstname = fullname.substr(0, 1);
|
|
// lastname = fullname.substr(1);
|
|
}else{
|
|
firstname = fullname;
|
|
}
|
|
return [firstname,true];
|
|
};
|
|
|
|
/**
|
|
* 判斷日期是否在周末
|
|
* @param {*} date
|
|
* @returns
|
|
*/
|
|
export function dateIsInWeekend(date) {
|
|
var givenDate=new Date(date);
|
|
var currentDay = givenDate.getDay();
|
|
// var dateIsInWeekend = (currentDay === 6) || (currentDay === 0);
|
|
return currentDay;
|
|
}
|
|
|
|
|
|
/**
|
|
* 判斷日期是number
|
|
* @param {*} value
|
|
* @returns
|
|
*/
|
|
export function IsNumber(value) {
|
|
return !isNaN(parseFloat(value)) && isFinite(value);
|
|
}
|
|
|
|
/**
|
|
* 過濾數據
|
|
* @param {*} condition
|
|
* @param {*} data
|
|
* @returns
|
|
*/
|
|
export function filterData(condition,data){
|
|
if(data.length<0){
|
|
return [];
|
|
}
|
|
return data.filter( item => {
|
|
return Object.keys( condition ).every( key => {
|
|
return String( item[ key ] ).toLowerCase().includes(
|
|
String( condition[ key ] ).trim().toLowerCase() )
|
|
} )
|
|
} )
|
|
}
|