Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set.colors = set.colors.map(c => {
let heteronymIdx = c.name.indexOf('藏') > -1 ? 1 : 0;
return {
...c,
RGB: convert.hex.rgb(c.hex),
CMYK: convert.hex.cmyk(c.hex),
pinyin: pinyin(c.name, {
heteronym: true, // 启用多音字模式
segment: true // 启用分词,以解决多音字问题。
})
.map(item => {
return item.length > 1 ? item[heteronymIdx] : item;
})
.join(' ')
};
});
return set;
function toPinyin(text) {
const pyArray = pinyin(text, { style: pinyin.STYLE_NORMAL });
return $.join($.flatMap(pyArray), ' ');
}
function getPinyin(name) {
return pinyin(name, {
style: pinyin.STYLE_NORMAL
}).join('');
}
return array.sort(function(a, b) {
let x = pinyin(a[key].toLowerCase());
let y = pinyin(b[key].toLowerCase());
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
async getCityName(req){
try{
const cityInfo = await this.guessPosition(req);
/*
汉字转换成拼音
*/
const pinyinArr = pinyin(cityInfo.city, {
style: pinyin.STYLE_NORMAL,
});
let cityName = '';
pinyinArr.forEach(item => {
cityName += item[0];
})
return cityName;
}catch(err){
return '北京';
}
}
async getExactAddress(req, res, next){
return array.sort(function(a, b) {
let x = pinyin(a[key].toLowerCase());
let y = pinyin(b[key].toLowerCase());
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
});
}
toolName.forEach(name => {
toolPinyin[name] = {
first: group(
pinyin(name.replace(/\s/g, '').toLowerCase(), {
style: pinyin.STYLE_FIRST_LETTER,
heteronym: true
})
),
pinyin: group(
pinyin(name.replace(/\s/g, '').toLowerCase(), {
style: pinyin.STYLE_NORMAL,
heteronym: true
})
)
};
});